Search in sources :

Example 91 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class SignerInfo method derEncode.

/**
 * DER encode this object onto an output stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out
 *            the output stream on which to write the DER encoding.
 *
 * @exception IOException on encoding error.
 */
@Override
public void derEncode(OutputStream out) throws IOException {
    try (DerOutputStream tmp = new DerOutputStream()) {
        DerOutputStream seq = new DerOutputStream();
        seq.putInteger(version);
        DerOutputStream issuerAndSerialNumber = new DerOutputStream();
        issuerName.encode(issuerAndSerialNumber);
        issuerAndSerialNumber.putInteger(certificateSerialNumber);
        seq.write(DerValue.tag_Sequence, issuerAndSerialNumber);
        digestAlgorithmId.encode(seq);
        // encode authenticated attributes if there are any
        if (authenticatedAttributes != null)
            authenticatedAttributes.encode((byte) 0xA0, seq);
        digestEncryptionAlgorithmId.encode(seq);
        seq.putOctetString(encryptedDigest);
        // encode unauthenticated attributes if there are any
        if (unauthenticatedAttributes != null)
            unauthenticatedAttributes.encode((byte) 0xA1, seq);
        tmp.write(DerValue.tag_Sequence, seq);
        out.write(tmp.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 92 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class SubjectInfoAccessExtension method encodeThis.

private void encodeThis() throws IOException {
    try (DerOutputStream seq = new DerOutputStream();
        DerOutputStream tmp = new DerOutputStream()) {
        for (int i = 0; i < mDesc.size(); i++) {
            DerOutputStream tmp0 = new DerOutputStream();
            AccessDescription ad = mDesc.elementAt(i);
            tmp0.putOID(ad.getMethod());
            ad.getLocation().encode(tmp0);
            tmp.write(DerValue.tag_Sequence, tmp0);
        }
        seq.write(DerValue.tag_Sequence, tmp);
        this.extensionValue = seq.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 93 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class SubjectInfoAccessExtension method encode.

/**
 * Write the extension to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
@Override
public void encode(OutputStream out) throws IOException {
    DerOutputStream tmp = new DerOutputStream();
    if (this.extensionValue == null) {
        encodeThis();
    }
    super.encode(tmp);
    out.write(tmp.toByteArray());
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream)

Example 94 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class PKCS10Attribute method encode.

/**
 * Write the output to the DerOutputStream.
 *
 * @param out the OutputStream to write the attribute to.
 * @exception CertificateException on certificate encoding errors.
 * @exception IOException on encoding errors.
 */
public void encode(OutputStream out) throws CertificateException, IOException {
    try (DerOutputStream tmp = new DerOutputStream()) {
        // Encode the attribute value
        DerOutputStream outAttrValue = new DerOutputStream();
        attributeValue.encode(outAttrValue);
        // Wrap the encoded attribute value into a SET
        DerValue outAttrValueSet = new DerValue(DerValue.tag_Set, outAttrValue.toByteArray());
        // Create the attribute
        DerOutputStream outAttr = new DerOutputStream();
        outAttr.putOID(attributeId);
        outAttr.putDerValue(outAttrValueSet);
        // Wrap the OID and the set of attribute values into a SEQUENCE
        tmp.write(DerValue.tag_Sequence, outAttr);
        // write the results to out
        out.write(tmp.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 95 with DerOutputStream

use of org.mozilla.jss.netscape.security.util.DerOutputStream in project jss by dogtagpki.

the class PKCS10Attributes method derEncode.

/**
 * Encode the attributes in DER form to the stream.
 * Implements the <code>DerEncoder</code> interface.
 *
 * @param out the OutputStream to marshal the contents to.
 * @exception IOException on encoding errors.
 */
@Override
public void derEncode(OutputStream out) throws IOException {
    try (DerOutputStream attrOut = new DerOutputStream()) {
        // first copy the elements into an array
        PKCS10Attribute[] attribs = new PKCS10Attribute[size()];
        copyInto(attribs);
        attrOut.putOrderedSetOf(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), attribs);
        out.write(attrOut.toByteArray());
    } catch (IOException e) {
        throw e;
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) IOException(java.io.IOException)

Aggregations

DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)141 IOException (java.io.IOException)37 BigInt (org.mozilla.jss.netscape.security.util.BigInt)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 CRLException (java.security.cert.CRLException)7 CertificateException (java.security.cert.CertificateException)7 InvalidKeyException (java.security.InvalidKeyException)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ANY (org.mozilla.jss.asn1.ANY)5 InvalidBERException (org.mozilla.jss.asn1.InvalidBERException)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 KeyFactory (java.security.KeyFactory)3 SignatureException (java.security.SignatureException)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 NoSuchProviderException (java.security.NoSuchProviderException)2 Provider (java.security.Provider)2 PublicKey (java.security.PublicKey)2