JDK-8308474 : DSA does not reset SecureRandom when initSign is called again
  • Type: Bug
  • Component: security-libs
  • Sub-Component: java.security
  • Affected Version: 8,11,17,21,22
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • Submitted: 2023-05-21
  • Updated: 2024-02-14
  • Resolved: 2023-06-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 22
21.0.1Fixed 22 b02Fixed
Related Reports
Relates :  
Description
sun.security.provider.DSA stores its SecureRandom in the signingRandom field and it's only set once when it's first used. If initSign is called again with a different SecureRandom, this value is not updated.
Comments
Fix Request (21u) Fixes the simple DSA bug, improves security. Applies cleanly. Test passes.
11-08-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk21u/pull/54 Date: 2023-08-11 10:36:08 +0000
11-08-2023

Seems to be that way since JDK-7044060 integration in 8.
14-06-2023

Changeset: bed9161c Author: Ben Perez <ben.perez@oracle.com> Committer: Weijun Wang <weijun@openjdk.org> Date: 2023-06-13 16:34:58 +0000 URL: https://git.openjdk.org/jdk/commit/bed9161c815b5b4773f36eac7e8dadc1384c7fd1
13-06-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/14273 Date: 2023-06-01 21:17:11 +0000
06-06-2023

Reproducer: import java.security.KeyPairGenerator; import java.security.PrivateKey; import java.security.SecureRandom; import java.security.Signature; import java.util.HexFormat; import java.util.Random; class A9 { public static void main(String[] args) throws Exception { KeyPairGenerator g = KeyPairGenerator.getInstance("DSA"); PrivateKey sk = g.generateKeyPair().getPrivate(); Signature s = Signature.getInstance("SHA256withDSA"); s.initSign(sk, deterministic()); System.out.println(HexFormat.of().formatHex(s.sign())); s.initSign(sk, deterministic()); System.out.println(HexFormat.of().formatHex(s.sign())); } static SecureRandom deterministic() { return new SecureRandom() { Random r = new Random(0); @Override public void nextBytes(byte[] bytes) { r.nextBytes(bytes); } }; } } The 2 signatures should look the same.
21-05-2023