Skip to content

Commit f1ca23c

Browse files
committed
avoid verifying the security provider when creating a cipher instance
when using reflection to create an instance of a cipher then we had already a SecurityException while using the javax Cipher factory. so avoid verifying the provider when creating the cipher instance via reflection. fixes #73 Sponsored by Lookout Inc.
1 parent c9b5af0 commit f1ca23c

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

src/main/java/org/jruby/ext/openssl/SecurityHelper.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public abstract class SecurityHelper {
107107
* classes are getting used.
108108
*
109109
* @param name the name under which the class gets registered
110-
* @param the CipherSpi class
110+
* @param clazz the CipherSpi class
111111
*/
112112
public static void addCipher(String name, Class<? extends CipherSpi> clazz) {
113113
implEngines.put("Cipher:" + name, clazz);
@@ -118,7 +118,7 @@ public static void addCipher(String name, Class<? extends CipherSpi> clazz) {
118118
* inject under a given name a signature
119119
*
120120
* @param name the name under which the class gets registered
121-
* @param the SignaturSpi class
121+
* @param clazz the SignaturSpi class
122122
*/
123123
public static void addSignature(String name, Class<? extends SignatureSpi> clazz) {
124124
implEngines.put("Signature:" + name, clazz);
@@ -431,22 +431,20 @@ private static Cipher getCipherInternal(String transformation, final Provider pr
431431

432432
}
433433
try {
434-
return newInstance(Cipher.class,
435-
new Class[] { CipherSpi.class, Provider.class, String.class },
436-
new Object[] { spi, provider, transformation }
437-
);
438-
}
439-
catch( IllegalStateException e ) {
440-
// this can be due to trusted check in Cipher constructor
441-
if (e.getCause().getClass() == NullPointerException.class) {
442-
Cipher cipher = newInstance(Cipher.class,
434+
// this constructor does not verify the provider
435+
Cipher cipher = newInstance(Cipher.class,
443436
new Class[] { CipherSpi.class, String.class },
444437
new Object[] { spi, transformation }
445-
);
446-
setField(cipher, Cipher.class, "provider", provider);
447-
return cipher;
448-
}
449-
throw e;
438+
);
439+
setField(cipher, Cipher.class, "provider", provider);
440+
return cipher;
441+
}
442+
catch( Exception e ) {
443+
// this constructor does verify the provider which might fail
444+
return newInstance(Cipher.class,
445+
new Class[] { CipherSpi.class, Provider.class, String.class },
446+
new Object[] { spi, provider, transformation }
447+
);
450448
}
451449
}
452450

0 commit comments

Comments
 (0)