private static List<Object> createSNIHostNames(String[] hostnames) { List<Object> list = new ArrayList<Object>(hostnames.length); // Create a list of SNIHostName from the String array. for (String hostname : hostnames) { // Create a new SNIHostName instance and add it to the list. list.add(createSNIHostName(hostname)); } return list; }
private static void setServerNames(SSLParameters parameters, String[] hostnames) { // Call parameters.setServerNames(List<SNIServerName>) method. Misc.invoke(sSetServerNamesMethod, parameters, createSNIHostNames(hostnames)); }
static void setServerNames(Socket socket, String[] hostnames) { if ((socket instanceof SSLSocket) == false) { return; } if (hostnames == null) { return; } SSLParameters parameters = ((SSLSocket)socket).getSSLParameters(); if (parameters == null) { return; } // Call SSLParameters.setServerNames(List<SNIServerName>) method. setServerNames(parameters, hostnames); } }
private SocketConnector createDirectRawSocket(String host, int port, boolean secure, int timeout) throws IOException { // Select a socket factory. SocketFactory factory = mSocketFactorySettings.selectSocketFactory(secure); // Let the socket factory create a socket. Socket socket = factory.createSocket(); // Set up server names for SNI as necessary if possible. SNIHelper.setServerNames(socket, mServerNames); // The address to connect to. Address address = new Address(host, port); // Create an instance that will execute the task to connect to the server later. return new SocketConnector(socket, address, timeout) .setVerifyHostname(mVerifyHostname); }
private static void setServerNames(SSLParameters parameters, String[] hostnames) { // Call parameters.setServerNames(List<SNIServerName>) method. Misc.invoke(sSetServerNamesMethod, parameters, createSNIHostNames(hostnames)); }
private static List<Object> createSNIHostNames(String[] hostnames) { List<Object> list = new ArrayList<Object>(hostnames.length); // Create a list of SNIHostName from the String array. for (String hostname : hostnames) { // Create a new SNIHostName instance and add it to the list. list.add(createSNIHostName(hostname)); } return list; }
private SocketConnector createProxiedRawSocket( String host, int port, boolean secure, int timeout) throws IOException { // Determine the port number of the proxy server. // Especially, if getPort() returns -1, the value // is converted to 80 or 443. int proxyPort = determinePort(mProxySettings.getPort(), mProxySettings.isSecure()); // Select a socket factory. SocketFactory socketFactory = mProxySettings.selectSocketFactory(); // Let the socket factory create a socket. Socket socket = socketFactory.createSocket(); // Set up server names for SNI as necessary if possible. SNIHelper.setServerNames(socket, mProxySettings.getServerNames()); // The address to connect to. Address address = new Address(mProxySettings.getHost(), proxyPort); // The delegatee for the handshake with the proxy. ProxyHandshaker handshaker = new ProxyHandshaker(socket, host, port, mProxySettings); // SSLSocketFactory for SSL handshake with the WebSocket endpoint. SSLSocketFactory sslSocketFactory = secure ? (SSLSocketFactory)mSocketFactorySettings.selectSocketFactory(secure) : null; // Create an instance that will execute the task to connect to the server later. return new SocketConnector( socket, address, timeout, handshaker, sslSocketFactory, host, port) .setVerifyHostname(mVerifyHostname); }
static void setServerNames(Socket socket, String[] hostnames) { if ((socket instanceof SSLSocket) == false) { return; } if (hostnames == null) { return; } SSLParameters parameters = ((SSLSocket)socket).getSSLParameters(); if (parameters == null) { return; } // Call SSLParameters.setServerNames(List<SNIServerName>) method. setServerNames(parameters, hostnames); } }
private SocketConnector createDirectRawSocket(String host, int port, boolean secure, int timeout) throws IOException { // Select a socket factory. SocketFactory factory = mSocketFactorySettings.selectSocketFactory(secure); // Let the socket factory create a socket. Socket socket = factory.createSocket(); // Set up server names for SNI as necessary if possible. SNIHelper.setServerNames(socket, mServerNames); // The address to connect to. Address address = new Address(host, port); // Create an instance that will execute the task to connect to the server later. return new SocketConnector(socket, address, timeout) .setVerifyHostname(mVerifyHostname); }
private SocketConnector createProxiedRawSocket( String host, int port, boolean secure, int timeout) throws IOException { // Determine the port number of the proxy server. // Especially, if getPort() returns -1, the value // is converted to 80 or 443. int proxyPort = determinePort(mProxySettings.getPort(), mProxySettings.isSecure()); // Select a socket factory. SocketFactory socketFactory = mProxySettings.selectSocketFactory(); // Let the socket factory create a socket. Socket socket = socketFactory.createSocket(); // Set up server names for SNI as necessary if possible. SNIHelper.setServerNames(socket, mProxySettings.getServerNames()); // The address to connect to. Address address = new Address(mProxySettings.getHost(), proxyPort); // The delegatee for the handshake with the proxy. ProxyHandshaker handshaker = new ProxyHandshaker(socket, host, port, mProxySettings); // SSLSocketFactory for SSL handshake with the WebSocket endpoint. SSLSocketFactory sslSocketFactory = secure ? (SSLSocketFactory)mSocketFactorySettings.selectSocketFactory(secure) : null; // Create an instance that will execute the task to connect to the server later. return new SocketConnector( socket, address, timeout, handshaker, sslSocketFactory, host, port) .setVerifyHostname(mVerifyHostname); }