Search in sources :

Example 1 with EXPLICIT

use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.

the class CertTemplate method encode.

@Override
public void encode(Tag t, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    seq.addElement(Tag.get(0), version);
    seq.addElement(Tag.get(1), serialNumber);
    seq.addElement(Tag.get(2), signingAlg);
    if (issuer != null) {
        // issuer is a CHOICE, so it must be EXPLICITly tagged
        seq.addElement(new EXPLICIT(Tag.get(3), issuer));
    }
    if (notBefore != null || notAfter != null) {
        SEQUENCE optionalVal = new SEQUENCE();
        // notBefore & notAfter are CHOICES, so must be EXPLICITly tagged
        if (notBefore != null) {
            optionalVal.addElement(new EXPLICIT(Tag.get(0), dateToASN1(notBefore)));
        }
        if (notAfter != null) {
            optionalVal.addElement(new EXPLICIT(Tag.get(1), dateToASN1(notAfter)));
        }
        seq.addElement(Tag.get(4), optionalVal);
    }
    if (subject != null) {
        // subject is a CHOICE, so it must be EXPLICITly tagged
        seq.addElement(new EXPLICIT(Tag.get(5), subject));
    }
    seq.addElement(Tag.get(6), publicKey);
    seq.addElement(Tag.get(7), issuerUID);
    seq.addElement(Tag.get(8), subjectUID);
    seq.addElement(Tag.get(9), extensions);
    seq.encode(t, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT)

Example 2 with EXPLICIT

use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.

the class CertificateInfo method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    if (version != v1) {
        // v1 is the default
        seq.addElement(new EXPLICIT(new Tag(0), new INTEGER(version.getNumber())));
    }
    seq.addElement(serialNumber);
    seq.addElement(signatureAlgId);
    seq.addElement(issuer);
    SEQUENCE validity = new SEQUENCE();
    validity.addElement(encodeValidityDate(notBefore));
    validity.addElement(encodeValidityDate(notAfter));
    seq.addElement(validity);
    seq.addElement(subject);
    seq.addElement(subjectPublicKeyInfo);
    if (issuerUniqueIdentifier != null) {
        seq.addElement(new Tag(1), issuerUniqueIdentifier);
    }
    if (subjectUniqueIdentifier != null) {
        seq.addElement(new Tag(2), subjectUniqueIdentifier);
    }
    if (extensions.size() > 0) {
        seq.addElement(new EXPLICIT(new Tag(3), extensions));
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT) INTEGER(org.mozilla.jss.asn1.INTEGER)

Example 3 with EXPLICIT

use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.

the class SafeBag method encode.

@Override
public void encode(Tag implicitTag, OutputStream ostream) throws IOException {
    SEQUENCE seq = new SEQUENCE();
    seq.addElement(bagType);
    seq.addElement(new EXPLICIT(new Tag(0), bagContent));
    if (bagAttributes != null) {
        seq.addElement(bagAttributes);
    }
    seq.encode(implicitTag, ostream);
}
Also used : SEQUENCE(org.mozilla.jss.asn1.SEQUENCE) Tag(org.mozilla.jss.asn1.Tag) EXPLICIT(org.mozilla.jss.asn1.EXPLICIT)

Example 4 with EXPLICIT

use of org.mozilla.jss.asn1.EXPLICIT 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 5 with EXPLICIT

use of org.mozilla.jss.asn1.EXPLICIT in project jss by dogtagpki.

the class IssuingDistributionPoint 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 raw = new ANY(derOut.toByteArray());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            raw.encodeWithAlternateTag(Tag.get(1), bos);
            ANY distPointName = new ANY(bos.toByteArray());
            EXPLICIT distPoint = new EXPLICIT(Tag.get(0), distPointName);
            seq.addElement(distPoint);
        }
        if (onlyContainsUserCerts != false) {
            seq.addElement(Tag.get(1), new BOOLEAN(true));
        }
        if (onlyContainsCACerts != false) {
            seq.addElement(Tag.get(2), new BOOLEAN(true));
        }
        // Encodes the ReasonFlags.
        if (onlySomeReasons != null) {
            derOut = new DerOutputStream();
            derOut.putUnalignedBitString(onlySomeReasons);
            ANY raw = new ANY(derOut.toByteArray());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            raw.encodeWithAlternateTag(Tag.get(3), bos);
            ANY reasonEncoding = new ANY(bos.toByteArray());
            seq.addElement(reasonEncoding);
        }
        if (indirectCRL != false) {
            seq.addElement(Tag.get(4), new BOOLEAN(true));
        }
        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) BOOLEAN(org.mozilla.jss.asn1.BOOLEAN)

Aggregations

EXPLICIT (org.mozilla.jss.asn1.EXPLICIT)7 SEQUENCE (org.mozilla.jss.asn1.SEQUENCE)5 Tag (org.mozilla.jss.asn1.Tag)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 ANY (org.mozilla.jss.asn1.ANY)2 BOOLEAN (org.mozilla.jss.asn1.BOOLEAN)2 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)2 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)2 INTEGER (org.mozilla.jss.asn1.INTEGER)1 NULL (org.mozilla.jss.asn1.NULL)1