Changeset ad24705


Ignore:
Timestamp:
Mar 29, 2011 8:23:59 PM (8 years ago)
Author:
Ted Faber <faber@…>
Branches:
abac0-leak, abac0-mei, compt_changes, gec13, master, mei-id, mei-rt0-n, mei_rt0, mei_rt2, mei_rt2_fix_1, meiyap-rt1, meiyap1, rt2, tvf-new-xml
Children:
20d3d3c
Parents:
dc9ae96
Message:

Support simple rt0 format

Location:
java
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • java/GraphTest.java

    r6432e35 rad24705  
    3939                else if (f.getPath().endsWith(".zip"))
    4040                    ctxt.load_zip_file(f, errs);
     41                else if (f.getPath().endsWith(".rt0"))
     42                    ctxt.load_rt0_file(f, errs);
    4143                else
    4244                    System.out.println(f + " of unknown type");
     
    6264        String suf = ".der";
    6365        System.out.println("Result: " + ret.getSuccess());
     66        System.out.println("Proof");
    6467        for (Credential c : ret.getCredentials()) {
    6568            System.out.println(c.simpleString(ctxt));
     
    7376        n = 0;
    7477        suf = ".pem";
     78        System.out.println("Identities");
    7579        for (Identity i: ids) {
    7680            System.out.println("ID: " + i);
    7781            i.write(fn + n++ + suf);
    7882        }
    79         ctxt.write_zip_file(new File("./testout.zip"), true, true);
     83        try {
     84            ctxt.write_zip_file(new File("./testout.zip"), true, true);
     85        }
     86        catch (IOException ioe) {
     87            System.err.println("Could not write ZIP: " + ioe);
     88        }
     89        System.out.println("rt0 with keyids");
     90        ctxt.write_rt0(new OutputStreamWriter(System.out), true);
    8091    }
    8192}
  • java/net/deterlab/abac/Context.java

    r238717d rad24705  
    66import java.io.*;
    77import java.util.*;
     8import java.util.regex.*;
    89import java.util.zip.*;
    910import java.security.*;
     
    275276        Collection<Credential> creds = new HashSet<Credential>();
    276277
    277         // only return creds with a cert: all others are derived edges
     278        // only non-derived edges
    278279        for (Credential cred : g.getEdges())
    279             if (cred.cert() != null)
     280            if (!derived_edges.contains(cred))
    280281                creds.add(cred);
    281282
     
    812813
    813814    /**
     815     * Load from a simple rt0 text format.  A jabac extension.  The format is
     816     * <br/>
     817     * # comments<br/>
     818     * role &lt;- role<br/>
     819     * <br/>
     820     *
     821     * Spaces are not significant around the arrow and the tail can be as long
     822     * as needed.
     823     * @param f the File to load
     824     * @param errors a Map of lines to errors
     825     * @throws IOException if there is an error getting the file open
     826     */
     827    public void load_rt0_file(File f, Map<String, Exception> errors)
     828            throws IOException {
     829        Pattern comment = Pattern.compile("(^\\s*#|^\\s*$)");
     830        Pattern rule = Pattern.compile("([\\w\\.]+)\\s*<-+\\s*([\\w\\.\\&]+)");
     831        LineNumberReader r = new LineNumberReader(new FileReader(f));
     832        String line = null;
     833
     834        while ((line = r.readLine()) != null) {
     835            Matcher cm = comment.matcher(line);
     836            Matcher rm = rule.matcher(line);
     837
     838            if (cm.find()) continue;
     839            if (rm.find())
     840                add_credential(new Credential(new Role(rm.group(1)),
     841                            new Role(rm.group(2))));
     842            else if (errors != null)
     843                errors.put("Line " + r.getLineNumber(),
     844                        new RuntimeException("Unexpected format"));
     845        }
     846    }
     847
     848    /**
     849     * Equivalent to load_rt0_file(d, null).
     850     * @param f the File to load
     851     * @throws IOException if there is an error getting the file open
     852     */
     853    public void load_rt0_file(File f) throws IOException {
     854        load_rt0_file(f, null);
     855    }
     856       
     857
     858    /**
    814859     * Write the certificates that make up the context as a zip file, with an
    815860     * entry for each credential or identity.  The files are all zipped in a
     
    853898
    854899    /**
     900     * Write to a simple rt0 text format.  A jabac extension.
     901     * The format is
     902     * <br/>
     903     * role &lt;- role<br/>
     904     * <br/>
     905     *
     906     * @param w a Writer to print on
     907     * @param useKeyIDs a boolean, true to print key IDs not mnemonics
     908     */
     909    public void write_rt0(Writer w, boolean useKeyIDs) {
     910        PrintWriter pw = w instanceof PrintWriter ?
     911            (PrintWriter) w : new PrintWriter(w);
     912
     913        for (Credential c: credentials())
     914            pw.println(useKeyIDs ? c.toString() : c.simpleString(this));
     915        pw.flush();
     916    }
     917
     918    /**
     919     * Call write_rt0 on a FileWriter derived from f.
     920     * @param f the File to write to
     921     * @param useKeyIDs a boolean, true to print key IDs not mnemonics
     922     * @throws IOException if there is a problem writing the file.
     923     */
     924    public void write_rt0(File f, boolean useKeyIDs) throws IOException {
     925        write_rt0(new FileWriter(f), useKeyIDs);
     926    }
     927
     928    /**
     929     * Equivalent to write_rt0(w, false);
     930     * @param w a Writer to print on
     931     */
     932    public void write_rt0(Writer w) { write_rt0(w, false); }
     933
     934    /**
     935     * Equivalent to write_rt0(f, false);
     936     * @param f the File to write to
     937     * @throws IOException if there is a problem writing the file.
     938     */
     939    public void write_rt0(File f) throws IOException {
     940        write_rt0(new FileWriter(f), false);
     941    }
     942
     943    /**
    855944     * Get to the SHA1 hash of the key.  Used by Roles and Identities to get a
    856945     * key ID.
Note: See TracChangeset for help on using the changeset viewer.