Skip to content

Commit 338cf0d

Browse files
author
Bob Du
committed
8325254: CKA_TOKEN private and secret keys are not necessarily sensitive
Backporting a fix from OpenJDK in advance that changes the sensitivity check for a key to only include CKA_TOKEN if it's using NSS. Signed-off-by: Bob Du <[email protected]>
1 parent bf83787 commit 338cf0d

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,9 @@ static PrivateKey privateKey(Session session, long keyID, String algorithm,
422422
new CK_ATTRIBUTE(CKA_EXTRACTABLE),
423423
});
424424

425-
boolean keySensitive = (attrs[0].getBoolean() ||
426-
attrs[1].getBoolean() || !attrs[2].getBoolean());
425+
boolean keySensitive =
426+
(attrs[0].getBoolean() && P11Util.isNSS(session.token)) ||
427+
attrs[1].getBoolean() || !attrs[2].getBoolean();
427428

428429
if (keySensitive && (SunPKCS11.mysunpkcs11 != null) && "RSA".equals(algorithm)) {
429430
try {

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)