aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes JSSE Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "JSSE Problem" Watch "JSSE Problem" New topic
Author

JSSE Problem

Ahilan Ponnusamy
Greenhorn

Joined: Aug 07, 2005
Posts: 1
I am trying to implement https download from our partners site.I got the .PFX(PKCS12) file from the client site & installed it in IE . I was able to connect to the site and download the file. But when I use the same file as keystore for my java client and try to connect to the site , I get a
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: No trusted certificate found
exception .

I learned that this is due to the unavailability of TrustStore ..So I created a certificate file (.cer) file from the .pfx file and added that to the trust store ..But that also didnt help.

I have added my code below

import java.security.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.*;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.KeyManagerFactorySpi;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;

public class KeyTest {
public static void main(String[] args) throws Exception {

javax.net.ssl.SSLContext ctx;
javax.net.ssl.KeyManagerFactory kmf;
javax.net.ssl.TrustManagerFactory tmf;
java.security.KeyStore ks,ks1;


ctx = javax.net.ssl.SSLContext.getInstance("SSL");
kmf = javax.net.ssl.KeyManagerFactory.getInstance("SunX509");
tmf = javax.net.ssl.TrustManagerFactory.getInstance("SunX509");
ks1 = java.security.KeyStore.getInstance("JKS");


ks = java.security.KeyStore.getInstance("JKS");

try
{
ks.load(new java.io.FileInputStream("AccessMed_Certificate1.pfx"), "cel_auto".toCharArray());

ks1.load(new java.io.FileInputStream("accessmedcatrust"), "cel_auto".toCharArray());
}
catch(java.io.IOException ex)
{
ex.printStackTrace();
}

kmf.init(ks, "cel_auto".toCharArray());

tmf.init(ks1);
System.out.println("Trust manager set :");

ctx.init(kmf.getKeyManagers(),tmf.getTrustManagers(),null);

java.net.URL myUrl = new java.net.URL("https://clientsite.com");
javax.net.ssl.HttpsURLConnection conn = (javax.net.ssl.HttpsURLConnection) myUrl.openConnection();
System.out.println("----------------------------------------------");
conn.setSSLSocketFactory(ctx.getSocketFactory());
System.out.println("after context factory::::::::::::::::");

java.io.InputStream in = conn.getInputStream();

}
}


Expecting some solution for this problem
warm regards
Ahilan
 
jQuery in Action, 2nd edition
 
subject: JSSE Problem
 
Similar Threads
This SSL code runs... but does it provide security?
HTML/Post java.lang.classcastexception
SSL Mutual Authentication Issue
SSL EXCEPTION!!!
javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure