1
1
/*
2
- * Copyright (c) 2000, 2022 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2000, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
33
33
import java .util .Arrays ;
34
34
import java .util .List ;
35
35
import java .util .logging .Level ;
36
- import java .util .Random ;
37
36
import java .security .MessageDigest ;
38
37
import java .security .NoSuchAlgorithmException ;
39
38
import java .security .InvalidKeyException ;
39
+ import java .security .SecureRandom ;
40
40
import java .security .spec .KeySpec ;
41
41
import java .security .spec .InvalidKeySpecException ;
42
42
import java .security .InvalidAlgorithmParameterException ;
59
59
import javax .security .sasl .*;
60
60
61
61
import com .sun .security .sasl .util .AbstractSaslImpl ;
62
+ import sun .security .jca .JCAUtil ;
62
63
63
64
/**
64
65
* Utility class for DIGEST-MD5 mechanism. Provides utility methods
@@ -132,6 +133,9 @@ abstract class DigestMD5Base extends AbstractSaslImpl {
132
133
133
134
protected static final byte [] EMPTY_BYTE_ARRAY = new byte [0 ];
134
135
136
+ /* SecureRandom instance to generate nonce */
137
+ private static final SecureRandom SECURE_RANDOM = JCAUtil .getDefSecureRandom ();
138
+
135
139
/* ------------------- Variable Fields ----------------------- */
136
140
137
141
/* Used to track progress of authentication; step numbers from RFC 2831 */
@@ -269,7 +273,6 @@ public Object getNegotiatedProperty(String propName) {
269
273
* is slightly faster and a more compact representation of the same info.
270
274
* @return A non-null byte array containing the nonce value for the
271
275
* digest challenge or response.
272
- * Could use SecureRandom to be more secure but it is very slow.
273
276
*/
274
277
275
278
/** This array maps the characters to their 6 bit values */
@@ -293,10 +296,8 @@ public Object getNegotiatedProperty(String propName) {
293
296
294
297
protected static final byte [] generateNonce () {
295
298
296
- // SecureRandom random = new SecureRandom();
297
- Random random = new Random ();
298
299
byte [] randomData = new byte [RAW_NONCE_SIZE ];
299
- random .nextBytes (randomData );
300
+ SECURE_RANDOM .nextBytes (randomData );
300
301
301
302
byte [] nonce = new byte [ENCODED_NONCE_SIZE ];
302
303
0 commit comments