Returns PEM represntation of the certificate
344341
def pem(self):
        
        bio = Membio()
        if libcrypto.PEM_write_bio_X509(bio.bio, self.cert) == 0:
            raise X509Error("error serializing certificate")
        return str(bio)
337330
def get_signing_policy(signing_policy_name):
    '''
    
    '''
    signing_policy = _get_signing_policy(signing_policy_name)
    if not signing_policy:
        return 'Signing policy {0} does not exist.'.format(signing_policy_name)

    if isinstance(signing_policy, list):
        dict_ = {}
        for item in signing_policy:
            dict_.update(item)
        signing_policy = dict_

    try:
        del signing_policy['signing_private_key']
    except KeyError:
        pass

    try:
        signing_policy['signing_cert'] = get_pem_entry(signing_policy['signing_cert'], 'CERTIFICATE')
    except KeyError:
        log.debug('Unable to get "certificate" PEM entry')

    return signing_policy
1354497
def verify_tokens(self):
    
    xidentity = key_utils.get_compressed_public_key_from_pem(self.pem)
    url = self.uri + "/tokens"
    xsignature = key_utils.sign(self.uri + "/tokens", self.pem)
    headers = {"content-type": "application/json", 'accept': 'application/json', 'X-Identity': xidentity, 'X-Signature': xsignature, 'X-accept-version': '2.0.0'}
    response = requests.get(self.uri + "/tokens", headers=headers, verify=self.verify)
    if response.ok:
      allTokens = response.json()['data']
      selfKeys = self.tokens.keys() 
      matchedTokens = [token for token in allTokens for key in selfKeys if token.get(key) == self.tokens.get(key)]
      if not matchedTokens:
        return False
      return True
934252
def load_pem(cls, private_key, password=None):
        
        # TODO(sam): try to break this in tests
        maybe_path = normpath(private_key)
        if os.path.isfile(maybe_path):
            with open(maybe_path, 'rb') as pkf:
                private_key = pkf.read()
        if not isinstance(private_key, six.binary_type):
            private_key = private_key.encode('utf-8')

        pkey = serialization.load_pem_private_key(
            private_key,
            password=password,
            backend=crypto_backends.default_backend())
        return cls(pkey)
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)
1233966
def verify_callback(_, cert)
            pem = cert.current_cert.public_key.to_pem
            sha256 = OpenSSL::Digest::SHA256.new
            hash = sha256.digest(pem).unpack("H*")

            hash[0].casecmp(@hash).zero?
        end
659114
def load_pem_private_key(data, password):
    """"""
    key = _serialization.load_pem_private_key(
        data, password, _backends.default_backend())
    return key
1253751
def certificate_object(self):
        
        if not self.certificate:
            return None
        self.certificate.seek(0)
        return crypto.parse_certificate(self.certificate.read())
140756
function makeRealPem(pem) {
	let result = null;
	if (typeof pem === 'string') {
		result = pem.replace(/-----BEGIN -----/, '-----BEGIN CERTIFICATE-----');
		result = result.replace(/-----END -----/, '-----END CERTIFICATE-----');
		result = result.replace(/-----([^-]+) ECDSA ([^-]+)-----([^-]*)-----([^-]+) ECDSA ([^-]+)-----/, '-----$1 EC $2-----$3-----$4 EC $5-----');
	}
	return result;
}
1097990
def get_system_cert_file():
    
    if os.name == 'posix':
        filename = "/etc/ssl/certs/ca-certificates.crt"
        if os.path.isfile(filename):
            return filename
    msg = "no system certificate file found"
    raise ValueError(msg)
1330567
def _retrieveRemoteCertificate(self, From, port=port):
        
        CS = self.service.certificateStorage
        host = str(From.domainAddress())
        p = AMP()
        p.wrapper = self.wrapper
        f = protocol.ClientCreator(reactor, lambda: p)
        connD = f.connectTCP(host, port)

        def connected(proto):
            dhost = From.domainAddress()
            iddom = proto.callRemote(Identify, subject=dhost)
            def gotCert(identifyBox):
                theirCert = identifyBox['certificate']
                theirIssuer = theirCert.getIssuer().commonName
                theirName = theirCert.getSubject().commonName
                if (theirName != str(dhost)):
                    raise VerifyError(
                        "%r claimed it was %r in IDENTIFY response"
                        % (theirName, dhost))
                if (theirIssuer != str(dhost)):
                    raise VerifyError(
                        "self-signed %r claimed it was issued by "
                        "%r in IDENTIFY response" % (dhost, theirIssuer))
                def storedCert(ignored):
                    return theirCert
                return CS.storeSelfSignedCertificate(
                    str(dhost), theirCert).addCallback(storedCert)
            def nothingify(x):
                proto.transport.loseConnection()
                return x
            return iddom.addCallback(gotCert).addBoth(nothingify)
        connD.addCallback(connected)
        return connD
951163
def get_pem_entries(glob_path):
    '''
    
    '''
    ret = {}

    for path in glob.glob(glob_path):
        if os.path.isfile(path):
            try:
                ret[path] = get_pem_entry(text=path)
            except ValueError as err:
                log.debug('Unable to get PEM entries from %s: %s', path, err)

    return ret
202096
def get(self, bits=2048, type=crypto.TYPE_RSA, digest='sha1'):
        
        self.log.debug('Creating a new self-signed SSL certificate')
        # Generate the key and ready our cert
        key = crypto.PKey()
        key.generate_key(type, bits)
        cert = crypto.X509()

        # Fill in some pseudo certificate information with a wildcard common name
        cert.get_subject().C  = 'US'
        cert.get_subject().ST = 'California'
        cert.get_subject().L  = 'Los Angeles'
        cert.get_subject().O  = 'Wright Anything Agency'
        cert.get_subject().OU = 'Law firm / talent agency'
        cert.get_subject().CN = '*.{dn}'.format(dn=self.site.domain.name)

        # Set the serial number, expiration and issued
        cert.set_serial_number(1000)
        cert.gmtime_adj_notBefore(0)
        cert.gmtime_adj_notAfter(315360000)
        cert.set_issuer(cert.get_subject())

        # Map the key and sign our certificate
        cert.set_pubkey(key)
        cert.sign(key, digest)

        # Dump the PEM data and return a certificate container
        _cert = crypto.dump_certificate(crypto.FILETYPE_PEM, cert)
        _key  = crypto.dump_privatekey(crypto.FILETYPE_PEM, key)

        return Certificate(_cert, _key, type, bits, digest)
720408
public static String getCertIdByKeyStoreMap(String certPath, String certPwd) {
		if (!keyStoreMap.containsKey(certPath)) {
			// 缓存中未查询到,则加载RSA证书
			loadSignCert(certPath, certPwd);
		}
		return getCertIdIdByStore(keyStoreMap.get(certPath));
	}
955457
def get_crt_common_name(certificate_path=OLD_CERTIFICATE_PATH):
    '''
        
    '''
    try:
        certificate_file = open(certificate_path)
        crt = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                              certificate_file.read())
        return crt.get_subject().commonName
    except IOError:
        return None
477226
def extract_self_cert(signed_raw: str) -> Identity:
        
        lines = signed_raw.splitlines(True)
        n = 0

        version = int(Revocation.parse_field("Version", lines[n]))
        n += 1

        Revocation.parse_field("Type", lines[n])
        n += 1

        currency = Revocation.parse_field("Currency", lines[n])
        n += 1

        issuer = Revocation.parse_field("Issuer", lines[n])
        n += 1

        unique_id = Revocation.parse_field("IdtyUniqueID", lines[n])
        n += 1

        timestamp = Revocation.parse_field("IdtyTimestamp", lines[n])
        n += 1

        signature = Revocation.parse_field("IdtySignature", lines[n])
        n += 1

        return Identity(version, currency, issuer, unique_id, timestamp, signature)
1277282
def repr_part(self):
        """"""
        optargs = [('weighting', self.const, 1.0),
                   ('exponent', self.exponent, 2.0)]
        return signature_string([], optargs, mod=':.4')