【问题标题】:HttpURLConnection SSL handshake aborted with AWS signed URL redirectHttpURLConnection SSL 握手因 AWS 签名 URL 重定向而中止
【发布时间】:2016-04-08 00:55:04
【问题描述】:

我正在尝试使用 Android 的 HttpURLConnection 从 Amazon S3 服务器下载文件,但遇到 SSLException。我们的服务器是运行在 Nginx 后面的 Node.js 服务器(Hapi)。该应用程序从我们的服务器请求文件,它以 302 重定向回复到 S3 服务器上资源的签名 URL。使用重定向回复的代码是:

        var params = {
            Bucket: bucketID, 
            Key: fullPath
        };
        var s3 = new AWS.S3({ apiVersion: '2006-03-01' });
        s3.getSignedUrl('getObject', params, function (err, url)
        {
            if (err || !url)
            {
                return reply(Boom.notFound());
            }

            return reply.redirect(url);

        });

使用浏览器或 curl 可以正常工作并正确重定向到 S3 并下载文件,但在使用 HttpURLConnection 的 Android 上(同样的问题也发生在 HttpClient 上),我得到一个 SSLException:

javax.net.ssl.SSLException: SSL handshake aborted: ssl=0x7148d680: I/O error during system call, Connection reset by peer

知道是什么原因造成的吗?

【问题讨论】:

    标签: android ssl nginx amazon-s3 hapijs


    【解决方案1】:

    没关系 - 应用支持的 TLS 版本与服务器支持的版本不匹配。服务器是为 TLSv1.1 和 TLSv1.2 设置的,我猜默认情况下 HttpURLConnection 和 HttpClient 是为 TLSv1.0 设置的。我已更改为 HttpClient,因此添加以下代码解决了问题:

            SSLContext sslContext = SSLContexts.createDefault();
            SSLConnectionSocketFactory sslConnectionSocketFactory = new SSLConnectionSocketFactory(sslContext,
                                                                              new String[]{"TLSv1.1", "TLSv1.2"},
                                                                              null,
                                                                              new NoopHostnameVerifier());
            CloseableHttpClient client = HttpClientBuilder.create()
                    .setDefaultCookieStore(cookieStore)
                    .setSSLSocketFactory(sslConnectionSocketFactory)
                    .build();
    

    【讨论】:

      猜你喜欢
      • 2015-04-06
      • 2017-01-27
      • 2016-03-22
      • 2016-04-01
      • 2016-06-20
      • 2016-04-02
      • 2015-09-02
      • 1970-01-01
      • 2016-10-19
      相关资源
      最近更新 更多