Search in sources :

Example 41 with Sequence

use of com.google.showcase.v1beta1.Sequence in project libSBOLj by SynBioDex.

the class SequenceOutput method main.

public static void main(String[] args) throws Exception {
    String prURI = "http://partsregistry.org/";
    SBOLDocument document = new SBOLDocument();
    document.setDefaultURIprefix(prURI);
    document.setTypesInURIs(true);
    Sequence seq = document.createSequence("BBa_J23119", "", "ttgacagctagctcagtcctaggtataatgctagc", URI.create("http://www.chem.qmul.ac.uk/iubmb/misc/naseq.html"));
    seq.addWasDerivedFrom(URI.create("http://parts.igem.org/Part:BBa_J23119:Design"));
    SBOLWriter.write(document, (System.out));
}
Also used : SBOLDocument(org.sbolstandard.core2.SBOLDocument) Sequence(org.sbolstandard.core2.Sequence)

Example 42 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class CRLDistributionPoint method main.

public static void main(String[] args) throws GeneralNamesException, IOException, InvalidBERException {
    try (FileOutputStream fos = new FileOutputStream(args[0]);
        ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        if (args.length != 1) {
            System.out.println("Usage: CRLDistributionPoint <outfile>");
            System.exit(-1);
        }
        SEQUENCE cdps = new SEQUENCE();
        // URI only
        CRLDistributionPoint cdp = new CRLDistributionPoint();
        URIName uri = new URIName("http://www.mycrl.com/go/here");
        GeneralNames generalNames = new GeneralNames();
        generalNames.addElement(uri);
        cdp.setFullName(generalNames);
        cdps.addElement(cdp);
        // DN only
        cdp = new CRLDistributionPoint();
        X500Name dn = new X500Name("CN=Otis Smith,E=otis@fedoraproject.org" + ",OU=Certificate Server,O=Fedora,C=US");
        generalNames = new GeneralNames();
        generalNames.addElement(dn);
        cdp.setFullName(generalNames);
        cdps.addElement(cdp);
        // DN + reason
        BitArray ba = new BitArray(5, new byte[] { (byte) 0x28 });
        cdp = new CRLDistributionPoint();
        cdp.setFullName(generalNames);
        cdp.setReasons(ba);
        cdps.addElement(cdp);
        // relative DN + reason + crlIssuer
        cdp = new CRLDistributionPoint();
        RDN rdn = new RDN("OU=foobar dept");
        cdp.setRelativeName(rdn);
        cdp.setReasons(ba);
        cdp.setCRLIssuer(generalNames);
        cdps.addElement(cdp);
        cdps.encode(bos);
        byte[] encoded = bos.toByteArray();
        fos.write(encoded);
        SEQUENCE.OF_Template seqt = new SEQUENCE.OF_Template(getTemplate());
        cdps = (SEQUENCE) ASN1Util.decode(seqt, encoded);
        int size = cdps.size();
        System.out.println("Total number of CDPs: " + size);
        for (int i = 0; i < size; i++) {
            System.out.println("\nCDP " + i);
            cdp = (CRLDistributionPoint) cdps.elementAt(i);
            GeneralNames gn = cdp.getFullName();
            if (gn == null) {
                System.out.println("No full name");
            } else {
                System.out.println(gn);
            }
            rdn = cdp.getRelativeName();
            if (rdn == null) {
                System.out.println("No relative name");
            } else {
                System.out.println(rdn);
            }
            if (cdp.getReasons() == null) {
                System.out.println("No reasons");
            } else {
                System.out.println(cdp.getReasons());
            }
            gn = cdp.getCRLIssuer();
            if (gn == null) {
                System.out.println("No cRLIssuer");
            } else {
                System.out.println(gn);
            }
        }
        System.out.println("Done");
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) BitArray(org.mozilla.jss.netscape.security.util.BitArray)

Example 43 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class CRLDistributionPoint method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    DerOutputStream derOut;
    try {
        // is a CHOICE, the [0] tag is forced to be EXPLICIT.
        if (fullName != null) {
            EXPLICIT distPoint = new EXPLICIT(Tag.get(0), fullNameEncoding);
            seq.addElement(distPoint);
        } else if (relativeName != null) {
            derOut = new DerOutputStream();
            relativeName.encode(derOut);
            ANY rn = new ANY(derOut.toByteArray());
            EXPLICIT raw = new EXPLICIT(Tag.get(1), rn);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            raw.encode(bos);
            ANY distPointName = new ANY(bos.toByteArray());
            EXPLICIT distPoint = new EXPLICIT(Tag.get(0), distPointName);
            seq.addElement(distPoint);
        }
        // Encodes the ReasonFlags.
        if (reasons != null) {
            derOut = new DerOutputStream();
            derOut.putUnalignedBitString(reasons);
            ANY raw = new ANY(derOut.toByteArray());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            raw.encodeWithAlternateTag(Tag.get(1), bos);
            ANY reasonEncoding = new ANY(bos.toByteArray());
            seq.addElement(Tag.get(1), reasonEncoding);
        }
        // Encodes the CRLIssuer
        if (CRLIssuer != null) {
            seq.addElement(Tag.get(2), CRLIssuerEncoding);
        }
        seq.encode(implicitTag, ostream);
    } catch (InvalidBERException e) {
        // the Sun encoding classes
        throw new IOException(e.toString());
    }
}
Also used : InvalidBERException(org.mozilla.jss.asn1.InvalidBERException) DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ANY(org.mozilla.jss.asn1.ANY) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT)

Example 44 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class PKCS12Util method getCertInfos.

public void getCertInfos(PKCS12 pkcs12, PFX pfx, Password password) throws Exception {
    logger.debug("Loading certificates:");
    AuthenticatedSafes safes = pfx.getAuthSafes();
    for (int i = 0; i < safes.getSize(); i++) {
        SEQUENCE contents = safes.getSafeContentsAt(password, i);
        for (int j = 0; j < contents.size(); j++) {
            SafeBag bag = (SafeBag) contents.elementAt(j);
            OBJECT_IDENTIFIER oid = bag.getBagType();
            if (!oid.equals(SafeBag.CERT_BAG))
                continue;
            logger.debug(" - Certificate:");
            PKCS12CertInfo certInfo = getCertInfo(bag);
            pkcs12.addCertInfo(certInfo, true);
        }
    }
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) OBJECT_IDENTIFIER(org.mozilla.jss.asn1.OBJECT_IDENTIFIER) SafeBag(org.mozilla.jss.pkcs12.SafeBag) AuthenticatedSafes(org.mozilla.jss.pkcs12.AuthenticatedSafes)

Example 45 with Sequence

use of com.google.showcase.v1beta1.Sequence in project jss by dogtagpki.

the class PKCS12Util method generatePFX.

public PFX generatePFX(PKCS12 pkcs12, Password password) throws Exception {
    logger.info("Generating PKCS #12 data");
    AuthenticatedSafes authSafes = new AuthenticatedSafes();
    Collection<PKCS12KeyInfo> keyInfos = pkcs12.getKeyInfos();
    Collection<PKCS12CertInfo> certInfos = pkcs12.getCertInfos();
    if (!keyInfos.isEmpty()) {
        SEQUENCE keySafeContents = new SEQUENCE();
        for (PKCS12KeyInfo keyInfo : keyInfos) {
            addKeyBag(keyInfo, password, keySafeContents);
        }
        authSafes.addSafeContents(keySafeContents);
    }
    if (!certInfos.isEmpty()) {
        SEQUENCE certSafeContents = new SEQUENCE();
        for (PKCS12CertInfo certInfo : certInfos) {
            addCertBag(certInfo, certSafeContents);
        }
        if (certEncryption == null) {
            authSafes.addSafeContents(certSafeContents);
        } else if (certEncryption == PBEAlgorithm.PBE_SHA1_RC2_40_CBC) {
            byte[] salt = new byte[16];
            random.nextBytes(salt);
            authSafes.addEncryptedSafeContents(certEncryption, password, salt, // iterations
            100000, certSafeContents);
        } else {
            throw new Exception("Unsupported certificate encryption: " + certEncryption);
        }
    }
    PFX pfx = new PFX(authSafes);
    // Use the same salt size and number of iterations as in pk12util.
    byte[] salt = new byte[16];
    random.nextBytes(salt);
    pfx.computeMacData(password, salt, 100000);
    return pfx;
}
Also used : PFX(org.mozilla.jss.pkcs12.PFX) SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) NoSuchItemOnTokenException(org.mozilla.jss.crypto.NoSuchItemOnTokenException) ObjectNotFoundException(org.mozilla.jss.crypto.ObjectNotFoundException) CertificateException(java.security.cert.CertificateException) InvalidNameException(javax.naming.InvalidNameException) AuthenticatedSafes(org.mozilla.jss.pkcs12.AuthenticatedSafes)

Aggregations

SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)50 OCTET_STRING (org.mozilla.jss.asn1.OCTET_STRING)16 Sequence (org.sbolstandard.core2.Sequence)11 SET (org.mozilla.jss.asn1.SET)9 ANY (org.mozilla.jss.asn1.ANY)8 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)8 OBJECT_IDENTIFIER (org.mozilla.jss.asn1.OBJECT_IDENTIFIER)8 URI (java.net.URI)7 BMPString (org.mozilla.jss.asn1.BMPString)7 CryptoToken (org.mozilla.jss.crypto.CryptoToken)7 ASN1Value (org.mozilla.jss.asn1.ASN1Value)6 INTEGER (org.mozilla.jss.asn1.INTEGER)6 AuthenticatedSafes (org.mozilla.jss.pkcs12.AuthenticatedSafes)6 FileOutputStream (java.io.FileOutputStream)5 IOException (java.io.IOException)5 SignatureException (java.security.SignatureException)5 EXPLICIT (org.mozilla.jss.asn1.EXPLICIT)5 SafeBag (org.mozilla.jss.pkcs12.SafeBag)5 Certificate (org.mozilla.jss.pkix.cert.Certificate)5 ComponentDefinition (org.sbolstandard.core2.ComponentDefinition)5