Search in sources :

Example 1 with RSASSAPSSparams

use of org.bouncycastle.asn1.pkcs.RSASSAPSSparams in project robovm by robovm.

the class DefaultSignatureAlgorithmIdentifierFinder method generate.

private static AlgorithmIdentifier generate(String signatureAlgorithm) {
    AlgorithmIdentifier sigAlgId;
    AlgorithmIdentifier encAlgId;
    AlgorithmIdentifier digAlgId;
    String algorithmName = Strings.toUpperCase(signatureAlgorithm);
    ASN1ObjectIdentifier sigOID = (ASN1ObjectIdentifier) algorithms.get(algorithmName);
    if (sigOID == null) {
        throw new IllegalArgumentException("Unknown signature type requested: " + algorithmName);
    }
    if (noParams.contains(sigOID)) {
        sigAlgId = new AlgorithmIdentifier(sigOID);
    } else if (params.containsKey(algorithmName)) {
        sigAlgId = new AlgorithmIdentifier(sigOID, (ASN1Encodable) params.get(algorithmName));
    } else {
        sigAlgId = new AlgorithmIdentifier(sigOID, DERNull.INSTANCE);
    }
    if (pkcs15RsaEncryption.contains(sigOID)) {
        encAlgId = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
    } else {
        encAlgId = sigAlgId;
    }
    if (sigAlgId.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
        digAlgId = ((RSASSAPSSparams) sigAlgId.getParameters()).getHashAlgorithm();
    } else {
        digAlgId = new AlgorithmIdentifier((ASN1ObjectIdentifier) digestOids.get(sigOID), DERNull.INSTANCE);
    }
    return sigAlgId;
}
Also used : ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 2 with RSASSAPSSparams

use of org.bouncycastle.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class AlgorithmUtil method extractDigesetAlgFromSigAlg.

public static AlgorithmIdentifier extractDigesetAlgFromSigAlg(AlgorithmIdentifier sigAlgId) throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier algOid = sigAlgId.getAlgorithm();
    ASN1ObjectIdentifier digestAlgOid;
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(algOid)) {
        ASN1Encodable asn1Encodable = sigAlgId.getParameters();
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(asn1Encodable);
        digestAlgOid = param.getHashAlgorithm().getAlgorithm();
    } else {
        HashAlgo digestAlg = sigAlgOidToDigestMap.get(algOid);
        if (digestAlg == null) {
            throw new NoSuchAlgorithmException("unknown signature algorithm " + algOid.getId());
        }
        digestAlgOid = digestAlg.getOid();
    }
    return new AlgorithmIdentifier(digestAlgOid, DERNull.INSTANCE);
}
Also used : HashAlgo(org.xipki.security.HashAlgo) RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 3 with RSASSAPSSparams

use of org.bouncycastle.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class AlgorithmUtil method getSigOrMacAlgoCode.

// method getHashOutputSizeInOctets
public static AlgorithmCode getSigOrMacAlgoCode(AlgorithmIdentifier algId) throws NoSuchAlgorithmException {
    ASN1ObjectIdentifier oid = algId.getAlgorithm();
    AlgorithmCode code = algOidToCodeMap.get(oid);
    if (code != null) {
        return code;
    }
    if (PKCSObjectIdentifiers.id_RSASSA_PSS.equals(oid)) {
        RSASSAPSSparams param = RSASSAPSSparams.getInstance(algId.getParameters());
        ASN1ObjectIdentifier digestAlgOid = param.getHashAlgorithm().getAlgorithm();
        code = digestToMgf1AlgCodeMap.get(digestAlgOid);
        if (code == null) {
            throw new NoSuchAlgorithmException("unsupported digest algorithm " + digestAlgOid);
        }
        return code;
    } else {
        throw new NoSuchAlgorithmException("unsupported signature algorithm " + oid.getId());
    }
}
Also used : RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier) AlgorithmCode(org.xipki.security.AlgorithmCode)

Example 4 with RSASSAPSSparams

use of org.bouncycastle.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class AlgorithmUtil method createPSSRSAParams.

// CHECKSTYLE:SKIP
private static RSASSAPSSparams createPSSRSAParams(HashAlgo digestAlg) throws NoSuchAlgorithmException {
    ParamUtil.requireNonNull("digestAlg", digestAlg);
    int saltSize = digestAlg.getLength();
    AlgorithmIdentifier digAlgId = new AlgorithmIdentifier(digestAlg.getOid(), DERNull.INSTANCE);
    return new RSASSAPSSparams(digAlgId, new AlgorithmIdentifier(PKCSObjectIdentifiers.id_mgf1, digAlgId), new ASN1Integer(saltSize), RSASSAPSSparams.DEFAULT_TRAILER_FIELD);
}
Also used : RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 5 with RSASSAPSSparams

use of org.bouncycastle.asn1.pkcs.RSASSAPSSparams in project xipki by xipki.

the class SignerUtil method createPSSRSASigner.

// CHECKSTYLE:SKIP
public static PSSSigner createPSSRSASigner(AlgorithmIdentifier sigAlgId, AsymmetricBlockCipher cipher) throws XiSecurityException {
    ParamUtil.requireNonNull("sigAlgId", sigAlgId);
    if (!PKCSObjectIdentifiers.id_RSASSA_PSS.equals(sigAlgId.getAlgorithm())) {
        throw new XiSecurityException("signature algorithm " + sigAlgId.getAlgorithm() + " is not allowed");
    }
    AlgorithmIdentifier digAlgId;
    try {
        digAlgId = AlgorithmUtil.extractDigesetAlgFromSigAlg(sigAlgId);
    } catch (NoSuchAlgorithmException ex) {
        throw new XiSecurityException(ex.getMessage(), ex);
    }
    RSASSAPSSparams param = RSASSAPSSparams.getInstance(sigAlgId.getParameters());
    AlgorithmIdentifier mfgDigAlgId = AlgorithmIdentifier.getInstance(param.getMaskGenAlgorithm().getParameters());
    Digest dig = getDigest(digAlgId);
    Digest mfgDig = getDigest(mfgDigAlgId);
    int saltSize = param.getSaltLength().intValue();
    int trailerField = param.getTrailerField().intValue();
    AsymmetricBlockCipher tmpCipher = (cipher == null) ? new RSABlindedEngine() : cipher;
    return new PSSSigner(tmpCipher, dig, mfgDig, saltSize, getTrailer(trailerField));
}
Also used : XiSecurityException(org.xipki.security.exception.XiSecurityException) Digest(org.bouncycastle.crypto.Digest) RSABlindedEngine(org.bouncycastle.crypto.engines.RSABlindedEngine) RSASSAPSSparams(org.bouncycastle.asn1.pkcs.RSASSAPSSparams) PSSSigner(org.bouncycastle.crypto.signers.PSSSigner) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier) AsymmetricBlockCipher(org.bouncycastle.crypto.AsymmetricBlockCipher)

Aggregations

RSASSAPSSparams (org.bouncycastle.asn1.pkcs.RSASSAPSSparams)8 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)5 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)5 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)2 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)2 AsymmetricBlockCipher (org.bouncycastle.crypto.AsymmetricBlockCipher)1 Digest (org.bouncycastle.crypto.Digest)1 RSABlindedEngine (org.bouncycastle.crypto.engines.RSABlindedEngine)1 PSSSigner (org.bouncycastle.crypto.signers.PSSSigner)1 AlgorithmCode (org.xipki.security.AlgorithmCode)1 HashAlgo (org.xipki.security.HashAlgo)1 XiSecurityException (org.xipki.security.exception.XiSecurityException)1