尝试实现: 根据Apple Pay for Web的要求,需要双向TLS 1.2。在我的情况下,我尝试使用json有效负载(可以说是客户端)从我的java中获取apple pay服务器。 https://developer.apple.com/reference/applepayjs/applepaysession#2166532
我的关注点:
1)列出所有支持的密码套件的任何命令?在java 1.8上运行。
2)将HttpsURLconnection.openconnection设为TLS1.2时需要什么?
3)我可以通过它实现此连接的任何示例代码。
4)证书和私钥需要什么设置?
任何帮助都会有用。 我知道我已经提出了非常直接的问题,但我会继续在这里添加更具体的问题。
更新:前3分完成。 现在仅关于第4点:我通过转换为cert.p12文件并保存为新的密钥库来发送文件密钥和证书。
openssl x509 -inform der -in merchant_id.cer -out merchant_id.pem
openssl pkcs12 -nodes -export -in merchant_id.pem -inkey clientprivate.key -out cert.p12 -name "Certificate"
之后在eclipse中运行带有VM参数的java代码:
-Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStore=cert.p12 -Djavax.net.debug=ssl
我可以在控制台中看到以下错误:
*ServerHelloDone
Warning: no suitable certificate found - continuing without client authentication
* Certificate chain
** ECDHClientKeyExchange
main, WRITE: TLSv1.2 Change Cipher Spec, length = 1
*** Finished
verify_data:
*
main, WRITE: TLSv1.2 Handshake, length = 64
main, handling exception: java.net.SocketException: Connection reset
%% Invalidated: [Session-1, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA]
main, SEND TLSv1.2 ALERT: fatal, description = unexpected_message
main, WRITE: TLSv1.2 Alert, length = 48
main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error
main, called closeSocket()
java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(Unknown Source)
at java.net.SocketInputStream.read(Unknown Source)
at sun.security.ssl.InputRecord.readFully(Unknown Source)
at sun.security.ssl.InputRecord.read(Unknown Source)
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 sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at java.net.HttpURLConnection.getResponseCode(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(Unknown Source)
这是java代码:
HttpsURLConnection conn = (HttpsURLConnection)url.openConnection();
conn.setSSLSocketFactory(factory);
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestMethod("POST");
OutputStream os = conn.getOutputStream();
os.write(jsonInString.getBytes("UTF-8"));
失败
conn.getOutputStream();
使用java 1.8
答案 0 :(得分:0)
要求的一般答案..
我发现列出所有密码非常有帮助:https://confluence.atlassian.com/stashkb/list-ciphers-used-by-jvm-679609085.html
我使用此System.setProperty("https.protocols", "TLSv1.2");
将其设置为TLS 1.2。