javax.net.ssl.SSLException: Certificate doesn't match any of the subject alternative names

前端 未结 5 872
攒了一身酷
攒了一身酷 2020-12-29 13:36

I recently added LetsEncrypt certificates to my server and my java applet is having problems connecting using TLS.

My applet uses Apache HttpClient.

My web s

5条回答
  •  無奈伤痛
    2020-12-29 14:09

    /*
     * Inner class for Proxy SSL Socket Connection.
     */
    static class MyConnectionSocketFactory extends SSLConnectionSocketFactory {
        private String proxyHost = null;
        private Integer proxyPort = null;
    
        public MyConnectionSocketFactory(final SSLContext sslContext, String proxyHost, Integer proxyPort) {
            super(sslContext, new NoopHostnameVerifier());
            this.proxyHost = proxyHost;
            this.proxyPort = proxyPort;
        }
    
        @Override
        public Socket createSocket(final HttpContext context) throws IOException {
            logger.debug("Create Socket:" + " ProxyHost: " + proxyHost + ", ProxyPort: " + proxyPort);
            InetSocketAddress socksaddr = new InetSocketAddress(proxyHost,proxyPort);
            Proxy proxy = new Proxy(Proxy.Type.SOCKS, socksaddr);
            return new Socket(proxy);
        }
    }
    
    
       else if (proxyType.equalsIgnoreCase("socks")) {
            logger.debug("Proxy Type: " + proxyType);
            TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
                @Override
                public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
                    return true;
                }
            };
    
            SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
                    .loadTrustMaterial(null, acceptingTrustStrategy)
                    .build();
            SSLConnectionSocketFactory csf = new MyConnectionSocketFactory(sslContext, proxyHost, proxyPort);
            CloseableHttpClient httpClient = HttpClients.custom()
                    .setSSLSocketFactory(csf)
                    .build();
            HttpComponentsClientHttpRequestFactory requestFactory =
                    new HttpComponentsClientHttpRequestFactory();
            requestFactory.setHttpClient(httpClient);
            restTemplate = new RestTemplate(requestFactory);
            return;
        } else {
    

提交回复
热议问题