Search in sources :

Example 51 with SSLSession

use of javax.net.ssl.SSLSession in project ORCID-Source by ORCID.

the class OrcidJerseyT2ClientOAuthConfig method afterPropertiesSet.

@Override
public void afterPropertiesSet() throws Exception {
    SSLContext ctx = createSslContext();
    HttpsURLConnection.setDefaultSSLSocketFactory(ctx.getSocketFactory());
    getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(new HostnameVerifier() {

        @Override
        public boolean verify(String s, SSLSession sslSession) {
            return true;
        }
    }, ctx));
}
Also used : SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) HTTPSProperties(com.sun.jersey.client.urlconnection.HTTPSProperties) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 52 with SSLSession

use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.

the class JSSEClient method runTest.

@Override
void runTest(CipherTestUtils.TestParameters params) throws Exception {
    SSLSocket socket = null;
    try {
        System.out.println("Connecting to server...");
        keyManager.setAuthType(params.clientAuth);
        sslContext.init(new KeyManager[] { keyManager }, new TrustManager[] { cipherTest.getClientTrustManager() }, CipherTestUtils.secureRandom);
        SSLSocketFactory factory = (SSLSocketFactory) sslContext.getSocketFactory();
        socket = (SSLSocket) factory.createSocket(serverHost, serverPort);
        socket.setSoTimeout(CipherTestUtils.TIMEOUT);
        socket.setEnabledCipherSuites(params.cipherSuite.split(","));
        if (params.protocol != null && !params.protocol.trim().equals("") && !params.protocol.trim().equals(DEFAULT)) {
            socket.setEnabledProtocols(params.protocol.split(","));
        }
        CipherTestUtils.printInfo(socket);
        InputStream in = socket.getInputStream();
        OutputStream out = socket.getOutputStream();
        sendRequest(in, out);
        SSLSession session = socket.getSession();
        session.invalidate();
        String cipherSuite = session.getCipherSuite();
        if (params.cipherSuite.equals(cipherSuite) == false) {
            throw new RuntimeException("Negotiated ciphersuite mismatch: " + cipherSuite + " != " + params.cipherSuite);
        }
        String protocol = session.getProtocol();
        if (!DEFAULT.equals(params.protocol) && !params.protocol.contains(protocol)) {
            throw new RuntimeException("Negotiated protocol mismatch: " + protocol + " != " + params.protocol);
        }
        if (!cipherSuite.contains("DH_anon")) {
            session.getPeerCertificates();
        }
        Certificate[] certificates = session.getLocalCertificates();
        if (params.clientAuth == null) {
            if (certificates != null) {
                throw new RuntimeException("Local certificates " + "should be null");
            }
        } else {
            if ((certificates == null) || (certificates.length == 0)) {
                throw new RuntimeException("Certificates missing");
            }
            String keyAlg = certificates[0].getPublicKey().getAlgorithm();
            if ("EC".equals(keyAlg)) {
                keyAlg = "ECDSA";
            }
            if (params.clientAuth == null ? keyAlg != null : !params.clientAuth.equals(keyAlg)) {
                throw new RuntimeException("Certificate type mismatch: " + keyAlg + " != " + params.clientAuth);
            }
        }
    } finally {
        if (socket != null) {
            socket.close();
        }
    }
}
Also used : InputStream(java.io.InputStream) SSLSocket(javax.net.ssl.SSLSocket) OutputStream(java.io.OutputStream) SSLSession(javax.net.ssl.SSLSession) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Certificate(java.security.cert.Certificate)

Example 53 with SSLSession

use of javax.net.ssl.SSLSession in project jdk8u_jdk by JetBrains.

the class AcceptLargeFragments method main.

public static void main(String[] args) throws Exception {
    SSLContext context = SSLContext.getDefault();
    // set the property before initialization SSLEngine.
    System.setProperty("jsse.SSLEngine.acceptLargeFragments", "true");
    SSLEngine cliEngine = context.createSSLEngine();
    cliEngine.setUseClientMode(true);
    SSLEngine srvEngine = context.createSSLEngine();
    srvEngine.setUseClientMode(false);
    SSLSession cliSession = cliEngine.getSession();
    SSLSession srvSession = srvEngine.getSession();
    // check packet buffer sizes.
    if (cliSession.getPacketBufferSize() < 33049 || srvSession.getPacketBufferSize() < 33049) {
        throw new Exception("Don't accept large SSL/TLS fragments");
    }
    // check application data buffer sizes.
    if (cliSession.getApplicationBufferSize() < 32768 || srvSession.getApplicationBufferSize() < 32768) {
        throw new Exception("Don't accept large SSL/TLS application data ");
    }
}
Also used : SSLEngine(javax.net.ssl.SSLEngine) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext)

Example 54 with SSLSession

use of javax.net.ssl.SSLSession in project undertow by undertow-io.

the class JettyAlpnProvider method getSelectedProtocol.

@Override
public String getSelectedProtocol(SSLEngine engine) {
    SSLSession handshake = engine.getHandshakeSession();
    if (handshake != null) {
        return (String) handshake.getValue(PROTOCOL_KEY);
    }
    handshake = engine.getSession();
    if (handshake != null) {
        return (String) handshake.getValue(PROTOCOL_KEY);
    }
    return null;
}
Also used : SSLSession(javax.net.ssl.SSLSession)

Example 55 with SSLSession

use of javax.net.ssl.SSLSession in project pictureapp by EyeSeeTea.

the class UnsafeOkHttpsClientFactory method getUnsafeOkHttpClient.

public static OkHttpClient getUnsafeOkHttpClient() {
    try {
        // Create a trust manager that does not validate certificate chains
        final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {

            @Override
            public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
            }

            @Override
            public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
            }

            @Override
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }
        } };
        // Install the all-trusting trust manager
        final SSLContext sslContext = SSLContext.getInstance("SSL");
        sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
        // Create an ssl socket factory with our all-trusting manager
        final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
        OkHttpClient okHttpClient = new OkHttpClient();
        okHttpClient.setSslSocketFactory(sslSocketFactory);
        okHttpClient.setHostnameVerifier(new HostnameVerifier() {

            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        });
        return okHttpClient;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) SSLSession(javax.net.ssl.SSLSession) SSLContext(javax.net.ssl.SSLContext) CertificateException(java.security.cert.CertificateException) X509TrustManager(javax.net.ssl.X509TrustManager) TrustManager(javax.net.ssl.TrustManager) HostnameVerifier(javax.net.ssl.HostnameVerifier) X509TrustManager(javax.net.ssl.X509TrustManager) SSLSocketFactory(javax.net.ssl.SSLSocketFactory)

Aggregations

SSLSession (javax.net.ssl.SSLSession)187 HostnameVerifier (javax.net.ssl.HostnameVerifier)50 SSLSocket (javax.net.ssl.SSLSocket)34 X509Certificate (java.security.cert.X509Certificate)32 IOException (java.io.IOException)31 SSLContext (javax.net.ssl.SSLContext)30 Test (org.junit.Test)29 CertificateException (java.security.cert.CertificateException)27 Certificate (java.security.cert.Certificate)20 SSLException (javax.net.ssl.SSLException)17 X509TrustManager (javax.net.ssl.X509TrustManager)16 URL (java.net.URL)14 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)14 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)14 TrustManager (javax.net.ssl.TrustManager)14 SecureRandom (java.security.SecureRandom)13 FakeSSLSession (okhttp3.FakeSSLSession)13 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)12 InputStream (java.io.InputStream)11 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11