Search in sources :

Example 26 with ObjectIdentifier

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

the class NSCCommentExtension method encode.

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

Example 27 with ObjectIdentifier

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

the class RSAPSSAlgorithmParameters method decode.

private void decode(DerInputStream in, byte[] encoded) throws IOException {
    if (in == null) {
        throw new IOException("Invalid input: got null DerInputStream");
    }
    // Sequence has 3 members, trailer field ignored
    DerValue[] seq = in.getSequence(3);
    if (seq.length < 3 || seq.length > 4) {
        throw new IOException("Invalid data! Expected a sequence with either 3 or 4 members; got " + seq.length);
    }
    if (seq[0].isContextSpecific((byte) 0)) {
        seq[0] = seq[0].data.getDerValue();
    } else {
        throw new IOException("Invalid encoded data! Expecting OAEP-PSSDigestAlgorithms (hashAlgorithm).");
    }
    AlgorithmId algid = AlgorithmId.parse(seq[0]);
    String specAlgName = getSpecAlgName(algid.getName());
    String specMGF1Name = "";
    // Now the MFG1 parameter hash fun is the same as the main hash func.
    MGF1ParameterSpec specMFG1ParamSpec = new MGF1ParameterSpec(specAlgName);
    if (seq[1].isContextSpecific((byte) 1)) {
        seq[1] = seq[1].data.getDerValue();
    } else {
        throw new IOException("Invalid encoded data! Expecting OAEP-PSSDigestAlgorithms (maskGenAlgorithm).");
    }
    DerInputStream mgf1Str = new DerInputStream(seq[1].toByteArray());
    DerValue[] seqMgf1 = mgf1Str.getSequence(2);
    ObjectIdentifier mgf1OID = seqMgf1[0].getOID();
    if (!mgf1OID.equals(AlgorithmId.MGF1_oid)) {
        throw new IOException("Invalid encoded data: expected MGF1 OID but got: " + mgf1OID.toString());
    } else {
        specMGF1Name = "MGF1";
    }
    if (seq[2].isContextSpecific((byte) 2)) {
        seq[2] = seq[2].data.getDerValue();
    } else {
        throw new IOException("Invalid encoded data! Expected INTEGER (saltLength).");
    }
    BigInt sLength = seq[2].getInteger();
    this.spec = new PSSParameterSpec(specAlgName, specMGF1Name, specMFG1ParamSpec, sLength.toInt(), 1);
    populateFromSpec();
}
Also used : AlgorithmId(org.mozilla.jss.netscape.security.x509.AlgorithmId) PSSParameterSpec(java.security.spec.PSSParameterSpec) DerValue(org.mozilla.jss.netscape.security.util.DerValue) BigInt(org.mozilla.jss.netscape.security.util.BigInt) DerInputStream(org.mozilla.jss.netscape.security.util.DerInputStream) IOException(java.io.IOException) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec) ObjectIdentifier(org.mozilla.jss.netscape.security.util.ObjectIdentifier)

Aggregations

ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)27 IOException (java.io.IOException)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)8 CertificateException (java.security.cert.CertificateException)8 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)8 DerValue (org.mozilla.jss.netscape.security.util.DerValue)8 InvalidKeyException (java.security.InvalidKeyException)7 NoSuchProviderException (java.security.NoSuchProviderException)7 SignatureException (java.security.SignatureException)7 CertificateEncodingException (java.security.cert.CertificateEncodingException)5 CertificateExpiredException (java.security.cert.CertificateExpiredException)5 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)5 CertificateParsingException (java.security.cert.CertificateParsingException)5 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)5 GeneralName (org.mozilla.jss.netscape.security.x509.GeneralName)3 CRLException (java.security.cert.CRLException)2 CertificateExtensions (org.mozilla.jss.netscape.security.x509.CertificateExtensions)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 CharArrayWriter (java.io.CharArrayWriter)1 File (java.io.File)1