Wednesday 18 September 2013

HTTPS connection between client and server SSL handshake

HTTPS connection between client and server SSL handshake

I've got an HTTPS client and a HTTPS server coded in java, i need to make
a SSL connection to the HTTPS server to get a message based on the
condition that the client should accept the connection if the certificate
hash of the server's certificate during SSL handshake equals to the one
I've declared already in my client.
Here is my code
package testsimulation;
import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.*;
import javax.security.auth.x500.X500Principal;
import org.bouncycastle.util.encoders.Hex;
public class HTTPclient extends akande {
private static String urlString;
public String k = a9 09 50 2d d8 2a e4 14 33 e6 f8 38 86 b0 0d 42 77
a3 2a 7b
public static void main(String[] args) throws Exception
{
//set necessary truststore properties - using JKS
System.setProperty("javax.net.ssl.trustStore",
"FiddlerKeystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "codedfar");
//
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
//
System.setProperty("java.protocol.handler.pkgs","com.sun.net.ssl.internal.www.protocol");
SSLContext sslContext = createSSLContext();
// sslContext.init(null, null, null);
SSLSocketFactory fact = sslContext.getSocketFactory();
// SSLSocketFactory fact =
(SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
URL url = new URL("https://localhost:9990");
System.setProperty("proxySet","true");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8888");
//-Djavax.net.ssl.trustStore=<path\to\FiddlerKeystore>
//-Djavax.net.ssl.trustStorePassword= codedfar;
Proxy proxy = new Proxy(Proxy.Type.HTTP, new
InetSocketAddress("127.0.0.1", 8888));
HttpsURLConnection connection =
(HttpsURLConnection)url.openConnection(proxy);
connection.setSSLSocketFactory(fact);
connection.setHostnameVerifier(new Validator());
connection.connect();
InputStream in = connection.getInputStream();
int ch=0;
while((ch = in.read()) >= 0)
{
System.out.println((char)ch);
}
in.close();
// int th =1;
// th.force(0);
}
}
I want to compare the server's certificate thumbprint collected from
another server which is declared in my class against the server's
thumbprint obtained in the SSL handshake to know if it is the same.

No comments:

Post a Comment