Skip to content

Commit d29fe03

Browse files
franferraxmartinuy
authored andcommitted
8325254: CKA_TOKEN private and secret keys are not necessarily sensitive
Reviewed-by: mbalao Backport-of: 0f5f3c9b9718c610406088327401210486447462
1 parent 7ced722 commit d29fe03

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Cipher.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,10 +261,8 @@ protected void engineSetPadding(String padding)
261261
// no native padding support; use our own padding impl
262262
paddingObj = new PKCS5Padding(blockSize);
263263
padBuffer = new byte[blockSize];
264-
char[] tokenLabel = token.tokenInfo.label;
265264
// NSS requires block-sized updates in multi-part operations.
266-
reqBlockUpdates = ((tokenLabel[0] == 'N' && tokenLabel[1] == 'S'
267-
&& tokenLabel[2] == 'S') ? true : false);
265+
reqBlockUpdates = P11Util.isNSS(token);
268266
}
269267
} else {
270268
throw new NoSuchPaddingException("Unsupported padding " + padding);

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Key.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ abstract class P11Key implements Key, Length {
139139
this.tokenObject = tokenObject;
140140
this.sensitive = sensitive;
141141
this.extractable = extractable;
142-
char[] tokenLabel = this.token.tokenInfo.label;
143-
isNSS = (tokenLabel[0] == 'N' && tokenLabel[1] == 'S'
144-
&& tokenLabel[2] == 'S');
142+
isNSS = P11Util.isNSS(this.token);
145143
boolean extractKeyInfo = (!DISABLE_NATIVE_KEYS_EXTRACTION && isNSS &&
146144
extractable && !tokenObject);
147145
this.keyIDHolder = new NativeKeyHolder(this, keyID, session,
@@ -395,8 +393,9 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm,
395393
new CK_ATTRIBUTE(CKA_EXTRACTABLE),
396394
});
397395

398-
boolean keySensitive = (attrs[0].getBoolean() ||
399-
attrs[1].getBoolean() || !attrs[2].getBoolean());
396+
boolean keySensitive =
397+
(attrs[0].getBoolean() && P11Util.isNSS(session.token)) ||
398+
attrs[1].getBoolean() || !attrs[2].getBoolean();
400399

401400
switch (algorithm) {
402401
case "RSA":

src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11Util.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ private P11Util() {
4444
// empty
4545
}
4646

47+
static boolean isNSS(Token token) {
48+
char[] tokenLabel = token.tokenInfo.label;
49+
if (tokenLabel != null && tokenLabel.length >= 3) {
50+
return (tokenLabel[0] == 'N' && tokenLabel[1] == 'S'
51+
&& tokenLabel[2] == 'S');
52+
}
53+
return false;
54+
}
55+
4756
static Provider getSunProvider() {
4857
Provider p = sun;
4958
if (p == null) {

0 commit comments

Comments
 (0)