Home | History | Annotate | Download | only in cms
      1 package org.bouncycastle.cms;
      2 
      3 import java.util.HashSet;
      4 import java.util.Set;
      5 
      6 import org.bouncycastle.asn1.DERNull;
      7 import org.bouncycastle.asn1.oiw.OIWObjectIdentifiers;
      8 import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
      9 import org.bouncycastle.asn1.teletrust.TeleTrusTObjectIdentifiers;
     10 import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
     11 
     12 public class DefaultCMSSignatureEncryptionAlgorithmFinder
     13     implements CMSSignatureEncryptionAlgorithmFinder
     14 {
     15     private static final Set RSA_PKCS1d5 = new HashSet();
     16 
     17     static
     18     {
     19         // BEGIN Android-removed: Unsupported algorithms
     20         // RSA_PKCS1d5.add(PKCSObjectIdentifiers.md2WithRSAEncryption);
     21         // RSA_PKCS1d5.add(PKCSObjectIdentifiers.md4WithRSAEncryption);
     22         // END Android-removed: Unsupported algorithms
     23         RSA_PKCS1d5.add(PKCSObjectIdentifiers.md5WithRSAEncryption);
     24         RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha1WithRSAEncryption);
     25         // BEGIN Android-added: Add support for SHA-2 family signatures
     26         RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha224WithRSAEncryption);
     27         RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha256WithRSAEncryption);
     28         RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha384WithRSAEncryption);
     29         RSA_PKCS1d5.add(PKCSObjectIdentifiers.sha512WithRSAEncryption);
     30         // END Android-added: Add support for SHA-2 family signatures
     31         // BEGIN Android-removed: Unsupported algorithms
     32         // RSA_PKCS1d5.add(OIWObjectIdentifiers.md4WithRSAEncryption);
     33         // RSA_PKCS1d5.add(OIWObjectIdentifiers.md4WithRSA);
     34         // END Android-removed: Unsupported algorithms
     35         RSA_PKCS1d5.add(OIWObjectIdentifiers.md5WithRSA);
     36         RSA_PKCS1d5.add(OIWObjectIdentifiers.sha1WithRSA);
     37         // BEGIN Android-removed: Unsupported algorithms
     38         // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128);
     39         // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160);
     40         // RSA_PKCS1d5.add(TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256);
     41         // END Android-removed: Unsupported algorithms
     42     }
     43 
     44     public AlgorithmIdentifier findEncryptionAlgorithm(AlgorithmIdentifier signatureAlgorithm)
     45     {
     46                // RFC3370 section 3.2 with RFC 5754 update
     47         if (RSA_PKCS1d5.contains(signatureAlgorithm.getAlgorithm()))
     48         {
     49             return new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
     50         }
     51 
     52         return signatureAlgorithm;
     53     }
     54 }
     55