File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSSE Problem

 
Ahilan Ponnusamy
Greenhorn
Posts: 1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic