Changeset 1a7e6d3


Ignore:
Timestamp:
Mar 11, 2011 11:13:43 AM (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:
51c5b54
Parents:
2750153
Message:

Write IDs and creds (better reading too)

Location:
java
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • java/GraphTest.java

    r9725efb r1a7e6d3  
    137137        Query q = graph.querier();
    138138        Graph<Role, Credential> ret = q.run(role, prin);
    139         for (Credential c : ret.getEdges())
     139        String fn = "attr";
     140        int n = 0;
     141        String suf = ".der";
     142        for (Credential c : ret.getEdges()) {
    140143            System.out.println(replace(c.toString(), keys));
     144            c.write(fn + n++ + suf);
     145        }
    141146
    142         for (Identity i: Credential.identities())
     147        fn = "id";
     148        n = 0;
     149        suf = ".pem";
     150        for (Identity i: Credential.identities()) {
    143151            System.out.println("ID: " + i);
     152            i.write(fn + n++ + suf);
     153        }
    144154    }
    145155}
  • java/build.xml

    r2750153 r1a7e6d3  
    99  <target name="clean">
    1010    <delete dir="${build.dir}"/>
     11    <delete>
     12      <fileset dir="${basedir}" includes="**/*.der"/>
     13      <fileset dir="${basedir}" includes="**/*.pem"/>
     14    </delete>
    1115  </target>
    1216
     
    2327  </target>
    2428
    25     <target name="jar" depends="compile" description="Make a jar">
    26       <mkdir dir="${jar.dir}"/>
    27       <jar destfile="${jar.dir}/abac.jar" basedir="${classes.dir}"
    28         excludes="**/GraphTest.class">
    29         <manifest>
    30             <attribute name="Class-Path" value="${classpath}" />
    31         </manifest>
    32         </jar>
    33     </target>
     29  <target name="jar" depends="compile" description="Make a jar">
     30    <mkdir dir="${jar.dir}"/>
     31    <jar destfile="${jar.dir}/abac.jar" basedir="${classes.dir}"
     32      excludes="**/GraphTest.class">
     33      <manifest>
     34        <attribute name="Class-Path" value="${classpath}" />
     35      </manifest>
     36    </jar>
     37  </target>
     38
     39  <target name="run" depends="compile" description="run visualizer">
     40    <!-- ant doesn't seem to understand symlinks right.  If you don't delete
     41    <symlink action="delete" link="${classes.dir}/resources"/>
     42    <symlink link="${classes.dir}/resources" resource="${basedir}/resources/"/>
     43         this before you create it, you wind up with extras. -->
     44    <java classname="${main.class}" fork="true" >
     45      <classpath>
     46        <path refid="compile.classpath"/>
     47        <pathelement path="${classes.dir}"/>
     48      </classpath>
     49      <arg file="../examples/acme_rockets"/>
     50      <arg value="Acme.buy_rockets"/>
     51      <arg value="Coyote"/>
     52    </java>
     53  </target>
    3454</project>
  • java/net/deterlab/abac/Credential.java

    r9725efb r1a7e6d3  
    3030     * Do the credential initialization from a filename.
    3131     */
    32     protected void init(String filename) throws Exception {
    33         FileInputStream fis = new FileInputStream(filename);
     32    protected void init(InputStream stream) throws Exception {
    3433        X509AttrCertParser parser = new X509AttrCertParser();
    35         parser.engineInit(fis);
     34        parser.engineInit(stream);
    3635        m_ac = (X509V2AttributeCertificate)parser.engineRead();
    3736        m_id = null;
     
    5554     */
    5655    public Credential(String filename) throws Exception {
    57         init(filename);
     56        init(new FileInputStream(filename));
    5857    }
    5958
     
    6362     */
    6463    public Credential(File file) throws Exception {
    65         init(file.getPath());
     64        init(new FileInputStream(file));
     65    }
     66
     67    /**
     68     * Create a credential from an InputStream.
     69     */
     70    public Credential(InputStream s) throws Exception {
     71        init(s);
    6672    }
    6773
     
    123129    }
    124130
     131    public void write(OutputStream s) throws IOException {
     132        s.write(m_ac.getEncoded());
     133    }
     134
     135    public void write(String fn) throws IOException, FileNotFoundException {
     136        write(new FileOutputStream(fn));
     137    }
     138
     139
    125140    private Role m_head, m_tail;
    126141
  • java/net/deterlab/abac/Identity.java

    r9725efb r1a7e6d3  
    1515import org.bouncycastle.jce.provider.X509CertificateObject;
    1616import org.bouncycastle.openssl.PEMReader;
     17import org.bouncycastle.openssl.PEMWriter;
    1718
    1819public class Identity {
     
    2122    private String m_cn;
    2223
    23     public void init(String filename) throws
     24    /**
     25     *  Initialize internals from PEM cert in a reader.  Use a PEMReader to get
     26     *  the certificate, confirm it is self signed,  and then the keyid and
     27     *  common name.  There's some work to get this stuff, but it's all an
     28     *  incantation of getting the right classes to get the right data.  Looks
     29     *  more complex than it is.
     30     */
     31    public void init(Reader r) throws
    2432        CertificateException, NoSuchAlgorithmException,InvalidKeyException,
    25         NoSuchProviderException, SignatureException, FileNotFoundException,
    26         IOException {
    27             PEMReader pr = new PEMReader(new FileReader(filename));
     33        NoSuchProviderException, SignatureException, IOException {
     34            PEMReader pr = new PEMReader(r);
    2835            Object c = pr.readObject();
    2936
     
    5663    }
    5764
     65    /**
     66     * Construct from a string, which is a filename, containing a PEM format
     67     * self signed certificate.
     68     */
    5869    public Identity(String filename) throws
    5970        CertificateException, NoSuchAlgorithmException,InvalidKeyException,
    6071        NoSuchProviderException, SignatureException, FileNotFoundException,
    61         IOException { init(filename); }
     72        IOException { init(new FileReader(filename)); }
    6273
    6374
     75    /**
     76     * Construct from a file, containing a self-signed PEM certificate.
     77     */
    6478    public Identity(File file) throws
    6579        CertificateException, NoSuchAlgorithmException,InvalidKeyException,
    6680        NoSuchProviderException, SignatureException, FileNotFoundException,
    67         IOException { init(file.getPath()); }
     81        IOException { init(new FileReader(file)); }
    6882
     83    /**
     84     * Construct from a reader, containing a self-signed PEM certificate.
     85     */
     86    public Identity(Reader r) throws
     87        CertificateException, NoSuchAlgorithmException,InvalidKeyException,
     88        NoSuchProviderException, SignatureException, IOException { init(r); }
     89
     90    /**
     91     * Construct from an InputStream, containing a self-signed PEM certificate.
     92     */
     93    public Identity(InputStream s) throws
     94        CertificateException, NoSuchAlgorithmException,InvalidKeyException,
     95        NoSuchProviderException, SignatureException, IOException {
     96            init(new InputStreamReader(s));
     97        }
     98
     99
     100    /**
     101     * Write the PEM cert to the given writer.
     102     */
     103    public void write(Writer w) throws IOException {
     104        PEMWriter pw = new PEMWriter(w);
     105
     106        pw.writeObject(m_cert);
     107        pw.close();
     108    }
     109
     110    /**
     111     * Write the PEM cert to a file with the given name.
     112     */
     113    public void write(String fn) throws IOException, FileNotFoundException {
     114        write(new FileWriter(fn));
     115    }
     116
     117    /**
     118     * Write the PEM cert to the given file.
     119     */
     120    public void write(File fn) throws IOException, FileNotFoundException {
     121        write(new FileWriter(fn));
     122    }
     123
     124    /**
     125     * Write the PEM cert to the given OutputStream.
     126     */
     127    public void write(OutputStream s)
     128        throws IOException, FileNotFoundException {
     129        write(new OutputStreamWriter(s));
     130    }
     131
     132    // Accessors
    69133    public String getKeyID() { return m_keyid; }
    70134    public String getName() { return m_cn; }
    71135    public String toString() { return m_keyid + " (" + m_cn + ")"; }
    72136    public X509CertificateObject getCertificate() { return m_cert; }
     137
    73138};
Note: See TracChangeset for help on using the changeset viewer.