Hi, I'm connecting to a Servlet over Https with Client and Server Authentication. I'm using JSSE on the client program and IIS/Jrun on the server. The client needs to send data to and receive from the Servlet. The client certificates are generated using java keytool and signed using openssl. The IIS server certificates are generated using its key manager and signed by openssl. The root certificate for the CA is installed in the IE 5.0 trusted root store on the Server. For the client, this root is supplied to the client program in a keystore. The client program starts writing to the servlet and reading from it after attempting client and server authentication. My query is: 1. The code throws a FileNotFOund Exception (see exact description below) when client authenticaion is enabled on the browser but works OK if it is not made mandatory. Am i failing client auth.. Exception: java.io.FileNotFoundException: https://t143/Servlet/FileServlet at com.sun.net.ssl.internal.www.protocol.https.HttpsURLConnection.getInputStream([DashoPro-V1.2-120198]) This is thrown at the line where i try to use the url inputstream... Basically, i feel it's a problem with the format of the certs.. I need to supply my java code with Base 64 encoded certs with 512 bit keys. Now , I generate a PEM cert which has the cert, the pvt key and the caRoot.der using openssl Now if i export it as DER, this becomes DER encoded. This is not acceptable to Java code. It throws an error while loading the cert (for DER encoding). if i supply it with the pem file itself, it gives the following error: ...With rsa:152 generated , when i supply the pem file..... java.security.cert.CertificateException: Unable to initialize, java.io.IOException: DerInputStream.getLength(): lengthTag=58, too big. at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:137) at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:86) at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:286) Now if i export(using pkcs12 export option of openssl) the pem to P12 and load it, it gives th e following error: ...With sk.p12 format, got from pkcs export cmd at openssl java.security.cert.CertificateException: Unable to initialize, java.io.IOException: Indefinite length encoding not supported at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:152) at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:89) at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:286) If i intall this p12 into the browser and export it (alonwith the pvt key) as Base 64 encoded, then try to load it in my code....then it starts throwing the following error: ..With Certificite sk.pfx..exported from the IE (with pvt key) java.security.cert.CertificateParsingException: signed fields invalid at sun.security.x509.X509CertImpl.parse(X509CertImpl.java:1031) at sun.security.x509.X509CertImpl.<init>(X509CertImpl.java:149) at sun.security.provider.X509Factory.engineGenerateCertificate(X509Factory.java:89) at java.security.cert.CertificateFactory.generateCertificate(CertificateFactory.java:286) Hope u get my requirements right. I need to supply a client cert that is acceptable to both java code and to IIS. i think base 64 encoded 512 key(non-US edition IIS) is what i finally want, right? Any suggestions.... Reply at the forum and at [EMAIL PROTECTED] code for the client............................ ///////////////////////// import com.sun.net.ssl.*; import javax.net.ssl.*; import java.security.*; import java.security.cert.*; import java.io.*; import java.net.*; public class ClientAuthenticationExample { private static final String CERTIFICATE_TYPE = "SunX509"; private static final String KEYSTORE_TYPE = "JKS"; private static final String SSL_PROTOCOL = "TLS"; private static final String CERTIFICATE_FACTORY_TYPE = "X.509"; /* server_cert is filename of trusted server cert client_cert is filename of personal cert to be given to server. certificate files are assumed to be base-64 encoded */ public static void main(String[] args) throws Exception { if (args.length < 3) { System.out.println("Usage: ClientAuthenticationExample url server_cert client_cert"); return; } String connectURL = args[0]; String serverCertificateFile = args[1]; String clientCertificateFile = args[2]; KeyStore ks = KeyStore.getInstance (KEYSTORE_TYPE); CertificateFactory cf = CertificateFactory.getInstance(CERTIFICATE_FACTORY_TYPE); TrustManagerFactory tmf = TrustManagerFactory.getInstance(CERTIFICATE_TYPE); KeyManagerFactory kmf = KeyManagerFactory.getInstance(CERTIFICATE_TYPE); System.setProperty ("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.prot ocol"); java.security.Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); ks.load(null, null); X509Certificate the_cert = (X509Certificate) cf.generateCertificate(new FileInputStream (serverCertificateFile)); ks.setCertificateEntry("server_cert", the_cert); tmf.init(ks); ks = KeyStore.getInstance(KEYSTORE_TYPE); ks.load(null, null); the_cert = (X509Certificate) cf.generateCertificate(new FileInputStream (clientCertificateFile)); ks.setCertificateEntry("client_cert", the_cert); kmf.init(ks, null); SSLContext ctx = SSLContext.getInstance (SSL_PROTOCOL); KeyManager[] km = kmf.getKeyManagers(); TrustManager[] tm = tmf.getTrustManagers(); ctx.init (km, tm, null); HttpsURLConnection.setDefaultSSLSocketFactory (ctx.getSocketFactory()); URL url = new URL(connectURL); HttpsURLConnection con = (HttpsURLConnection) url.openConnection(); con.setRequestMethod("GET") ; con.connect(); if (con.getResponseCode() != HttpURLConnection.HTTP_OK) System.out.println ("HttpsURLConnection received response #" + con.getResponseCode () + ": " + con.getResponseMessage()); InputStream in = con.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); System.out.println("Here's the file:"); String line = null; while ((line = br.readLine()) != null) System.out.println(line); } } /////////////////////////////////////////////////end/////////////// ------------------------------------------------------------------------------------- "Contents of this E-Mail message are confidential, proprietary and privileged and are intended for the addressee(s) only. Any unauthorised dissemination, publication transfer or use of the contents of this message, with or without modification(s) is punishable under the relevant law." ------------------------------------------------------------------------------------- Tata Consultancy Services www.tcs.com ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List [EMAIL PROTECTED] Automated List Manager [EMAIL PROTECTED]
