-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSSLPoke.java
More file actions
37 lines (31 loc) · 1.28 KB
/
SSLPoke.java
File metadata and controls
37 lines (31 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import java.io.*;
/** Establish a SSL connection to a host and port. Will print if there is a certificate validation error */
public class SSLPoke {
public static void main(String[] args) {
if (args.length != 2) {
System.out.println("Usage: "+SSLPoke.class.getName()+" <host> <port>");
System.exit(1);
}
try {
SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));
InputStream in = sslsocket.getInputStream();
OutputStream out = sslsocket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
System.out.println("SUCCESS");
} catch (Exception exception) {
String message = exception.getClass().getName();
if (message != null && message.length() > 0)
{
message += " : " + exception.getMessage();
}
System.err.println("FAILURE: " + message);
}
}
}