List of usage examples for javax.net.ssl SSLSocket setEnabledProtocols
public abstract void setEnabledProtocols(String protocols[]);
From source file:org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory.java
/** * Attempts to get a new socket connection to the given host within the given time limit. * <p>/*from ww w .j av a 2 s .c o m*/ * To circumvent the limitations of older JREs that do not support connect timeout a controller thread is executed. * The controller thread attempts to create a new socket within the given limit of time. If socket constructor does * not return until the timeout expires, the controller terminates and throws an {@link ConnectTimeoutException} * </p> * * @param host * the host name/IP * @param port * the port on the host * @param clientHost * the local host name/IP to bind the socket to * @param clientPort * the port on the local machine * @param params * {@link HttpConnectionParams Http connection parameters} * * @return Socket a new socket * * @throws IOException * if an I/O error occurs while creating the socket * @throws UnknownHostException * if the IP address of the host cannot be determined */ public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = sslcontext.getSocketFactory(); if (timeout == 0) { SSLSocket socket = (SSLSocket) socketfactory.createSocket(host, port, localAddress, localPort); socket.setEnabledProtocols(new String[] { "SSLv3" }); return socket; } else { SSLSocket socket = (SSLSocket) socketfactory.createSocket(); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); socket.connect(remoteaddr, timeout); socket.setEnabledProtocols(new String[] { "SSLv3" }); return socket; } }
From source file:org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory.java
/** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int,java.net.InetAddress,int) *//*from w ww.jav a 2 s. c o m*/ public Socket createSocket(String host, int port, InetAddress clientHost, int clientPort) throws IOException, UnknownHostException { SSLSocket socket = (SSLSocket) sslcontext.getSocketFactory().createSocket(host, port, clientHost, clientPort); socket.setEnabledProtocols(new String[] { "SSLv3" }); return socket; }
From source file:org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory.java
/** * @see SecureProtocolSocketFactory#createSocket(java.lang.String,int) *///ww w . java 2s . co m public Socket createSocket(String host, int port) throws IOException, UnknownHostException { SSLSocket socket = (SSLSocket) sslcontext.getSocketFactory().createSocket(host, port); socket.setEnabledProtocols(new String[] { "SSLv3" }); return socket; }
From source file:org.ovirt.engine.core.utils.ssl.AuthSSLProtocolSocketFactory.java
/** * @see SecureProtocolSocketFactory#createSocket(java.net.Socket,java.lang.String,int,boolean) *//* ww w . j av a2 s .c o m*/ public Socket createSocket(Socket socket, String host, int port, boolean autoClose) throws IOException, UnknownHostException { SSLSocket sslSocket = (SSLSocket) sslcontext.getSocketFactory().createSocket(socket, host, port, autoClose); sslSocket.setEnabledProtocols(new String[] { "SSLv3" }); return sslSocket; }
From source file:org.sonatype.nexus.internal.httpclient.NexusSSLConnectionSocketFactory.java
private SSLSocket configure(final SSLSocket socket) { if (supportedProtocols != null) { socket.setEnabledProtocols(supportedProtocols); } else {//from w ww . j a v a 2 s. com // If supported protocols are not explicitly set, remove all SSL protocol versions String[] allProtocols = socket.getSupportedProtocols(); List<String> enabledProtocols = new ArrayList<>(allProtocols.length); for (String protocol : allProtocols) { if (!protocol.startsWith("SSL")) { enabledProtocols.add(protocol); } } socket.setEnabledProtocols(enabledProtocols.toArray(new String[enabledProtocols.size()])); } if (supportedCipherSuites != null) { socket.setEnabledCipherSuites(supportedCipherSuites); } return socket; }
From source file:org.wso2.carbon.databridge.agent.endpoint.binary.BinarySecureClientPoolFactory.java
@Override public Object createClient(String protocol, String hostName, int port) throws DataEndpointException, DataEndpointSecurityException, DataEndpointAgentConfigurationException { if (protocol.equalsIgnoreCase(DataEndpointConfiguration.Protocol.SSL.toString())) { int timeout = AgentHolder.getInstance() .getDataEndpointAgent(DataEndpointConstants.BINARY_DATA_AGENT_TYPE).getAgentConfiguration() .getSocketTimeoutMS();//from w w w . j a v a2 s . co m String sslProtocols = AgentHolder.getInstance() .getDataEndpointAgent(DataEndpointConstants.BINARY_DATA_AGENT_TYPE).getAgentConfiguration() .getSslEnabledProtocols(); String ciphers = AgentHolder.getInstance() .getDataEndpointAgent(DataEndpointConstants.BINARY_DATA_AGENT_TYPE).getAgentConfiguration() .getCiphers(); try { SSLSocketFactory sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault(); SSLSocket sslSocket = (SSLSocket) sslsocketfactory.createSocket(hostName, port); sslSocket.setSoTimeout(timeout); if (sslProtocols != null && sslProtocols.length() != 0) { String[] sslProtocolsArray = sslProtocols.split(","); sslSocket.setEnabledProtocols(sslProtocolsArray); } if (ciphers != null && ciphers.length() != 0) { String[] ciphersArray = ciphers.split(","); sslSocket.setEnabledCipherSuites(ciphersArray); } else { sslSocket.setEnabledCipherSuites(sslSocket.getSupportedCipherSuites()); } return sslSocket; } catch (IOException e) { throw new DataEndpointException( "Error while opening socket to " + hostName + ":" + port + ". " + e.getMessage(), e); } } else { throw new DataEndpointException("Unsupported protocol: " + protocol + ". Currently only " + DataEndpointConfiguration.Protocol.SSL.toString() + " supported."); } }
From source file:processing.app.debug.EasySSLProtocolSocketFactory.java
/** * Attempts to get a new socket connection to the given host within the given time limit. * <p>//from ww w.j ava 2 s . c o m * To circumvent the limitations of older JREs that do not support connect timeout a * controller thread is executed. The controller thread attempts to create a new socket * within the given limit of time. If socket constructor does not return until the * timeout expires, the controller terminates and throws an {@link ConnectTimeoutException} * </p> * * @param host the host name/IP * @param port the port on the host * @param clientHost the local host name/IP to bind the socket to * @param clientPort the port on the local machine * @param params {@link HttpConnectionParams Http connection parameters} * @return Socket a new socket * @throws IOException if an I/O error occurs while creating the socket * @throws UnknownHostException if the IP address of the host cannot be * determined */ public Socket createSocket(final String host, final int port, final InetAddress localAddress, final int localPort, final HttpConnectionParams params) throws IOException, UnknownHostException, ConnectTimeoutException { if (params == null) { throw new IllegalArgumentException("Parameters may not be null"); } int timeout = params.getConnectionTimeout(); SocketFactory socketfactory = getSSLContext().getSocketFactory(); Socket socket; if (timeout == 0) { socket = socketfactory.createSocket(host, port, localAddress, localPort); } else { socket = socketfactory.createSocket(); SocketAddress localaddr = new InetSocketAddress(localAddress, localPort); SocketAddress remoteaddr = new InetSocketAddress(host, port); socket.bind(localaddr); socket.connect(remoteaddr, timeout); } SSLSocket sslSocket = (SSLSocket) socket; sslSocket.setEnabledProtocols(SSL_PROTOCOLS); sslSocket.setEnabledCipherSuites(SSL_CYPHER_SUITES); return socket; }