@@ -1444,7 +1444,7 @@ private void updatePkey(String alias,
14441444 throw new KeyStoreException
14451445 ("expected but could not find private key " +
14461446 "with CKA_ID " +
1447- getID (cka_id ));
1447+ getIDNullSafe (cka_id ));
14481448 }
14491449
14501450 // next find existing end entity cert
@@ -1454,7 +1454,7 @@ private void updatePkey(String alias,
14541454 throw new KeyStoreException
14551455 ("expected but could not find certificate " +
14561456 "with CKA_ID " +
1457- getID (cka_id ));
1457+ getIDNullSafe (cka_id ));
14581458 } else {
14591459 if (replaceCert ) {
14601460 // replacing existing cert and chain
@@ -1964,8 +1964,8 @@ private boolean destroyCert(byte[] cka_id)
19641964 token .p11 .C_DestroyObject (session .id (), h .handle );
19651965 if (debug != null ) {
19661966 debug .println ("destroyCert destroyed cert with CKA_ID [" +
1967- getID (cka_id ) +
1968- "]" );
1967+ getIDNullSafe (cka_id ) +
1968+ "]" );
19691969 }
19701970 return true ;
19711971 } finally {
@@ -1999,7 +1999,7 @@ private boolean destroyChain(byte[] cka_id)
19991999 if (debug != null ) {
20002000 debug .println ("destroyChain destroyed end entity cert " +
20012001 "with CKA_ID [" +
2002- getID (cka_id ) +
2002+ getIDNullSafe (cka_id ) +
20032003 "]" );
20042004 }
20052005
@@ -2124,7 +2124,7 @@ private boolean destroyPkey(byte[] cka_id)
21242124 if (debug != null ) {
21252125 debug .println
21262126 ("destroyPkey did not find private key with CKA_ID [" +
2127- getID (cka_id ) +
2127+ getIDNullSafe (cka_id ) +
21282128 "]" );
21292129 }
21302130 return false ;
@@ -2169,6 +2169,13 @@ private static String getID(byte[] bytes) {
21692169 }
21702170 }
21712171
2172+ /**
2173+ * Null safe version of getID.
2174+ */
2175+ private static String getIDNullSafe (byte [] bytes ) {
2176+ return (bytes != null ) ? getID (bytes ) : "null" ;
2177+ }
2178+
21722179 /**
21732180 * find an object on the token
21742181 *
@@ -2205,12 +2212,12 @@ private THandle getTokenObject(Session session,
22052212 } else if (type == ATTR_CLASS_CERT ) {
22062213 debug .println
22072214 ("getTokenObject did not find cert with CKA_ID [" +
2208- getID (cka_id ) +
2215+ getIDNullSafe (cka_id ) +
22092216 "]" );
22102217 } else {
22112218 debug .println ("getTokenObject did not find private key " +
22122219 "with CKA_ID [" +
2213- getID (cka_id ) +
2220+ getIDNullSafe (cka_id ) +
22142221 "]" );
22152222 }
22162223 }
@@ -2253,13 +2260,13 @@ private THandle getTokenObject(Session session,
22532260 "found " +
22542261 h .length +
22552262 " certificates sharing CKA_ID " +
2256- getID (cka_id ));
2263+ getIDNullSafe (cka_id ));
22572264 } else {
22582265 throw new KeyStoreException ("invalid KeyStore state: " +
22592266 "found " +
22602267 h .length +
22612268 " private keys sharing CKA_ID " +
2262- getID (cka_id ));
2269+ getIDNullSafe (cka_id ));
22632270 }
22642271 }
22652272 return new THandle (NO_HANDLE , null );
@@ -2515,7 +2522,7 @@ private ArrayList<AliasInfo> mapPrivateKeys(ArrayList<byte[]> pkeyIDs,
25152522 if (debug != null ) {
25162523 debug .println
25172524 ("did not find match for private key with CKA_ID [" +
2518- getID (pkeyID ) +
2525+ getIDNullSafe (pkeyID ) +
25192526 "] (ignoring entry)" );
25202527 }
25212528 }
0 commit comments