java - Where SSLSocketFactory and HttpsURLConnection work diffrerently? -


I have found a server with a self-signed certificate. I have imported it with a significant toll on my computer and compile the usage

  -Djavax.net.ssl.trustStore = blabla   

logic . When I try to run the following code:

  SSLSocketFactory factory = HttpsURLConnection.getDefaultSSLSocketFactory (); SSLSocket Socket = (SSLSocket) factory.createSocket ("MY_URL_DIGITS", 443); OutputStream OS = socket.getOutputStream (); os.write ("test request \ n" .getBytes ()); Os.flush (); Os.close ();   

Everything is fine and I can see the "test request" on the server. However, when I run:

  url = new URL ("https: // MY_URL_DIGITS"); HttpsURLConnection con = (HttpsURLConnection) url.openConnection (); OutputStream OS = con.getOutputStream (); os.write ("test request \ n" .getBytes ()); Os.flush (); Os.close (); I got  
  javax.net.ssl.SSLHandshakeException: java.security.cert. By default, SSLSocket only checks if you trust the certificate.   

SSLSocket only checks if you trust the certificate. HttpsURLConnection checks whether you trust the certificate and also checks whether the certificate says that it is coming from the place that you actually navigate to your HTTPS URL connection to succeed, the certificate You must specify a Subject Alternative Name (SAN) which was the same type of server that you are conferencing on. In this case SAN will need to be "DNS: MY_URL_DIGITS", where the "DNS" part says that you are specifying a host name instead of an IP address.

If you need additional information, see a certificate with a subject optional name:



Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -