Search in sources :

Example 36 with DerValue

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

the class CertificateValidity method construct.

// Construct the class from the DerValue
private void construct(DerValue derVal) throws IOException {
    if (derVal.tag != DerValue.tag_Sequence) {
        throw new IOException("Invalid encoded CertificateValidity, " + "starting sequence tag missing.");
    }
    // check if UTCTime encoded or GeneralizedTime
    if (derVal.data.available() == 0)
        throw new IOException("No data encoded for CertificateValidity");
    DerInputStream derIn = new DerInputStream(derVal.toByteArray());
    DerValue[] seq = derIn.getSequence(2);
    if (seq.length != 2)
        throw new IOException("Invalid encoding for CertificateValidity");
    if (seq[0].tag == DerValue.tag_UtcTime) {
        notBefore = derVal.data.getUTCTime();
    } else if (seq[0].tag == DerValue.tag_GeneralizedTime) {
        notBefore = derVal.data.getGeneralizedTime();
    } else {
        throw new IOException("Invalid encoding for CertificateValidity");
    }
    if (seq[1].tag == DerValue.tag_UtcTime) {
        notAfter = derVal.data.getUTCTime();
    } else if (seq[1].tag == DerValue.tag_GeneralizedTime) {
        notAfter = derVal.data.getGeneralizedTime();
    } else {
        throw new IOException("Invalid encoding for CertificateValidity");
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream) IOException(java.io.IOException)

Example 37 with DerValue

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

the class CertificateX509Key method decode.

/**
 * Decode the key in DER form from the stream.
 *
 * @param in the InputStream to unmarshal the contents from
 * @exception IOException on decoding or validity errors.
 */
@Override
public void decode(InputStream in) throws IOException {
    DerValue val = new DerValue(in);
    key = X509Key.parse(val);
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 38 with DerValue

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

the class Extensions method decode.

/**
 * Decode the extensions from the InputStream.
 *
 * @param in the InputStream to unmarshal the contents from.
 * @exception IOException on decoding or validity errors.
 */
@Override
public void decode(InputStream in) throws IOException {
    DerValue val = new DerValue(in);
    DerInputStream str = val.toDerInputStream();
    map = new Hashtable<>();
    DerValue[] exts = str.getSequence(5);
    for (int i = 0; i < exts.length; i++) {
        Extension ext = new Extension(exts[i]);
        parseExtension(ext);
    }
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream)

Example 39 with DerValue

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

the class CertificateSerialNumber method decode.

/**
 * Decode the serial number in DER form from the stream.
 *
 * @param in the InputStream to marshal the contents from.
 * @exception IOException on errors.
 */
@Override
public void decode(InputStream in) throws IOException {
    DerValue derVal = new DerValue(in);
    serial = new SerialNumber(derVal);
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue)

Example 40 with DerValue

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

the class AlgorithmId method parse.

/**
 * Parse (unmarshal) an ID from a DER sequence input value. This form
 * parsing might be used when expanding a value which has already been
 * partially unmarshaled as a set or sequence member.
 *
 * @exception IOException on error.
 * @param val the input value, which contains the algid and, if
 *            there are any parameters, those parameters.
 * @return an ID for the algorithm. If the system is configured
 *         appropriately, this may be an instance of a class
 *         with some kind of special support for this algorithm.
 *         In that case, you may "narrow" the type of the ID.
 */
public static AlgorithmId parse(DerValue val) throws IOException {
    if (val.tag != DerValue.tag_Sequence)
        throw new IOException("algid parse error, not a sequence");
    /*
         * Get the algorithm ID and any parameters.
         */
    ObjectIdentifier algid;
    DerValue params;
    DerInputStream in = val.toDerInputStream();
    algid = in.getOID();
    if (in.available() == 0)
        params = null;
    else {
        params = in.getDerValue();
        if (params.tag == DerValue.tag_Null)
            params = null;
    }
    /*
         * Figure out what class (if any) knows about this oid's
         * parameters.  Make one, and give it the data to decode.
         */
    AlgorithmId alg = null;
    // omit parameter field for ECDSA
    if (!algid.equals(sha224WithEC_oid) && !algid.equals(sha256WithEC_oid) && !algid.equals(sha384WithEC_oid) && !algid.equals(sha512WithEC_oid)) {
        alg = new AlgorithmId(algid, params);
    } else {
        try {
            alg = new AlgorithmId(algid);
        } catch (Exception e) {
            throw new IOException(e);
        }
    }
    if (params != null)
        alg.decodeParams();
    /*
         * Set the raw params string in case
         * higher level code might want the info
        */
    String paramStr = null;
    if (params != null) {
        paramStr = params.toString();
    }
    alg.setParametersString(paramStr);
    return alg;
}
Also used : DerValue(org.mozilla.jss.netscape.security.util.DerValue) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream) IOException(java.io.IOException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) NoSuchProviderException(java.security.NoSuchProviderException) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

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