Search in sources :

Example 16 with BigInt

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

the class RSAPSSAlgorithmParameters method populateFromSpec.

private void populateFromSpec() {
    if (spec == null || hashAlg == null) {
        return;
    }
    String hashAlgName = spec.getDigestAlgorithm();
    String maskGenName = spec.getMGFAlgorithm();
    int saltLen = spec.getSaltLength();
    this.saltLen = new BigInt(saltLen);
    int trailer = spec.getTrailerField();
    // Create the hash alg and mask gen func objects
    if (hashAlgName.equals("SHA-256")) {
        hashAlg = new AlgorithmId(AlgorithmId.SHA256_oid);
    } else if (hashAlgName.equals("SHA-512")) {
        hashAlg = new AlgorithmId(AlgorithmId.SHA512_oid);
    } else if (hashAlgName.equals("SHA-384")) {
        hashAlg = new AlgorithmId(AlgorithmId.SHA384_oid);
    } else {
        // Default to SHA-1 per above ASN.1 encoding.
        hashAlg = new AlgorithmId(AlgorithmId.SHA_oid);
    }
}
Also used : AlgorithmId(org.mozilla.jss.netscape.security.x509.AlgorithmId) BigInt(org.mozilla.jss.netscape.security.util.BigInt)

Example 17 with BigInt

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

BigInt (org.mozilla.jss.netscape.security.util.BigInt)17 DerOutputStream (org.mozilla.jss.netscape.security.util.DerOutputStream)13 DerValue (org.mozilla.jss.netscape.security.util.DerValue)3 IOException (java.io.IOException)2 AlgorithmId (org.mozilla.jss.netscape.security.x509.AlgorithmId)2 BigInteger (java.math.BigInteger)1 SignatureException (java.security.SignatureException)1 CRLException (java.security.cert.CRLException)1 X509Certificate (java.security.cert.X509Certificate)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)1 PSSParameterSpec (java.security.spec.PSSParameterSpec)1 DerInputStream (org.mozilla.jss.netscape.security.util.DerInputStream)1 ObjectIdentifier (org.mozilla.jss.netscape.security.util.ObjectIdentifier)1 CertificateX509Key (org.mozilla.jss.netscape.security.x509.CertificateX509Key)1 X500Name (org.mozilla.jss.netscape.security.x509.X500Name)1 X509Key (org.mozilla.jss.netscape.security.x509.X509Key)1 PK11ECPublicKey (org.mozilla.jss.pkcs11.PK11ECPublicKey)1