Skip to content

Commit

Permalink
Allow configuring the preferred PRNG for SecureRandom.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Aug 5, 2016
1 parent 50882dc commit 1b3111e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
9 changes: 5 additions & 4 deletions core/src/main/java/org/jruby/runtime/ThreadContext.java
Expand Up @@ -59,6 +59,7 @@
import org.jruby.runtime.scope.ManyVarsDynamicScope;
import org.jruby.util.RecursiveComparator;
import org.jruby.util.RubyDateFormatter;
import org.jruby.util.cli.Options;
import org.jruby.util.log.Logger;
import org.jruby.util.log.LoggerFactory;

Expand Down Expand Up @@ -140,17 +141,17 @@ public static ThreadContext newContext(Ruby runtime) {
@Deprecated
public transient SecureRandom secureRandom;

private static boolean trySHA1PRNG = true;
private static boolean tryPreferredPRNG = true;

@SuppressWarnings("deprecated")
public SecureRandom getSecureRandom() {
SecureRandom secureRandom = this.secureRandom;
if (secureRandom == null) {
if (trySHA1PRNG) {
if (tryPreferredPRNG) {
try {
secureRandom = SecureRandom.getInstance("SHA1PRNG");
secureRandom = SecureRandom.getInstance(Options.PREFERRED_PRNG.load());
} catch (Exception e) {
trySHA1PRNG = false;
tryPreferredPRNG = false;
}
}
if (secureRandom == null) {
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/jruby/util/cli/Options.java
Expand Up @@ -166,6 +166,7 @@ public class Options {
public static final Option<Boolean> FCNTL_LOCKING = bool(MISCELLANEOUS, "file.flock.fcntl", true, "Use fcntl rather than flock for File#flock");
public static final Option<Boolean> VOLATILE_VARIABLES = bool(MISCELLANEOUS, "volatile.variables", true, "Always ensure volatile semantics for instance variables.");
public static final Option<Boolean> RECORD_LEXICAL_HIERARCHY = bool(MISCELLANEOUS, "record.lexical.hierarchy", false, "Maintain children static scopes to support scope dumping.");
public static final Option<String> PREFERRED_PRNG = string(MISCELLANEOUS, "preferred.prng", "SHA1PRNG", "Maintain children static scopes to support scope dumping.");

public static final Option<Boolean> DEBUG_LOADSERVICE = bool(DEBUG, "debug.loadService", false, "Log require/load file searches.");
public static final Option<Boolean> DEBUG_LOADSERVICE_TIMING = bool(DEBUG, "debug.loadService.timing", false, "Log require/load parse+evaluate times.");
Expand Down

0 comments on commit 1b3111e

Please sign in to comment.