当前位置: 首页>>代码示例>>Python>>正文


Python M2Crypto.Err类代码示例

本文整理汇总了Python中M2Crypto.Err的典型用法代码示例。如果您正苦于以下问题:Python Err类的具体用法?Python Err怎么用?Python Err使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Err类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_pkcs7

def load_pkcs7(p7file):
    bio = m2.bio_new_file(p7file, 'r')
    if bio is None:
        raise BIO.BIOError(Err.get_error())

    try:
        p7_ptr = m2.pkcs7_read_bio(bio)
    finally:
        m2.bio_free(bio)

    if p7_ptr is None:
        raise PKCS7_Error(Err.get_error())
    return PKCS7(p7_ptr, 1)
开发者ID:rodrigc,项目名称:m2crypto,代码行数:13,代码来源:SMIME.py

示例2: load_cert

def load_cert(file, format=FORMAT_PEM):
    """
    Load certificate from file.

    @type file: string
    @param file: Name of file containing certificate in either DER or
                 PEM format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the file to be loaded,
                   either PEM or DER.

    @rtype: M2Crypto.X509.X509
    @return: M2Crypto.X509.X509 object.
    """
    bio = BIO.openfile(file)
    if format == FORMAT_PEM:
        return load_cert_bio(bio)
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509(bio._ptr())
        if cptr is None:
            raise X509Error(Err.get_error())
        return X509(cptr, _pyfree=1)
    else:
        raise ValueError(
            "Unknown format. Must be either FORMAT_DER or FORMAT_PEM")
开发者ID:rodrigc,项目名称:m2crypto,代码行数:25,代码来源:X509.py

示例3: load_request

def load_request(file, format=FORMAT_PEM):
    """
    Load certificate request from file.

    @type file: string
    @param file: Name of file containing certificate request in
                 either PEM or DER format.
    @type format: int, either FORMAT_PEM or FORMAT_DER
    @param format: Describes the format of the file to be loaded,
                   either PEM or DER.

    @rtype: M2Crypto.X509.Request
    @return: M2Crypto.X509.Request object.
    """
    f = BIO.openfile(file)
    if format == FORMAT_PEM:
        cptr = m2.x509_req_read_pem(f.bio_ptr())
    elif format == FORMAT_DER:
        cptr = m2.d2i_x509_req(f.bio_ptr())
    else:
        raise ValueError(
            "Unknown filetype. Must be either FORMAT_PEM or FORMAT_DER")
    f.close()
    if cptr is None:
        raise X509Error(Err.get_error())
    return Request(cptr, 1)
开发者ID:rodrigc,项目名称:m2crypto,代码行数:26,代码来源:X509.py

示例4: load_session

def load_session(pemfile):
    f = BIO.openfile(pemfile)
    cptr = m2.ssl_session_read_pem(f.bio_ptr())
    f.close()
    if cptr is None:
        raise Err.get_error()
    return Session(cptr, 1)
开发者ID:mikedougherty,项目名称:M2Crypto,代码行数:7,代码来源:Session.py

示例5: sign

 def sign(self, data_bio, flags=0):
     if not hasattr(self, 'pkey'):
         raise SMIME_Error('no private key: use load_key()')
     if hasattr(self, 'x509_stack'):
         pkcs7 = m2.pkcs7_sign1(self.x509._ptr(), self.pkey._ptr(),
                                self.x509_stack._ptr(),
                                data_bio._ptr(), flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
     else:
         pkcs7 = m2.pkcs7_sign0(self.x509._ptr(), self.pkey._ptr(),
                                data_bio._ptr(), flags)
         if pkcs7 is None:
             raise SMIME_Error(Err.get_error())
         return PKCS7(pkcs7, 1)
开发者ID:rodrigc,项目名称:m2crypto,代码行数:16,代码来源:SMIME.py

示例6: text_crlf

def text_crlf(text):
    bio_in = BIO.MemoryBuffer(text)
    bio_out = BIO.MemoryBuffer()
    if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()):
        return bio_out.read()
    else:
        raise SMIME_Error(Err.get_error())
开发者ID:rodrigc,项目名称:m2crypto,代码行数:7,代码来源:SMIME.py

示例7: _validatepubkeygeneric

 def _validatepubkeygeneric(self, signing_cert, digest_alg, payload,
                            enc_digest):
     m2_cert = M2_X509.load_cert_der_string(der_encoder.encode(signing_cert))
     pubkey = m2_cert.get_pubkey()
     pubkey.reset_context(digest_alg().name)
     pubkey.verify_init()
     pubkey.verify_update(payload)
     v = pubkey.verify_final(enc_digest)
     if v != 1:
         self.openssl_error = M2_Err.get_error()
         # Let's try a special case. I have no idea how I would determine when
         # to use this instead of the above code, so I'll always try. The
         # observed problem was that for one countersignature (RSA on MD5),
         # the encrypted digest did not contain an ASN.1 structure, but the
         # raw hash value instead.
         try:
             rsa = pubkey.get_rsa()
         except ValueError:
             # It's not an RSA key, just fall through...
             pass
         else:
             clear = rsa.public_decrypt(enc_digest, M2_RSA.pkcs1_padding)
             if digest_alg(payload).digest() == clear:
                 return 1
     return v
开发者ID:sebdraven,项目名称:verify-sigs,代码行数:25,代码来源:auth_data.py

示例8: load_session

def load_session(pemfile):
    # type: (AnyStr) -> Session
    with BIO.openfile(pemfile) as f:
        cptr = m2.ssl_session_read_pem(f.bio_ptr())
    if cptr is None:
        raise SSLError(Err.get_error())
    return Session(cptr, 1)
开发者ID:appknox,项目名称:m2crypto,代码行数:7,代码来源:Session.py

示例9: run

    def run(self):
        ctx = SSL.Context()
        ctx.load_cert_chain("tests/server.pem")
        conn = SSL.Connection(ctx)
        cipher_list = conn.get_cipher_list()
        sslbio = BIO.SSLBio()
        readbio = BIO.MemoryBuffer()
        writebio = BIO.MemoryBuffer()
        sslbio.set_ssl(conn)
        conn.set_bio(readbio, writebio)
        conn.set_connect_state()
        sock = socket.socket()
        sock.connect((self.host, self.port))

        handshake_complete = False
        while not handshake_complete:
            ret = sslbio.do_handshake()
            if ret <= 0:
                if not sslbio.should_retry() or not sslbio.should_read():
                    err_string = Err.get_error()
                    print(err_string)
                    sys.exit("unrecoverable error in handshake - client")
                else:
                    output_token = writebio.read()
                    if output_token is not None:
                        sock.sendall(output_token)
                    else:
                        input_token = sock.recv(1024)
                        readbio.write(input_token)
            else:
                handshake_complete = True

        sock.close()
开发者ID:pywbem,项目名称:m2crypto,代码行数:33,代码来源:test_bio_ssl.py

示例10: text_crlf_bio

def text_crlf_bio(bio_in):
    # type: (BIO.BIO) -> BIO.BIO
    bio_out = BIO.MemoryBuffer()
    if m2.smime_crlf_copy(bio_in._ptr(), bio_out._ptr()):
        return bio_out
    else:
        raise SMIME_Error(Err.get_error())
开发者ID:mcepl,项目名称:M2Crypto,代码行数:7,代码来源:SMIME.py

示例11: smime_load_pkcs7

def smime_load_pkcs7(p7file):
    bio = m2.bio_new_file(p7file, 'r')
    if bio is None:
        raise BIO.BIOError(Err.get_error())

    try:
        p7_ptr, bio_ptr = m2.smime_read_pkcs7(bio)
    finally:
        m2.bio_free(bio)

    if p7_ptr is None:
        raise SMIME_Error(Err.get_error())
    if bio_ptr is None:
        return PKCS7(p7_ptr, 1), None
    else:
        return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
开发者ID:rodrigc,项目名称:m2crypto,代码行数:16,代码来源:SMIME.py

示例12: load_session

def load_session(pemfile):
    f = BIO.openfile(pemfile)
    cptr = m2.ssl_session_read_pem(f.bio_ptr())
    f.close()
    if cptr is None:
        from M2Crypto.SSL import SSLError
        raise SSLError(Err.get_error())
    return Session(cptr, 1)
开发者ID:0xkag,项目名称:M2Crypto,代码行数:8,代码来源:Session.py

示例13: smime_load_pkcs7_bio

def smime_load_pkcs7_bio(p7_bio):
    p7_ptr, bio_ptr = m2.smime_read_pkcs7(p7_bio._ptr())
    if p7_ptr is None:
        raise SMIME_Error(Err.get_error())
    if bio_ptr is None:
        return PKCS7(p7_ptr, 1), None
    else:
        return PKCS7(p7_ptr, 1), BIO.BIO(bio_ptr, 1)
开发者ID:rodrigc,项目名称:m2crypto,代码行数:8,代码来源:SMIME.py

示例14: ctrl_cmd_string

 def ctrl_cmd_string(self, cmd, arg, optional=0):
     # type: (AnyStr, Optional[AnyStr], int) -> None
     """Call ENGINE_ctrl_cmd_string"""
     cmd = six.ensure_str(cmd)
     if arg is not None:
         arg = six.ensure_str(arg)
     if not m2.engine_ctrl_cmd_string(self._ptr, cmd, arg, optional):
         raise EngineError(Err.get_error())
开发者ID:mcepl,项目名称:M2Crypto,代码行数:8,代码来源:Engine.py

示例15: test_makefile_err

 def test_makefile_err(self):
     pid = self.start_server(self.args)
     try:
         ctx = SSL.Context()
         s = SSL.Connection(ctx)
         try:
             s.connect(self.srv_addr)
         except SSL.SSLError, e:
             assert 0, e
         f = s.makefile()
         data = self.http_get(s)
         s.close()
         del f
         del s
         err_code = Err.peek_error_code()
         assert not err_code, 'Unexpected error: %s' % err_code
         err = Err.get_error()
         assert not err, 'Unexpected error: %s' % err
开发者ID:CongLi,项目名称:autotest-client-tests,代码行数:18,代码来源:test_ssl.py


注:本文中的M2Crypto.Err类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。