< prev index next >

src/java.base/share/classes/sun/security/ssl/EphemeralKeyManager.java

Print this page

        

*** 24,34 **** */ package sun.security.ssl; import java.security.*; - import java.util.concurrent.locks.ReentrantLock; /** * The "KeyManager" for ephemeral RSA keys. Ephemeral DH and ECDH keys * are handled by the DHCrypt and ECDHCrypt classes, respectively. * --- 24,33 ----
*** 47,58 **** private final EphemeralKeyPair[] keys = new EphemeralKeyPair[] { new EphemeralKeyPair(null), new EphemeralKeyPair(null), }; - private final ReentrantLock cachedKeysLock = new ReentrantLock(); - EphemeralKeyManager() { // empty } /* --- 46,55 ----
*** 66,101 **** } else { length = 1024; index = INDEX_RSA1024; } ! KeyPair kp = keys[index].getKeyPair(); ! if (kp != null) { ! return kp; ! } ! ! cachedKeysLock.lock(); ! try { ! // double check ! kp = keys[index].getKeyPair(); ! if (kp != null) { ! return kp; } ! ! try { ! KeyPairGenerator kgen = KeyPairGenerator.getInstance("RSA"); ! kgen.initialize(length, random); ! keys[index] = new EphemeralKeyPair(kgen.genKeyPair()); ! kp = keys[index].getKeyPair(); ! } catch (Exception e) { ! // ignore ! } ! } finally { ! cachedKeysLock.unlock(); } - - return kp; } /** * Inner class to handle storage of ephemeral KeyPairs. */ --- 63,86 ---- } else { length = 1024; index = INDEX_RSA1024; } ! synchronized (keys) { ! KeyPair kp = keys[index].getKeyPair(); ! if (kp == null) { ! try { ! KeyPairGenerator kgen = KeyPairGenerator.getInstance("RSA"); ! kgen.initialize(length, random); ! keys[index] = new EphemeralKeyPair(kgen.genKeyPair()); ! kp = keys[index].getKeyPair(); ! } catch (Exception e) { ! // ignore ! } } ! return kp; } } /** * Inner class to handle storage of ephemeral KeyPairs. */
< prev index next >