< prev index next >

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

Print this page




 107     }
 108 
 109     // Only can be used in client side to generate TLS RSA premaster secret.
 110     protected SecretKey engineGenerateKey() {
 111         if (spec == null) {
 112             throw new IllegalStateException
 113                         ("TlsRsaPremasterSecretGenerator must be initialized");
 114         }
 115 
 116         CK_VERSION version = new CK_VERSION(
 117                         spec.getMajorVersion(), spec.getMinorVersion());
 118         Session session = null;
 119         try {
 120             session = token.getObjSession();
 121             CK_ATTRIBUTE[] attributes = token.getAttributes(
 122                     O_GENERATE, CKO_SECRET_KEY,
 123                     CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]);
 124             long keyID = token.p11.C_GenerateKey(session.id(),
 125                     new CK_MECHANISM(mechanism, version), attributes);
 126             SecretKey key = P11Key.secretKey(session,
 127                     keyID, "TlsRsaPremasterSecret", 48 << 3, attributes);
 128             return key;
 129         } catch (PKCS11Exception e) {
 130             throw new ProviderException(
 131                     "Could not generate premaster secret", e);
 132         } finally {
 133             token.releaseSession(session);
 134         }
 135     }
 136 
 137 }


 107     }
 108 
 109     // Only can be used in client side to generate TLS RSA premaster secret.
 110     protected SecretKey engineGenerateKey() {
 111         if (spec == null) {
 112             throw new IllegalStateException
 113                         ("TlsRsaPremasterSecretGenerator must be initialized");
 114         }
 115 
 116         CK_VERSION version = new CK_VERSION(
 117                         spec.getMajorVersion(), spec.getMinorVersion());
 118         Session session = null;
 119         try {
 120             session = token.getObjSession();
 121             CK_ATTRIBUTE[] attributes = token.getAttributes(
 122                     O_GENERATE, CKO_SECRET_KEY,
 123                     CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]);
 124             long keyID = token.p11.C_GenerateKey(session.id(),
 125                     new CK_MECHANISM(mechanism, version), attributes);
 126             SecretKey key = P11Key.secretKey(session,
 127                     keyID, "TlsRsaPremasterSecret", 48 << 3, attributes, true);
 128             return key;
 129         } catch (PKCS11Exception e) {
 130             throw new ProviderException(
 131                     "Could not generate premaster secret", e);
 132         } finally {
 133             token.releaseSession(session);
 134         }
 135     }
 136 
 137 }
< prev index next >