From: Victor Wagner Date: Sun, 15 Feb 2015 11:36:30 +0000 (+0300) Subject: Add X509 to __all__. Add pem() method to X509 X-Git-Url: http://wagner.pp.ru/gitweb/?a=commitdiff_plain;h=286eefceb9abdd5f09ba85eaf15c7dd47a45856c;p=oss%2Fctypescrypto.git Add X509 to __all__. Add pem() method to X509 --- diff --git a/ctypescrypto/x509.py b/ctypescrypto/x509.py index e2ddea8..bd81fdd 100644 --- a/ctypescrypto/x509.py +++ b/ctypescrypto/x509.py @@ -36,7 +36,7 @@ except ImportError: utc=UTC() -__all__ = ['X509Error','X509Name','X509Store','StackOfX509'] +__all__ = ['X509','X509Error','X509Name','X509Store','StackOfX509'] class _validity(Structure): """ ctypes representation of X509_VAL structure @@ -305,6 +305,12 @@ class X509(object): def pubkey(self): """EVP PKEy object of certificate public key""" return PKey(ptr=libcrypto.X509_get_pubkey(self.cert,False)) + def pem(self): + """ Returns PEM represntation of the certificate """ + b=Membio() + if libcrypto.PEM_write_bio_X509(b.bio,self.cert)==0: + raise X509Error("error serializing certificate") + return str(b) def verify(self,store=None,chain=[],key=None): """ Verify self. Supports verification on both X509 store object @@ -540,6 +546,10 @@ class StackOfX509(object): libcrypto.sk_push(self.ptr,libcrypto.X509_dup(value.cert)) libcrypto.i2a_ASN1_INTEGER.argtypes=(c_void_p,c_void_p) libcrypto.ASN1_STRING_print_ex.argtypes=(c_void_p,c_void_p,c_long) +libcrypto.PEM_read_bio_X509.restype=c_void_p +libcrypto.PEM_read_bio_X509.argtypes=(c_void_p,POINTER(c_void_p),c_void_p,c_void_p) +libcrypto.PEM_write_bio_X509.restype=c_int +libcrypto.PEM_write_bio_X509.argtypes=(c_void_p,c_void_p) libcrypto.ASN1_TIME_print.argtypes=(c_void_p,c_void_p) libcrypto.ASN1_INTEGER_get.argtypes=(c_void_p,) libcrypto.ASN1_INTEGER_get.restype=c_long diff --git a/setup.py b/setup.py index 4849428..634f049 100644 --- a/setup.py +++ b/setup.py @@ -33,7 +33,7 @@ class MyTests(distutils.cmd.Command): setup( name="ctypescrypto", - version="0.2.4", + version="0.2.6", description="CTypes-based interface for some OpenSSL libcrypto features", author="Victor Wagner", author_email="vitus@wagner.pp.ru", diff --git a/tests/testx509.py b/tests/testx509.py index 060d811..50b3b6a 100644 --- a/tests/testx509.py +++ b/tests/testx509.py @@ -115,6 +115,9 @@ zVMSW4SOwg/H7ZMZ2cn6j1g0djIvruFQFGHUqFijyDATI+/GJYw2jxyA c=X509(self.cert1) p=c.pubkey self.assertEqual(p.exportpub(),self.pubkey1) + def test_pem(self): + c=X509(self.cert1) + self.assertEqual(c.pem(),self.cert1) def test_subject(self): c=X509(self.cert1) self.assertEqual(unicode(c.subject),u'C=RU,ST=Москва,L=Москва,O=Частное лицо,CN=Виктор Вагнер')