From bfc5335b3138cb5902f5c807d2d27a2250380045 Mon Sep 17 00:00:00 2001 From: Victor Wagner Date: Wed, 10 Sep 2014 16:22:00 +0400 Subject: [PATCH] Fix variable keylength on 64 bit env --- ctypescrypto/cipher.py | 4 ++-- ctypescrypto/x509.py | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ctypescrypto/cipher.py b/ctypescrypto/cipher.py index f4a2d47..8734b6d 100644 --- a/ctypescrypto/cipher.py +++ b/ctypescrypto/cipher.py @@ -121,7 +121,7 @@ class Cipher: if len(key) != cipher_type.key_length(): if (cipher_type.flags() & 8) != 0: # Variable key length cipher. - result = libcrypto.EVP_CipherInit_ex(self.ctx,cipher_type.cipher,None,None,None,c_int(enc)) + result = libcrypto.EVP_CipherInit_ex(self.ctx, cipher_type.cipher, None, key_ptr, iv_ptr, c_int(enc)) result=libcrypto.EVP_CIPHER_CTX_set_key_length(self.ctx,len(key)) if result == 0: self._clean_ctx() @@ -187,7 +187,7 @@ class Cipher: raise CipherError, "Cipher operation is already completed" outbuf=create_string_buffer(self.block_size) self.cipher_finalized = True - outlen=c_int() + outlen=c_int(0) result = libcrypto.EVP_CipherFinal_ex(self.ctx,outbuf , byref(outlen)) if result == 0: self._clean_ctx() diff --git a/ctypescrypto/x509.py b/ctypescrypto/x509.py index 9005fc2..82c0ec7 100644 --- a/ctypescrypto/x509.py +++ b/ctypescrypto/x509.py @@ -1,6 +1,7 @@ from ctypes import c_void_p from ctypescrypto.bio import Membio from ctypescrypto.pkey import Pkey +from ctypescrypto.oid import oid from ctypescrypto.exception import LibCryptoError from crypescrypto import libcrypto @@ -22,9 +23,16 @@ class X509Name: return libcrypto.X509_NAME_entry_count(self.ptr) def __getattr__(self,key): + if isinstatce(key,Oid): + # Return list of strings - def __setattr__(self,key,val): + elif isinstance(key,int): + # Return OID, sting tuple + else: + raise TypeError("X509 name can be indexed with oids and numbers only") + def __setattr__(self,key,val): + pass class X509_extlist: def __init__(self,ptr): self.ptr=ptr @@ -65,21 +73,29 @@ class X509: b=Membio() if libcrypto.i2d_X509_bio(b.bio,self.cert)==0: raise X509Error("error serializing certificate") + @property def pubkey(self): - """ Returns EVP PKEy object of certificate public key""" + """EVP PKEy object of certificate public key""" return PKey(ptr=libcrypto.X509_get_pubkey(self.cert,False)) def verify(self,key): """ Verify self on given issuer key """ - + @property def subject(self): + """ X509Name for certificate subject name """ return X509Name(libcrypto.X509_get_subject_name(self.cert)) + @property def issuer(self): + """ X509Name for certificate issuer name """ return X509Name(libcrypto.X509_get_issuer_name(self.cert)) + @property def serial(self): + """ Serial number of certificate as integer """ return - + @property def startDate(self): - + """ Certificate validity period start date """ + @property def endDate(self); + """ Certificate validity period end date """ def extensions(self): -- 2.39.2