Example usage for org.apache.commons.ssl SSLClient SSLClient

List of usage examples for org.apache.commons.ssl SSLClient SSLClient

Introduction

In this page you can find the example usage for org.apache.commons.ssl SSLClient SSLClient.

Prototype

public SSLClient() throws GeneralSecurityException, IOException 

Source Link

Usage

From source file:clientetcp.ClienteTCP.java

public static void main(String[] args) {

    try {//from w w  w  .java 2  s .  com
        SSLClient client = new SSLClient();
        SSLSocket s = (SSLSocket) client.createSocket("localhost", 7443);
        PrintWriter writer = new PrintWriter(s.getOutputStream());
        InputStream reader = s.getInputStream();
        writer.println("Hola");
    } catch (Exception exception) {

    }

}

From source file:com.eviware.loadui.impl.messaging.socket.SocketMessageEndpointProvider.java

public SocketMessageEndpointProvider() throws IOException, GeneralSecurityException {
    client = new SSLClient();

    client.addTrustMaterial(new TrustMaterial(System.getProperty(LoadUI.TRUST_STORE),
            System.getProperty(LoadUI.TRUST_STORE_PASSWORD).toCharArray()));

    client.setCheckHostname(false); // default setting is "true" for SSLClient
    client.setCheckCRL(false); // default setting is "true" for SSLClient

    client.setKeyMaterial(new KeyMaterial(System.getProperty(LoadUI.KEY_STORE),
            System.getProperty(LoadUI.KEY_STORE_PASSWORD).toCharArray()));
}

From source file:org.binding.openhab.samsungac.communicator.AirConditioner.java

private void connect() throws Exception {
    if (isConnected()) {
        return;/* w w  w . jav  a2 s .  co  m*/
    } else {
        logger.debug("Disconnected so we'll try again");
        disconnect();
    }

    if (CERTIFICATE_FILE_NAME != null && new File(CERTIFICATE_FILE_NAME).isFile()) {
        if (CERTIFICATE_PASSWORD == null) {
            CERTIFICATE_PASSWORD = "";
        }
        try {
            SSLClient client = new SSLClient();

            client.addTrustMaterial(TrustMaterial.DEFAULT);
            client.setCheckHostname(false);
            client.setKeyMaterial(new KeyMaterial(CERTIFICATE_FILE_NAME, CERTIFICATE_PASSWORD.toCharArray()));
            client.setConnectTimeout(10000);
            socket = (SSLSocket) client.createSocket(IP, PORT);
            socket.setSoTimeout(30000);
            socket.startHandshake();
        } catch (Exception e) {
            throw new Exception("Could not connect using certificate: " + CERTIFICATE_FILE_NAME, e);
        }
    } else {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {
                }

                public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {
                }
            } };

            ctx.init(null, trustAllCerts, null);
            socket = (SSLSocket) ctx.getSocketFactory().createSocket(IP, PORT);
            socket.setSoTimeout(10000);
            socket.startHandshake();
        } catch (Exception e) {
            throw new Exception("Cannot connect to " + IP + ":" + PORT, e);
        }
    }
    handleResponse();
}

From source file:org.openhab.binding.samsungac.internal.AirConditioner.java

private void connect() throws Exception {
    if (isConnected()) {
        return;/*from w  ww. j  a v a2  s.  co m*/
    } else {
        logger.debug("Disconnected so we'll try again");
        disconnect();
    }

    if (CERTIFICATE_FILE_NAME != null && new File(CERTIFICATE_FILE_NAME).isFile()) {
        if (CERTIFICATE_PASSWORD == null) {
            CERTIFICATE_PASSWORD = "";
        }
        try {
            SSLClient client = new SSLClient();

            client.addTrustMaterial(TrustMaterial.DEFAULT);
            client.setCheckHostname(false);
            client.setKeyMaterial(new KeyMaterial(CERTIFICATE_FILE_NAME, CERTIFICATE_PASSWORD.toCharArray()));
            client.setConnectTimeout(10000);
            socket = (SSLSocket) client.createSocket(IP, PORT);
            socket.setSoTimeout(2000);
            socket.startHandshake();
        } catch (Exception e) {
            throw new Exception("Could not connect using certificate: " + CERTIFICATE_FILE_NAME, e);
        }
    } else {
        try {
            SSLContext ctx = SSLContext.getInstance("TLS");
            final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
                public X509Certificate[] getAcceptedIssuers() {
                    return null;
                }

                public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {
                }

                public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                        throws CertificateException {
                }
            } };

            ctx.init(null, trustAllCerts, null);
            socket = (SSLSocket) ctx.getSocketFactory().createSocket(IP, PORT);
            socket.setSoTimeout(2000);
            socket.startHandshake();
        } catch (Exception e) {
            throw new Exception("Cannot connect to " + IP + ":" + PORT, e);
        }
    }
    handleResponse();
}