簡體   English   中英

嘗試從Java客戶端建立SSL連接時出錯

[英]Error trying to establish SSL connection from java client

我正在嘗試建立從獨立的Java客戶端到apache服務器的ssl連接。 在ssl握手階段出現錯誤。 使用curl訪問相同的rest API可以正常工作。

我在服務器端遇到的錯誤:

d Apr 08 18:26:27 2015] [info] [client 192.168.100.250] Connection to child 1 established (server vcops-slice-1:443)
[Wed Apr 08 18:26:27 2015] [info] Seeding PRNG with 144 bytes of entropy
[Wed Apr 08 18:26:27 2015] [debug] ssl_engine_kernel.c(1931): OpenSSL: Handshake: start
[Wed Apr 08 18:26:27 2015] [debug] ssl_engine_kernel.c(1939): OpenSSL: Loop: before/accept initialization
[Wed Apr 08 18:26:37 2015] [info] [client 192.168.100.250] Request header read timeout
[Wed Apr 08 18:26:37 2015] [debug] ssl_engine_io.c(1904): OpenSSL: I/O error, 11 bytes expected to read on BIO#7f998f3c9630 [
mem: 7f998f3b7ad0]
[Wed Apr 08 18:26:37 2015] [debug] ssl_engine_kernel.c(1968): OpenSSL: Exit: error in SSLv2/v3 read client hello A
[Wed Apr 08 18:26:37 2015] [info] [client 192.168.100.250] (70007)The timeout specified has expired: SSL handshake interrupte
d by system [Hint: Stop button pressed in browser?!]
[Wed Apr 08 18:26:37 2015] [info] [client 192.168.100.250] Connection closed to child 1 with abortive shutdown (server vcops-
slice-1:44 

Java客戶端上的錯誤:

11:26:25.759 [main] DEBUG o.a.h.i.c.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {s}->https://192.168.100.162:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://192.168.100.162/casa/sysadmin/cluster/status":Remote host closed connection during handshake; nested exception is javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:557)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:502)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:444)
    at com.vmware.vrack.vrm.vrops.VropsServiceImpl.createAdapter(VropsServiceImpl.java:426)
    at com.vmware.vrack.vrm.vrops.VropsServiceImpl.createVcenterAdapter(VropsServiceImpl.java:358)
    at com.vmware.vrack.vrm.workflow.tasks.vcops.VropsTest.main(VropsTest.java:43)
Caused by: javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:533)
    at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:118)
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:314)
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363)
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219)
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195)
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:85)
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108)
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:186)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:84)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:46)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:52)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:541)
    ... 5 more
Caused by: java.io.EOFException: SSL peer shut down incorrectly
    at sun.security.ssl.InputRecord.read(Unknown Source)
    ... 23 more

Java客戶端使用spring RestTemplate

httpHeaders.add(AUTH_HEADER, BASIC_AUTH +
                             new String(Base64.encodeBase64((vropsUsername + ":" + vropsPassword).getBytes())));
    httpHeaders.setAccept(new ArrayList<MediaType>() {{
        add(new MediaType("application", "json"));
    }});
    httpHeaders.setContentType(new MediaType("application", "json"));
  HttpEntity request = new HttpEntity<String> ("", httpHeaders);
    ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, request, String.class);

問題是由於在握手過程中發生超時。 在apache ssl配置中增加超時可以解決該問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM