SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0

前端 未结 17 2830
栀梦
栀梦 2020-11-22 06:35

I upgraded from Java 1.6 to Java 1.7 today. Since then an error occur when I try to establish a connection to my webserver over SSL:

javax.net.ssl.SSLProtoco         


        
17条回答
  •  遥遥无期
    2020-11-22 06:57

    If you are building a client with Resttemplate, you can only set the endpoint like this: https://IP/path_to_service and set the requestFactory.
    With this solution you don't need to RESTART your TOMCAT or Apache:

    public static HttpComponentsClientHttpRequestFactory requestFactory(CloseableHttpClient httpClient) {
        TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
            @Override
            public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
                return true;
            }
        };
    
        SSLContext sslContext = null;
        try {
            sslContext = org.apache.http.ssl.SSLContexts.custom()
                    .loadTrustMaterial(null, acceptingTrustStrategy)
                    .build();
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }   
    
        HostnameVerifier hostnameVerifier = new HostnameVerifier() {
            @Override
            public boolean verify(String hostname, SSLSession session) {
                return true;
            }
        };
    
        final SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext,hostnameVerifier);
    
        final Registry registry = RegistryBuilder.create()
                .register("http", new PlainConnectionSocketFactory())
                .register("https", csf)
                .build();
    
        final PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(registry);
        cm.setMaxTotal(100);
        httpClient = HttpClients.custom()
                .setSSLSocketFactory(csf)
                .setConnectionManager(cm)
                .build();
    
        HttpComponentsClientHttpRequestFactory requestFactory =
                new HttpComponentsClientHttpRequestFactory();
    
        requestFactory.setHttpClient(httpClient);
    
        return requestFactory;
    }
    

提交回复
热议问题