< prev index next >

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

Print this page

        

@@ -195,11 +195,11 @@
         Session session = null;
         try {
             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);
         }
     }
 

@@ -217,11 +217,11 @@
         Session session = null;
         try {
             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);
         }
     }
 

@@ -247,11 +247,11 @@
         Session session = null;
         try {
             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);
         }
     }
 

@@ -261,11 +261,16 @@
             session[0] = token.getObjSession();
             CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
                 new CK_ATTRIBUTE(CKA_MODULUS),
                 new CK_ATTRIBUTE(CKA_PUBLIC_EXPONENT),
             };
+            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()
             );
             return keySpec.cast(spec);

@@ -287,11 +292,16 @@
                 new CK_ATTRIBUTE(CKA_PRIME_2),
                 new CK_ATTRIBUTE(CKA_EXPONENT_1),
                 new CK_ATTRIBUTE(CKA_EXPONENT_2),
                 new CK_ATTRIBUTE(CKA_COEFFICIENT),
             };
+            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(),
                 attributes[2].getBigInteger(),
                 attributes[3].getBigInteger(),

@@ -305,11 +315,16 @@
             session[0] = token.getObjSession();
             CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTE[] {
                 new CK_ATTRIBUTE(CKA_MODULUS),
                 new CK_ATTRIBUTE(CKA_PRIVATE_EXPONENT),
             };
+            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()
             );
             return keySpec.cast(spec);
< prev index next >