Return the DN from the client side certificate as a D1 subject if a client side
    cert has been configured.

    Else return None.
557536
def _get_client_side_certificate_subject():
    
    subject = django.core.cache.cache.get('client_side_certificate_subject')
    if subject is not None:
        return subject
    cert_pem = _get_client_side_certificate_pem()
    if cert_pem is None:
        return None
    subject = _extract_subject_from_pem(cert_pem)
    django.core.cache.cache.set('client_side_certificate_subject', subject)
    return subject
814063
def get_public_dsn(self, scheme=None):
        
        if self.is_enabled():
            url = self.remote.get_public_dsn()
            if scheme:
                return '%s:%s' % (scheme, url)

            return url
168135
protected String findCertInfo(X509Certificate[] x509certificates) throws NamingException {
        if (x509certificates != null && x509certificates.length != 0) {
            // Only ever use the first certificate, as this si the client supplied one.
            // Further ones are trust stores and CAs that have signed the first cert.
            Principal subject = x509certificates[0].getSubjectDN();
            if (subject != null && subject.getName() != null) {
                List<Rdn> rdns;
                try {
                    rdns = new LdapName(subject.getName()).getRdns();
                }
                catch (InvalidNameException ine) {
                    return null;
                }
                return certInfoExtractor.extractCertInfo(rdns);
            }
        }
        return null;
    }
644489
def issue_cert
      test_dn = { 'C'  => 'US',
                  'ST' => 'California',
                  'L'  => 'Santa Barbara',
                  'O'  => 'Agent',
                  'OU' => 'Certification Services',
                  'CN' => 'Agent test' }
      dn = DistinguishedName.new(test_dn)
      key = RsaKeyPair.new
      [ Certificate.new(key, dn, dn), key ]
    end
672684
def get_certificate(self, certificate_uid):
        
        logging.debug('Retrieving certificate for uid=%s', certificate_uid)

        is_v1_uid = model.is_v1_uid(certificate_uid)
        if not is_v1_uid:
            return super(V1AwareCertificateStore, self).get_certificate(certificate_uid)

        # else it's V1.1 (if not valid, it will throw)
        certificate = self._find_certificate_metadata(uid=certificate_uid)
        if certificate:
            certificate_bytes = self._get_certificate_raw(certificate_uid)
            certificate_json = helpers.certificate_bytes_to_json(certificate_bytes)
            return model.to_certificate_model(certificate_json, certificate['txid'], certificate_bytes)

        message = 'Certificate metadata not found for certificate uid=%s' % certificate_uid
        logging.error(message)
        raise KeyError(message)
1471
def certificate_rabbitmq(self):
        
        if not self.__certificate_rabbitmq:
            self.__certificate_rabbitmq = CertificateRabbitMQ(self.__connection)
        return self.__certificate_rabbitmq
455060
def _get_subject_uri(self, guid=None):
        
        uri = self.uri + '/v1/subject'
        if guid:
            uri += '/' + urllib.quote_plus(guid)
        return uri
680744
def get_default_ssl_version():
    
    if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
        return ssl.PROTOCOL_TLSv1_2
    elif hasattr(ssl, 'PROTOCOL_TLSv1_1'):
        return ssl.PROTOCOL_TLSv1_1
    elif hasattr(ssl, 'PROTOCOL_TLSv1'):
        return ssl.PROTOCOL_TLSv1
    return None
352135
def certificate(self, value):
        

        if value is not None:
            is_oscrypto = isinstance(value, asymmetric.Certificate)
            if not is_oscrypto and not isinstance(value, x509.Certificate):
                raise TypeError(_pretty_message(
                    '''
                    certificate must be an instance of asn1crypto.x509.Certificate
                    or oscrypto.asymmetric.Certificate, not %s
                    ''',
                    _type_name(value)
                ))

            if is_oscrypto:
                value = value.asn1

        self._certificate = value
674847
def _find_certificate_metadata(self, uid=None):
        
        certificate = self.db.certificates.find_one({'uid': uid})
        return certificate
1313801
def getCert(username, password,
            certHost=_SERVER,
            certfile=None,
            certQuery=_PROXY):
    """"""

    if certfile is None:
        certfile = tempfile.NamedTemporaryFile()

    # Add the username and password.
    # If we knew the realm, we could use it instead of ``None``.
    password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
    top_level_url = "http://" + certHost
    logging.debug(top_level_url)
    password_mgr.add_password(None, top_level_url, username, password)
    handler = urllib2.HTTPBasicAuthHandler(password_mgr)
    logging.debug(str(handler))
    # create "opener" (OpenerDirector instance)
    opener = urllib2.build_opener(handler)

    # Install the opener.   
    urllib2.install_opener(opener)

    # buuld the url that with 'GET' a certificat using user_id/password info
    url = "http://" + certHost + certQuery
    logging.debug(url)

    r = None
    try:
        r = opener.open(url)
    except urllib2.HTTPError as e:
        logging.debug(url)
        logging.debug(str(e))
        return False

    logging.debug(str(r))

    if r is not None:
        while True:
            buf = r.read()
            logging.debug(buf)
            if not buf:
                break
            certfile.write(buf)
        r.close()

    return certfile
1195784
static String getDNSubField(String varName, String DN) throws CertificateMapperException {
        if (varName.equals("DN")) {
            return DN; // return the whole DN
        }
        // Parse the DN looking for 'varName'
        StringTokenizer st = new StringTokenizer(DN);
        for (;;) {
            String name, value;
            try {
                name = st.nextToken(",= ");
                value = st.nextToken(",");
                if (value != null) {
                    value = value.substring(1);
                }
            } catch (NoSuchElementException e) {
                e.getMessage();
                break;
            }
            if (name.equals(varName)) {
                return value;
            }
        }

        throw new CertificateMapperException(WIMMessageKey.UNKNOWN_DN_FIELD, Tr.formatMessage(
                                                                                              tc,
                                                                                              WIMMessageKey.UNKNOWN_DN_FIELD,
                                                                                              WIMMessageHelper.generateMsgParms(varName)));
    }
536116
def public_dsn(dsn):
    ''''''
    m = RE_DSN.match(dsn)
    if not m:
        log.error('Unable to parse Sentry DSN')
    public = '{scheme}://{client_id}@{domain}/{site_id}'.format(
        **m.groupdict())
    return public
47308
def process_der(self, data, name):
        
        from cryptography.x509.base import load_der_x509_certificate
        try:
            x509 = load_der_x509_certificate(data, self.get_backend())
            self.num_der_certs += 1
            return self.process_x509(x509, name=name, pem=False, source='der-cert')

        except Exception as e:
            logger.debug('DER processing failed: %s : %s' % (name, e))
            self.trace_logger.log(e)
405414
def confirm_not_old_proxy(loaded_cert):
    
    # Examine the last CommonName to see if it looks like an old proxy.
    last_cn = loaded_cert.subject.get_attributes_for_oid(x509.oid.NameOID.COMMON_NAME)[
        -1
    ]
    # if the last CN is 'proxy' or 'limited proxy' we are in an old proxy
    if last_cn.value in ("proxy", "limited proxy"):
        raise ValueError(
            "Proxy certificate is in an outdated format " "that is no longer supported"
        )
1366120
def verify_cb(conn, cert, errnum, depth, ok):
    
    if not ok:
        raise SecurityError("Could not verify CA certificate {0}"
                            .format(cert.get_subject()))
    return ok
563231
def LoadServerCertificate(self, server_certificate=None, ca_certificate=None):
    """"""
    # Check that the server certificate verifies
    try:
      server_certificate.Verify(ca_certificate.GetPublicKey())
    except rdf_crypto.VerificationError as e:
      self.server_name = None
      raise IOError("Server cert is invalid: %s" % e)

    # Make sure that the serial number is higher.
    server_cert_serial = server_certificate.GetSerialNumber()

    if server_cert_serial < config.CONFIG["Client.server_serial_number"]:
      # We can not accept this serial number...
      raise IOError("Server certificate serial number is too old.")
    elif server_cert_serial > config.CONFIG["Client.server_serial_number"]:
      logging.info("Server serial number updated to %s", server_cert_serial)
      config.CONFIG.Set("Client.server_serial_number", server_cert_serial)

      # Save the new data to the config file.
      config.CONFIG.Write()

    self.server_name = server_certificate.GetCN()
    self.server_certificate = server_certificate
    self.ca_certificate = ca_certificate
    self.server_public_key = server_certificate.GetPublicKey()
    # If we still have a cached session key, we need to remove it.
    self._ClearServerCipherCache()