Search in sources :

Example 51 with SSLSocket

use of javax.net.ssl.SSLSocket in project custom-cert-https by nelenkov.

the class MySSLSocketFactory method createSocket.

@Override
public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException {
    SSLSocket sslSocket = (SSLSocket) socketFactory.createSocket(socket, host, port, autoClose);
    hostnameVerifier.verify(host, sslSocket);
    return sslSocket;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket)

Example 52 with SSLSocket

use of javax.net.ssl.SSLSocket in project custom-cert-https by nelenkov.

the class MySSLSocketFactory method connectSocket.

@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    if (host == null) {
        throw new IllegalArgumentException("Target host may not be null.");
    }
    if (params == null) {
        throw new IllegalArgumentException("Parameters may not be null.");
    }
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
    if ((localAddress != null) || (localPort > 0)) {
        if (localPort < 0)
            localPort = 0;
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    try {
        hostnameVerifier.verify(host, sslsock);
    } catch (IOException iox) {
        try {
            sslsock.close();
        } catch (Exception x) {
        }
        throw iox;
    }
    return sslsock;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket) IOException(java.io.IOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException)

Example 53 with SSLSocket

use of javax.net.ssl.SSLSocket in project jodd by oblac.

the class SocketHttpConnectionProvider method createHttpConnection.

/**
	 * Creates new connection from current {@link jodd.http.HttpRequest request}.
	 *
	 * @see #createSocket(String, int, int)
	 */
public HttpConnection createHttpConnection(HttpRequest httpRequest) throws IOException {
    SocketHttpConnection httpConnection;
    final boolean https = httpRequest.protocol().equalsIgnoreCase("https");
    if (https) {
        SSLSocket sslSocket = createSSLSocket(httpRequest.host(), httpRequest.port(), httpRequest.connectionTimeout(), httpRequest.trustAllCertificates(), httpRequest.verifyHttpsHost());
        httpConnection = new SocketHttpSecureConnection(sslSocket);
    } else {
        Socket socket = createSocket(httpRequest.host(), httpRequest.port(), httpRequest.connectionTimeout());
        httpConnection = new SocketHttpConnection(socket);
    }
    // prepare connection config
    httpConnection.setTimeout(httpRequest.timeout());
    try {
        // additional socket initialization
        httpConnection.init();
    } catch (Throwable throwable) {
        // @wjw_add
        httpConnection.close();
        throw new HttpException(throwable);
    }
    return httpConnection;
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) HttpException(jodd.http.HttpException) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket)

Example 54 with SSLSocket

use of javax.net.ssl.SSLSocket in project openhab1-addons by openhab.

the class EasySSLSocketFactory method connectSocket.

/**
     * @see org.apache.http.conn.scheme.SocketFactory#connectSocket(java.net.Socket,
     *      java.lang.String, int, java.net.InetAddress, int,
     *      org.apache.http.params.HttpParams)
     */
@Override
public Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
    int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
    int soTimeout = HttpConnectionParams.getSoTimeout(params);
    InetSocketAddress remoteAddress = new InetSocketAddress(host, port);
    SSLSocket sslsock = (SSLSocket) ((sock != null) ? sock : createSocket());
    if ((localAddress != null) || (localPort > 0)) {
        // we need to bind explicitly
        if (localPort < 0) {
            // indicates "any"
            localPort = 0;
        }
        InetSocketAddress isa = new InetSocketAddress(localAddress, localPort);
        sslsock.bind(isa);
    }
    sslsock.connect(remoteAddress, connTimeout);
    sslsock.setSoTimeout(soTimeout);
    return sslsock;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SSLSocket(javax.net.ssl.SSLSocket)

Example 55 with SSLSocket

use of javax.net.ssl.SSLSocket in project orientdb by orientechnologies.

the class OClientConnectionManager method shutdown.

public void shutdown() {
    timerTask.cancel();
    final Iterator<Entry<Integer, OClientConnection>> iterator = connections.entrySet().iterator();
    while (iterator.hasNext()) {
        final Entry<Integer, OClientConnection> entry = iterator.next();
        final ONetworkProtocol protocol = entry.getValue().getProtocol();
        if (protocol != null)
            protocol.sendShutdown();
        OLogManager.instance().debug(this, "Sending shutdown to thread %s", protocol);
        OCommandRequestText command = entry.getValue().getData().command;
        if (command != null && command.isIdempotent()) {
            protocol.interrupt();
        } else {
            if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == OChannelBinaryProtocol.REQUEST_SHUTDOWN) {
                continue;
            }
            final Socket socket;
            if (protocol == null || protocol.getChannel() == null)
                socket = null;
            else
                socket = protocol.getChannel().socket;
            if (socket != null && !socket.isClosed() && !socket.isInputShutdown()) {
                try {
                    OLogManager.instance().debug(this, "Closing input socket of thread %s", protocol);
                    if (// An SSLSocket will throw an UnsupportedOperationException.
                    !(socket instanceof SSLSocket))
                        socket.shutdownInput();
                } catch (IOException e) {
                    OLogManager.instance().debug(this, "Error on closing connection of %s client during shutdown", e, entry.getValue().getRemoteAddress());
                }
            }
            if (protocol.isAlive()) {
                if (protocol instanceof ONetworkProtocolBinary && ((ONetworkProtocolBinary) protocol).getRequestType() == -1) {
                    try {
                        OLogManager.instance().debug(this, "Closing socket of thread %s", protocol);
                        protocol.getChannel().close();
                    } catch (Exception e) {
                        OLogManager.instance().debug(this, "Error during chanel close at shutdown", e);
                    }
                    OLogManager.instance().debug(this, "Sending interrupt signal to thread %s", protocol);
                    protocol.interrupt();
                }
            // protocol.join();
            }
        }
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Entry(java.util.Map.Entry) OCommandRequestText(com.orientechnologies.orient.core.command.OCommandRequestText) ONetworkProtocolBinary(com.orientechnologies.orient.server.network.protocol.binary.ONetworkProtocolBinary) SSLSocket(javax.net.ssl.SSLSocket) ONetworkProtocol(com.orientechnologies.orient.server.network.protocol.ONetworkProtocol) IOException(java.io.IOException) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) OException(com.orientechnologies.common.exception.OException) OTokenSecurityException(com.orientechnologies.orient.enterprise.channel.binary.OTokenSecurityException) IOException(java.io.IOException)

Aggregations

SSLSocket (javax.net.ssl.SSLSocket)326 IOException (java.io.IOException)101 Test (org.junit.Test)62 SSLContext (javax.net.ssl.SSLContext)59 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)59 Socket (java.net.Socket)57 OutputStream (java.io.OutputStream)50 InetSocketAddress (java.net.InetSocketAddress)39 CertificateException (java.security.cert.CertificateException)33 SSLException (javax.net.ssl.SSLException)32 SSLSession (javax.net.ssl.SSLSession)31 InputStream (java.io.InputStream)30 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)30 SSLServerSocket (javax.net.ssl.SSLServerSocket)27 SocketTimeoutException (java.net.SocketTimeoutException)24 SocketException (java.net.SocketException)23 ServerSocket (java.net.ServerSocket)22 UnknownHostException (java.net.UnknownHostException)21 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)21 InputStreamReader (java.io.InputStreamReader)19