Skip to content

Commit b310858

Browse files
authored
Try direct path for MessageDigest before invasive path (#194)
This logic is responsible for the remaining known "illegal access" warning on Java 9+. I am not sure why we do not trust the default provide to give us most algorithms, since it should be identical to the one provied by Bouncy Castle. This change reverses the logic and only uses the invasive provider-specific form when the direct lookup fails. Relates to jruby/jruby#6098.
1 parent c208a87 commit b310858

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,14 @@ static KeyStore getKeyStore(final String type, final Provider provider)
355355
*/
356356
public static MessageDigest getMessageDigest(final String algorithm) throws NoSuchAlgorithmException {
357357
try {
358+
return MessageDigest.getInstance(algorithm);
359+
} catch (NoSuchAlgorithmException nsae) {
360+
// try reflective logic
358361
final Provider provider = getSecurityProviderIfAccessible();
359362
if ( provider != null ) return getMessageDigest(algorithm, provider);
363+
364+
throw nsae; // give up
360365
}
361-
catch (NoSuchAlgorithmException e) { }
362-
return MessageDigest.getInstance(algorithm);
363366
}
364367

365368
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)