我想使用PyOpenSSL复制以下命令
openssl smime -sign -in company.mobileconfig -out signed.mobileconfig -signer server.crt -inkey server.key -certfile cert-chain.crt -outform der -nodetach
我可以使用M2Crypto进行签名,但我更喜欢用PyOpenSSL实现相同的目标
这是M2Crypto等效代码:
def sign(cert_file, key_file, message, flags):
"""
Returns a der encoded signed message
"""
signer = SMIME.SMIME()
signer.load_key(key_file, cert_file)
Rand.load_file('randpool.dat', -1)
p7 = signer.sign(BIO_from_buffer(message), flags=flags)
Rand.save_file('randpool.dat')
signed_message = BIO_from_buffer()
p7.write_der(signed_message)
return signed_message.read()