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 SSL certificate is not self-signed, but provided by StartSSL , and I'm using the Eclipse IDE.

Can someone point me in the right direction? i.e. what files do I need, where should I import them, and what code do I need in Java, etc?

Vineet Reynolds:

I found that to ensure the highest security/validity I had to import the SSL certificate used by the website into my application

You were partially correct when you said that. You don't need to import the SSL certificate. It is enough to import the StartSSL CA certificate.

Also, there is no such thing as importing the certificate into the Java application. SSL support in Java relies on the concept of keystores and truststores rather than some certificates packaged in the application. If you are publishing an application to be downloaded and executed by end users, you do not need to publish a certificate or use a private key in the application for this purpose. The private key and associated certificate will be stored in the keystore, accessible only to you.

End users of the application will rely on SSL support in the Java runtime, which will enable the application to establish an SSL connection to the site after validating the server certificate. The Java runtime ships with a default set of CA certificates in the truststore, and the only prerequisite for a successful SSL connection is that the server's SSL certificate is issued by a CA in the truststore. As of version 6, StartSSL's certificate does not exist, at least in the Java runtime's truststore , so:

  • You can instruct end users to perform the activity of importing the StartSSL CA certificate into the Java truststore. Links that might help include this StartSSL forum thread (importing a CA certificate into the truststore only requires the first four steps), a GitHub project , and this blog post ; disclaimer - I haven't tried any of these, you should Use at your own risk.
  • Alternatively, you can use the -Djavax.net.ssl.trustStore=<path_to_truststore> -Djavax.net.ssl.trustStorePassword=<truststore_password>JVM startup flag to initialize the application with your own truststore , or execute the following code before initializing the SSL connection:

    System.setProperty("javax.net.ssl.trustStore","<path_to_truststore>");
    System.setProperty("javax.net.ssl.trustStorePassword","<truststore_password>");
    

    This only works if your application is a Java SE application that doesn't happen to be an applet (or an application with similar restrictions on how to specify the truststore).


Reading the Java keytool documentation will also help .

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

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

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

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

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

Where are SSL certificates stored?

iOS Monkey I understand how SSL works, but my question is more about the storage of certificates on the client side. To understand the exact context, let's assume I'm writing my own browser. My rendering part will be done by WebKit and the HTTP request handlin