SSL Java example

sdk

#1

Hi

I need to do a secure socket connection.
I use the SSL-2.0-api.jar library

This is my sample code :

		CertificateFactory certificateFactory = null;
		certificateFactory = CertificateFactory.getInstance("X.509");
		ByteArrayInputStream rootFile = new ByteArrayInputStream(sRootCert.getBytes());
		ByteArrayInputStream clientFile = new ByteArrayInputStream(sClientCert.getBytes());
		X509Certificate certificat_root = (X509Certificate) certificateFactory.generateCertificate(rootFile);
		X509Certificate certificat_client = (X509Certificate) certificateFactory.generateCertificate(clientFile);

		TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
		KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
		ks.setCertificateEntry("CA_CERT", certificat_root);
		ks.setCertificateEntry("client", certificat_client);

		tmf.init(ks);

		SSLContext sc = SSLContext.getInstance("TLS");
		sc.init(null, tmf.getTrustManagers(), null);

		SSLSocketFactory ssf = sc.getSocketFactory();
		s = (SSLSocket) ssf.createSocket(HOST_CLIENT, PORT_CLIENT);
		s.startHandshake();

I just want to add my certificats.
I’ve got a CertificateException : “X.509 not found” (certificateFactory = CertificateFactory.getInstance(“X.509”):wink:

Is it normal ?

Thanks


#2

Hi @tomdu85,

This is a compatibility issue with ssl-api-2.0.4, we’ll try to fix it on the next versions.
As a workaround, could you use:
certificateFactory = CertificateFactory.getInstance(“X509”);

Regards,


#3

Ok Thanks. That was my problem !

Regards