Changeset 3a52bed


Ignore:
Timestamp:
Mar 16, 2011 10:05:34 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:
f63aa1b
Parents:
88e139a
Message:

Allow IDs to generate new certs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • java/net/deterlab/abac/Identity.java

    r5cf72cc r3a52bed  
    66import java.security.*;
    77import java.security.cert.*;
     8import javax.security.auth.x500.*;
    89
     10import java.math.BigInteger;
    911
    1012import org.bouncycastle.asn1.*;
     
    5759
    5860    /**
    59      * Construct from a string, which is a filename, containing a PEM format
    60      * self signed certificate.
     61     * Construct from a string, used as a CN
    6162     */
    62     public Identity(String filename) throws
    63         CertificateException, NoSuchAlgorithmException,InvalidKeyException,
    64         NoSuchProviderException, SignatureException, FileNotFoundException,
    65         IOException { init(new FileReader(filename)); }
     63    public Identity(String cn) throws
     64            CertificateException, NoSuchAlgorithmException,InvalidKeyException,
     65            NoSuchProviderException, SignatureException, IOException {
     66        KeyPair kp = KeyPairGenerator.getInstance("RSA").genKeyPair();
     67        X509V1CertificateGenerator gen = new X509V1CertificateGenerator();
     68
     69        gen.setIssuerDN(new X500Principal("CN=" + cn));
     70        gen.setSubjectDN(new X500Principal("CN=" + cn));
     71        gen.setNotAfter(new Date(System.currentTimeMillis()
     72                    + 3600 * 1000 * 24 * 365));
     73        gen.setNotBefore(new Date(System.currentTimeMillis()));
     74        gen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
     75        gen.setPublicKey(kp.getPublic());
     76        gen.setSignatureAlgorithm("SHA256WithRSAEncryption");
     77        X509CertificateObject a = (X509CertificateObject) gen.generate(kp.getPrivate());
     78        init(a);
     79    }
     80
    6681
    6782
Note: See TracChangeset for help on using the changeset viewer.