【发布时间】:2015-11-04 08:15:36
【问题描述】:
我正在尝试通过 SSL 从 Java/Spring 4 应用程序向远程服务器上的资源发出 GET 请求。 说资源是:
我的应用程序使用https://github.com/square/okhttp 作为 HTTP 客户端来执行操作。
不幸的是,它在此资源上引发了异常;但令人惊讶的是,在其他服务器上通过 SSL 公开的其他资源上取得了成功。
这是我得到的例外:
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.8.0_51]
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154) ~[na:1.8.0_51]
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2023) ~[na:1.8.0_51]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1125) ~[na:1.8.0_51]
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_51]
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) ~[na:1.8.0_51]
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) ~[na:1.8.0_51]
at com.squareup.okhttp.internal.http.SocketConnector.connectTls(SocketConnector.java:103) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Connection.connect(Connection.java:143) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Connection.connectAndSetOwner(Connection.java:185) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.OkHttpClient$1.connectAndSetOwner(OkHttpClient.java:128) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.internal.http.HttpEngine.nextConnection(HttpEngine.java:341) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:330) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:248) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Call.getResponse(Call.java:273) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201) ~[okhttp-2.4.0.jar!/:na]
at com.squareup.okhttp.Call.execute(Call.java:81) ~[okhttp-2.4.0.jar!/:na]
at com.org.package.util.Utils.getUrlResponse(MyUtils.java:54) ~[app-0.0.1-SNAPSHOT.jar!/:na]
at com.org.package.service.impl.MyApp.uploadUrl(MyApp.java:303) [app.jar!/:na]
at com.org.package.service.impl.MyApp.uploadResource(MyApp.java:135) [app.jar!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at com.sun.proxy.$Proxy155.uploadR(Unknown Source) [na:na]
at com.org.myprocess.receiveRequest(Processor.java:42) [app.jar!/:na]
at com.org.myprocess$$FastClassBySpringCGLIB$$e05dc31.invoke(<generated>) [spring-core-4.1.7.RELEASE.jar!/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) [spring-core-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:717) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) [spring-tx-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) [spring-aop-4.1.7.RELEASE.jar!/:4.1.7.RELEASE]
at com.org.myprocess$$EnhancerBySpringCGLIB$$d16a8116.receiveRequest(<generated>) [spring-core-4.1.7.RELEASE.jar!/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:185) [spring-messaging-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:104) [spring-messaging-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMatch(AbstractMethodMessageHandler.java:447) [spring-messaging-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessageInternal(AbstractMethodMessageHandler.java:408) [spring-messaging-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.messaging.handler.invocation.AbstractMethodMessageHandler.handleMessage(AbstractMethodMessageHandler.java:346) [spring-messaging-4.1.6.RELEASE.jar!/:4.1.6.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer.executeMessage(SimpleMessageListenerContainer.java:160) [spring-cloud-aws-messaging-1.0.3.RELEASE.jar!/:1.0.3.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$MessageExecutor.run(SimpleMessageListenerContainer.java:226) [spring-cloud-aws-messaging-1.0.3.RELEASE.jar!/:1.0.3.RELEASE]
at org.springframework.cloud.aws.messaging.listener.SimpleMessageListenerContainer$SignalExecutingRunnable.run(SimpleMessageListenerContainer.java:250) [spring-cloud-aws-messaging-1.0.3.RELEASE.jar!/:1.0.3.RELEASE]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_51]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_51]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_51]
Suppressed: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
... 60 common frames omitted
我在部署了我的应用程序的机器上尝试了 curl:
curl -v https://www.remote-app/foo.pdf
回应>>>
Trying 121.1.102.15...
* Connected to www.remote-app (121.1.102.15) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* NSS error -12286 (SSL_ERROR_NO_CYPHER_OVERLAP)
* Cannot communicate securely with peer: no common encryption algorithm(s).
* Closing connection 0
curl: (35) Cannot communicate securely with peer: no common encryption algorithm(s).
但后来我尝试传递密码算法以使用它并且它有效:
curl -v --cipher ecdhe_rsa_aes_128_gcm_sha_256 https://www.remote-app/foo.pdf
回应>>>
Trying 121.1.102.15...
200 OK...
Content...
Content...
现在我的问题是如何让我的应用程序连接到可能具有不同 ssl 配置的不同 SSL 服务器。因为应用程序通过 ssl 连接到大多数资源,但不是全部。
或者我怎样才能支持更多可供不同服务器使用的密码套件? (假设这是正确的问题)
【问题讨论】:
-
看起来应该支持github.com/square/okhttp/blob/master/okhttp/src/main/java/com/…,但是master分支似乎没有
com.squareup.okhttp.internal.http.SocketConnector类。你用的是什么版本的 okhttp? -
@ptomli okhttp:2.4.0
-
看起来 okHttp 发布了 2.5.0 - mvnrepository.com/artifact/com.squareup.okhttp/okhttp 但我不确定是否是 okHttp 这就是失败点?我会尝试升级以防万一。从 2014 年开始,加密套件文件就在那里。
-
您的远程服务器是否可以公开访问?您是否尝试过对其进行 SSLLabs 分析?如果其他站点工作但它没有(尤其是你的 curl 测试结果),听起来它可能无法正确枚举其支持的密码。 ssllabs.com/ssltest
-
是的,该网站可公开访问。浏览器可以看到我试图以编程方式访问的 pdf 文件。我一直在使用 ssllabs.com 来查看远程服务器支持 4 种密码。 Here are the ciphers: TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (0xc030) ECDH 256 bits (eq. 3072 bits RSA) FS 256 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 (0xc028) ECDH 256 bits (eq. 3072 bits RSA) FS 256 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (0xc02f) ECDH 256 bits (eq. 3072 bits RSA ) FS 128 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 (0xc027) ECDH 256 位 (eq. 3072 位 RSA) FS
标签: java linux spring ssl https