Last active
March 2, 2021 21:08
-
-
Save copperlight/615efd224ff106df6e22535414e18514 to your computer and use it in GitHub Desktop.
SSLPoke
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 javax.net.ssl.SSLSocket; | |
import javax.net.ssl.SSLSocketFactory; | |
import java.io.*; | |
/** Establish a SSL connection to a host and port, writes a byte and | |
* prints the response. See | |
* http://confluence.atlassian.com/display/JIRA/Connecting+to+SSL+services | |
* | |
* KB Entry: https://confluence.atlassian.com/kb/unable-to-connect-to-ssl-services-due-to-pkix-path-building-failed-error-779355358.html | |
* | |
* Source File: https://confluence.atlassian.com/download/attachments/117455/SSLPoke.java | |
*/ | |
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("Successfully connected"); | |
} catch (Exception exception) { | |
exception.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment