I'm trying to debug following error:
javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name
at sun.security.ssl.ClientHandshaker.handshakeAlert
at sun.security.ssl.SSLSocketImpl.recvAlert
(...)
I've already headed SNI Extension problem described here: SSL handshake alert: unrecognized_name error since upgrade to Java 1.7.0
I still get error, so I'd like to print SSL Certificates which I'm sending to the server for debugging purpose. Here's my code:
URL url = new URL(text);
HttpsURLConnection conn = (HttpsURLConnection)
url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.setRequestProperty("Content-length", String.valueOf(query.length()));
DataOutputStream os = new DataOutputStream(conn.getOutputStream());
os.writeBytes(query);
Certificate[] certs = conn.getLocalCertificates();
for (int i = 0; i < certs.length; i++) {
System.out.println("########### LocalCertNr " + String.valueOf(i) + " ##############");
System.out.println(certs[i].toString());
}
My problems it that before I hit os.writeBytes(query)
connection is not open yet and I can't read certificates, but I can't open it, because after hitting OutputStream
or InputStream
hits the error from begin of the post.
How can I print the certificates, which HTTPSURLConnection
is going to send?