--- old/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSAKeyFactory.java 2018-06-04 19:27:25.496715017 -0300 +++ new/src/jdk.crypto.cryptoki/share/classes/sun/security/pkcs11/P11RSAKeyFactory.java 2018-06-04 19:27:25.344713937 -0300 @@ -197,7 +197,7 @@ session = token.getObjSession(); long keyID = token.p11.C_CreateObject(session.id(), attributes); return P11Key.publicKey - (session, keyID, "RSA", n.bitLength(), attributes); + (session, keyID, "RSA", n.bitLength(), attributes, true); } finally { token.releaseSession(session); } @@ -219,7 +219,7 @@ session = token.getObjSession(); long keyID = token.p11.C_CreateObject(session.id(), attributes); return P11Key.privateKey - (session, keyID, "RSA", n.bitLength(), attributes); + (session, keyID, "RSA", n.bitLength(), attributes, true); } finally { token.releaseSession(session); } @@ -249,7 +249,7 @@ session = token.getObjSession(); long keyID = token.p11.C_CreateObject(session.id(), attributes); return P11Key.privateKey - (session, keyID, "RSA", n.bitLength(), attributes); + (session, keyID, "RSA", n.bitLength(), attributes, true); } finally { token.releaseSession(session); } @@ -263,7 +263,12 @@ new CK_ATTRIBUTE(CKA_MODULUS), new CK_ATTRIBUTE(CKA_PUBLIC_EXPONENT), }; - token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + key.incNativeKeyRef(); + try { + token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + } finally { + key.decNativeKeyRef(); + } KeySpec spec = new RSAPublicKeySpec( attributes[0].getBigInteger(), attributes[1].getBigInteger() @@ -289,7 +294,12 @@ new CK_ATTRIBUTE(CKA_EXPONENT_2), new CK_ATTRIBUTE(CKA_COEFFICIENT), }; - token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + key.incNativeKeyRef(); + try { + token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + } finally { + key.decNativeKeyRef(); + } KeySpec spec = new RSAPrivateCrtKeySpec( attributes[0].getBigInteger(), attributes[1].getBigInteger(), @@ -307,7 +317,12 @@ new CK_ATTRIBUTE(CKA_MODULUS), new CK_ATTRIBUTE(CKA_PRIVATE_EXPONENT), }; - token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + key.incNativeKeyRef(); + try { + token.p11.C_GetAttributeValue(session[0].id(), key.keyID, attributes); + } finally { + key.decNativeKeyRef(); + } KeySpec spec = new RSAPrivateKeySpec( attributes[0].getBigInteger(), attributes[1].getBigInteger()