apache httpclient use https proxy: peer not authenticated



我正在尝试使用 hidemyass.com(https://hidemyass.com/proxy-list/search-225434)上的免费https-proxy-servers大列表之一与Apache httpclient 4.1。 我现在几乎尝试了所有这些,但我总是得到javax.net.ssl.SSLPeerUnverifiedException:对等方未经过身份验证所以我用谷歌搜索发现没有服务器有对等证书,例如:

> openssl s_client -tls1 -showcerts -connect 109.75.178.230:3128  
CONNECTED(00000003)
139856907785896:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:337:
no peer certificate available
No client certificate CA names sent
SSL handshake has read 5 bytes and written 7 bytes
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
SSL-Session:
    Protocol  : TLSv1
    Cipher    : 0000
    Session-ID: 
    Session-ID-ctx: 
    Master-Key: 
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1393183549
    Timeout   : 7200 (sec)
    Verify return code: 0 (ok)

当我尝试在同一端口上切换到HTTP时,它可以工作,但是在Hidemyass的代理列表中,类型是HTTPS。 所以我不知道现在该怎么办...请帮忙。

如果你需要看看我的代码:http://paste.debian.net/83674/

因此,

如果您没问题,您可以信任以下所有证书

final TrustStrategy trustStrategy = new TrustStrategy() {
        @Override
        public boolean isTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
            return true;
        }
    };
    SSLContext sslcontext = null;
    try {
        sslcontext = SSLContexts.custom().loadTrustMaterial(null, trustStrategy).build();
    } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    socketFactory = new SSLConnectionSocketFactory(sslcontext, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

然后使用

httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();

这将确保所有https调用的证书都是受信任的但请确保您只调用受信任的站点

最新更新