![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e499. Creating an SSL Client SocketWhen an SSL client socket connects to an SSL server, it receives a certificate of authentication from the server. The client socket then validates the certificate against a set of certificates in its \meta{trust store}. The default truststore is try { int port = 443; String hostname = "hostname"; SocketFactory socketFactory = SSLSocketFactory.getDefault(); Socket socket = socketFactory.createSocket(hostname, port); // Create streams to securely send and receive data to the server InputStream in = socket.getInputStream(); OutputStream out = socket.getOutputStream(); // Read from in and write to out... // Close the socket in.close(); out.close(); } catch(IOException e) { } A different truststore can be specified using the
> java -Djavax.net.ssl.trustStore=truststore -Djavax.net.ssl.trustStorePassword=123456 MyApp
e501. Retrieving the Certification Path of an SSL Server e502. Disabling Certificate Validation in an HTTPS Connection © 2002 Addison-Wesley. |