Note that there are some explanatory texts on larger screens.

plurals
  1. POJava SSL factory connection to SSL server (with just public-key and certificate)
    text
    copied!<p>I am trying to connect to a SSL web server. We currently have a pkcs12 file and connect, that is our private-key and certificate. Is it possible to connect using Java code with a public-key and certificate. Imagine I have a file (it is digital but here is the pem output).</p> <pre><code>&gt; Myfile.pk12 / Myfile.pem &gt; &gt; -----BEGIN CERTIFICATE----- ... &gt; -----END CERTIFICATE----- &gt; &gt; -----BEGIN ENCRYPTED PRIVATE KEY----- ... &gt; -----END ENCRYPTED PRIVATE KEY----- </code></pre> <p>And we can connect to the server with this:</p> <pre><code>import org.apache.commons.httpclient.DefaultHttpMethodRetryHandler; import org.apache.commons.httpclient.params.HttpMethodParams; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.conn.scheme.Scheme; import org.apache.http.conn.ssl.SSLSocketFactory; import org.apache.http.conn.ssl.X509HostnameVerifier; import org.apache.http.impl.client.DefaultHttpClient; KeyStore keyStore = generateKeyStore(); System.out.println("==&gt;" + keyStore); SSLSocketFactory socketFactory = new SSLSocketFactory( SSLSocketFactory.TLS, keyStore, KEYSTORE_PASSCODE, null, null, (X509HostnameVerifier) SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); </code></pre> <p>...</p> <p>This works, but let's say we connect with the certificate and public key. Wouldn't Java internally create a private key based on the keystore we provide and that would allow us to connect? E.g.</p> <pre><code>&gt; MyfileNEW.pk12 / MyfileNEW.pem &gt; &gt; -----BEGIN CERTIFICATE----- ... &gt; -----END CERTIFICATE----- &gt; &gt; -----BEGIN PUBLIC KEY----- ... &gt; -----END PUBLIC KEY----- </code></pre> <p>If the public key is embedded in the certificate? Can I use Java to send a request to the server without pre-creating a private key?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload