當前位置: 首頁>>代碼示例>>Python>>正文


Python X509.load_cert_string方法代碼示例

本文整理匯總了Python中M2Crypto.X509.load_cert_string方法的典型用法代碼示例。如果您正苦於以下問題:Python X509.load_cert_string方法的具體用法?Python X509.load_cert_string怎麽用?Python X509.load_cert_string使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在M2Crypto.X509的用法示例。


在下文中一共展示了X509.load_cert_string方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_certificate

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def add_certificate(self, certificate):
		"""
		Certificates are either packed binary strings in DER format, or
		instances of m2crypto.X509.X509
		"""
		if not isinstance(certificate, X509.X509):
			try:
				certificate = X509.load_cert_string(certificate, X509.FORMAT_DER)
			except:  # pylint: disable=bare-except
				return 1

		newFingerprint = certificate.get_fingerprint()
		for oldcert in self.x509certs:
			if newFingerprint == oldcert.get_fingerprint():
				return -1

		self.x509certs.append(certificate)
		return 0 
開發者ID:rsmusllp,項目名稱:eapeak,代碼行數:20,代碼來源:networks.py

示例2: get_cert_data

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def get_cert_data(self, network, cert_layer):
		cert_data = cert_layer.certificate[3:]
		tmp_certs = []
		while cert_data:
			if len(cert_data) < 4:
				break  # Length and 1 byte are at least 4 bytes
			tmp_length = struct.unpack('!I', '\x00' + cert_data[:3])[0]
			cert_data = cert_data[3:]
			if len(cert_data) < tmp_length:
				break  # I smell corruption
			tmp_certs.append(cert_data[:tmp_length])
			cert_data = cert_data[tmp_length:]
		for certificate in tmp_certs:
			try:
				certificate = X509.load_cert_string(certificate, X509.FORMAT_DER)
			except X509.X509Error:
				pass
			network.add_certificate(certificate) 
開發者ID:rsmusllp,項目名稱:eapeak,代碼行數:20,代碼來源:parse.py

示例3: clean_certificate

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def clean_certificate(self):
        if not check_smime_status():
            raise forms.ValidationError(_('Improperly configured S/MIME: Email backend is incompatible'))
        try:
            from M2Crypto import X509
            certificate = self.cleaned_data['certificate']
            X509.load_cert_string(str(certificate))
        except ImportError:
            raise forms.ValidationError(_('Improperly configured S/MIME: missing dependencies'))
        except X509.X509Error:
            raise forms.ValidationError(_('Invalid certificate: unknown format'))
        return certificate 
開發者ID:certsocietegenerale,項目名稱:FIR,代碼行數:14,代碼來源:forms.py

示例4: mk_cacert

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def mk_cacert():
    csr = {"CN": config.get('ca','cert_ca_name'),
           "key": {
               "algo": "rsa",
               "size": config.getint('ca','cert_bits')
               },
           "names": [
               {
                   "C": config.get('ca','cert_country'),
                   "L": config.get('ca','cert_locality'),
                   "O": config.get('ca','cert_organization'),
                   "OU": config.get('ca','cert_org_unit'),
                   "ST": config.get('ca','cert_state')
                   }
                     ]
           }
    try:
        start_cfssl()
        body = post_cfssl('api/v1/cfssl/init_ca',csr)
    finally:
        stop_cfssl()

    if body['success']:
        pk_str = body['result']['private_key']
        pk = EVP.load_key_string(body['result']['private_key'].encode('utf-8'))
        cert = X509.load_cert_string(body['result']['certificate'].encode('utf-8'))
        pkey = cert.get_pubkey()

        return pk_str, cert, pk, pkey
    else:
        raise Exception("Unable to create CA") 
開發者ID:keylime,項目名稱:keylime,代碼行數:33,代碼來源:ca_impl_cfssl.py

示例5: find_certs

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def find_certs(self, network, newNetwork):
		for cert in network.findall('certificate'):
			if cert.get('encoding') == 'DER':
				newNetwork.add_certificate(X509.load_cert_string(base64.standard_b64decode(cert.text.strip()), X509.FORMAT_DER))
			elif cert.get('encoding') == 'PEM':
				newNetwork.add_certificate(X509.load_cert_string(base64.standard_b64decode(cert.text.strip()), X509.FORMAT_PEM)) 
開發者ID:rsmusllp,項目名稱:eapeak,代碼行數:8,代碼來源:parse.py

示例6: __init__

# 需要導入模塊: from M2Crypto import X509 [as 別名]
# 或者: from M2Crypto.X509 import load_cert_string [as 別名]
def __init__(self):
        self.request = current.request
        self.ssl_client_raw_cert = self.request.env.ssl_client_raw_cert

        # rebuild the certificate passed by the env
        # this is double work, but it is the only way
        # since we cannot access the web server ssl engine directly

        if self.ssl_client_raw_cert:

            x509 = X509.load_cert_string(
                self.ssl_client_raw_cert, X509.FORMAT_PEM)
            # extract it from the cert
            self.serial = self.request.env.ssl_client_serial or (
                '%x' % x509.get_serial_number()).upper()

            subject = x509.get_subject()

            # Reordering the subject map to a usable Storage map
            # this allows us a cleaner syntax:
            # cn = self.subject.cn
            self.subject = Storage(filter(None,
                                          map(lambda x:
                                              (x, map(lambda y:
                                                      y.get_data(
                                                      ).as_text(),
                                                      subject.get_entries_by_nid(subject.nid[x]))),
                                              subject.nid.keys()))) 
開發者ID:uwdata,項目名稱:termite-visualizations,代碼行數:30,代碼來源:x509_auth.py


注:本文中的M2Crypto.X509.load_cert_string方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。