initialization aborted by UnsupportedOperationException from isAvailable()

Issue #7 resolved
Brian Campbell repo owner created an issue

The NCipher/Thales HSM security provider apparently doesn't like the setParameter(AlgorithmParameterSpec params) on Signature (for RSA PSS anyway) and throws an UnsupportedOperationException.

AlgorithmFactoryFactory initialization checks isAvailable() on all the algorithms to give them the opportunity to do whatever they need to do to see if the runtime environment supports what they need. It's fine if PSS isn't supported but in this case the runtime UnsupportedOperationException was being thrown out of isAvailable() and it kills the whole initialization process.

Initialization and isAvailable() need to handle runtime exceptions more robustly.

Log snippet below:

10:15:53,863 INFO [AlgorithmFactoryFactory] Initializing jose4j (running with Java 1.7.0_71 from Oracle Corporation at C:\Program Files\Java\jdk1.7.0_71\jre with [SUN version 1.7, SunRsaSign version
1.7, SunEC version 1.7, SunJSSE version 1.7, SunJCE version 1.7, SunJGSS version 1.7, SunSASL version 1.7, XMLDSig version 1.0, SunPCSC version 1.7, SunMSCAPI version 1.7, nCipherKM version 1.024013]
security providers installed)...
10:15:53,878 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.PlaintextNoneAlgorithm@5506cac0 registered for alg algorithm none
10:15:53,878 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.HmacUsingShaAlgorithm$HmacSha256@1b68f060 registered for alg algorithm HS256
10:15:53,894 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.HmacUsingShaAlgorithm$HmacSha384@1915eb registered for alg algorithm HS384
10:15:53,894 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.HmacUsingShaAlgorithm$HmacSha512@19707bb9 registered for alg algorithm HS512
10:15:53,910 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.EcdsaUsingShaAlgorithm$EcdsaP256UsingSha256@357a25c3 registered for alg algorithm ES256
10:15:53,910 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.EcdsaUsingShaAlgorithm$EcdsaP384UsingSha384@1bfdf1d7 registered for alg algorithm ES384
10:15:53,925 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.EcdsaUsingShaAlgorithm$EcdsaP521UsingSha512@4ef59130 registered for alg algorithm ES512
10:15:53,925 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.RsaUsingShaAlgorithm$RsaSha256@528d8c58 registered for alg algorithm RS256
10:15:53,925 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.RsaUsingShaAlgorithm$RsaSha384@4076fc9 registered for alg algorithm RS384
10:15:53,925 INFO [AlgorithmFactory->JsonWebSignatureAlgorithm] org.jose4j.jws.RsaUsingShaAlgorithm$RsaSha512@284df714 registered for alg algorithm RS512
.... omitted ....
Caused by: java.lang.ExceptionInInitializerError
at org.jose4j.jwe.JsonWebEncryption.getKeyManagementModeAlgorithm(JsonWebEncryption.java:132)
at org.jose4j.jwe.JsonWebEncryption.decrypt(JsonWebEncryption.java:158)
at org.jose4j.jwe.JsonWebEncryption.getPlaintextBytes(JsonWebEncryption.java:77)
at org.jose4j.jwe.JsonWebEncryption.getPlaintextString(JsonWebEncryption.java:70)
.... omitted ....
... 8 more
Caused by: java.lang.UnsupportedOperationException: This implementation of Signature does not have AlgorithmParameters
at com.ncipher.provider.nCSignature.engineSetParameter(nCSignature.java:487)
at java.security.Signature$Delegate.engineSetParameter(Signature.java:1210)
at java.security.Signature.setParameter(Signature.java:841)
at org.jose4j.jws.BaseSignatureAlgorithm.getSignature(BaseSignatureAlgorithm.java:116)
at org.jose4j.jws.BaseSignatureAlgorithm.isAvailable(BaseSignatureAlgorithm.java:177)
at org.jose4j.jwa.AlgorithmFactory.registerAlgorithm(AlgorithmFactory.java:70)
at org.jose4j.jwa.AlgorithmFactoryFactory.initialize(AlgorithmFactoryFactory.java:73)
at org.jose4j.jwa.AlgorithmFactoryFactory.<init>(AlgorithmFactoryFactory.java:45)
at org.jose4j.jwa.AlgorithmFactoryFactory.<clinit>(AlgorithmFactoryFactory.java:36)
... 30 more

Comments (1)

  1. Log in to comment