我猜你在签名者和签名者的证书链之间混淆了.PKCS7_get0_signers返回签名者列表.
要使用2个签名者构建PKCS7消息,您可以使用以下步骤:
为第一个签名者建立密钥和证书:
openssl genrsa -out key1.pem openssl req -new -key key1.pem -subj "/CN=key1" | openssl x509 -req -signkey key1.pem -out cert1.pem
为第二个签名者建立密钥和证书:
openssl genrsa -out key2.pem openssl req -new -key key2.pem -subj "/CN=key2" | openssl x509 -req -signkey key2.pem -out cert2.pem
使用两个签名者创建PKCS7消息:
echo "Hello" | openssl smime -sign -nodetach \ -out signature.der -outform DER \ -inkey key1.pem -signer cert1.pem -inkey key2.pem -signer cert2.pem
然后可以打印签名者运行你的python脚本:
from M2Crypto import * bio=BIO.File(open('signature.der')) smime_object = SMIME.PKCS7(m2.pkcs7_read_bio_der(bio._ptr())) signers = smime_object.get0_signers(X509.X509_Stack()) for cert in signers: print(cert.get_issuer().as_text())
它给签名者的签发者:
CN = key1
CN = key2