1

pkcs7 エンベロープと発行者の公開鍵を受け取り、証明書を返すこの関数を実行しました。

def get_cert_from_pkcs7(pkcs7, cert_parent):
    """
    Take a pkcs7 and return a certificate.

    @type pkcs7: string
    @param pkcs7: The base64 of the PKCS7 envelop as 
    -----BEGIN PKCS7-----
    base64 of the pkcs7 envelop
    -----END PKCS7-----

    @type cert_parent : string
    @param cert_parent : Issuer certificate file path

    @rtype : M2Crypto.X509
    @return : The certificate

    """
    sm_obj = SMIME.SMIME()
    x509 = X509.load_cert(cert_parent) # public key cert used by the remote
                                       # client when signing the message
    sk = X509.X509_Stack()
    sk.push(x509)
    sm_obj.set_x509_stack(sk)

    st = X509.X509_Store()
    st.load_info(cert_parent) # Public cert for the CA which signed
                              # the above certificate

    sm_obj.set_x509_store(st)

    buf = BIO.MemoryBuffer(pkcs7)
    p7 = SMIME.load_pkcs7_bio(buf)

    signers = p7.get0_signers(sk)
    certificat = signers[0]
    return certificat

問題は、certificat が Python にバインドされた C オブジェクトであり、関数が返すときに C オブジェクトがガベージ コレクションされるため、_ptr が存在せず、証明書へのアクセスがセグメンテーション エラーを返すことです。

エラー (コピー/クローン) なしで証明書を返すことは可能ですか?

4

0 に答える 0