I am trying to connect to an SSL-Server implemented in Python from an Android phone. I self-signed a certificate server.crt and want to use this certificate inside the Android App.
How do I do this in Java? In Python this can be done in the following way:
sock = socket.socket(socket.AF_INET6) context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH, cafile = 'server.crt') conn = context.wrap_socket(sock, server_hostname = HOST) conn.connect((HOST, PORT)) My current Java code looks like this:
SSLSocketFactory factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslsocket = (SSLSocket) factory.createSocket(HOST, PORT); How can I extend this such that it uses the certificate? Thanks in advance!