Skip to content

Commit 790802b

Browse files
committedApr 27, 2023
8293858: Change PKCS7 code to use default SecureRandom impl instead of SHA1PRNG
Backport-of: 2157145766f9789ade0940e9ae1715a3b74d508b
1 parent 394a756 commit 790802b

File tree

1 file changed

+4
-22
lines changed
  • src/java.base/share/classes/sun/security/pkcs

1 file changed

+4
-22
lines changed
 

‎src/java.base/share/classes/sun/security/pkcs/PKCS7.java

+4-22
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.security.*;
3838
import java.util.function.Function;
3939

40+
import sun.security.jca.JCAUtil;
4041
import sun.security.provider.SHAKE256;
4142
import sun.security.timestamp.*;
4243
import sun.security.util.*;
@@ -67,23 +68,6 @@ public class PKCS7 {
6768

6869
private Principal[] certIssuerNames;
6970

70-
/*
71-
* Random number generator for creating nonce values
72-
* (Lazy initialization)
73-
*/
74-
private static class SecureRandomHolder {
75-
static final SecureRandom RANDOM;
76-
static {
77-
SecureRandom tmp = null;
78-
try {
79-
tmp = SecureRandom.getInstance("SHA1PRNG");
80-
} catch (NoSuchAlgorithmException e) {
81-
// should not happen
82-
}
83-
RANDOM = tmp;
84-
}
85-
}
86-
8771
/**
8872
* Unmarshals a PKCS7 block from its encoded form, parsing the
8973
* encoded bytes from the InputStream.
@@ -1027,11 +1011,9 @@ public static byte[] generateTimestampToken(Timestamper tsa,
10271011
}
10281012

10291013
// Generate a nonce
1030-
BigInteger nonce = null;
1031-
if (SecureRandomHolder.RANDOM != null) {
1032-
nonce = new BigInteger(64, SecureRandomHolder.RANDOM);
1033-
tsQuery.setNonce(nonce);
1034-
}
1014+
BigInteger nonce = new BigInteger(64, JCAUtil.getDefSecureRandom());
1015+
tsQuery.setNonce(nonce);
1016+
10351017
tsQuery.requestCertificate(true);
10361018

10371019
TSResponse tsReply = tsa.generateTimestamp(tsQuery);

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Apr 27, 2023

@openjdk-notifier[bot]
Please sign in to comment.