Distinguish between Windows & other OSes when testing with SecureRandom, to use available PRNG algorithm (#14874)

Closes #14610
This commit is contained in:
Maciej Jaworski 2022-11-03 09:21:55 +01:00 committed by GitHub
parent d859b03193
commit 70e2843a58
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -39,7 +39,7 @@ public class ElytronHmacTest extends HmacTest {
public void testHmacSignaturesUsingKeyGen() throws Exception {
KeyGenerator keygen = KeyGenerator.getInstance("HmacSHA256");
SecureRandom random = SecureRandom.getInstance("NativePRNG");
SecureRandom random = isWindows() ? SecureRandom.getInstance("Windows-PRNG") : SecureRandom.getInstance("NativePRNG");
random.setSeed(UUID.randomUUID().toString().getBytes());
keygen.init(random);
SecretKey secret = keygen.generateKey();
@ -50,4 +50,7 @@ public class ElytronHmacTest extends HmacTest {
JWSInput input = new JWSInput(encoded);
Assert.assertTrue(HMACProvider.verify(input, secret));
}
private boolean isWindows(){
return System.getProperty("os.name").startsWith("Windows");
}
}