2 way TLS (1.2) between Java client and Apple pay server
<p>Trying to achieve:
As required in Apple Pay for Web, 2 way TLS 1.2 is required. In my case i'm trying to hit apple pay server from my java  with json payload (which you can say as client).
<a href="https://developer.apple.com/reference/applepayjs/applepaysession#2166532" rel="nofollow">https://developer.apple.com/reference/applepayjs/applepaysession#2166532</a></p>

<p>My points of Concern:</p>

<p>1) Any command that list all the cipher suites supported? running on java 1.8.</p>

<p>2) What is required while making HttpsURLconnection.openconnection to be TLS1.2?</p>

<p>3) Any example code by which i can achieve this connection.</p>

<p>4) What are the settings required like certificate and private key?</p>

<p>Any help would be useful. 
I know i have asked very direct questions, but i will keep adding more specific questions in this.  </p>

<p><strong>Update: First 3 points are done.
Now only Regarding point 4</strong>: I'm sending both the files key and cert by converting to cert.p12 file and saving as new keystore.</p>

<pre><code>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"
</code></pre>

<p>After that running java code with VM arguments in eclipse:</p>

<pre><code>-Djavax.net.ssl.keyStoreType=pkcs12 -Djavax.net.ssl.keyStore=cert.p12 -Djavax.net.debug=ssl
</code></pre>

<p>I can see following error in console:</p>

<pre><code>*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)
</code></pre>

<p>Here is the java code:</p>

<pre><code>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"));
</code></pre>

<p>Failing at</p>

<pre><code>conn.getOutputStream();
</code></pre>

<p>Using java 1.8</p>