Search in sources :

Example 56 with DerValue

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

the class AccessDescription method readObject.

/**
 * For serialization
 * Note that GeneralName is not serializable. That is
 * why we need to define our own serialization method.
 */
private void readObject(java.io.ObjectInputStream in) throws IOException {
    DerValue val = new DerValue(in);
    DerValue seq = val.data.getDerValue();
    mOID = seq.getOID();
    DerValue derLoc = val.data.getDerValue();
    mLocation = new GeneralName(derLoc);
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) GeneralName(org.mozilla.jss.netscape.security.x509.GeneralName)

Example 57 with DerValue

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

the class EnumerationZeroTest method buildAuthorityKeyIdentifier.

/**
 * Calculate the KeyIdentifier for an RSAPublicKey and place it in an AuthorityKeyIdentifier extension.
 *
 * Java encodes RSA public keys using the SubjectPublicKeyInfo type described in RFC 5280.
 * <pre>
 * SubjectPublicKeyInfo  ::=  SEQUENCE  {
 *   algorithm            AlgorithmIdentifier,
 *   subjectPublicKey     BIT STRING  }
 *
 * AlgorithmIdentifier  ::=  SEQUENCE  {
 *   algorithm               OBJECT IDENTIFIER,
 *   parameters              ANY DEFINED BY algorithm OPTIONAL  }
 * </pre>
 *
 * A KeyIdentifier is a SHA-1 digest of the subjectPublicKey bit string from the ASN.1 above.
 *
 * @param key the RSAPublicKey to use
 * @return an AuthorityKeyIdentifierExtension based on the key
 * @throws IOException if we can't construct a MessageDigest object.
 */
public static AuthorityKeyIdentifierExtension buildAuthorityKeyIdentifier(RSAPublicKey key) throws IOException {
    try {
        MessageDigest d = MessageDigest.getInstance("SHA-1");
        byte[] encodedKey = key.getEncoded();
        DerInputStream s = new DerValue(encodedKey).toDerInputStream();
        // Skip the first item in the sequence, AlgorithmIdentifier.
        // The parameter, startLen, is required for skipSequence although it's unused.
        s.skipSequence(0);
        // Get the subjectPublicKey bit string
        BitArray b = s.getUnalignedBitString();
        byte[] digest = d.digest(b.toByteArray());
        KeyIdentifier ki = new KeyIdentifier(digest);
        return new AuthorityKeyIdentifierExtension(ki, null, null);
    } catch (NoSuchAlgorithmException e) {
        throw new IOException("Could not find SHA1 implementation", e);
    }
}
Also used : KeyIdentifier(org.mozilla.jss.netscape.security.x509.KeyIdentifier) DerValue(org.mozilla.jss.netscape.security.util.DerValue) AuthorityKeyIdentifierExtension(org.mozilla.jss.netscape.security.x509.AuthorityKeyIdentifierExtension) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream) BitArray(org.mozilla.jss.netscape.security.util.BitArray) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Example 58 with DerValue

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

the class ConverterTestUtil method convert.

public static byte[] convert(AVAValueConverter converter, String string, byte[] tags) throws Exception {
    DerOutputStream os = new DerOutputStream();
    DerValue value = converter.getValue(string, tags);
    value.encode(os);
    return os.toByteArray();
}
Also used : DerOutputStream(org.mozilla.jss.netscape.security.util.DerOutputStream) DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 59 with DerValue

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

the class X509CertInfo method decode.

/**
 * Decode an X.509 certificate from an input stream.
 *
 * @param in an input stream holding at least one certificate
 * @exception CertificateParsingException on decoding errors.
 * @exception IOException on other errors.
 */
@Override
public void decode(InputStream in) throws CertificateParsingException, IOException {
    DerValue val = new DerValue(in);
    parse(val);
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 60 with DerValue

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

the class X509CertInfo method parse.

/*
     * This routine unmarshals the certificate information.
     */
private void parse(DerValue val) throws CertificateParsingException, IOException {
    DerInputStream in;
    DerValue tmp;
    if (val.tag != DerValue.tag_Sequence) {
        throw new CertificateParsingException("signed fields invalid");
    }
    rawCertInfo = val.toByteArray();
    in = val.data;
    // Version
    tmp = in.getDerValue();
    if (tmp.isContextSpecific((byte) 0)) {
        version = new CertificateVersion(tmp);
        tmp = in.getDerValue();
    }
    // Serial number ... an integer
    serialNum = new CertificateSerialNumber(tmp);
    // Algorithm Identifier
    algId = new CertificateAlgorithmId(in);
    // Issuer name
    issuer = new CertificateIssuerName(in);
    // validity:  SEQUENCE { start date, end date }
    interval = new CertificateValidity(in);
    // subject name
    subject = new CertificateSubjectName(in);
    // public key
    pubKey = new CertificateX509Key(in);
    // If more data available, make sure version is not v1.
    if (in.available() != 0) {
        if (version.compare(CertificateVersion.V1) == 0) {
            throw new CertificateParsingException("excess cert data");
        }
    } else {
        return;
    }
    // Get the issuerUniqueId if present
    tmp = in.getDerValue();
    if (tmp.isContextSpecific((byte) 1)) {
        issuerUniqueId = new CertificateIssuerUniqueIdentity(tmp);
        if (in.available() == 0) {
            return;
        }
        tmp = in.getDerValue();
    }
    // Get the subjectUniqueId if present.
    if (tmp.isContextSpecific((byte) 2)) {
        subjectUniqueId = new CertificateSubjectUniqueIdentity(tmp);
        if (in.available() == 0) {
            return;
        }
        tmp = in.getDerValue();
    }
    // Get the extensions.
    if (version.compare(CertificateVersion.V3) != 0) {
        throw new CertificateParsingException("excess cert data");
    }
    if (tmp.isConstructed() && tmp.isContextSpecific((byte) 3)) {
        extensions = new CertificateExtensions(tmp.data);
    }
}
Also used : CertificateParsingException(java.security.cert.CertificateParsingException) 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