Disable unsecure ssl
 Ref: https://www.ruby-lang.org/en/news/2014/10/27/changing-default-settings-of-ext-openssl/
510412
def ssl_opts
      ssl_opts = OpenSSL::SSL::OP_ALL
      ssl_opts &= ~OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS if defined?(OpenSSL::SSL::OP_DONT_INSERT_EMPTY_FRAGMENTS)
      ssl_opts |= OpenSSL::SSL::OP_NO_COMPRESSION if defined?(OpenSSL::SSL::OP_NO_COMPRESSION)
      ssl_opts |= OpenSSL::SSL::OP_NO_SSLv2 if defined?(OpenSSL::SSL::OP_NO_SSLv2)
      ssl_opts |= OpenSSL::SSL::OP_NO_SSLv3 if defined?(OpenSSL::SSL::OP_NO_SSLv3)
      ssl_opts
    end
444767
def post_ssl(address, data={})
      uri = URI.parse(address)
      data["nonce"] = get_nonce

      begin
        req = Net::HTTP::Post.new(uri)
        req.set_form_data(data)
        req["Key"] = @api_key
        req["Sign"] = get_sign(req)

        https = initialize_https(uri)
        https.start {|w|
          response = w.request(req)
          case response
            when Net::HTTPSuccess
              json = JSON.parse(response.body)
              raise JSONException, response.body if json == nil
              return json
            else
              raise ConnectionFailedException, "Failed to connect to #{@name}: " + response.value
          end
        }
      rescue
        raise
      end
    end
447370
def ssl_context
        openssl_verify_mode = settings[:openssl_verify_mode]

        if openssl_verify_mode.kind_of?(String)
          openssl_verify_mode = OpenSSL::SSL.const_get("VERIFY_#{openssl_verify_mode.upcase}")
        end

        context = Net::SMTP.default_ssl_context
        context.verify_mode = openssl_verify_mode if openssl_verify_mode
        context.ca_path = settings[:ca_path] if settings[:ca_path]
        context.ca_file = settings[:ca_file] if settings[:ca_file]
        context
      end
1225266
def reset
      VALID_CONFIG_KEYS.each do |k, v|
        send((k.to_s + '='), v)
      end
      self.interceptors = Gruf::Interceptors::Registry.new
      self.root_path = Rails.root.to_s.chomp('/') if defined?(Rails)
      if defined?(Rails) && Rails.logger
        self.logger = Rails.logger
      else
        require 'logger'
        self.logger = ::Logger.new(STDOUT)
      end
      self.grpc_logger = logger if grpc_logger.nil?
      self.ssl_crt_file = "#{root_path}config/ssl/#{environment}.crt"
      self.ssl_key_file = "#{root_path}config/ssl/#{environment}.key"
      self.controllers_path = root_path.to_s.empty? ? 'app/rpc' : "#{root_path}/app/rpc"
      if use_default_interceptors
        interceptors.use(Gruf::Interceptors::ActiveRecord::ConnectionReset)
        interceptors.use(Gruf::Interceptors::Instrumentation::OutputMetadataTimer)
      end
      options
    end
804228
def wrap_socket(self, sock, server_side=False,
                    do_handshake_on_connect=True,
                    suppress_ragged_eofs=True, dummy=None):
        
        return ssl.wrap_socket(sock, keyfile=self._keyfile,
                               certfile=self._certfile,
                               server_side=server_side,
                               cert_reqs=self._verify_mode,
                               ssl_version=self._protocol,
                               ca_certs=self._cafile,
                               do_handshake_on_connect=do_handshake_on_connect,
                               suppress_ragged_eofs=suppress_ragged_eofs)
890238
public static function isSSL() : bool {
		if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https') {
			return true;
		} else if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') {
			return true;
		} else {
			return false;
		}
	}
403583
def revoke!(cakey=nil, crl=nil, next_update=36000)
      if cakey.nil?
        fail EasyRSA::Revoke::MissingCARootKey,
          'Please provide the root CA cert for the CRL'
      end

    # Get cert details if it's in a file
      unless cakey.is_a? OpenSSL::PKey::RSA
        if cakey.include?('BEGIN RSA PRIVATE KEY')
          cakey = OpenSSL::PKey::RSA.new cakey
        else
          begin
            cakey = OpenSSL::PKey::RSA.new File.read cakey
          rescue OpenSSL::PKey::RSAError => e
            fail EasyRSA::Revoke::InvalidCARootPrivateKey,
              'This is not a valid Private key file.'
          end
        end
      end

    # This is not a private key
      unless cakey.private?
        fail EasyRSA::Revoke::InvalidCARootPrivateKey,
          'This is not a valid Private key file.'
      end

    # Create or load the CRL
      unless crl.nil?
        begin
          @crl = OpenSSL::X509::CRL.new crl
        rescue
          fail EasyRSA::Revoke::InvalidCertificateRevocationList,
            'Invalid CRL provided.'
        end
      else
        @crl = OpenSSL::X509::CRL.new
      end

    # Add the revoked cert
      @crl.add_revoked(@revoked)

    # Needed CRL options
      @crl.last_update = @revoked.time
      @crl.next_update = Time.now + next_update
      @crl.version = 1

    # Update the CRL issuer
      @crl.issuer = EasyRSA::gen_issuer

    # Sign the CRL
      @updated_crl = @crl.sign(cakey, OpenSSL::Digest::SHA256.new)
      @updated_crl
    end
1241265
private boolean doSSLShutdown() {
        if (SSL.isInInit(ssl) != 0) {
            // Only try to call SSL_shutdown if we are not in the init state anymore.
            // Otherwise we will see 'error:140E0197:SSL routines:SSL_shutdown:shutdown while in init' in our logs.
            //
            // See also http://hg.nginx.org/nginx/rev/062c189fee20
            return false;
        }
        int err = SSL.shutdownSSL(ssl);
        if (err < 0) {
            int sslErr = SSL.getError(ssl, err);
            if (sslErr == SSL.SSL_ERROR_SYSCALL || sslErr == SSL.SSL_ERROR_SSL) {
                if (logger.isDebugEnabled()) {
                    int error = SSL.getLastErrorNumber();
                    logger.debug("SSL_shutdown failed: OpenSSL error: {} {}", error, SSL.getErrorString(error));
                }
                // There was an internal error -- shutdown
                shutdown();
                return false;
            }
            SSL.clearError();
        }
        return true;
    }
617316
def update_ssl_termination(self, loadbalancer, securePort=None, enabled=None,
            secureTrafficOnly=None):
        
        ssl_info = self.get_ssl_termination(loadbalancer)
        if not ssl_info:
            raise exc.NoSSLTerminationConfiguration("You must configure SSL "
                    "termination on this load balancer before attempting "
                    "to update it.")
        if securePort is None:
            securePort = ssl_info["securePort"]
        if enabled is None:
            enabled = ssl_info["enabled"]
        if secureTrafficOnly is None:
            secureTrafficOnly = ssl_info["secureTrafficOnly"]
        uri = "/loadbalancers/%s/ssltermination" % utils.get_id(loadbalancer)
        req_body = {"sslTermination": {
                "enabled": enabled,
                "secureTrafficOnly": secureTrafficOnly,
                "securePort": securePort,
                }}
        resp, body = self.api.method_put(uri, body=req_body)
        return body
1297296
def shutdown(self) -> None:
        
        self._is_handshake_completed = False
        try:
            self._flush_ssl_engine()
        except IOError:
            # Ensure shutting down the connection never raises an exception
            pass

        try:
            self._ssl.shutdown()
        except OpenSSLError as e:
            # Ignore "uninitialized" exception
            if 'SSL_shutdown:uninitialized' not in str(e) and 'shutdown while in init' not in str(e):
                raise
        if self._sock:
            self._sock.close()
59316
def __enableProxy(self):
        
        os.environ[
            "HTTP_PROXY"] = self.httpProxy()
        os.environ[
            "HTTPS_PROXY"] = self.httpsProxy()

        os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(
            os.path.dirname(
                os.path.abspath(__file__)),
            "cert.pem")
7456
def key=(*args)
      cert, passphrase = args.flatten
      ssl_context.key = OpenSSL::PKey::RSA.new(cert, passphrase)
    end
334822
def SetUseSSL(self, use_ssl):
    
    self._use_ssl = use_ssl
    logger.debug('Elasticsearch use_ssl: {0!s}'.format(use_ssl))
665078
def _resume_ssl_session(
            server_info: ServerConnectivityInfo,
            ssl_version_to_use: OpenSslVersionEnum,
            ssl_session: Optional[nassl._nassl.SSL_SESSION] = None,
            should_enable_tls_ticket: bool = False
    ) -> nassl._nassl.SSL_SESSION:
        
        ssl_connection = server_info.get_preconfigured_ssl_connection(override_ssl_version=ssl_version_to_use)
        if not should_enable_tls_ticket:
            # Need to disable TLS tickets to test session IDs, according to rfc5077:
            # If a ticket is presented by the client, the server MUST NOT attempt
            # to use the Session ID in the ClientHello for stateful session resumption
            ssl_connection.ssl_client.disable_stateless_session_resumption()  # Turning off TLS tickets.

        if ssl_session:
            ssl_connection.ssl_client.set_session(ssl_session)

        try:
            # Perform the SSL handshake
            ssl_connection.connect()
            new_session = ssl_connection.ssl_client.get_session()  # Get session data
        finally:
            ssl_connection.close()

        return new_session
522093
@Override
  public boolean isSecure()
  {
    if (_s == null || _sslSocketClass == null)
      return false;
    else
      return _sslSocketClass.isAssignableFrom(_s.getClass());
  }
613218
def ssl_required?
        return ENV['SSL'] == 'on' ? true : false if defined? ENV['SSL']
        return false if local_request?
        return false if RAILS_ENV == 'test'
        ((self.class.read_inheritable_attribute(:ssl_required_actions) || []).include?(action_name.to_sym)) && (::Rails.env == 'production' || ::Rails.env == 'staging')
      end
319112
def use_ssl=(flag)
      flag = flag ? true : false
      if started? and @use_ssl != flag
        raise IOError, "use_ssl value changed, but session already started"
      end
      @use_ssl = flag
    end