Initiate an SSL renegotiation.
558713
def do_renegotiate(self) -> None:
        
        if not self._is_handshake_completed:
            raise IOError('SSL Handshake was not completed; cannot renegotiate.')

        self._ssl.renegotiate()
        self.do_handshake()
311532
def connect(self):
    ""
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.connect((self.host, self.port))
    boto.log.debug("wrapping ssl socket; CA certificate file=%s",
                   self.ca_certs)
    self.sock = ssl.wrap_socket(sock, keyfile=self.key_file,
                                certfile=self.cert_file,
                                cert_reqs=ssl.CERT_REQUIRED,
                                ca_certs=self.ca_certs)
    cert = self.sock.getpeercert()
    hostname = self.host.split(':', 0)[0]
    if not ValidateCertificateHostname(cert, hostname):
      raise InvalidCertificateException(hostname,
                                        cert,
                                        'remote hostname "%s" does not match '\
                                        'certificate' % hostname)
35710
def reconnect(self):
        """"""
        if len(self._host) == 0:
            raise ValueError('Invalid host.')
        if self._port <= 0:
            raise ValueError('Invalid port number.')

        self._in_packet = {
            "command": 0,
            "have_remaining": 0,
            "remaining_count": [],
            "remaining_mult": 1,
            "remaining_length": 0,
            "packet": b"",
            "to_process": 0,
            "pos": 0}

        self._out_packet_mutex.acquire()
        self._out_packet = []
        self._out_packet_mutex.release()

        self._current_out_packet_mutex.acquire()
        self._current_out_packet = None
        self._current_out_packet_mutex.release()

        self._msgtime_mutex.acquire()
        self._last_msg_in = time.time()
        self._last_msg_out = time.time()
        self._msgtime_mutex.release()

        self._ping_t = 0
        self._state_mutex.acquire()
        self._state = mqtt_cs_new
        self._state_mutex.release()
        if self._ssl:
            self._ssl.close()
            self._ssl = None
            self._sock = None
        elif self._sock:
            self._sock.close()
            self._sock = None

        # Put messages in progress in a valid state.
        self._messages_reconnect_reset()

        try:
            if (sys.version_info[0] == 2 and sys.version_info[1] < 7) or (sys.version_info[0] == 3 and sys.version_info[1] < 2):
                sock = socket.create_connection((self._host, self._port))
            else:
                sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
        except socket.error as err:
            if err.errno != errno.EINPROGRESS and err.errno != errno.EWOULDBLOCK and err.errno != EAGAIN:
                raise

        verify_hostname = self._tls_insecure is False  # Decide whether we need to verify hostname

        if self._tls_ca_certs is not None:
            if self._useSecuredWebsocket:
                # Never assign to ._ssl before wss handshake is finished
                # Non-None value for ._ssl will allow ops before wss-MQTT connection is established
                rawSSL = ssl.wrap_socket(sock, ca_certs=self._tls_ca_certs, cert_reqs=ssl.CERT_REQUIRED)  # Add server certificate verification
                rawSSL.setblocking(0)  # Non-blocking socket
                self._ssl = SecuredWebSocketCore(rawSSL, self._host, self._port, self._AWSAccessKeyIDCustomConfig, self._AWSSecretAccessKeyCustomConfig, self._AWSSessionTokenCustomConfig)  # Override the _ssl socket
                # self._ssl.enableDebug()
            elif self._alpn_protocols is not None:
                # SSLContext is required to enable ALPN support
                # Assuming Python 2.7.10+/3.5+ till the end of this elif branch
                ssl_context = SSLContextBuilder()\
                    .with_ca_certs(self._tls_ca_certs)\
                    .with_cert_key_pair(self._tls_certfile, self._tls_keyfile)\
                    .with_cert_reqs(self._tls_cert_reqs)\
                    .with_check_hostname(True)\
                    .with_ciphers(self._tls_ciphers)\
                    .with_alpn_protocols(self._alpn_protocols)\
                    .build()
                self._ssl = ssl_context.wrap_socket(sock, server_hostname=self._host, do_handshake_on_connect=False)
                verify_hostname = False  # Since check_hostname in SSLContext is already set to True, no need to verify it again
                self._ssl.do_handshake()
            else:
                self._ssl = ssl.wrap_socket(
                    sock,
                    certfile=self._tls_certfile,
                    keyfile=self._tls_keyfile,
                    ca_certs=self._tls_ca_certs,
                    cert_reqs=self._tls_cert_reqs,
                    ssl_version=self._tls_version,
                    ciphers=self._tls_ciphers)

            if verify_hostname:
                if sys.version_info[0] < 3 or (sys.version_info[0] == 3 and sys.version_info[1] < 5):  # No IP host match before 3.5.x
                    self._tls_match_hostname()
                else:
                    ssl.match_hostname(self._ssl.getpeercert(), self._host)

        self._sock = sock

        if self._ssl and not self._useSecuredWebsocket:
            self._ssl.setblocking(0)  # For X.509 cert mutual auth.
        elif not self._ssl:
            self._sock.setblocking(0)  # For plain socket
        else:
            pass  # For MQTT over WebSocket

        return self._send_connect(self._keepalive, self._clean_session)
1011954
public static InternalProtocolNegotiator.ProtocolNegotiator tls(SslContext sslContext) {
    final io.grpc.netty.ProtocolNegotiator negotiator = ProtocolNegotiators.tls(sslContext);
    final class TlsNegotiator implements InternalProtocolNegotiator.ProtocolNegotiator {

      @Override
      public AsciiString scheme() {
        return negotiator.scheme();
      }

      @Override
      public ChannelHandler newHandler(GrpcHttp2ConnectionHandler grpcHandler) {
        return negotiator.newHandler(grpcHandler);
      }

      @Override
      public void close() {
        negotiator.close();
      }
    }
    
    return new TlsNegotiator();
  }
858044
function (changes, cb) {
        var self = this;

        this._log('info', 'Initiating incoming session');

        this.state = 'pending';

        this.pc.isInitiator = false;
        this.pc.handleOffer({
            type: 'offer',
            jingle: changes
        }, function (err) {
            if (err) {
                self._log('error', 'Could not create WebRTC answer');
                return cb({condition: 'general-error'});
            }
            cb();
        });
    }
375734
def _ttl(self):
        """"""
        return self.hlim if isinstance(self, scapy.layers.inet6.IPv6) else self.ttl
1102261
def create_ssl_context():
        """"""
        ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
        ssl_context.check_hostname = False
        ssl_context.verify_mode = ssl.CERT_NONE
        return ssl_context
312385
def reset (self):
        
        super(HttpUrl, self).reset()
        # initialize check data
        # server headers
        self.headers = {}
        self.auth = None
        self.ssl_cipher = None
        self.ssl_cert = None
560336
def register_ssl_context(self):
        
        if not empty('ssl', self.config['app']):
            self.ssl_context = self.config['app']['ssl']
        else:
            self.ssl_context = None
277955
def ssl_required(allow_non_ssl=False):
    
    def wrapper(view_func):
        def _checkssl(request, *args, **kwargs):
            # allow_non_ssl=True lets non-https requests to come
            # through to this view (and hence not redirect)
            if hasattr(settings, 'SSL_ENABLED') and settings.SSL_ENABLED \
                    and not request.is_secure() and not allow_non_ssl:
                return HttpResponseRedirect(
                    request.build_absolute_uri().replace('http://', 'https://'))
            return view_func(request, *args, **kwargs)

        return _checkssl
    return wrapper
474764
def catch_conn_reset(f):
    
    try:
        import OpenSSL
        ConnectionError = OpenSSL.SSL.SysCallError
    except:
        ConnectionError = None

    def new_f(self, *args, **kwargs):
        # Only handle if pyOpenSSL is installed.
        if ConnectionError:
            try:
                return f(self, *args, **kwargs)
            except ConnectionError as e:
                log.warning("caught connection reset error: %s", e)
                self.connect()
                return f(self, *args, **kwargs)
        else:
            return f(self, *args, **kwargs)
    return new_f
966900
def accept(self):
        """"""
        socket = Socket(self._llc, None)
        socket._tco = self.llc.accept(self._tco)
        return socket
132625
def negotiate_safe(self, name, params):
        
        for param in params.iterkeys():
            if param not in self.defaults:
                return

        try:
            return dict(self.negotiate(name, params))
        except (KeyError, ValueError, AssertionError):
            pass
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
113952
def sanitize_ssl(self):
        """"""
        if self["sslverify"] is True:
            try:
                self["sslverify"] = get_system_cert_file()
            except ValueError:
                try:
                    self["sslverify"] = get_certifi_file()
                except (ValueError, ImportError):
                    try:
                        self["sslverify"] = get_share_file('cacert.pem')
                    except ValueError:
                        pass
525435
def _setup_transport(self):
        """"""
        if hasattr(self, 'sslopts'):
            self.sock = ssl.wrap_socket(self.sock, **self.sslopts)
        else:
            self.sock = ssl.wrap_socket(self.sock)
        self.sock.do_handshake()
        self._quick_recv = self.sock.read
472836
def tls(force=False):
    
    def middleware(conn):
        if force or conn.has_extn('STARTTLS'):
            conn.starttls()
            conn.ehlo()
    return middleware