Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75607

M2Crypto - Extract detached PKCS7 signature from PKCS7 (signature&data)

X-Received by 10.50.73.168 with SMTP id m8mr6555999igv.7.1407078825777; Sun, 03 Aug 2014 08:13:45 -0700 (PDT)
X-Received by 10.140.19.213 with SMTP id 79mr226478qgh.5.1407078825594; Sun, 03 Aug 2014 08:13:45 -0700 (PDT)
Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h18no13201154igc.0!news-out.google.com!b3ni5434qac.1!nntp.google.com!v10no4099896qac.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sun, 3 Aug 2014 08:13:45 -0700 (PDT)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=195.95.167.6; posting-account=LAUtCwoAAABTn7VjGQTpNj493BA_1qMg
NNTP-Posting-Host 195.95.167.6
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <f7fc5ad5-190e-459e-9a06-9179f04aaa90@googlegroups.com> (permalink)
Subject M2Crypto - Extract detached PKCS7 signature from PKCS7 (signature&data)
From Alexander Williams <alexandrucalin29@gmail.com>
Injection-Date Sun, 03 Aug 2014 15:13:45 +0000
Content-Type text/plain; charset=ISO-8859-1
Xref csiph.com comp.lang.python:75607

Show key headers only | View raw


I want to break a PKCS7 signature that contains data + signature into separate: raw data & detached PKCS7 signature in python.

I can get the data fro the signature because the verification routine returns it, but how can I get the detached signature ?

def verify_pkcs7(data_bio, signature_bio, cacert_bio, format=X509.FORMAT_PEM):
    sm_obj = SMIME.SMIME()
    st = X509.X509_Store()

    st.add_cert(X509.load_cert_string(cacert_bio))
    sm_obj.set_x509_store(st)


    if format == X509.FORMAT_PEM:
        p7 = SMIME.load_pkcs7_bio(signature_bio)
    else:
        p7 = SMIME.PKCS7(m2.pkcs7_read_bio_der(signature_bio._ptr()), 1)


    sk = p7.get0_signers(X509.X509_Stack())
    sm_obj.set_x509_stack(sk)

    try:
        v = sm_obj.verify(p7, data_bio)
        if v:
            print "Client signature verified."
            with open('file.rar', 'wb') as ff:
                ff.write(v)
    except Exception as e:
        print str(e)
        print "*** INVALID CLIENT MESSAGE SIGNATURE ***"
My wild guess is that it one of these functions.. I base my assumption on the fact that M2Crypto is a wrapper over OpenSSL.

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

M2Crypto - Extract detached PKCS7 signature from PKCS7 (signature&data) Alexander Williams <alexandrucalin29@gmail.com> - 2014-08-03 08:13 -0700

csiph-web