X-Git-Url: http://www.wagner.pp.ru/gitweb/?a=blobdiff_plain;f=ctypescrypto%2Fcms.py;h=d92b7335f2dc4917352c0c422a6376332dd6f016;hb=HEAD;hp=c4ee1e9e1e2fbc04c09a9f387ea0ab9deeb4bb0b;hpb=1c45d3f211f72ce19c9e92be868c15afe5e6ec62;p=oss%2Fctypescrypto.git diff --git a/ctypescrypto/cms.py b/ctypescrypto/cms.py index c4ee1e9..d92b733 100644 --- a/ctypescrypto/cms.py +++ b/ctypescrypto/cms.py @@ -17,6 +17,12 @@ from ctypescrypto.bio import Membio from ctypescrypto.oid import Oid from ctypescrypto.x509 import StackOfX509 +# Check for neccesary functionality in libcrypto +# LibreSSL fails this check + +if not hasattr(libcrypto,"CMS_decrypt"): + raise OSError("libcrypto lacks CMS functionality. Try using different libcrypto") + class CMSError(LibCryptoError): """ Exception which is raised when error occurs @@ -120,7 +126,7 @@ class SignedData(CMSBase): raise ValueError("Certificate doesn't match public key") bio = Membio(data) if certs is not None and len(certs) > 0: - certstack = StackOfX509(certs) + certstack = StackOfX509(certs).ptr else: certstack = None ptr = libcrypto.CMS_sign(cert.cert, pkey.key, certstack, bio.bio, flags) @@ -243,7 +249,7 @@ class EnvelopedData(CMSBase): """ recp = StackOfX509(recipients) bio = Membio(data) - cms_ptr = libcrypto.CMS_encrypt(recp.ptr, bio.bio, cipher.cipher_type, + cms_ptr = libcrypto.CMS_encrypt(recp.ptr, bio.bio, cipher.cipher, flags) if cms_ptr is None: raise CMSError("encrypt EnvelopedData") @@ -263,7 +269,7 @@ class EnvelopedData(CMSBase): if pkey != cert.pubkey: raise ValueError("Certificate doesn't match private key") bio = Membio() - res = libcrypto.CMS_decrypt(self.ptr, pkey.key, cert.ccert, None, + res = libcrypto.CMS_decrypt(self.ptr, pkey.key, cert.cert, None, bio.bio, flags) if res <= 0: raise CMSError("decrypting CMS") @@ -285,7 +291,7 @@ class EncryptedData(CMSBase): @param flags - OR-ed combination of Flags constant """ bio = Membio(data) - ptr = libcrypto.CMS_EncryptedData_encrypt(bio.bio, cipher.cipher_type, + ptr = libcrypto.CMS_EncryptedData_encrypt(bio.bio, cipher.cipher, key, len(key), flags) if ptr is None: raise CMSError("encrypt data")