Skip to content

Commit

Permalink
8293858: Change PKCS7 code to use default SecureRandom impl instead o…
Browse files Browse the repository at this point in the history
…f SHA1PRNG

Backport-of: 2157145766f9789ade0940e9ae1715a3b74d508b
  • Loading branch information
GoeLin committed Jun 19, 2023
1 parent c1f759e commit 2cc4596
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/java.base/share/classes/sun/security/pkcs/PKCS7.java
Expand Up @@ -36,6 +36,7 @@
import java.security.cert.CertificateFactory;
import java.security.*;

import sun.security.jca.JCAUtil;
import sun.security.timestamp.*;
import sun.security.util.*;
import sun.security.x509.AlgorithmId;
Expand Down Expand Up @@ -69,23 +70,6 @@ public class PKCS7 {

private Principal[] certIssuerNames;

/*
* Random number generator for creating nonce values
* (Lazy initialization)
*/
private static class SecureRandomHolder {
static final SecureRandom RANDOM;
static {
SecureRandom tmp = null;
try {
tmp = SecureRandom.getInstance("SHA1PRNG");
} catch (NoSuchAlgorithmException e) {
// should not happen
}
RANDOM = tmp;
}
}

/*
* Object identifier for the timestamping key purpose.
*/
Expand Down Expand Up @@ -885,11 +869,9 @@ private static byte[] generateTimestampToken(Timestamper tsa,
}

// Generate a nonce
BigInteger nonce = null;
if (SecureRandomHolder.RANDOM != null) {
nonce = new BigInteger(64, SecureRandomHolder.RANDOM);
tsQuery.setNonce(nonce);
}
BigInteger nonce = new BigInteger(64, JCAUtil.getDefSecureRandom());
tsQuery.setNonce(nonce);

tsQuery.requestCertificate(true);

TSResponse tsReply = tsa.generateTimestamp(tsQuery);
Expand Down

1 comment on commit 2cc4596

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.