Skip to content

Commit 5710d7d

Browse files
authored
WICKET-7174: DefaultSecureRandomSupplier does not work for FIPS (#1361)
1. Lazy load DefaultSecureRandomSupplier in SecuritySettings.java 2. Lazy load `SecureRandom.getInstance("SHA1PRNG")` in DefaultSecureRandomSupplier.java
1 parent 0443369 commit 5710d7d

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

wicket-core/src/main/java/org/apache/wicket/core/random/DefaultSecureRandomSupplier.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,24 @@
3232
*/
3333
public class DefaultSecureRandomSupplier implements ISecureRandomSupplier
3434
{
35-
private SecureRandom random;
36-
37-
public DefaultSecureRandomSupplier()
35+
private static final class Holder
3836
{
39-
try
40-
{
41-
random = SecureRandom.getInstance("SHA1PRNG");
42-
}
43-
catch (NoSuchAlgorithmException e)
37+
private static final SecureRandom INSTANCE;
38+
39+
static
4440
{
45-
throw new WicketRuntimeException(e);
41+
try
42+
{
43+
INSTANCE = SecureRandom.getInstance("SHA1PRNG");
44+
} catch (NoSuchAlgorithmException e) {
45+
throw new WicketRuntimeException(e);
46+
}
4647
}
4748
}
4849

4950
@Override
5051
public SecureRandom getRandom()
5152
{
52-
return random;
53+
return Holder.INSTANCE;
5354
}
5455
}

wicket-core/src/main/java/org/apache/wicket/settings/SecuritySettings.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SecuritySettings
5959
private ICryptFactory cryptFactory;
6060

6161
/** supplier of random data and SecureRandom */
62-
private ISecureRandomSupplier randomSupplier = new DefaultSecureRandomSupplier();
62+
private ISecureRandomSupplier randomSupplier;
6363

6464
/**
6565
* Whether mounts should be enforced. If {@code true}, requests for a page will be
@@ -139,6 +139,10 @@ public synchronized ICryptFactory getCryptFactory()
139139
*/
140140
public ISecureRandomSupplier getRandomSupplier()
141141
{
142+
if (randomSupplier == null)
143+
{
144+
randomSupplier = new DefaultSecureRandomSupplier();
145+
}
142146
return randomSupplier;
143147
}
144148

0 commit comments

Comments
 (0)