Search in sources :

Example 26 with DerOutputStream

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

the class AuthorityKeyIdentifierExtension method encodeThis.

// Encode only the extension value
private void encodeThis() throws IOException {
    try (DerOutputStream tmp = new DerOutputStream();
        DerOutputStream seq = new DerOutputStream()) {
        if (id != null) {
            DerOutputStream tmp1 = new DerOutputStream();
            id.encode(tmp1);
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, false, TAG_ID), tmp1);
        }
        try {
            if (names != null) {
                DerOutputStream tmp1 = new DerOutputStream();
                names.encode(tmp1);
                tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, true, TAG_NAMES), tmp1);
            }
        } catch (Exception e) {
            throw new IOException(e);
        }
        if (serialNum != null) {
            DerOutputStream tmp1 = new DerOutputStream();
            serialNum.encode(tmp1);
            tmp.writeImplicit(DerValue.createTag(DerValue.TAG_CONTEXT, false, TAG_SERIAL_NUM), tmp1);
        }
        seq.write(DerValue.tag_Sequence, tmp);
        this.extensionValue = seq.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Example 27 with DerOutputStream

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

the class CRLDistributionPoint method setFullName.

/**
 * Sets the <code>fullName</code> of the <code>DistributionPointName</code>. It may be set to <code>null</code>.
 * If it is set to a non-null value, <code>relativeName</code> will be
 * set to <code>null</code>, because at most one of these two attributes
 * can be specified at a time.
 *
 * @exception GeneralNamesException If an error occurs encoding the
 *                name.
 */
public void setFullName(GeneralNames fullName) throws GeneralNamesException, IOException {
    this.fullName = fullName;
    if (fullName != null) {
        // encode the name to catch any problems with it
        DerOutputStream derOut = new DerOutputStream();
        fullName.encode(derOut);
        try {
            ANY raw = new ANY(derOut.toByteArray());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            raw.encodeWithAlternateTag(Tag.get(0), bos);
            fullNameEncoding = new ANY(bos.toByteArray());
        } catch (InvalidBERException e) {
            // in DerOutputStream
            throw new GeneralNamesException(e.toString());
        }
        this.relativeName = null;
    }
}
Also used : InvalidBERException(org.mozilla.jss.asn1.InvalidBERException) DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ANY(org.mozilla.jss.asn1.ANY)

Example 28 with DerOutputStream

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

the class Attribute method encodeValueSet.

// encode the attribute object
private void encodeValueSet(OutputStream out) throws IOException {
    try (DerOutputStream tmp2 = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        // get the attribute converter
        AVAValueConverter converter = attrMap.getValueConverter(oid);
        if (converter == null) {
            converter = new GenericValueConverter();
        // throw new IOException("Converter not found: unsupported attribute type");
        }
        // loop through all the values and encode
        Enumeration<String> vals = valueSet.elements();
        while (vals.hasMoreElements()) {
            String val = vals.nextElement();
            DerValue derobj = converter.getValue(val);
            derobj.encode(tmp);
        }
        tmp2.write(DerValue.tag_SetOf, tmp);
        out.write(tmp2.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 29 with DerOutputStream

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

the class KerberosName method encode.

/**
 * Write the extension to the DerOutputStream.
 *
 * @param out the DerOutputStream to write the extension to.
 * @exception IOException on encoding errors.
 */
public void encode(OutputStream out) throws IOException {
    try (DerOutputStream seq = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();
        DerOutputStream realm = new DerOutputStream();
        realm.putGeneralString(m_realm);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), realm);
        DerOutputStream seq1 = new DerOutputStream();
        DerOutputStream tmp1 = new DerOutputStream();
        DerOutputStream name_type = new DerOutputStream();
        name_type.putInteger(new BigInt(m_name_type));
        tmp1.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 0), name_type);
        DerOutputStream name_strings = new DerOutputStream();
        DerOutputStream name_string = new DerOutputStream();
        for (int i = 0; i < m_name_strings.size(); i++) {
            name_string.putGeneralString(m_name_strings.elementAt(i));
        }
        name_strings.write(DerValue.tag_SequenceOf, name_string);
        tmp1.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), name_strings);
        seq1.write(DerValue.tag_Sequence, tmp1);
        tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte) 1), seq1);
        seq.write(DerValue.tag_Sequence, tmp);
        out.write(seq.toByteArray());
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 30 with DerOutputStream

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

the class PresenceServerExtension method encodeThis.

public void encodeThis() throws IOException {
    try (DerOutputStream out = new DerOutputStream()) {
        DerOutputStream temp = new DerOutputStream();
        temp.putInteger(new BigInt(mVersion));
        temp.putOctetString(mStreetAddress.getBytes());
        temp.putOctetString(mTelephoneNumber.getBytes());
        temp.putOctetString(mRFC822Name.getBytes());
        temp.putOctetString(mID.getBytes());
        temp.putOctetString(mHostName.getBytes());
        temp.putInteger(new BigInt(mPortNumber));
        temp.putInteger(new BigInt(mMaxUsers));
        temp.putInteger(new BigInt(mServiceLevel));
        out.write(DerValue.tag_Sequence, temp);
        this.extensionValue = out.toByteArray();
    }
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

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