Search in sources :

Example 46 with DerValue

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

the class PKCS9Attributes method decode.

/**
 * Decode this set of PKCS9 attribute set from the contents of its
 * DER encoding.
 *
 * @param buf
 *            the contents of the DER encoding of the attribute set.
 *
 * @exception IOException
 *                on i/o error, encoding syntax error, unacceptable or
 *                unsupported attribute, or duplicate attribute.
 */
private byte[] decode(DerInputStream in) throws IOException {
    DerValue val = in.getDerValue();
    // save the DER encoding with its proper tag byte.
    byte[] derEncoding = val.toByteArray();
    derEncoding[0] = DerValue.tag_SetOf;
    DerInputStream derIn = new DerInputStream(derEncoding);
    DerValue[] derVals = derIn.getSet(3, true);
    PKCS9Attribute attrib;
    ObjectIdentifier oid;
    for (int i = 0; i < derVals.length; i++) {
        attrib = new PKCS9Attribute(derVals[i]);
        oid = attrib.getOID();
        if (attributes.get(oid) != null)
            throw new IOException("Duplicate PKCS9 attribute: " + oid);
        if (permittedAttributes != null && !permittedAttributes.containsKey(oid))
            throw new IOException("Attribute " + oid + " not permitted in this attribute set");
        attributes.put(oid, attrib);
    }
    return derEncoding;
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream) IOException(java.io.IOException) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Example 47 with DerValue

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

the class SubjectInfoAccessExtension method decodeThis.

private void decodeThis() throws IOException {
    DerValue val = new DerValue(this.extensionValue);
    if (val.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoding of AuthInfoAccess extension");
    }
    while (val.data.available() != 0) {
        DerValue seq = val.data.getDerValue();
        ObjectIdentifier method = seq.data.getDerValue().getOID();
        GeneralName gn = new GeneralName(seq.data.getDerValue());
        addAccessDescription(method, gn);
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) IOException(java.io.IOException) GeneralName(org.mozilla.jss.netscape.security.x509.GeneralName) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Example 48 with DerValue

use of org.mozilla.jss.netscape.security.util.DerValue 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 49 with DerValue

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

the class PresenceServerExtension method main.

public static void main(String[] args) {
    /*
           0 30  115: SEQUENCE {
           2 06    9:   OBJECT IDENTIFIER '2 16 840 1 113730 1 100'
          13 04  102:   OCTET STRING, encapsulates {
          15 30  100:       SEQUENCE {
          17 02    1:         INTEGER 0
          20 04   31:         OCTET STRING
                    :           34 30 31 45 20 4D 69 64 64 6C 65 66 69 65 6C 64
                    :           20 52 64 2E 2C 4D 56 2C 43 41 39 34 30 34 31
          53 04   12:         OCTET STRING
                    :           36 35 30 2D 31 31 31 2D 31 31 31 31
          67 04   18:         OCTET STRING
                    :           61 64 6D 69 6E 40 6E 65 74 73 63 61 70 65 2E 63
                    :           6F 6D
          87 04   10:         OCTET STRING
                    :           70 73 2D 63 61 70 69 74 6F 6C
          99 04    7:         OCTET STRING
                    :           63 61 70 69 74 6F 6C
         108 02    1:         INTEGER 80
         111 02    1:         INTEGER 10
         114 02    1:         INTEGER 1
                    :         }
                    :       }
                    :   }
         */
    ByteArrayOutputStream dos = null;
    FileOutputStream fos = null;
    try {
        boolean critical = false;
        int version = 1;
        String streetAddress = "401E Middlefield Rd.,MV,CA94041";
        String telephoneNumber = "650-111-1111";
        String rfc822Name = "admin@netscape.com";
        String ID = "ps-capitol";
        String hostName = "capitol";
        int portNumber = 80;
        int maxUsers = 10;
        int serviceLevel = 1;
        PresenceServerExtension ext = new PresenceServerExtension(critical, version, streetAddress, telephoneNumber, rfc822Name, ID, hostName, portNumber, maxUsers, serviceLevel);
        // encode
        dos = new ByteArrayOutputStream();
        ext.encode(dos);
        fos = new FileOutputStream("pse.der");
        fos.write(dos.toByteArray());
        Extension ext1 = new Extension(new DerValue(dos.toByteArray()));
        @SuppressWarnings("unused") PresenceServerExtension ext2 = new PresenceServerExtension(Boolean.valueOf(false), ext1.getExtensionValue());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (CertificateException e) {
        e.printStackTrace();
    } finally {
        if (dos != null) {
            try {
                dos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (fos != null) {
            try {
                fos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : Extension(org.mozilla.jss.netscape.security.x509.Extension) FileOutputStream(java.io.FileOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue) CertificateException(java.security.cert.CertificateException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 50 with DerValue

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

the class PresenceServerExtension method decodeThis.

public void decodeThis() throws IOException {
    DerInputStream val = new DerInputStream(this.extensionValue);
    byte[] data = null;
    DerValue[] seq = val.getSequence(0);
    mVersion = seq[0].getInteger().toInt();
    data = null;
    if (seq[1].length() > 0) {
        data = seq[1].getOctetString();
    }
    if (data == null) {
        mStreetAddress = "";
    } else {
        mStreetAddress = new String(data);
    }
    data = null;
    if (seq[2].length() > 0)
        data = seq[2].getOctetString();
    if (data == null) {
        mTelephoneNumber = "";
    } else {
        mTelephoneNumber = new String(data);
    }
    data = null;
    if (seq[3].length() > 0)
        data = seq[3].getOctetString();
    if (data == null) {
        mRFC822Name = "";
    } else {
        mRFC822Name = new String(data);
    }
    data = null;
    if (seq[4].length() > 0)
        data = seq[4].getOctetString();
    if (data == null) {
        mID = "";
    } else {
        mID = new String(data);
    }
    data = null;
    if (seq[5].length() > 0)
        data = seq[5].getOctetString();
    if (data == null) {
        mHostName = "";
    } else {
        mHostName = new String(data);
    }
    mPortNumber = seq[6].getInteger().toInt();
    mMaxUsers = seq[7].getInteger().toInt();
    mServiceLevel = seq[8].getInteger().toInt();
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream)

Aggregations

DerValue (org.mozilla.jss.netscape.security.util.DerValue)70 IOException (java.io.IOException)31 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)20 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)8 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)8 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 ByteBuffer (java.nio.ByteBuffer)4 CharBuffer (java.nio.CharBuffer)4 CharacterCodingException (java.nio.charset.CharacterCodingException)4 CharsetEncoder (java.nio.charset.CharsetEncoder)4 MessageDigest (java.security.MessageDigest)4 CRLException (java.security.cert.CRLException)4 BitArray (org.mozilla.jss.netscape.security.util.BitArray)4 AuthorityKeyIdentifierExtension (org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension)4 KeyIdentifier (org.mozilla.jss.netscape.security.x509.KeyIdentifier)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InvalidKeyException (java.security.InvalidKeyException)3 BigInt (org.mozilla.jss.netscape.security.util.BigInt)3 GeneralName (org.mozilla.jss.netscape.security.x509.GeneralName)3 CertificateException (java.security.cert.CertificateException)2