Skip to content

Commit e003210

Browse files
committed
[feat] remove SHA1PRNG fallback: use default SecureRandom
ehen the preferred PRNG (NativePRNGNonBlocking) is unavailable, fall through directly to new SecureRandom() which lets the JDK pick the best available provider
1 parent e49a4d9 commit e003210

2 files changed

Lines changed: 2 additions & 19 deletions

File tree

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

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private static void setSecureRandom(ThreadContext context, java.security.SecureR
160160
}
161161
// setting it to "" (empty) or "default" should just use new SecureRandom() :
162162
if (prng.isEmpty() || prng.equalsIgnoreCase("default")) {
163-
prng = null; tryPreferredPRNG = false; trySHA1PRNG = false;
163+
prng = null; tryPreferredPRNG = false;
164164
}
165165

166166
PREFERRED_PRNG = prng;
@@ -177,7 +177,6 @@ private static void setSecureRandom(ThreadContext context, java.security.SecureR
177177
}
178178

179179
private static boolean tryPreferredPRNG = true;
180-
private static boolean trySHA1PRNG = true;
181180
private static boolean tryStrongPRNG = false; // NOT-YET-IMPLEMENTED
182181

183182
// copied from JRuby (not available in all 1.7.x) :
@@ -194,17 +193,6 @@ public java.security.SecureRandom getSecureRandomImpl() {
194193
}
195194
}
196195

197-
// Try SHA1PRNG
198-
if (secureRandom == null && trySHA1PRNG) {
199-
try {
200-
secureRandom = java.security.SecureRandom.getInstance("SHA1PRNG");
201-
}
202-
catch (Exception e) {
203-
trySHA1PRNG = false;
204-
OpenSSL.debug("SecureRandom SHA1PRNG failed:", e);
205-
}
206-
}
207-
208196
// Just let JDK do whatever it does
209197
if (secureRandom == null) {
210198
secureRandom = new java.security.SecureRandom();

src/main/java/org/jruby/ext/openssl/x509store/PEMInputOutput.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,12 +1213,7 @@ private static void writePemEncrypted(final BufferedWriter out,
12131213

12141214
private static SecureRandom secureRandom() {
12151215
if ( random == null ) {
1216-
try {
1217-
random = SecureRandom.getInstance("SHA1PRNG");
1218-
}
1219-
catch (NoSuchAlgorithmException e) {
1220-
random = new SecureRandom();
1221-
}
1216+
random = new SecureRandom();
12221217
}
12231218
return random;
12241219
}

0 commit comments

Comments
 (0)