Skip to content

Commit 68c7757

Browse files
committed
make the creation of the Cipher more robust in case some trust check fails
Sponsored by Lookout Inc.
1 parent 42e5d96 commit 68c7757

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,22 @@ private static Cipher getCipherInternal(String transformation, final Provider pr
408408
}
409409

410410
}
411-
return newInstance(Cipher.class,
412-
new Class[] { CipherSpi.class, Provider.class, String.class },
413-
new Object[] { spi, provider, transformation }
414-
);
411+
try {
412+
return newInstance(Cipher.class,
413+
new Class[] { CipherSpi.class, Provider.class, String.class },
414+
new Object[] { spi, provider, transformation }
415+
);
416+
}
417+
catch( IllegalStateException e ) {
418+
// this can be due to trusted check in Cipher constructor
419+
if (e.getCause().getClass() == NullPointerException.class) {
420+
return newInstance(Cipher.class,
421+
new Class[] { CipherSpi.class, String.class },
422+
new Object[] { spi, transformation }
423+
);
424+
}
425+
throw e;
426+
}
415427
}
416428

417429
/**

0 commit comments

Comments
 (0)