Checks whether a socket connection is secure. This factory creates plain socket connections which are not
considered secure.

@param sock the connected socket
@return <code>false</code>
@throws IllegalArgumentException if the argument is invalid
762243
@Override
    public final boolean isSecure(Socket sock)
            throws IllegalArgumentException {

        if (sock == null) {
            throw new IllegalArgumentException("Socket may not be null.");
        }
        // This check is performed last since it calls a method implemented
        // by the argument object. getClass() is final in java.lang.Object.
        if (sock.isClosed()) {
            throw new IllegalArgumentException("Socket is closed.");
        }
        return false;
    }
1316050
public static SSLServerSocketChannel open(SocketAddress address) throws IOException
    {
        try
        {
            return open(address, SSLContext.getDefault());
        }
        catch (NoSuchAlgorithmException ex)
        {
            throw new IOException(ex);
        }
    }
1033576
private boolean privilegedIsMasterSecretValid(final Socket socket) {
        if (socket instanceof SSLSocket) {
            SSLSession session = getSslSession(socket);
            if (session != null) {
                String className = session.getClass().getName();
                if ("sun.security.ssl.SSLSessionImpl".equals(className)) {
                    try {
                        Object masterSecret = getMasterSecret(session, className);
                        if (masterSecret == null) {
                            session.invalidate();
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Invalidated session " + session);
                            }
                            return false;
                        }
                    } catch (Exception e) {
                        failedToVerifyMasterSecret(e);
                    }
                }
            }
        }
        return true;

    }
1318588
public boolean shouldProxy(SocketAddress address) {
		SocketAddress addr = address;
		if (address instanceof TcpUtils.SocketAddressSupplier) {
			addr = ((TcpUtils.SocketAddressSupplier) address).get();
		}
		return addr instanceof InetSocketAddress && shouldProxy(((InetSocketAddress) addr).getHostString());
	}
522093
@Override
  public boolean isSecure()
  {
    if (_s == null || _sslSocketClass == null)
      return false;
    else
      return _sslSocketClass.isAssignableFrom(_s.getClass());
  }
321019
public static boolean available(final String host, final int port)
	{
		Socket socket = null;
		try
		{
			socket = newSocket(host, port);
			return false;
		}
		catch (final IOException ignored)
		{
			return true;
		}
		finally
		{
			if (!closeClientSocket(socket))
			{
				LOGGER.error("Socket could not be closed on host " + host + " on port " + port);
			}
		}
	}
1215409
public Socket getSocket(String host, int port, boolean useSecureSocket) throws Exception 
	{
		// Get the registered security domain for the URI
		SecurityDomain securityDomain = null;
		if (useSecureSocket) {
			securityDomain = CONTEXT.getSecurityDomainManager().getSecurityDomain(host,port);
		}
		return getSocket(host,port,useSecureSocket,securityDomain);
	}
987496
@InterfaceAudience.Public
    public void allowSelfSignedSSLCertificates() {
        // SSLSocketFactory that bypasses certificate verification.
        try {
            setSSLSocketFactory(selfSignedSSLSocketFactory());
        } catch (GeneralSecurityException e) {
            throw new RuntimeException(e);
        }

        // HostnameVerifier that bypasses hotname verification
        setHostnameVerifier(ignoreHostnameVerifier());
    }
31960
protected SSLSocket createSecureSocket(String host, int port, SecurityDomain securityDomain, Socket nestedSocket) throws NoSecurityDomainException, NoSuchAlgorithmException, KeyManagementException, UnknownHostException, IOException {
        if (!CONTEXT.isTLSEnabled())
            throw new NoSuchAlgorithmException("TLS has been disabled for ATNA connections via " + SecurityDomainManager.class.getName() + ".setSetTLSEnabled(false)");

        SSLContext ctx = null;

        // Attempt to get an instance of the first support TLS protocol
        try {
            ctx = SSLContext.getInstance(securityDomain.getJdkTlsClientProtocols()[0]);
        } catch (NoSuchAlgorithmException e) {
            securityDomain.restoreSystemEnvironment();
            throw e;
        }

        // Initialize the instance for the key and trust stores
        try {
            KeyManager[] keyMgrs = securityDomain.getKeyManagers();
            TrustManager[] trustMgrs = securityDomain.getTrustManagers();

            ctx.init(keyMgrs, trustMgrs, null);
        } catch (KeyManagementException e) {
            throw e;
        }

        SSLSocketFactory factory = ctx.getSocketFactory();
        SSLSocket socket = null;

        if (logger.isDebugEnabled()) {
            String[] supportedSuites = factory.getSupportedCipherSuites();
            logger.debug("\n\nSupported cipher suites are:");
            for (int i = 0; i < supportedSuites.length; i++) {
                logger.debug("\t" + supportedSuites[i]);
            }
        }

        int retries = 0;

        Throwable cause = null;
        // Loop to get a connection or until we've exhausted number of retries
        while (retries < CONTEXT.getConfig().getSocketRetries()) {
            try {

                if (logger.isDebugEnabled()) {
                    logger.debug("Connecting to " + host + " on port " + port +
                            " (timeout: " + CONTEXT.getConfig().getConnectTimeout() + " ms) using factory " + factory.getClass().getName());
                }

                //SocketAddress address = new InetSocketAddress(host,port);
                if (nestedSocket instanceof Socket) {
                    socket = (SSLSocket) (factory.createSocket(nestedSocket, host, port, true));
                } else {
                    socket = (SSLSocket) (factory.createSocket(host, port));
                }

                //socket.connect(address, CONTEXT.getConfig().getConnectTimeout());
                // Set amount of time to wait on socket read before timing out
                socket.setSoTimeout(CONTEXT.getConfig().getSocketTimeout());
                socket.setKeepAlive(true);

                socket.setEnabledProtocols(securityDomain.getJdkTlsClientProtocols());
                socket.setEnabledCipherSuites(securityDomain.getCipherSuites());

                if (logger.isDebugEnabled()) {
                    logger.debug("\n\nEnabled Cipher suites for connection are: ");
                    String[] suites = socket.getEnabledCipherSuites();
                    for (int i = 0; i < suites.length; i++) {
                        logger.debug("\t" + suites[i]);
                    }
                }

                // Force the TLS handshake at this point so we can catch any authentication errors
                socket.startHandshake();
                break;

            } catch (SSLHandshakeException e) {
                logger.error("Handshake failed with server " + host + " on port " + port + " reason " + e.getLocalizedMessage(), e);
                try {
                    socket.close();
                } catch (IOException e1) {
                    logger.error("Error trying to close socket for " + host + " on port " + port + " reason " + e1.getLocalizedMessage(), e1);
                }
                //securityDomain.restoreSystemEnvironment();
                throw e;
            } catch (UnknownHostException e) {
                logger.error("Unable to establish connection to " + host + " on port " + port + " reason " + e.getLocalizedMessage(), e);
                //securityDomain.restoreSystemEnvironment();
                throw e;
            } catch (SocketException e) {
                logger.error("Error connecting to " + host + " on port " + port + ". Will retry in "
                        + CONTEXT.getConfig().getSocketRetryWait() / 1000 + " seconds.", e);
                retries++;
                cause = e;

                try {
                    Thread.sleep(CONTEXT.getConfig().getSocketRetryWait());
                    continue;
                } catch (InterruptedException ie) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Sleep awoken early");
                    }
                    continue;
                }

            } catch (IOException e) {
                logger.error("Error connecting to " + host + " on port " + port + ". Will retry in "
                        + CONTEXT.getConfig().getSocketRetryWait() / 1000 + " seconds." + " reason " + e.getLocalizedMessage(), e);
                retries++;
                cause = e;

                try {
                    Thread.sleep(CONTEXT.getConfig().getSocketRetryWait());
                    continue;
                } catch (InterruptedException ie) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("Sleep awoken early");
                    }
                    continue;
                }
            }

        }

        // If socket retries exceed maximum allowed, throw an exception
        if (retries >= CONTEXT.getConfig().getSocketRetries()) {
            //securityDomain.restoreSystemEnvironment();
            logger.error("Secure Socket Connect Retries Exhausted.", cause);
            throw new ConnectException("Secure socket retries exhausted");
        }

        //securityDomain.restoreSystemEnvironment();
        return socket;
    }
230353
@Override
    public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException {
        final SSLSocketFactory factory = sslCtxt.getSocketFactory();
        final SSLSocket ss = (SSLSocket) factory.createSocket(host, port, localHost, localPort);

        ss.setEnabledProtocols(protocols);

        return ss;
    }
493447
@Override
    protected InetAddress isAcceptable(NetworkInterface networkInterface, InetAddress address) throws SocketException {

        if( networkInterface.isPointToPoint() )
            return address;
        return null;
    }
1280265
def secure(self):
        '''
        
        '''
        log.debug('ConCache securing sockets')
        if os.path.exists(self.cache_sock):
            os.chmod(self.cache_sock, 0o600)
        if os.path.exists(self.update_sock):
            os.chmod(self.update_sock, 0o600)
        if os.path.exists(self.upd_t_sock):
            os.chmod(self.upd_t_sock, 0o600)
334364
SocketChannel createSock() throws IOException {
        SocketChannel sock;
        sock = SocketChannel.open();
        sock.configureBlocking(false);
        sock.socket().setSoLinger(false, -1);
        sock.socket().setTcpNoDelay(true);
        return sock;
    }
642681
public boolean isConnected() {
    if (socket != null && socket.isConnected() && !socket.isInputShutdown() && !socket.isOutputShutdown())
      return true;
    return false;
  }
950566
void notifyNewClientConnected(Socket socket)
    {
        try
        {
            int secure = 0;
            while (clients.containsKey(Byte.valueOf(lastId)))
            {
                lastId++;
                secure++;
                final int max = 127;
                if (secure > max)
                {
                    break;
                }
            }
            // Prepare first data
            final ClientSocket client = new ClientSocket(lastId, socket);
            client.setState(StateConnection.CONNECTING);
            client.getOut().writeByte(NetworkMessageSystemId.CONNECTING);
            client.getOut().writeByte(client.getId());
            client.getOut().flush();

            // Update list
            clients.put(Byte.valueOf(client.getId()), client);
            clientsNumber++;
        }
        catch (final IOException exception)
        {
            errorNewClientConnected(exception);
        }
        catch (final LionEngineException exception)
        {
            errorNewClientConnected(exception);
        }
    }
865659
public Socket connectSocket(
        final Socket sock,
        final String host,
        final int port,
        final InetAddress localAddress,
        int localPort,
        final HttpParams params
    ) throws IOException {

        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)) {

            // we need to bind explicitly
            if (localPort < 0)
                localPort = 0; // indicates "any"

            InetSocketAddress isa =
                new InetSocketAddress(localAddress, localPort);
            sslsock.bind(isa);
        }

        int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
        int soTimeout = HttpConnectionParams.getSoTimeout(params);

        InetSocketAddress remoteAddress;
        if (this.nameResolver != null) {
            remoteAddress = new InetSocketAddress(this.nameResolver.resolve(host), port); 
        } else {
            remoteAddress = new InetSocketAddress(host, port);            
        }
        
        sslsock.connect(remoteAddress, connTimeout);

        sslsock.setSoTimeout(soTimeout);
        try {
            hostnameVerifier.verify(host, sslsock);
            // verifyHostName() didn't blowup - good!
        } catch (IOException iox) {
            // close the socket before re-throwing the exception
            try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
            throw iox;
        }

        return sslsock;
    }
377195
public static synchronized boolean canConnect(String url) {
        boolean result = false;
        HttpURLConnection conn = null;
        try {
            conn = getNormalCon(formatUrl(url));
            conn.connect();

            int resultCode = conn.getResponseCode();
            result = (200 == resultCode);

                /*
            if (!result) {
                Log.d("canConnect", resultCode + "|" + url);
            }
            // */

        } catch (IOException e) {
            result = false;
//            Log.e("canConnect", url + "|error:" + e.toString());
        } finally {
            if (conn != null) {
                conn.disconnect();
            }
        }

        return result;
    }