SSL 异常:“在握手期间收到 close

编程入门 行业动态 更新时间:2024-10-25 11:19:28
本文介绍了SSL 异常:“在握手期间收到 close_notify"初始化 Alexa 技能管理 API (SMAPI)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 SMAPI 与使用 Java 的 Alexa Skill 进行交互.

I am trying to use SMAPI to interact with my Alexa Skill using Java.

以下代码失败:

package io.mirko.impl; import com.amazon.ask.model.services.skillManagement.SkillManagementService; import com.amazon.ask.smapi.SmapiClients; import org.junit.jupiter.api.Test; public class IntegrationTest { // These come from `ask util generate-lwa-tokens` passing ClientID and SecretID from LWA private static final String CLIENT_ID = "<client_id>"; private static final String CLIENT_SECRET = "<client_secret>"; private static final String REFRESH_TOKEN = "<refresh_token>"; private static final String SKILL_ID = "<skill_id>"; @Test public void test() { final SkillManagementService smapiClient = SmapiClients.createDefault( CLIENT_ID, CLIENT_SECRET, REFRESH_TOKEN ); System.out.println(smapiClient.getSkillManifestV1(SKILL_ID, "developement")); } }

您可以在此链接中找到 SSL 日志失败如下:

You can find the SSL logs at this link The failure is the following:

"throwable" : { javax.ssl.SSLProtocolException: Received close_notify during handshake at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:126) at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255) at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:244) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181) at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152) at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) at com.amazon.ask.services.ApacheHttpApiClient.invoke(ApacheHttpApiClient.java:70) at com.amazon.ask.model.services.BaseServiceClient.executeRequest(BaseServiceClient.java:124) at com.amazon.ask.model.services.BaseServiceClient.invoke(BaseServiceClient.java:87) at com.amazon.ask.model.services.lwa.LwaClient.generateAccessToken(LwaClient.java:112) at com.amazon.ask.model.services.lwa.LwaClient.getAccessTokenForScope(LwaClient.java:82) at com.amazon.ask.model.services.lwa.LwaClient.getAccessTokenForRefreshToken(LwaClient.java:65) at com.amazon.ask.model.services.skillManagement.SkillManagementServiceClient.callGetSkillManifestV1(SkillManagementServiceClient.java:3484) at com.amazon.ask.model.services.skillManagement.SkillManagementServiceClient.getSkillManifestV1(SkillManagementServiceClient.java:3513) at io.mirko.impl.IntegrationTest.test(IntegrationTest.java:20) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.platformmons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)} ) javax.ssl|DEBUG|01|main|2019-12-21 12:34:44.530 CET|SSLSocketImpl.java:1361|close the underlying socket javax.ssl|DEBUG|01|main|2019-12-21 12:34:44.531 CET|SSLSocketImpl.java:1380|close the SSL connection (passive) com.amazon.ask.model.services.ServiceException: Call to service failed: There was an error executing the request at com.amazon.ask.model.services.BaseServiceClient.executeRequest(BaseServiceClient.java:126) at com.amazon.ask.model.services.BaseServiceClient.invoke(BaseServiceClient.java:87) at com.amazon.ask.model.services.lwa.LwaClient.generateAccessToken(LwaClient.java:112) at com.amazon.ask.model.services.lwa.LwaClient.getAccessTokenForScope(LwaClient.java:82) at com.amazon.ask.model.services.lwa.LwaClient.getAccessTokenForRefreshToken(LwaClient.java:65) at com.amazon.ask.model.services.skillManagement.SkillManagementServiceClient.callGetSkillManifestV1(SkillManagementServiceClient.java:3484) at com.amazon.ask.model.services.skillManagement.SkillManagementServiceClient.getSkillManifestV1(SkillManagementServiceClient.java:3513) at io.mirko.impl.IntegrationTest.test(IntegrationTest.java:20) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:566) at org.junit.platformmons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:675) at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:125) at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:132) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:124) at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:74) at org.junit.jupiter.engine.execution.ExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(ExecutableInvoker.java:115) at org.junit.jupiter.engine.execution.ExecutableInvoker.lambda$invoke$0(ExecutableInvoker.java:105) at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:104) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:62) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:43) at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:35) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:104) at org.junit.jupiter.engine.execution.ExecutableInvoker.invoke(ExecutableInvoker.java:98) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$6(TestMethodTestDescriptor.java:202) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:198) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:135) at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:69) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:135) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at java.base/java.util.ArrayList.forEach(ArrayList.java:1540) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:38) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$5(NodeTestTask.java:139) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$7(NodeTestTask.java:125) at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:135) at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:123) at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73) at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:122) at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:80) at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:32) at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57) at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:51) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:229) at org.junit.platform.launcher.core.DefaultLauncher.lambda$execute$6(DefaultLauncher.java:197) at org.junit.platform.launcher.core.DefaultLauncher.withInterceptedStreams(DefaultLauncher.java:211) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:191) at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:128) at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:69) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: java.lang.RuntimeException: There was an error executing the request at com.amazon.ask.services.ApacheHttpApiClient.invoke(ApacheHttpApiClient.java:74) at com.amazon.ask.model.services.BaseServiceClient.executeRequest(BaseServiceClient.java:124) ... 70 more Caused by: javax.ssl.SSLProtocolException: Received close_notify during handshake at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:126) at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:308) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:264) at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:255) at java.base/sun.security.ssl.Alert$AlertConsumer.consume(Alert.java:244) at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181) at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164) at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152) at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063) at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:436) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:384) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:374) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:393) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) at com.amazon.ask.services.ApacheHttpApiClient.invoke(ApacheHttpApiClient.java:70) ... 71 more Process finished with exit code 255

相比之下,以下 vanilla Java 代码运行良好,我可以获得访问令牌:

By contrast, the following vanilla Java code works perfectly and I can get the access token:

package io.mirko; import org.apache.http.HttpHost; import org.apache.http.client.protocol.HttpClientContext; import org.apache.http.conn.ssl.SSLConnectionSocketFactory; import org.apache.http.protocol.BasicHttpContext; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; import java.io.DataOutputStream; import java.HttpURLConnection; import java.InetSocketAddress; import java.Socket; import java.URL; import java.nio.charset.StandardCharsets; public class Main { private static final String HOST = "api.amazon"; private static final String URL = String.format("%s/auth/O2/token", HOST); private static final String URL_PARAMETERS = "grant_type=refresh_token&client_id=<client_id>&client_secret=<client_secret>&refresh_token=<refresh_token>"; private static String connectVanillaJava() throws Exception { byte[] postData = URL_PARAMETERS.getBytes( StandardCharsets.UTF_8 ); int postDataLength = postData.length; URL url = new URL(URL); HttpURLConnection conn= (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setInstanceFollowRedirects(false); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); conn.setRequestProperty("charset", "utf-8"); conn.setRequestProperty("Content-Length", Integer.toString(postDataLength )); conn.setUseCaches(false); try(DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) { wr.write( postData ); } DataInputStream is = new DataInputStream(conn.getInputStream()); byte[] data = new byte[32768]; final ByteArrayOutputStream os = new ByteArrayOutputStream(); for (int i = is.read(data); i > 0; i = is.read(data)) { os.write(data, 0, i); } return new String(os.toByteArray()); } public static void main(String ... args) throws Exception { System.out.print("Test Vanilla Java..."); final String vanillaJavaResult = connectVanillaJava(); System.out.format("SUCCESS! Returned %s ", vanillaJavaResult); } }

您可以在此处获取 SSL 日志以及返回的响应,

You can get here the SSL logs, together with th returned response,

我能看到的主要区别是,在 Produced client Finished handshake message 之后,在第一种情况下,超过 10 秒后,我收到错误,而在工作示例中,我收到 消费服务器完成握手消息.

The main difference I can see is that, after Produced client Finished handshake message, in the first case, after more than 10 seconds, I receive the error, whereas in the working example I receive Consuming server Finished handshake message.

感谢您的帮助.

附言基于 SSL 日志的差异,似乎是中断的交互从 api.amazonalexa 接收 SSL 证书,这是 DOWN.通过在浏览中访问该主机,我收到 此消息.它说该网站暂时不可用.我已经使用该主机修改了工作示例,但似乎出现了相同的错误.

P.S. Based on the SSL logs differences, it seems to be that the broken interaction receives SSL certificates from api.amazonalexa, which is DOWN. By accessing that host in a browse, I receive this message. It says that the website is temporary unavailable. I have modified the working example by using that host and it seems to be that I get the same error.

P.P.S.我设法通过使用 api.amazon 创建 LWAClient 来获取身份验证令牌.与 api.amazonalexa 的任何交互都会引发上述问题.

P.P.S. I managed to get the authentication token by creating an LWAClient using api.amazon. Any interaction with api.amazonalexa raises the above issue.

inal LwaClient lwaClient = LwaClient.builder() .withAuthenticationConfiguration( DefaultAuthenticationConfiguration.builder() .withClientSecret(CLIENT_SECRET) .withClientId(CLIENT_ID) .withRefreshToken(REFRESH_TOKEN) .build() ) .withGrantType(GrantType.REFRESH_TOKEN) .withApiConfiguration(DefaultApiConfiguration.builder() .withApiClient(apiConfiguration.getApiClient()) // Without this, it does not work .withApiEndpoint("api.amazon") .withSerializer(apiConfiguration.getSerializer()) .build()) .build(); final SkillManagementServiceClient myClient = new SkillManagementServiceClient( apiConfiguration, lwaClient); // This WORKS System.out.println(lwaClient.getAccessTokenForRefreshToken());

推荐答案

最后我设法解决了这个问题.通过在调试模式下运行代码,可以捕获将要运行的与问题相关的请求.如果您使用 curl 调用该请求,您会立即收到一个错误不言自明:

In the end I managed to solve the issue. By running the code in debug mode, it is possible to catch the request that is going to be run and that is related to the issue. If you invoke that request using curl, you receive immediately an error that is self-explained:

curl -vvv -X POST -H "Content-Type: application/json" -H "Authorization: Bearer Atza|XXXXX" -d "{}" api.amazonalexa/v1/skills/<skill_id>/simulations Note: Unnecessary use of -X or --request, POST is already inferred. * Trying 143.204.11.219... * TCP_NODELAY set * Connected to api.amazonalexa (143.204.11.219) port 443 (#0) * ALPN, offering h2 * ALPN, offering http/1.1 * successfully set certificate verify locations: * CAfile: /etc/ssl/certs/ca-certificates.crt CApath: /etc/ssl/certs * TLSv1.3 (OUT), TLS handshake, Client hello (1): * TLSv1.3 (IN), TLS handshake, Server hello (2): * TLSv1.2 (IN), TLS handshake, Certificate (11): * TLSv1.2 (IN), TLS handshake, Server key exchange (12): * TLSv1.2 (IN), TLS handshake, Server finished (14): * TLSv1.2 (OUT), TLS handshake, Client key exchange (16): * TLSv1.2 (OUT), TLS change cipher, Client hello (1): * TLSv1.2 (OUT), TLS handshake, Finished (20): * TLSv1.2 (IN), TLS handshake, Finished (20): * SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256 * ALPN, server accepted to use h2 * Server certificate: * subject: CN=api.amazonalexa * start date: May 3 00:00:00 2019 GMT * expire date: Apr 26 12:00:00 2020 GMT * subjectAltName: host "api.amazonalexa" matched cert's "api.amazonalexa" * issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon * SSL certificate verify ok. * Using HTTP2, server supports multi-use * Connection state changed (HTTP/2 confirmed) * Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0 * Using Stream ID: 1 (easy handle 0x55ba1fa314b0) > POST /v1/skills/<skill_id>/simulations HTTP/2 > Host: api.amazonalexa > User-Agent: curl/7.58.0 > Accept: */* > Content-Type: application/json > Authorization: Bearer Atza|xxxxx > Content-Length: 2 > * Connection state changed (MAX_CONCURRENT_STREAMS updated)! * We are completely uploaded and fine < HTTP/2 400 < content-type: application/json < content-length: 110 < server: Server < date: Thu, 26 Dec 2019 15:53:04 GMT < x-amzn-requestid: 300413fa-09db-4a13-95a7-a4749ef5130a < x-amz-date: Thu, 26 Dec 2019 15:53:04 GMT < vary: Accept-Encoding,X-Amzn-CDN-Cache,X-Amzn-AX-Treatment,User-Agent < x-amz-rid: 4TW7K1A311QVNFQ8M6BJ < x-cache: Error from cloudfront < via: 1.1 1a3a682cf8d843fe52f3224f60584fad.cloudfront (CloudFront) < x-amz-cf-pop: MXP64-C1 < x-amz-cf-id: djdsKqkXYy8BOzvhZyD9G2iUXa8NeLscxBi45x4fs6EUc3C6tOrD6Q== < * Connection #0 to host api.amazonalexa left intact {"message":"Invalid request payload. Please ensure that the request payload has all required fields present."}

我不明白为什么 Java 库会卡在这种情况下.

What I do not understand is why the Java library gets stuck in such cases.

总而言之,我的问题解决了.

更多推荐

SSL 异常:“在握手期间收到 close

本文发布于:2023-11-28 07:37:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641501.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   SSL   close

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!