Skip to content

Instantly share code, notes, and snippets.

@thanhhh
Forked from 4ndrej/SSLPoke.java
Created October 11, 2021 15:37
Show Gist options
  • Select an option

  • Save thanhhh/e5329068e96ee62c653984d8a3836a13 to your computer and use it in GitHub Desktop.

Select an option

Save thanhhh/e5329068e96ee62c653984d8a3836a13 to your computer and use it in GitHub Desktop.

Revisions

  1. @4ndrej 4ndrej revised this gist Jan 9, 2020. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions SSLPoke.java
    Original file line number Diff line number Diff line change
    @@ -34,6 +34,7 @@ public static void main(String[] args) {

    } catch (Exception exception) {
    exception.printStackTrace();
    System.exit(1);
    }
    }
    }
  2. @4ndrej 4ndrej revised this gist Aug 8, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion SSLPoke.java
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,4 @@
    import javax.net.ssl.SSLParameters;
    import javax.net.ssl.SSLSocket;
    import javax.net.ssl.SSLSocketFactory;
    import java.io.*;
    @@ -16,6 +17,10 @@ public static void main(String[] args) {
    SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
    SSLSocket sslsocket = (SSLSocket) sslsocketfactory.createSocket(args[0], Integer.parseInt(args[1]));

    SSLParameters sslparams = new SSLParameters();
    sslparams.setEndpointIdentificationAlgorithm("HTTPS");
    sslsocket.setSSLParameters(sslparams);

    InputStream in = sslsocket.getInputStream();
    OutputStream out = sslsocket.getOutputStream();

    @@ -31,4 +36,4 @@ public static void main(String[] args) {
    exception.printStackTrace();
    }
    }
    }
    }
  3. @4ndrej 4ndrej created this gist Jan 16, 2013.
    34 changes: 34 additions & 0 deletions SSLPoke.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    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
    */
    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();
    }
    }
    }