Skip to content

Commit a624b17

Browse files
committed
removed log check and renamed logs from keymanager to ssl,keymanager
1 parent b62fc9a commit a624b17

File tree

2 files changed

+26
-63
lines changed

2 files changed

+26
-63
lines changed

src/java.base/share/classes/sun/security/ssl/X509KeyManagerImpl.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,9 @@ private PrivateKeyEntry getEntry(String alias) {
256256
IndexOutOfBoundsException e) {
257257
// ignore and only log exception
258258
if (SSLLogger.isOn && SSLLogger.isOn("ssl,keymanager")) {
259-
SSLLogger.warning("Exception thrown while getting an alias " +
260-
alias + ": " + e);
259+
SSLLogger.warning(
260+
"Exception thrown while getting an alias" +
261+
" " + alias + ": " + e);
261262
}
262263
return null;
263264
}
@@ -295,7 +296,9 @@ private String chooseAlias(List<KeyType> keyTypeList, Principal[] issuers,
295296
if (results != null) {
296297
for (EntryStatus status : results) {
297298
if (status.checkResult == CheckResult.OK) {
298-
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
299+
if (SSLLogger.isOn
300+
&& SSLLogger
301+
.isOn("ssl,keymanager")) {
299302
SSLLogger.fine("Choosing key: " + status);
300303
}
301304
return makeAlias(status);
@@ -311,13 +314,13 @@ private String chooseAlias(List<KeyType> keyTypeList, Principal[] issuers,
311314
}
312315
}
313316
if (allResults == null) {
314-
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
317+
if (SSLLogger.isOn && SSLLogger.isOn("ssl,keymanager")) {
315318
SSLLogger.fine("No matching key found");
316319
}
317320
return null;
318321
}
319322
Collections.sort(allResults);
320-
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
323+
if (SSLLogger.isOn && SSLLogger.isOn("ssl,keymanager")) {
321324
SSLLogger.fine(
322325
"No good matching key found, "
323326
+ "returning best match out of", allResults);
@@ -357,13 +360,13 @@ private String[] getAliases(
357360
}
358361
}
359362
if (allResults == null || allResults.isEmpty()) {
360-
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
363+
if (SSLLogger.isOn && SSLLogger.isOn("ssl,keymanager")) {
361364
SSLLogger.fine("No matching alias found");
362365
}
363366
return null;
364367
}
365368
Collections.sort(allResults);
366-
if (SSLLogger.isOn && SSLLogger.isOn("keymanager")) {
369+
if (SSLLogger.isOn && SSLLogger.isOn("ssl,keymanager")) {
367370
SSLLogger.fine("Getting aliases", allResults);
368371
}
369372
return toAliases(allResults);

test/jdk/sun/security/ssl/X509KeyManager/NullCases.java

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* @library /test/lib /test/jdk/java/net/httpclient/lib
3838
* @modules java.base/sun.security.x509
3939
*
40-
* @run junit/othervm -Djavax.net.debug=ssl:keymanager NullCases
40+
* @run junit NullCases
4141
*/
4242

4343
import jdk.test.lib.Asserts;
@@ -48,8 +48,6 @@
4848

4949
import javax.net.ssl.KeyManagerFactory;
5050
import javax.net.ssl.X509KeyManager;
51-
import java.io.ByteArrayOutputStream;
52-
import java.io.PrintStream;
5351
import java.security.KeyPair;
5452
import java.security.SecureRandom;
5553
import java.security.KeyStore;
@@ -63,12 +61,9 @@
6361

6462

6563
public class NullCases {
66-
private static final String KEY_MGR_EXCEPTION_MESSAGE =
67-
"Exception thrown while getting an alias";
6864

6965
private static KeyManagerFactory kmf;
7066
private static X509KeyManager km;
71-
private final PrintStream initialErrStream = System.err;
7267

7368
@BeforeAll
7469
public static void beforeAll() throws Exception {
@@ -145,44 +140,26 @@ public void JDK6302271Test() {
145140
* The following tests are testing JDK-8369995
146141
*/
147142

148-
private ByteArrayOutputStream replaceSystemError() {
149-
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
150-
final PrintStream newErrStream = new PrintStream(outputStream);
151-
System.setErr(newErrStream);
152-
153-
return outputStream;
154-
}
155-
156143
@Test
157144
public void incompleteChainAndKeyTest() {
158145
final X509Certificate[] certs = km.getCertificateChain("1.1");
159146
final PrivateKey priv = km.getPrivateKey("1.1");
160147

161148
Asserts.assertNull(certs,
162-
"Should return null if the alias can't be found");
149+
"Should return null if the alias is incomplete");
163150
Asserts.assertNull(priv,
164-
"Should return null if the alias can't be found");
151+
"Should return null if the alias is incomplete");
165152
}
166153

167154
@Test
168155
public void nonexistentBuilderTest() {
169-
// recording logs to the output stream
170-
final ByteArrayOutputStream outputStream = replaceSystemError();
171-
172156
final X509Certificate[] certs = km.getCertificateChain("RSA.1.1");
173157
final PrivateKey priv = km.getPrivateKey("RSA.1.1");
174158

175159
Asserts.assertNull(certs,
176-
"Should return null if the alias can't be found");
160+
"Should return null if builder doesn't exist");
177161
Asserts.assertNull(priv,
178-
"Should return null if the alias can't be found");
179-
180-
System.setErr(initialErrStream);
181-
System.err.println(" => nonexistentBuilderTest: \n" + outputStream);
182-
183-
Asserts.assertFalse(
184-
!outputStream.toString().contains(KEY_MGR_EXCEPTION_MESSAGE),
185-
"No log triggered");
162+
"Should return null if builder doesn't exist");
186163
}
187164

188165
@Test
@@ -192,53 +169,36 @@ public void nonexistentKSTest() {
192169
final PrivateKey priv = km.getPrivateKey("RSA.0.1");
193170

194171
Asserts.assertNull(certs,
195-
"Should return null if the alias can't be found");
172+
"Should return null if KS doesn't exist");
196173
Asserts.assertNull(priv,
197-
"Should return null if the alias can't be found");
174+
"Should return null if KS doesn't exist");
198175
}
199176

200177
@Test
201178
public void wrongNumberFormatTest() {
202-
// recording logs to the output stream
203-
final ByteArrayOutputStream outputStream = replaceSystemError();
204179
final X509Certificate[] certs =
205180
km.getCertificateChain("RSA.not.exist");
206181
final PrivateKey priv = km.getPrivateKey("RSA.not.exist");
207182

208183
Asserts.assertNull(certs,
209-
"Should return null if the alias can't be found");
184+
"Should return null if number format is wrong in alias");
210185
Asserts.assertNull(priv,
211-
"Should return null if the alias can't be found");
212-
213-
System.setErr(initialErrStream);
214-
System.err.println(" => wrongNumberFormatTest: \n" + outputStream);
215-
216-
Asserts.assertFalse(
217-
!outputStream.toString().contains(KEY_MGR_EXCEPTION_MESSAGE),
218-
"No log triggered");
219-
186+
"Should return null if number format is wrong in alias");
220187
}
221188

222189
@ParameterizedTest
223-
@ValueSource(strings = {"1..",".1.", "..1", ".9.123456789"})
190+
@ValueSource(strings = {"1..1", "1..",".1.", "..1", ".9.123456789"})
224191
public void invalidAliasTest(final String alias) {
225-
// recording logs to the output stream
226-
final ByteArrayOutputStream outputStream = replaceSystemError();
227192
final X509Certificate[] certs = km.getCertificateChain(alias);
228193
final PrivateKey priv = km.getPrivateKey(alias);
229194

230195
Asserts.assertNull(certs,
231-
"Should return null if the alias can't be found");
196+
String.format(
197+
"Should return null if the alias is invalid <%s>",
198+
alias));
232199
Asserts.assertNull(priv,
233-
"Should return null if the alias can't be found");
234-
235-
System.setErr(initialErrStream);
236-
System.err.println(" => wrongNumberFormatTest alias<" + alias + ">: \n"
237-
+ outputStream);
238-
239-
Asserts.assertFalse(!outputStream.toString()
240-
.contains("Invalid alias format:"),
241-
"No log triggered");
242-
200+
String.format(
201+
"Should return null if the alias is invalid <%s>",
202+
alias));
243203
}
244204
}

0 commit comments

Comments
 (0)