SSL sockets - Java and certificates?


bob

I am trying to implement SSL sockets between an Android application and a Python API.

The code below...

SSLSocketFactory ssf = (SSLSocketFactory) SSLSocketFactory.getDefault();
Socket s = ssf.createSocket("10.0.2.2", 5001);
DataOutputStream myDataOut = new DataOutputStream(s.getOutputStream());
myDataOut.writeUTF("Hello Server");
myDataOut.flush();
myDataOut.close();
s.close();

As you can see it doesn't work:

590.0750 - Establishing connection to ('127.0.0.1', 50888)
590.0970 - Error while connecting
590.0970 - Error information: [SSL: SSLV3_ALERT_CERTIFICATE_UNKNOWN] sslv3 alert certificate unknown (_ssl.c:590)

I believe it's not because I didn't specify the certificate. See a working example in Python for the client:

import socket, ssl, pprint

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

ssl_sock = ssl.wrap_socket(s,
                           ca_certs="server.crt",
                           cert_reqs=ssl.CERT_REQUIRED)

ssl_sock.connect(('localhost', 5001))

print repr(ssl_sock.getpeername())
print ssl_sock.cipher()
print pprint.pformat(ssl_sock.getpeercert())

ssl_sock.write("Hello from the client...")

How to specify certificate in Java like in Python?

Tom Connery

Taking I understand you right, this answer to a related question may be of interest to you. It describes the way to specify the certificate.

Related


Java and SSL certificates

Andy: I'm trying to use Secure Sockets Layer (HTTPS) to connect to a PHP script in Java, but I've found that for maximum security/validity I have to import the SSL certificate used by the website into my application. ..I do not know what to do. If it helps, my

Java and SSL certificates

Andy: I'm trying to use Secure Sockets Layer (HTTPS) to connect to a PHP script in Java, but I've found that for maximum security/validity I have to import the SSL certificate used by the website into my application. ..I do not know what to do. If it helps, my

Java and SSL certificates

Andy: I'm trying to use Secure Sockets Layer (HTTPS) to connect to a PHP script in Java, but I've found that for maximum security/validity I have to import the SSL certificate used by the website into my application. ..I do not know what to do. If it helps, my

Are Java code signing certificates the same as SSL certificates?

Expect: I'm looking for a Java code signing certificate so my Java applet doesn't throw such scary security warnings. However, I found that all the places they offered were charging too much (I think) like over $200 a year. While doing research, code signing c

Are Java code signing certificates the same as SSL certificates?

Expect: I'm looking for a Java code signing certificate so my Java applet doesn't throw such scary security warnings. However, I find that all the places they offer are charging too much (I think) like over $200 a year. While doing research, code signing certi

java - Ignore expired SSL certificates

Dick Braz: URL myUrl = new URL("https://www....."); The website's SSL certificate has expired. How to avoid it and make URL() work? Bruno: You should build one that TrustManagerwraps the default trust manager, catch it and ignore it.CertificiateExpiredExcepti

java - Ignore expired SSL certificates

Dick Braz: URL myUrl = new URL("https://www....."); The website's SSL certificate has expired. How to avoid it and make URL() work? Bruno: You should build one that TrustManagerwraps the default trust manager, catch it and ignore it.CertificiateExpiredExcepti

java - Ignore expired SSL certificates

Dick Braz: URL myUrl = new URL("https://www....."); The website's SSL certificate has expired. How to avoid it and make URL() work? Bruno: You should build one that TrustManagerwraps the default trust manager, catch it and ignore it.CertificiateExpiredExcepti

How to have multiple SSL certificates for Java server

Lawrence Dol: I have an internal HTTP server written in Java; the full source code is at my disposal. The HTTP server can be configured with any number of websites, each with a separate listening socket, which is created with the following command: skt=SSLServ

Trust all SSL certificates in Java Playframework 2.2

asvignesh: I'm trying to call a web service (with a self-signed SSL certificate) in the Play framework using the following function: public static play.libs.F.Promise<Result> webcall() { String feedUrl = "https://10.0.1.1/client/api"; final play.

How to load multiple SSL certificates in Java KeyStore?

Peter I have two SSL certificate files. The first is labeled "OU=Certificate Authority" and the second is labeled "OU=Root Certificate". Our C++ application loads both certificates for proper client/server handshake. Now, I need to use these certificates in my

How to load multiple SSL certificates in Java KeyStore?

Peter I have two SSL certificate files. The first is labeled "OU=Certificate Authority" and the second is labeled "OU=Root Certificate". Our C++ application loads both certificates for proper client/server handshake. Now, I need to use these certificates in my

How to Use SSL Certificates in Java on Mac

beitseeb I found this question: Import Windows Certificates into Java , which gives the answer for Windows machines. I haven't been able to find a -Djavax.net.ssl.trustStoreType=WINDOWS-ROOTMacOS equivalent . beitseeb Jacob Blanton provided the solution in the

How to have multiple SSL certificates for Java server

Lawrence Dol: I have an internal HTTP server written in Java; the full source code is at my disposal. The HTTP server can be configured with any number of websites, each with a separate listening socket, which is created with the following command: skt=SSLServ

Trust all SSL certificates in Java Playframework 2.2

asvignesh: I'm trying to call a web service (with a self-signed SSL certificate) in the Play framework using the following function: public static play.libs.F.Promise<Result> webcall() { String feedUrl = "https://10.0.1.1/client/api"; final play.

Java 7 - How SSL trusts all certificates

Uri Lukach I'm writing a Java proxy that uses SSL to communicate with other servers. With ServerSocketFactory and keystore and truststore populated by server certificate everything works perfectly. I was wondering, is there a way in Java 7 to disable authentic

Trust all SSL certificates in Java Playframework 2.2

Avines I'm trying to call a web service (with a self-signed SSL certificate) in the Play framework using the following function: public static play.libs.F.Promise<Result> webcall() { String feedUrl = "https://10.0.1.1/client/api"; final play.libs

Java 7 - How SSL trusts all certificates

Uri Lukach I'm writing a Java proxy that uses SSL to communicate with other servers. With ServerSocketFactory and keystore and truststore populated by server certificate everything works perfectly. I was wondering, is there a way in Java 7 to disable authentic

How to load multiple SSL certificates in Java KeyStore?

Peter I have two SSL certificate files. The first is labeled "OU=Certificate Authority" and the second is labeled "OU=Root Certificate". Our C++ application loads both certificates for proper client/server handshake. Now, I need to use these certificates in my

Trust all SSL certificates in Java Playframework 2.2

asvignesh: I'm trying to call a web service (with a self-signed SSL certificate) in the Play framework using the following function: public static play.libs.F.Promise<Result> webcall() { String feedUrl = "https://10.0.1.1/client/api"; final play.

How to have multiple SSL certificates for Java server

Lawrence Dol: I have an internal HTTP server written in Java; the full source code is at my disposal. The HTTP server can be configured with any number of websites, each with a separate listening socket, which is created with the following command: skt=SSLServ

How to Use SSL Certificates in Java on Mac

beitseeb I found this question: Import Windows Certificates into Java , which gives the answer for Windows machines. I haven't been able to find a -Djavax.net.ssl.trustStoreType=WINDOWS-ROOTMacOS equivalent . beitseeb Jacob Blanton provided the solution in the

How to Use SSL Certificates in Java on Mac

beitseeb I found this question: Import Windows Certificates into Java , which gives the answer for Windows machines. I haven't been able to find a -Djavax.net.ssl.trustStoreType=WINDOWS-ROOTMacOS equivalent . beitseeb Jacob Blanton provided the solution in the

Java SSL Sockets - Client Certificate Attestation

Galveston 01 I am trying to create a java SSL socket server application to which some java SSL socket client applications will connect. In order to ensure the credibility of both parties in the communication, (1) The server SHOULD only accept client connection

Using multiple SSL client certificates with the same host in Java

cwick: In my Java application, I need to connect to the same host using SSL, but using a different certificate each time. The reason I need to use a different certificate is that the remote site uses the userid attribute embedded in the certificate to identify