【问题标题】:apache httpclient use https proxy: peer not authenticatedapache httpclient 使用 https 代理:对等体未通过身份验证
【发布时间】:2014-02-23 19:44:08
【问题描述】:

我正在尝试将 hidemyass.com (https://hidemyass.com/proxy-list/search-225434) 上的免费 https-proxy-servers 大列表之一与 apache httpclient 4.1 一起使用。我现在几乎尝试了所有这些,但我总是得到 javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated 所以我google了一下,发现没有服务器有对等证书,例如:

> 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/

【问题讨论】:

    标签: java ssl proxy apache-httpclient-4.x


    【解决方案1】:

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

    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
    httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2014-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多