I have a AudioCodes SIP gateway, and I am writing a lightweight SIP client in JAVA, I got this working for TCP, however I am trying to implement TLS. I have the certificates, however I cannot find an example of how to use JAVA sockets to connect over TLS using external certificates, can somebody please point me in the right direction. Thank you.
Below is what I have, I imported the root CA in the truststore using keytool,
keytool -import -trustcacerts -alias caroot2 -file ca-root-cert.pem -keystore keystore.jks
I get the following error:
> javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
Can somebody please help me ??
package atobtls; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import java.io.*; public class Atobtls { public static void main(String[] arstring) { try { String truststorePath = "keystore.jks"; String truststorePass = "abc123"; System.setProperty("javax.net.ssl.trustStore", truststorePath); System.setProperty("javax.net.ssl.trustStorePassword", truststorePass); SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket("192.168.217.1", 443); InputStream inputstream = System.in; InputStreamReader inputstreamreader = new InputStreamReader(inputstream); BufferedReader bufferedreader = new BufferedReader(inputstreamreader); OutputStream outputstream = sslsocket.getOutputStream(); OutputStreamWriter outputstreamwriter = new OutputStreamWriter(outputstream); BufferedWriter bufferedwriter = new BufferedWriter(outputstreamwriter); String string = "test"; bufferedwriter.write(string + '\n'); bufferedwriter.flush(); } catch (Exception exception) { exception.printStackTrace(); } } }