Created
December 13, 2016 15:42
-
-
Save martinweiler/ac7e2260171d3160ee596df047a8c300 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.*; | |
import java.net.*; | |
import java.util.*; | |
import javax.net.ssl.*; | |
public class SslSocketClient { | |
public static void main(String[] args) { | |
BufferedReader in = new BufferedReader( | |
new InputStreamReader(System.in)); | |
PrintStream out = System.out; | |
SSLSocketFactory f = | |
(SSLSocketFactory) SSLSocketFactory.getDefault(); | |
try { | |
SSLSocket c = | |
(SSLSocket) f.createSocket("etdr-uat.globalrateset.com", 443); | |
SSLParameters sslParameters = c.getSSLParameters(); | |
SNIHostName serverName = new SNIHostName("etdr-uat.globalrateset.com"); | |
List<SNIServerName> serverNames = new ArrayList<>(1); | |
serverNames.add(serverName); | |
sslParameters.setServerNames(serverNames); | |
c.setSSLParameters(sslParameters); | |
System.out.println("server name set"); | |
printSocketInfo(c); | |
c.startHandshake(); | |
BufferedWriter w = new BufferedWriter( | |
new OutputStreamWriter(c.getOutputStream())); | |
BufferedReader r = new BufferedReader( | |
new InputStreamReader(c.getInputStream())); | |
String m = null; | |
while ((m=r.readLine())!= null) { | |
out.println(m); | |
m = in.readLine(); | |
w.write(m,0,m.length()); | |
w.newLine(); | |
w.flush(); | |
} | |
w.close(); | |
r.close(); | |
c.close(); | |
} catch (IOException e) { | |
System.err.println(e.toString()); | |
} | |
} | |
private static void printSocketInfo(SSLSocket s) { | |
System.out.println("Socket class: "+s.getClass()); | |
System.out.println(" Remote address = " | |
+s.getInetAddress().toString()); | |
System.out.println(" Remote port = "+s.getPort()); | |
System.out.println(" Local socket address = " | |
+s.getLocalSocketAddress().toString()); | |
System.out.println(" Local address = " | |
+s.getLocalAddress().toString()); | |
System.out.println(" Local port = "+s.getLocalPort()); | |
System.out.println(" Need client authentication = " | |
+s.getNeedClientAuth()); | |
SSLSession ss = s.getSession(); | |
System.out.println(" Cipher suite = "+ss.getCipherSuite()); | |
System.out.println(" Protocol = "+ss.getProtocol()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment