--- a/jdk/src/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java Fri Sep 06 13:36:33 2013 +0100
+++ b/jdk/src/share/classes/sun/security/pkcs11/P11TlsRsaPremasterSecretGenerator.java Sat Sep 07 20:27:20 2013 -0700
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -88,23 +88,33 @@
throw new IllegalStateException
("TlsRsaPremasterSecretGenerator must be initialized");
}
- CK_VERSION version =
- new CK_VERSION(spec.getMajorVersion(), spec.getMinorVersion());
- Session session = null;
- try {
- session = token.getObjSession();
- CK_ATTRIBUTE[] attributes = token.getAttributes
- (O_GENERATE, CKO_SECRET_KEY, CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]);
- long keyID = token.p11.C_GenerateKey
- (session.id(), new CK_MECHANISM(mechanism, version), attributes);
- SecretKey key = P11Key.secretKey
- (session, keyID, "TlsRsaPremasterSecret", 48 << 3, attributes);
- return key;
- } catch (PKCS11Exception e) {
- throw new ProviderException("Could not generate premaster secret", e);
- } finally {
- token.releaseSession(session);
+
+ byte[] b = spec.getEncodedSecret();
+ if (b == null) {
+ CK_VERSION version = new CK_VERSION(
+ spec.getMajorVersion(), spec.getMinorVersion());
+ Session session = null;
+ try {
+ session = token.getObjSession();
+ CK_ATTRIBUTE[] attributes = token.getAttributes(
+ O_GENERATE, CKO_SECRET_KEY,
+ CKK_GENERIC_SECRET, new CK_ATTRIBUTE[0]);
+ long keyID = token.p11.C_GenerateKey(session.id(),
+ new CK_MECHANISM(mechanism, version), attributes);
+ SecretKey key = P11Key.secretKey(session,
+ keyID, "TlsRsaPremasterSecret", 48 << 3, attributes);
+ return key;
+ } catch (PKCS11Exception e) {
+ throw new ProviderException(
+ "Could not generate premaster secret", e);
+ } finally {
+ token.releaseSession(session);
+ }
}
+
+ // Won't worry, the TlsRsaPremasterSecret will be soon converted to
+ // TlsMasterSecret.
+ return new SecretKeySpec(b, "TlsRsaPremasterSecret");
}
}