Called by _sslpsk.c to return the (psk, identity) tuple for the socket with
    the specified ssl socket.
504396
def _python_psk_client_callback(ssl_id, hint):
    
    if ssl_id not in _callbacks:
        return ("", "")
    else:
        res = _callbacks[ssl_id](hint)
        return res if isinstance(res, tuple) else (res, "")
867537
def _get_ssl_opts():
    '''
    
    '''
    sslopts = __salt__['config.option']('cassandra').get('ssl_options', None)
    ssl_opts = {}

    if sslopts:
        ssl_opts['ca_certs'] = sslopts['ca_certs']
        if SSL_VERSION in sslopts:
            if not sslopts[SSL_VERSION].startswith('PROTOCOL_'):
                valid_opts = ', '.join(
                    [x for x in dir(ssl) if x.startswith('PROTOCOL_')]
                )
                raise CommandExecutionError('Invalid protocol_version '
                                            'specified! '
                                            'Please make sure '
                                            'that the ssl protocol'
                                            'version is one from the SSL'
                                            'module. '
                                            'Valid options are '
                                            '{0}'.format(valid_opts))
            else:
                ssl_opts[SSL_VERSION] = \
                    getattr(ssl, sslopts[SSL_VERSION])
        return ssl_opts
    else:
        return None
1108036
def _create_socket(self):
        
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s = ssl.wrap_socket(s)
        s.connect((self.host, self.__port))
        s.settimeout(self.timeout)
        return s
984946
def start_tls(self, ssl_context: Union[bool, dict, ssl.SSLContext]=True) \
            -> 'SSLConnection':
        '''
        '''
        sock = self.writer.get_extra_info('socket')
        ssl_conn = SSLConnection(
            self._address,
            ssl_context=ssl_context,
            hostname=self._hostname, timeout=self._timeout,
            connect_timeout=self._connect_timeout, bind_host=self._bind_host,
            bandwidth_limiter=self._bandwidth_limiter, sock=sock
        )

        yield from ssl_conn.connect()

        return ssl_conn
994130
public static SSLSocketChannel open(String peer, int port, SSLContext sslContext) throws IOException
    {
        SSLEngine engine = sslContext.createSSLEngine(peer, port);
        engine.setUseClientMode(true);
        SSLParameters sslParameters = engine.getSSLParameters();
        SNIServerName  hostName = new SNIHostName(peer);
        List<SNIServerName> list = new ArrayList<>();
        list.add(hostName);
        sslParameters.setServerNames(list);
        engine.setSSLParameters(sslParameters);
        InetSocketAddress address = new InetSocketAddress(peer, port);
        SocketChannel socketChannel = SocketChannel.open(address);
        SSLSocketChannel sslSocketChannel = new SSLSocketChannel(socketChannel, engine, null, false);
        return sslSocketChannel;
    }
749529
def new_client_stream(self, sock):
        

        assert sock
        newsocket, fromaddr = sock.accept()
        logger.debug("New connection from"
                     " %s:%s", fromaddr[0], fromaddr[1])
        # NB: Despite the name, ssl.PROTOCOL_SSLv23 selects the highest
        # protocol version that both the client and server support. In modern
        # Python versions (>= 3.4) it supports TLS >= 1.0 with SSLv2 and SSLv3
        # being disabled. For Python >=3.5, PROTOCOL_SSLv23 is an alias for
        # PROTOCOL_TLS which should be used once compatibility with Python 3.4
        # is no longer desired.
        try:
            ssl_socket = ssl.wrap_socket(newsocket, cert_reqs=ssl.CERT_REQUIRED,
                                         server_side=True,
                                         certfile=self.certs['cert_file'],
                                         keyfile=self.certs['key_file'],
                                         ca_certs=self.certs['ca_file'],
                                         ssl_version=ssl.PROTOCOL_SSLv23)
        except (ssl.SSLError, socket.error) as message:
            logger.error(message)
            return None
        return ssl_socket
162864
def makeSocket(self, timeout=1):
        """"""
        plain_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

        if hasattr(plain_socket, 'settimeout'):
            plain_socket.settimeout(timeout)

        wrapped_socket = ssl.wrap_socket(
            plain_socket,
            ca_certs=self.ca_certs,
            cert_reqs=self.reqs,
            keyfile=self.keyfile,
            certfile=self.certfile
        )
        wrapped_socket.connect((self.host, self.port))

        return wrapped_socket
478419
def _get_socket_no_auth(self):
        """"""
        # We use the pid here to avoid issues with fork / multiprocessing.
        # See test.test_client:TestClient.test_fork for an example of
        # what could go wrong otherwise
        if self.pid != os.getpid():
            self.reset()

        # Get a free socket or create one.
        if not self._socket_semaphore.acquire(
                True, self.opts.wait_queue_timeout):
            self._raise_wait_queue_timeout()
        with self.lock:
            self.active_sockets += 1

        # We've now acquired the semaphore and must release it on error.
        try:
            try:
                # set.pop() isn't atomic in Jython less than 2.7, see
                # http://bugs.jython.org/issue1854
                with self.lock:
                    # Can raise ConnectionFailure.
                    sock_info = self.sockets.pop()
            except KeyError:
                # Can raise ConnectionFailure or CertificateError.
                sock_info = self.connect()
            else:
                # Can raise ConnectionFailure.
                sock_info = self._check(sock_info)
        except:
            self._socket_semaphore.release()
            with self.lock:
                self.active_sockets -= 1
            raise

        return sock_info
131973
private Socket createSimulatedSocket(SSLSocket socket) {
        SimulatedSocketFactory.configure(socket);
        socket.setEnabledProtocols(new String[] { SSLAlgorithm.SSLv3.name(), SSLAlgorithm.TLSv1.name() } );
        //socket.setEnabledCipherSuites(new String[] { "SSL_RSA_WITH_RC4_128_MD5" });
        return new SimulatedSSLSocket(socket, streamManager);
    }
1094418
def start(io)
      # start SSL negotiation
      ssl = OpenSSL::SSL::SSLSocket.new(io, @ctx)
      # connect to server socket
      ssl.accept
      # make sure to close also the underlying io
      ssl.sync_close = true
      # return as new io socket
      return ssl
    end
575597
def _sslobj(sock):
    
    pass
    if isinstance(sock._sslobj, _ssl._SSLSocket):
        return sock._sslobj
    else:
        return sock._sslobj._sslobj
638704
public SSLSocket getSSLSocket() throws KeystoreException, CommunicationException {
		SSLSocketFactory socketFactory = getSSLSocketFactory();
		logger.debug("Creating SSLSocket to " + getServerHost() + ":" + getServerPort());

		try {
			if (ProxyManager.isUsingProxy(server)) {
				return tunnelThroughProxy(socketFactory);
			} else {
				return (SSLSocket) socketFactory.createSocket(getServerHost(), getServerPort());
			}
		} catch (Exception e) {
			throw new CommunicationException("Communication exception: " + e, e);
		}
	}
1098572
public SSLSocket buildSocket() throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, KeyManagementException
    {
        if (host == null) throw new IllegalStateException("Cannot create socket without host");

        // Get socket
        final SSLSocket s = (SSLSocket) build().getSocketFactory().createSocket(host, port);

        // Set protocols
        s.setEnabledProtocols(TLS.getUsable(TLS.TLS_PROTOCOLS, s.getSupportedProtocols()));
        s.setEnabledCipherSuites(TLS.getUsable(TLS.TLS_CIPHER_SUITES, s.getSupportedCipherSuites()));

        return s;
    }
967403
def sni_certs(self):
		
		if not g_ssl_has_server_sni or self._ssl_sni_entries is None:
			return tuple()
		return tuple(entry.certificate for entry in self._ssl_sni_entries.values())
168977
def cipher(self):
        

        if not self._handshake_done:
            return

        current_cipher = SSL_get_current_cipher(self._ssl.value)
        cipher_name = SSL_CIPHER_get_name(current_cipher)
        cipher_version = SSL_CIPHER_get_version(current_cipher)
        cipher_bits = SSL_CIPHER_get_bits(current_cipher)
        return cipher_name, cipher_version, cipher_bits
603751
def wrap(self, sock):
        """"""
        EMPTY_RESULT = None, {}
        try:
            s = self.context.wrap_socket(
                sock, do_handshake_on_connect=True, server_side=True,
            )
        except ssl.SSLError as ex:
            if ex.errno == ssl.SSL_ERROR_EOF:
                # This is almost certainly due to the cherrypy engine
                # 'pinging' the socket to assert it's connectable;
                # the 'ping' isn't SSL.
                return EMPTY_RESULT
            elif ex.errno == ssl.SSL_ERROR_SSL:
                if _assert_ssl_exc_contains(ex, 'http request'):
                    # The client is speaking HTTP to an HTTPS server.
                    raise errors.NoSSLError

                # Check if it's one of the known errors
                # Errors that are caught by PyOpenSSL, but thrown by
                # built-in ssl
                _block_errors = (
                    'unknown protocol', 'unknown ca', 'unknown_ca',
                    'unknown error',
                    'https proxy request', 'inappropriate fallback',
                    'wrong version number',
                    'no shared cipher', 'certificate unknown',
                    'ccs received early',
                    'certificate verify failed',  # client cert w/o trusted CA
                )
                if _assert_ssl_exc_contains(ex, *_block_errors):
                    # Accepted error, let's pass
                    return EMPTY_RESULT
            elif _assert_ssl_exc_contains(ex, 'handshake operation timed out'):
                # This error is thrown by builtin SSL after a timeout
                # when client is speaking HTTP to an HTTPS server.
                # The connection can safely be dropped.
                return EMPTY_RESULT
            raise
        except generic_socket_error as exc:
            """It is unclear why exactly this happens.

            It's reproducible only with openssl>1.0 and stdlib ``ssl`` wrapper.
            In CherryPy it's triggered by Checker plugin, which connects
            to the app listening to the socket port in TLS mode via plain
            HTTP during startup (from the same process).


            Ref: https://github.com/cherrypy/cherrypy/issues/1618
            """
            is_error0 = exc.args == (0, 'Error')

            if is_error0 and IS_ABOVE_OPENSSL10:
                return EMPTY_RESULT
            raise
        return s, self.get_environ(s)
93017
def _tcp_socket(self):
        
        sock = iostream.IOStream(socket.socket(
                    socket.AF_INET, socket.SOCK_STREAM, socket.IPPROTO_TCP))
        sock.connect(self._address, self._tcp_on_connected)
        sock.set_close_callback(self._tcp_on_closed)
        return sock