Code example for SSLContext

Methods: createSSLEngineinit

0
    } 
    
    protected void doStart() throws Exception 
    { 
        _context=createSSLContext();
        SSLEngine engine=_context.createSSLEngine();
        SSLSession session=engine.getSession();
        if (getHeaderBufferSize()<session.getApplicationBufferSize())
            setHeaderBufferSize(session.getApplicationBufferSize());
        if (getRequestBufferSize()<session.getApplicationBufferSize())
            setRequestBufferSize(session.getApplicationBufferSize());
        super.doStart(); 
    } 
 
    protected SSLContext createSSLContext() throws Exception
    { 
        if (_truststore==null)
        { 
            _truststore=_keystore;
            _truststoreType=_keystoreType;
        } 
 
        InputStream keystoreInputStream = null;
 
        KeyManager[] keyManagers=null;
        KeyStore keyStore = null;
        try 
        { 
            if (_keystore!=null)
            { 
                keystoreInputStream=Resource.newResource(_keystore).getInputStream();
                keyStore = KeyStore.getInstance(_keystoreType);
                keyStore.load(keystoreInputStream,_password==null?null:_password.toString().toCharArray());
            } 
        } 
        finally 
        { 
            if (keystoreInputStream != null)
                keystoreInputStream.close();
        } 
 
        KeyManagerFactory keyManagerFactory=KeyManagerFactory.getInstance(_sslKeyManagerFactoryAlgorithm);
        keyManagerFactory.init(keyStore,_keyPassword==null?(_password==null?null:_password.toString().toCharArray()):_keyPassword.toString().toCharArray());
        keyManagers=keyManagerFactory.getKeyManagers();
 
 
        TrustManager[] trustManagers=null;
        InputStream truststoreInputStream = null;
        KeyStore trustStore = null;
        try 
        { 
            if (_truststore!=null)
            { 
                truststoreInputStream = Resource.newResource(_truststore).getInputStream();
                trustStore=KeyStore.getInstance(_truststoreType);
                trustStore.load(truststoreInputStream,_trustPassword==null?null:_trustPassword.toString().toCharArray());
            } 
        } 
        finally 
        { 
            if (truststoreInputStream != null)
                truststoreInputStream.close();
        } 
 
 
        TrustManagerFactory trustManagerFactory=TrustManagerFactory.getInstance(_sslTrustManagerFactoryAlgorithm);
        trustManagerFactory.init(trustStore);
        trustManagers=trustManagerFactory.getTrustManagers();
 
        SecureRandom secureRandom=_secureRandomAlgorithm==null?null:SecureRandom.getInstance(_secureRandomAlgorithm);
        SSLContext context=_provider==null?SSLContext.getInstance(_protocol):SSLContext.getInstance(_protocol,_provider);
        context.init(keyManagers,trustManagers,secureRandom);
        return context;
    } 
 
    /** 
     * Simple bundle of information that is cached in the SSLSession. Stores the 
Contextual code suggestions in your IDE  Get Codota for Java