2012-01-08 6 views
3

내가 놀고있어 BouncyCastle 1.46 놀랍게도 아래의 스 니펫에있는 catch 블록은 매우 자주 트립됩니다.BouncyCastle은 제공하는 알고리즘을 찾지 못합니까?

Security.addProvider(new BouncyCastleProvider()); 

final Set<String> found = new HashSet<String>(); 
final Set<String> missing = new HashSet<String>(); 

final DefaultSignatureAlgorithmIdentifierFinder finder = new DefaultSignatureAlgorithmIdentifierFinder(); 
for (Service service : new BouncyCastleProvider().getServices()) { 
    if ("Signature".equals(service.getType())) { 
     final String algorithm = service.getAlgorithm(); 
     try { 
      finder.find(algorithm); 
      found.add(algorithm); 
     } catch (IllegalArgumentException ex) { 
      missing.add(algorithm); 
     } 
    } 
} 

System.out.println("Found: " + found); 
System.out.println("Missing: " + missing); 

이러한 알고리즘을 제공하는 서비스가 있지만 Finder에서 대부분의 알고리즘을 사용할 수없는 것으로 보입니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

업데이트 업데이트를 개선하기 위해 코드를 약간 변경했습니다. 흥미로운 점은 BouncyCastle의 JDK1.5 버전을 사용하고 있다는 것입니다. 위의 코드는이 출력을 제공한다 :

실측치 : RIPEMD256WithRSAEncryption, MD5WithRSAEncryption, MD2WithRSAEncryption, SHA384WithRSAEncryption, SHA224WITHECDSA, SHA384WITHDSA, SHA256WITHDSA, SHA512WithRSAEncryption, SHA512WITHDSA, RIPEMD160WithRSAEncryption, SHA224WithRSAEncryption, SHA256WITHECDSA, RIPEMD128WithRSAEncryption, SHA384WITHECDSA, SHA256WithRSAEncryption, SHA512WITHECDSA, sha1WithRSAEncryption을, SHA224WITHDSA]

누락 : [SHA1WITHECNR, NONEwithECDSA, ECDSA, SHA512withRSA/PSS, RIPEMD160WITHECDSA, RSA, GOST3410, SHA256WITHECNR, MD5withRSA가/ISO9796-2, SHA1WITHCVC-ECDSA, SHA384withRSA/PSS, SHA1withRSA와/PSS, MD4WithRSAEncryption, RSASSA-PSS, SHA512WITHECNR , SHA256WITHCVC-ECDSA, SHA1withRSA/ISO9796-2, SHA224withRSA/PSS, SHA224WITHCVC-ECDSA, RAWRSASS A-PSS, SHA256withRSA/PSS, NONEWITHDSA, SHA384WITHECNR, RIPEMD160withRSA/ISO9796-2, DSA, ECGOST3410, SHA224WITHECNR, 1.2.840.113549.1.1.10]

+1

디버깅하여'service.getAlgorithm()'에 반환되는 것을 질문에 추가 할 수 있습니까? –

+0

오스카 : 방금했습니다. – Guus

답변

5

나는 DefaultSignatureAlgorithmIdentifierFinder이 bcmail API의 일부라고 생각합니다. 이 API가 인식하는 알고리즘 식별자를 반환합니다. (Cryptographic Message Syntax) 반면에 탄력적 카스트 공급자는 더 많은 알고리즘을 제공합니다.

algorithms.put("MD2WITHRSAENCRYPTION", PKCSObjectIdentifiers.md2WithRSAEncryption); 
algorithms.put("MD2WITHRSA", PKCSObjectIdentifiers.md2WithRSAEncryption); 
algorithms.put("MD5WITHRSAENCRYPTION", PKCSObjectIdentifiers.md5WithRSAEncryption); 
algorithms.put("MD5WITHRSA", PKCSObjectIdentifiers.md5WithRSAEncryption); 
algorithms.put("SHA1WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha1WithRSAEncryption); 
algorithms.put("SHA1WITHRSA", PKCSObjectIdentifiers.sha1WithRSAEncryption); 
algorithms.put("SHA224WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha224WithRSAEncryption); 
algorithms.put("SHA224WITHRSA", PKCSObjectIdentifiers.sha224WithRSAEncryption); 
algorithms.put("SHA256WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha256WithRSAEncryption); 
algorithms.put("SHA256WITHRSA", PKCSObjectIdentifiers.sha256WithRSAEncryption); 
algorithms.put("SHA384WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha384WithRSAEncryption); 
algorithms.put("SHA384WITHRSA", PKCSObjectIdentifiers.sha384WithRSAEncryption); 
algorithms.put("SHA512WITHRSAENCRYPTION", PKCSObjectIdentifiers.sha512WithRSAEncryption); 
algorithms.put("SHA512WITHRSA", PKCSObjectIdentifiers.sha512WithRSAEncryption); 
algorithms.put("SHA1WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS); 
algorithms.put("SHA224WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS); 
algorithms.put("SHA256WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS); 
algorithms.put("SHA384WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS); 
algorithms.put("SHA512WITHRSAANDMGF1", PKCSObjectIdentifiers.id_RSASSA_PSS); 
algorithms.put("RIPEMD160WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160); 
algorithms.put("RIPEMD160WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd160); 
algorithms.put("RIPEMD128WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128); 
algorithms.put("RIPEMD128WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd128); 
algorithms.put("RIPEMD256WITHRSAENCRYPTION", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256); 
algorithms.put("RIPEMD256WITHRSA", TeleTrusTObjectIdentifiers.rsaSignatureWithripemd256); 
algorithms.put("SHA1WITHDSA", X9ObjectIdentifiers.id_dsa_with_sha1); 
algorithms.put("DSAWITHSHA1", X9ObjectIdentifiers.id_dsa_with_sha1); 
algorithms.put("SHA224WITHDSA", NISTObjectIdentifiers.dsa_with_sha224); 
algorithms.put("SHA256WITHDSA", NISTObjectIdentifiers.dsa_with_sha256); 
algorithms.put("SHA384WITHDSA", NISTObjectIdentifiers.dsa_with_sha384); 
algorithms.put("SHA512WITHDSA", NISTObjectIdentifiers.dsa_with_sha512); 
algorithms.put("SHA1WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA1); 
algorithms.put("ECDSAWITHSHA1", X9ObjectIdentifiers.ecdsa_with_SHA1); 
algorithms.put("SHA224WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA224); 
algorithms.put("SHA256WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA256); 
algorithms.put("SHA384WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA384); 
algorithms.put("SHA512WITHECDSA", X9ObjectIdentifiers.ecdsa_with_SHA512); 
algorithms.put("GOST3411WITHGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94); 
algorithms.put("GOST3411WITHGOST3410-94", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_94); 
algorithms.put("GOST3411WITHECGOST3410", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001); 
algorithms.put("GOST3411WITHECGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001); 
algorithms.put("GOST3411WITHGOST3410-2001", CryptoProObjectIdentifiers.gostR3411_94_with_gostR3410_2001); 

환호 : 당신은 인식 알고리즘이 하드 코딩되어 DefaultSignatureAlgorithmIdentifierFinder의 소스를 체크 할 수있다!

3

당신은 보안 업체에 BouncyCastle를 추가 했습니까? 이 라인이 작업을 수행 할 수 있습니다

Security.addProvider(new BouncyCastleProvider()); 
+0

네, 그랬습니다.하지만 여기에 올린 스 니펫에 복사하는 것을 게을리했습니다. 나는 그것을 새롭게 할 것이다. – Guus

0

당신은 두 단계로 자바 플랫폼에서 보안 공급자에 탄력이 성을 추가 할 수 있습니다

1 복사 BC의 librarys (현재 bcpkix-jdk15on-149.jar, bcprov-jdk15on-149.jar를) 디렉토리에 $ JAVA_HOME/JRE/lib 디렉토리/내선/

2 등록 BC 제공
: 편집 파일 $ JAVA_HOME/jre/lib/security/java.security에 및 밑줄

security.provider.1=sun.security.provider.Sun 

귀하의 BC 공급자를 추가하십시오

security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider 

나머지 공급자 수를 변경하십시오. 제공자 전체는 다음과 유사해야합니다.

security.provider.1=sun.security.provider.Sun 
security.provider.2=org.bouncycastle.jce.provider.BouncyCastleProvider 
security.provider.3=sun.security.rsa.SunRsaSign 
security.provider.4=sun.security.ec.SunEC 
security.provider.5=com.sun.net.ssl.internal.ssl.Provider 
security.provider.6=com.sun.crypto.provider.SunJCE 
security.provider.7=sun.security.jgss.SunProvider 
security.provider.8=com.sun.security.sasl.Provider 
security.provider.9=org.jcp.xml.dsig.internal.dom.XMLDSigRI 
security.provider.10=sun.security.smartcardio.SunPCSC 
1

이 답변은 BouncyCastle과 직접적인 관련이 없습니다. 그러나 이것이 다른 사람들에게 유용 할 것이라고 생각했습니다.

내 경우 SpongyCastle을 사용하고있었습니다. 비슷한 문제가 있습니다 : org.e.h.p : 서명자를 만들 수 없습니다. 제공자 SC는 SHA256WITHRSA를 제공하지 않습니다. 을 org.e.h.a.a.a (SourceFile : 101)

proguard가 필수 클래스 중 일부를 제거하고있는 것으로 나타났습니다. proguard 구성 파일에 다음을 추가 한 후 -keep class org.spongycastle. ** {*; }

문제가 해결되었습니다.

관련 문제