Some patches for new features
Conrad Steenberg <[email protected]>
| Newsgroups | gmane.comp.python.cryptography |
|---|---|
| Message-ID | <[email protected]> |
Hi I've been maintaining some out of tree patches that may be of interest for testing and eventual merging by others on the list. Compared to the earlier set of patches I sent in December (http://listserv.surfnet.nl/scripts/wa.exe?A2=ind0412&L=python- crypto&F=&S=&P=1293), these enables the user to run a python-scripted CA. This became agonizingly close with the 0.13 release, so I couldn't resist doing the last 1% to get it done :-) 1. m2crypto-0.11.getkey.diff implements a way to get an RSA object from an EVP_PKEY object. Sample use: user_cert=X509.load_cert(cert_file) user_pub_key=user_cert.get_pubkey() user_pub_rsa=RSA.RSA_pub(m2.rsa_from_pkey(user_pub_key)) Obviously it would be nice not to have to go to the low-level m2 interface. Maybe next time... 2. m2crypto-0.13.x509.diff Verify an X509 object using the public key that signed it. Implements m2.x509_set_serial_number to set the serial number of an X509 certificate. Adds the ability to obtain a PEM-formatted version of the X509 cert. Sample use (continuing from above): signer_cert=X509.load_cert(signer_file) m2.x509_verify(user_cert.x509, signer_cert.get_pubkey()) Returns 0 or 1 depending on verification status 3. m2crypto-0.13.asn1.diff Implements m2.asn1_integer_set to set the value of an ASN integer object. this is the opposite of m2.asn1_integer_get. 4. m2crypto-0.13.rsapem.diff Adds the ability to obtain a PEM-encoded version of an RSA private key as a string. It also adds an alias RSA.save_pem() that saves the private key as a PEM file. This is just for symmetry with the X509.save_pem() method. Sample usage: print user_priv_rsa.as_pem(ciper=None) # For no encryption print user_priv_rsa.as_pem() # default cipher='des_ede3_cbc' The patches should be attached to this message, but can also be obtained from http://cvs.sourceforge.net/viewcvs.py/clarens/openpkg/m2crypto/ as soon as the SF public CVS catches up (usually 24 hours). Cheers Conrad
m2crypto-0.11.getkey.diff
(text/x-patch, 732 B)
--- SWIG/_rsa.i.orig Mon Jul 21 14:11:48 2003
+++ SWIG/_rsa.i Mon Jul 21 14:12:38 2003
@@ -6,15 +6,18 @@
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
+#include <openssl/evp.h>
%}
%apply Pointer NONNULL { RSA * };
%apply Pointer NONNULL { PyObject *pyfunc };
+%apply Pointer NONNULL { EVP_PKEY * };
%name(rsa_new) extern RSA *RSA_new(void);
%name(rsa_free) extern void RSA_free(RSA *);
%name(rsa_size) extern int RSA_size(const RSA *);
%name(rsa_check_key) extern int RSA_check_key(const RSA *);
+%name(rsa_from_pkey) extern RSA *EVP_PKEY_get1_RSA(EVP_PKEY *);
%constant int no_padding = RSA_NO_PADDING;
%constant int pkcs1_padding = RSA_PKCS1_PADDING;
m2crypto-0.13.x509.diff
(text/x-patch, 1.6 KB)
--- SWIG/_x509.i.orig Sun Mar 21 04:37:46 2004
+++ SWIG/_x509.i Tue Jan 4 11:24:53 2005
@@ -26,8 +26,10 @@
%name(x509_set_pubkey) extern int X509_set_pubkey(X509 *, EVP_PKEY *);
%name(x509_set_issuer_name) extern int X509_set_issuer_name(X509 *, X509_NAME *);
%name(x509_set_subject_name) extern int X509_set_subject_name(X509 *, X509_NAME *);
+%name(x509_set_serial_number) extern int X509_set_serialNumber(X509 *x, ASN1_INTEGER *serial);
-%name(x509_get_verify_error) extern const char *X509_verify_cert_error_string(long);
+%name(x509_verify) extern int X509_verify(X509 *a, EVP_PKEY *r);
+%name(x509_verify_error_string) extern const char *X509_verify_cert_error_string(long);
%name(x509_name_new) extern X509_NAME *X509_NAME_new( void );
%name(x509_name_free) extern void X509_NAME_free(X509_NAME *);
@@ -111,6 +113,10 @@
return PEM_read_bio_X509(bio, NULL, NULL, NULL);
}
+int x509_write_pem(BIO *bio, X509 *x) {
+ return PEM_write_bio_X509(bio, x);
+}
+
X509_REQ *x509_req_read_pem(BIO *bio) {
return PEM_read_bio_X509_REQ(bio, NULL, NULL, NULL);
}
--- M2Crypto/X509.py.orig Tue Mar 23 21:46:38 2004
+++ M2Crypto/X509.py Tue Jan 18 10:44:38 2005
@@ -173,6 +173,15 @@
m2.x509_print(buf.bio_ptr(), self.x509)
return buf.read_all()
+ def as_pem(self):
+ buf=BIO.MemoryBuffer()
+ m2.x509_write_pem(buf.bio_ptr(), self.x509)
+ return buf.read_all()
+
+ def save_pem(self, filename):
+ bio=BIO.openfile(filename, 'wb')
+ return m2.x509_write_pem(bio.bio_ptr(), self.x509)
+
def as_der(self):
assert m2.x509_type_check(self.x509), "'x509' type error"
buf=BIO.MemoryBuffer()
m2crypto-0.13.asn1.diff
(text/x-patch, 590 B)
--- SWIG/_asn1.i.orig Tue Jan 4 11:43:27 2005
+++ SWIG/_asn1.i Tue Jan 4 12:04:09 2005
@@ -30,6 +30,7 @@
%name(asn1_utctime_print) extern int ASN1_UTCTIME_print(BIO *, ASN1_UTCTIME *);
%name(asn1_integer_get) extern long ASN1_INTEGER_get(ASN1_INTEGER *);
+%name(asn1_integer_set) extern int ASN1_INTEGER_set(ASN1_INTEGER *a, long v);
%inline %{
/* ASN1_UTCTIME_set_string () is a macro */
@@ -38,3 +39,12 @@
}
%}
+
+%inline %{
+/* M_ASN1_INTEGER_new () is a macro */
+ASN1_INTEGER * asn1_integer_new(void) {
+
+ return M_ASN1_INTEGER_new();
+}
+
+%}
m2crypto-0.13.rsapem.diff
(text/x-patch, 663 B)
--- M2Crypto/RSA.py.orig Thu Dec 30 10:08:37 2004
+++ M2Crypto/RSA.py Thu Dec 30 11:36:31 2004
@@ -97,6 +97,16 @@
bio = BIO.openfile(file, 'wb')
return self.save_key_bio(bio, cipher, callback)
+ save_pem = save_key
+
+ def as_pem(self, cipher='des_ede3_cbc', callback=util.passphrase_callback):
+ """
+ Returns the key(pair) as a string in PEM format.
+ """
+ bio = BIO.MemoryBuffer()
+ self.save_key_bio(bio, cipher, callback)
+ return bio.read()
+
def save_key_der_bio(self, bio):
"""
Save the key pair to the M2Crypto.BIO object 'bio' in DER format.
smime.p7s
(application/x-pkcs7-signature, 2.5 KB) - not displayed