/** * Static accessor for the SSLManager object. The SSLManager is a singleton. * * @return the singleton {@link SSLManager} */ public static synchronized SSLManager getInstance() { if (null == SSLManager.manager) { SSLManager.manager = new JsseSSLManager(null); } return SSLManager.manager; }
private SSLSocketFactory getSSLSocketFactory() throws IOException { try { SSLContext sslContext = ((JsseSSLManager)SSLManager.getInstance()).getContext(); return sslContext.getSocketFactory(); } catch (GeneralSecurityException ex) { throw new IOException("Rethrown as IOE", ex); } }
/** * Create the SSLContext, and wrap all the X509KeyManagers with * our X509KeyManager so that we can choose our alias. * * @param provider * Description of Parameter */ public JsseSSLManager(Provider provider) { log.debug("ssl Provider = {}", provider); setProvider(provider); if (null == this.rand) { // Surely this is always null in the constructor? this.rand = new SecureRandom(); } try { if (SHARED_SESSION_CONTEXT) { log.debug("Creating shared context"); this.defaultContext = createContext(); } else { this.threadlocal = new ThreadLocal<>(); } HttpsURLConnection.setDefaultSSLSocketFactory(new HttpSSLProtocolSocketFactory(CPS)); HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> true); log.debug("SSL stuff all set"); } catch (GeneralSecurityException ex) { log.error("Could not set up SSLContext", ex); } log.debug("JsseSSLManager installed"); }
JmeterKeyStore keys = this.getKeyStore(); managerFactory.init(null, defaultpw == null ? new char[]{} : defaultpw.toCharArray()); KeyManager[] managers = managerFactory.getKeyManagers(); tmfactory.init(this.getTrustStore());
/** * Returns the SSLContext we are using. This is either a context per thread, * or, for backwards compatibility, a single shared context. * * @return The Context value * @throws GeneralSecurityException * when constructing the context fails */ public SSLContext getContext() throws GeneralSecurityException { if (SHARED_SESSION_CONTEXT) { if (log.isDebugEnabled()){ log.debug("Using shared SSL context for: {}", Thread.currentThread().getName()); } return this.defaultContext; } SSLContext sslContext = this.threadlocal.get(); if (sslContext == null) { if (log.isDebugEnabled()){ log.debug("Creating threadLocal SSL context for: {}", Thread.currentThread().getName()); } sslContext = createContext(); this.threadlocal.set(sslContext); } if (log.isDebugEnabled()){ log.debug("Using threadLocal SSL context for: {}", Thread.currentThread().getName()); } return sslContext; }
/** * Reset SSL State. <br/> * In order to do that we need to: * <ul> * <li>Call resetContext() on SSLManager</li> * <li>Close current Idle or Expired connections that hold SSL State</li> * <li>Remove HttpClientContext.USER_TOKEN from {@link HttpClientContext}</li> * </ul> * @param jMeterVariables {@link JMeterVariables} * @param clientContext {@link HttpClientContext} * @param mapHttpClientPerHttpClientKey Map of {@link Pair} holding {@link CloseableHttpClient} and {@link PoolingHttpClientConnectionManager} */ private void resetStateIfNeeded(JMeterVariables jMeterVariables, HttpClientContext clientContext, Map<HttpClientKey, Pair<CloseableHttpClient, PoolingHttpClientConnectionManager>> mapHttpClientPerHttpClientKey) { if (resetStateOnThreadGroupIteration.get()) { closeCurrentConnections(mapHttpClientPerHttpClientKey); clientContext.removeAttribute(HttpClientContext.USER_TOKEN); ((JsseSSLManager) SSLManager.getInstance()).resetContext(); resetStateOnThreadGroupIteration.set(false); } }