在我的要求規格上寫着:指定的密碼組的TLS握手
TLS實現支持這些安全框架應至少實現以下密碼套件:TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256
Java的說,它提供了實現這個密碼套件的使用TLSv1的。 2在Java7中。
我是新來的安全,所以不知道如何使用它。
在我的客戶端,我使用:
sslcontext = SSLContexts.custom()
.loadTrustMaterial(..)
.loadKeyMaterial(..)
.useProtocol("TLSv1.2")
.build();
我從谷歌學到的是,客戶端提供了多種選擇,服務器和服務器需要挑他們。如果我錯了,請糾正我。
現在我想指定它在服務器端,我不知道該怎麼做。如果我使用碼頭的帶安全連接器:
<Call name="addConnector">
<Arg>
<New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
<Arg>
<New class="org.eclipse.jetty.http.ssl.SslContextFactory">
<Set name="KeyStore">./etc/keystores/server.jks</Set>
<Set name="KeyStorePassword">password</Set>
<Set name="KeyManagerPassword">password</Set>
<Set name="TrustStore">./etc/keystores/trust_store.jks</Set>
<Set name="TrustStorePassword">password</Set>
<Set name="wantClientAuth">true</Set>
<Set name="needClientAuth">true</Set>
</New>
</Arg>
<Set name="port">8443</Set>
<Set name="maxIdleTime">30000</Set>
</New>
</Arg>
</Call>
它的工作原理,
如果我添加以下,這將使TLSv1.1:
<Set name="excludeProtocols">
<Array type="java.lang.String">
<Item>SSLv3</Item>
<Item>TLSv1.2</Item>
<Item>TLSv1</Item>
<Item>SSLv2Hello</Item>
</Array>
</Set>
它會給錯誤:
executing requestGET https://localhost:8443/ HTTP/1.1 Exception in thread "main" javax.net.ssl.SSLHandshakeException: Server chose TLSv1.1, but that protocol version is not enabled or not supported by the client.
但是,如果我只允許TLSv1.2工作,它運行:
<Set name="excludeProtocols">
<Array type="java.lang.String">
<Item>SSLv3</Item>
<Item>TLSv1.1</Item>
<Item>TLSv1</Item>
<Item>SSLv2Hello</Item>
</Array>
</Set>
但在這裏,如果我指定密碼套件非常久遠的規範協議:
:Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:912) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1294) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1321) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1305) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:394) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:353) at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:134) at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:353) at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:380) at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:236) at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:184) at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:88) at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110) at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82) at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:107) at client.ClientCustomSSL.main(ClientCustomSSL.java:69) Caused by: java.io.EOFException: SSL peer shut down incorrectly at sun.security.ssl.InputRecord.read(InputRecord.java:352) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:893) ... 16 more
<Set name="IncludeCipherSuites">
<Array type="java.lang.String">
<Item>TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256</Item>
</Array>
</Set>
我得到以下異常
我試過的下一件事是在客戶端使用工廠:
SSLConnectionSocketFactory factory=new SSLConnectionSocketFactory(sslcontext, new String[]{"TLSv1.2"},sslcontext.getDefaultSSLParameters().getCipherSuites(), SSLConnectionSocketFactory.getDefaultHostnameVerifier());
而且我在屏幕上印刷了這些密碼套件。
sslcontext.getDefaultSSLParameters().getCipherSuites()
然後,我已經排除了所有這些密碼套件除了「TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256」,它給了我錯誤
<Set name="ExcludeCipherSuites">
<Array type="java.lang.String">
<Item>...</Item>
<!--
<Item>TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256</Item>
-->
</Array>
</Set>
但是,如果我排除所有除「TLS_RSA_WITH_AES_128_CBC_SHA256」,它的工作。
<Set name="ExcludeCipherSuites">
<Array type="java.lang.String">
<Item>...</Item>
<!--
<Item>TLS_RSA_WITH_AES_128_CBC_SHA256</Item>
-->
</Array>
</Set>
這意味着某些密碼套件由jetty支持,而有些密碼套件則不支持。
是這樣嗎?我們有沒有這樣的清單。或者還有其他辦法可以做到這一點。請指導。 我想用這個密碼套件進行這個握手,但我不知道該怎麼做。
可能要啓用Java調試SSL,看看客戶端和/或服務器正在做你所期望的keyalg。將'-Djavax.net.debug = all'添加到您的客戶端java命令行。 –
感謝您的回覆,但我無法理解它的輸出。 – HimanshuR
但我想添加一個重要的點,我已經改變密碼套件,它的工作。有沒有像jetty支持哪些套件的列表,哪些不支持。我已經更新了我的問題 – HimanshuR