You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by dr...@apache.org on 2007/11/23 11:48:49 UTC
svn commit: r597636 - /labs/badca/openssl/certmodule.c
Author: dreid
Date: Fri Nov 23 02:48:48 2007
New Revision: 597636
URL: http://svn.apache.org/viewvc?rev=597636&view=rev
Log:
Add the certmodule.c.
I was going to wait until the nest commit for the Certificate
code, but as I broke the build sans this build, here it is...
Nowehere near complete yet ;-)
Added:
labs/badca/openssl/certmodule.c
Added: labs/badca/openssl/certmodule.c
URL: http://svn.apache.org/viewvc/labs/badca/openssl/certmodule.c?rev=597636&view=auto
==============================================================================
--- labs/badca/openssl/certmodule.c (added)
+++ labs/badca/openssl/certmodule.c Fri Nov 23 02:48:48 2007
@@ -0,0 +1,91 @@
+#include <Python.h>
+
+#include <openssl/asn1.h>
+#include <openssl/rsa.h>
+#include <openssl/err.h>
+#include <openssl/ssl.h>
+#include <openssl/pem.h>
+
+static void delcert(void *ptr)
+{
+ X509_free((X509 *)ptr);
+}
+
+static void delrsa(void *ptr)
+{
+ RSA_free((RSA *)ptr);
+}
+
+static PyObject *
+readCert(PyObject *self, PyObject *args)
+{
+ X509 *cert = NULL;
+ char *fn = NULL;
+ BIO *in = NULL;
+ PyObject *rv = NULL;
+
+ if (!PyArg_ParseTuple(args, "z", &fn))
+ return NULL;
+ if (!fn)
+ return NULL;
+
+ in = BIO_new(BIO_s_file());
+ if (!in)
+ return NULL;
+ BIO_read_filename(in, fn);
+ cert = PEM_read_bio_X509_AUX(in, NULL, NULL, NULL);
+ (void) BIO_free_all(in);
+
+ if (cert)
+ rv = PyCObject_FromVoidPtr(cert, delcert);
+
+ return rv;
+}
+
+static PyObject *
+getPublicKey(PyObject *self, PyObject *args)
+{
+ X509 *cert = NULL;
+ EVP_PKEY *pkey = NULL;
+ PyObject *pCert = NULL;
+
+ if (!PyArg_ParseTuple(args, "O", &pCert))
+ return NULL;
+ cert = (X509 *)PyCObject_AsVoidPtr(pCert);
+ if (!cert)
+ return NULL;
+
+ pkey = X509_get_pubkey(cert);
+ if (!pkey)
+ return NULL;
+
+ if (pkey->type != EVP_PKEY_RSA)
+ goto err;
+printf("got public key!!!\n");
+
+ return PyCObject_FromVoidPtr(pkey->pkey.rsa, delrsa);
+
+err:
+ if (pkey)
+ EVP_PKEY_free(pkey);
+ return NULL;
+}
+
+static PyMethodDef CertMethods[] = {
+ { "read", readCert, METH_VARARGS, "Read a certificate from a file" },
+ { "getPublicKey", getPublicKey, METH_VARARGS, "Get Public Key object" },
+ { NULL, NULL, 0, NULL },
+};
+
+PyMODINIT_FUNC
+initcert(void)
+{
+ PyObject *mod = NULL;
+
+ CRYPTO_malloc_init();
+ ERR_load_crypto_strings();
+ OpenSSL_add_all_algorithms();
+
+ mod = Py_InitModule("cert", CertMethods);
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org