< prev index next >
src/share/classes/com/sun/crypto/provider/JceKeyStore.java
Print this page
rev 13649 : 8218553: Enhance keystore load debug output
Reviewed-by: weijun
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 1998, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1998, 2019, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,10 +23,12 @@
* questions.
*/
package com.sun.crypto.provider;
+import sun.security.util.Debug;
+
import java.io.*;
import java.util.*;
import java.security.AccessController;
import java.security.DigestInputStream;
import java.security.DigestOutputStream;
@@ -59,10 +61,11 @@
* @see java.security.KeyStoreSpi
*/
public final class JceKeyStore extends KeyStoreSpi {
+ private static final Debug debug = Debug.getInstance("keystore");
private static final int JCEKS_MAGIC = 0xcececece;
private static final int JKS_MAGIC = 0xfeedfeed;
private static final int VERSION_1 = 0x01;
private static final int VERSION_2 = 0x02;
@@ -680,10 +683,11 @@
MessageDigest md = null;
CertificateFactory cf = null;
Hashtable<String, CertificateFactory> cfs = null;
ByteArrayInputStream bais = null;
byte[] encoded = null;
+ int trustedKeyCount = 0, privateKeyCount = 0, secretKeyCount = 0;
if (stream == null)
return;
if (password != null) {
@@ -726,11 +730,11 @@
String alias;
tag = dis.readInt();
if (tag == 1) { // private-key entry
-
+ privateKeyCount++;
PrivateKeyEntry entry = new PrivateKeyEntry();
// read the alias
alias = dis.readUTF();
@@ -786,11 +790,11 @@
// Add the entry to the list
entries.put(alias, entry);
} else if (tag == 2) { // trusted certificate entry
-
+ trustedKeyCount++;
TrustedCertEntry entry = new TrustedCertEntry();
// read the alias
alias = dis.readUTF();
@@ -825,11 +829,11 @@
// Add the entry to the list
entries.put(alias, entry);
} else if (tag == 3) { // secret-key entry
-
+ secretKeyCount++;
SecretKeyEntry entry = new SecretKeyEntry();
// read the alias
alias = dis.readUTF();
@@ -858,12 +862,20 @@
// Add the entry to the list
entries.put(alias, entry);
} else {
- throw new IOException("Unrecognized keystore entry");
+ throw new IOException("Unrecognized keystore entry: " +
+ tag);
+ }
}
+
+ if (debug != null) {
+ debug.println("JceKeyStore load: private key count: " +
+ privateKeyCount + ". trusted key count: " +
+ trustedKeyCount + ". secret key count: " +
+ secretKeyCount);
}
/*
* If a password has been provided, we check the keyed digest
* at the end. If this check fails, the store has been tampered
< prev index next >