labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject svn commit: r602004 - in /labs/badca: BaDCA/Certificates.py Makefile.in openssl/certmodule.c tests/03CertTestCase.py tests/certs/ tests/certs/test1.pem tests/runTests.py
Date Fri, 07 Dec 2007 06:31:34 GMT
Author: dreid
Date: Thu Dec  6 22:31:32 2007
New Revision: 602004

URL: http://svn.apache.org/viewvc?rev=602004&view=rev
Log:
Add ability to limit tests to be run via runTests.py
Add a makefile rule to just run the certificate tests - more to
follow
Add more parsing of certificate data
Add more tests for parsed certificate data
Add test certificate


Added:
    labs/badca/tests/certs/
    labs/badca/tests/certs/test1.pem
Modified:
    labs/badca/BaDCA/Certificates.py
    labs/badca/Makefile.in
    labs/badca/openssl/certmodule.c
    labs/badca/tests/03CertTestCase.py
    labs/badca/tests/runTests.py

Modified: labs/badca/BaDCA/Certificates.py
URL: http://svn.apache.org/viewvc/labs/badca/BaDCA/Certificates.py?rev=602004&r1=602003&r2=602004&view=diff
==============================================================================
--- labs/badca/BaDCA/Certificates.py (original)
+++ labs/badca/BaDCA/Certificates.py Thu Dec  6 22:31:32 2007
@@ -33,7 +33,10 @@
         if self.cert is None or len(self.info) == 0:
             return None
         if part is None:
-            return self.info[section]
+            try:
+                return self.info[section]
+            except:
+                return None
         try:
             return self.info[section][part]
         except:

Modified: labs/badca/Makefile.in
URL: http://svn.apache.org/viewvc/labs/badca/Makefile.in?rev=602004&r1=602003&r2=602004&view=diff
==============================================================================
--- labs/badca/Makefile.in (original)
+++ labs/badca/Makefile.in Thu Dec  6 22:31:32 2007
@@ -12,3 +12,7 @@
 	PYTHONPATH="@EXT_PATH@:$$PYTHONPATH" \
 	@PYTHON@ @top_srcdir@/tests/runTests.py @top_srcdir@/tests
 
+test-cert:
+	PYTHONPATH="@EXT_PATH@:$$PYTHONPATH" \
+	@PYTHON@ @top_srcdir@/tests/runTests.py @top_srcdir@/tests Cert
+

Modified: labs/badca/openssl/certmodule.c
URL: http://svn.apache.org/viewvc/labs/badca/openssl/certmodule.c?rev=602004&r1=602003&r2=602004&view=diff
==============================================================================
--- labs/badca/openssl/certmodule.c (original)
+++ labs/badca/openssl/certmodule.c Thu Dec  6 22:31:32 2007
@@ -16,6 +16,72 @@
     RSA_free((RSA *)ptr);
 }
 
+/* We may want to make this more generic and able to cope with any
+ * possible entry in an X509_NAME structure?
+ */
+static PyObject *
+parseX509Name(X509_NAME *name)
+{
+    PyObject *sdict = PyDict_New();
+    int i;
+    struct sParts {
+        int nid;
+        const char *dict;
+    } parts[] = {
+        { NID_commonName, "CN" },
+        { NID_countryName, "C" },
+        { NID_organizationName, "O" },
+        { NID_organizationalUnitName, "OU" },
+        { NID_localityName, "L" },
+        { NID_stateOrProvinceName, "ST" },
+        { NID_pkcs9_emailAddress, "Email" },
+        { 0, NULL }
+    };
+
+    for (i = 0; parts[i].nid != 0; i++) {
+        char buf[512];
+        int rv = X509_NAME_get_text_by_NID(name, parts[i].nid, buf, 512);
+        if (rv > 0)
+            PyDict_SetItem(sdict, Py_BuildValue("s", parts[i].dict),
+                           PyString_FromStringAndSize(buf, rv));
+    }
+    return sdict;
+}
+
+static PyObject *
+makePyObjectFromASN1Time(ASN1_TIME *tm)
+{
+    BIO *bio = BIO_new(BIO_s_mem());
+    PyObject *rv = NULL;
+    char buf[2048];
+    int len;
+
+    if (bio) {
+        ASN1_TIME_print(bio, tm);
+        len = BIO_gets(bio, buf, sizeof(buf)-1);
+        rv = PyString_FromStringAndSize(buf, len);
+        BIO_free_all(bio);
+    }
+    return rv;
+}
+
+static PyObject *
+makePyStringFromASN1Integer(ASN1_INTEGER *i)
+{
+    BIO *bio = BIO_new(BIO_s_mem());
+    PyObject *rv = NULL;
+    char buf[2048];
+    int len;
+
+    if (bio) {
+        i2a_ASN1_INTEGER(bio, i);
+        len = BIO_gets(bio, buf, sizeof(buf)-1);
+        rv = PyString_FromStringAndSize(buf, len);
+        BIO_free_all(bio);
+    }
+    return rv;
+}
+
 static PyObject *
 readCert(PyObject *self, PyObject *args)
 {
@@ -85,7 +151,6 @@
     void *tmp = NULL;
     PyObject *dict = NULL;
     X509 *cert = NULL;
-    X509_REQ_INFO *ri = NULL;
     X509_NAME *subject = NULL, *issuer = NULL;
 
     if (! PyArg_ParseTuple(args, "O", &tmp))
@@ -115,6 +180,14 @@
                              Py_BuildValue("i", (ver + 1)));
 
     }
+    /* Serial number as a hex string */
+    {
+        PyObject *serStr = makePyStringFromASN1Integer(X509_get_serialNumber(cert));
+        if (serStr) {
+	    PyDict_SetItemString(dict, "serial", serStr);
+            Py_DECREF(serStr);
+        }
+    }
     /* Public Key information */
     {
         EVP_PKEY *pkey = X509_get_pubkey(cert);
@@ -123,7 +196,7 @@
         /* Public Key Algorithm */
 /*        {
             BIO *bp = BIO_new(BIO_s_mem());
-            if (bp && i2a_ASN1_OBJECT(bp, ri->pubkey->algor->algorithm)
> 0) {
+            if (bp && i2a_ASN1_OBJECT(bp, pkey->algor->algorithm) > 0) {
                 char *strPtr = NULL;
                 long sz = BIO_get_mem_data(bp, &strPtr);
                 (void)BIO_set_close(bp, BIO_NOCLOSE);
@@ -140,36 +213,31 @@
 
         PyDict_SetItem(dict, Py_BuildValue("s", "public_key"), pkdict);
     }
-    /* CSR Subject */
-/*
     {
+        PyObject *ndict = parseX509Name(subject);
+        PyDict_SetItem(dict, Py_BuildValue("s", "subject"), ndict);
+        Py_DECREF(ndict);
+    }
+    {
+        PyObject *ndict = parseX509Name(issuer);
+        PyDict_SetItem(dict, Py_BuildValue("s", "issuer"), ndict);
+        Py_DECREF(ndict);
+    }
+    {
+        PyObject *obj = makePyObjectFromASN1Time(X509_get_notBefore(cert));
+        if (obj) {
+	    PyDict_SetItemString(dict, "notBefore", obj);
+            Py_DECREF(obj);
+        }
+    }
+    {
+        PyObject *obj = makePyObjectFromASN1Time(X509_get_notAfter(cert));
+        if (obj) {
+	    PyDict_SetItemString(dict, "notAfter", obj);
+            Py_DECREF(obj);
 
-        PyObject *sdict = PyDict_New();
-        int i;
-        struct sParts {
-            int nid;
-            const char *dict;
-        } parts[] = {
-            { NID_commonName, "CN" },
-            { NID_countryName, "C" },
-            { NID_organizationName, "O" },
-            { NID_organizationalUnitName, "OU" },
-            { NID_localityName, "L" },
-            { NID_stateOrProvinceName, "ST" },
-            { NID_pkcs9_emailAddress, "Email" },
-            { 0, NULL }
-        };
-
-        for (i = 0; parts[i].nid != 0; i++) {
-            char buf[512];
-            int rv = X509_NAME_get_text_by_NID(ri->subject, parts[i].nid, buf, 512);
-            if (rv > 0)
-                PyDict_SetItem(sdict, Py_BuildValue("s", parts[i].dict),
-                               PyString_FromStringAndSize(buf, rv));
         }
-        PyDict_SetItem(dict, Py_BuildValue("s", "subject"), sdict);
     }
-*/
 
     return dict;
 err:

Modified: labs/badca/tests/03CertTestCase.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/03CertTestCase.py?rev=602004&r1=602003&r2=602004&view=diff
==============================================================================
--- labs/badca/tests/03CertTestCase.py (original)
+++ labs/badca/tests/03CertTestCase.py Thu Dec  6 22:31:32 2007
@@ -33,6 +33,33 @@
             "Failed to get correct version from certificate information"
         assert self.obj.getInformation("public_key", "strength") == 2048, \
        "Failed to get correct key strength from certificate information"
+        assert self.obj.getInformation("notBefore") == "Feb 11 22:42:35 2006 GMT", \
+                            "Failed to get correct net before date/time"
+        assert self.obj.getInformation("notAfter") == "Mar 13 22:42:35 2006 GMT", \
+                            "Failed to get correct net after date/time"
+        assert self.obj.getInformation("subject", "C") == 'GB', \
+                        "Failed to get correct country from certificate"
+        assert self.obj.getInformation("subject", "O") == 'ASF Development Authority', \
+                   "Failed to get correct organisation from certificate"
+        assert self.obj.getInformation("subject", "CN") == 'asylum.zones.apache.org', \
+                    "Failed to get correct common name from certificate"
+        assert self.obj.getInformation("subject", "Email") == 'dreid@apache.org', \
+                    "Failed to get correct email address from certificate"
+
+        assert self.obj.getInformation("issuer", "C") == 'GB', \
+                        "Failed to get correct country from certificate"
+        assert self.obj.getInformation("issuer", "O") == 'ASF Development Authority', \
+                   "Failed to get correct organisation from certificate"
+        assert self.obj.getInformation("issuer", "OU") == 'Server Certificates', \
+                   "Failed to get correct organisation from certificate"
+        assert self.obj.getInformation("issuer", "CN") == 'CA Administrator', \
+                    "Failed to get correct common name from certificate"
+        assert self.obj.getInformation("issuer", "Email") == 'dreid@apache.org', \
+                    "Failed to get correct email address from certificate"
+        assert self.obj.getInformation("serial") == 'B80A8A59ACEB819B64C60F726A32E935', \
+                         "Failed to get correct serial from certificate"
+
+
 
 if __name__ == "__main__":
     unittest.main()

Added: labs/badca/tests/certs/test1.pem
URL: http://svn.apache.org/viewvc/labs/badca/tests/certs/test1.pem?rev=602004&view=auto
==============================================================================
--- labs/badca/tests/certs/test1.pem (added)
+++ labs/badca/tests/certs/test1.pem Thu Dec  6 22:31:32 2007
@@ -0,0 +1,34 @@
+-----BEGIN CERTIFICATE-----
+MIIF4DCCBMigAwIBAgIRALgKilms64GbZMYPcmoy6TUwDQYJKoZIhvcNAQEFBQAw
+gYsxCzAJBgNVBAYTAkdCMSIwIAYDVQQKExlBU0YgRGV2ZWxvcG1lbnQgQXV0aG9y
+aXR5MRwwGgYDVQQLExNTZXJ2ZXIgQ2VydGlmaWNhdGVzMRkwFwYDVQQDExBDQSBB
+ZG1pbmlzdHJhdG9yMR8wHQYJKoZIhvcNAQkBFhBkcmVpZEBhcGFjaGUub3JnMB4X
+DTA2MDIxMTIyNDIzNVoXDTA2MDMxMzIyNDIzNVowgZIxCzAJBgNVBAYTAkdCMSIw
+IAYDVQQKExlBU0YgRGV2ZWxvcG1lbnQgQXV0aG9yaXR5MRwwGgYDVQQLExNTZXJ2
+ZXIgQ2VydGlmaWNhdGVzMSAwHgYDVQQDExdhc3lsdW0uem9uZXMuYXBhY2hlLm9y
+ZzEfMB0GCSqGSIb3DQEJARYQZHJlaWRAYXBhY2hlLm9yZzCCASIwDQYJKoZIhvcN
+AQEBBQADggEPADCCAQoCggEBAOCqYQZPDq7QBx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kM1REZFMEJCQkU2RTA5REUwMS5jcmww
+HwYJYIZIAYb4QgENBBIWEGNyZWF0ZWQgYnkgQmFEQ0EwDQYJKoZIhvcNAQEFBQAD
+ggEBAEoLr7t82OgWDu623HEA/p7hMT4mYJmzyhmjOPWhzc5BtYu/lU3XC0ZmdeDa
+/kbr9upoqyazhbVESFv5WVmTV+job5wTMkiG0v2JOGEpggYnK7/uSC9sYT6Ilkzd
+AII083C8wr6yP4LKOdQoK7ycCXC6FiFFlYKscman1w+Sf+hlZeyxPtYWsfeaNwuy
+VRImvG5vArITb8RTibvHqDQ0qhNLrz2b1OkMvpGaJ9yMKsQm7YjnWCjXw9uf2e3E
+gATxbafsDM/8r6Cu9Y0RR8GYtHdebqNJ0gmgPki0pPhZfVrxeYgf6g1BbcWaNua6
+wUxwI7uPTf5kllT7OksrcAJHClM=
+-----END CERTIFICATE-----

Modified: labs/badca/tests/runTests.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/runTests.py?rev=602004&r1=602003&r2=602004&view=diff
==============================================================================
--- labs/badca/tests/runTests.py (original)
+++ labs/badca/tests/runTests.py Thu Dec  6 22:31:32 2007
@@ -12,20 +12,28 @@
     fileMatcher = None
     loader = unittest.defaultTestLoader
     testRunner = None
+    filter = []
 
     def __init__(self):
         self.fileMatcher = re.compile("^\S*TestCase\.py$")
-        if len(sys.argv) != 2:
+        if len(sys.argv) < 2:
             self.exitUsage('You MUST supply a directory to scan')
         if not os.path.isdir(sys.argv[1]):
             self.exitUsage('You must supply a directory to scan')
         self.directory = os.path.abspath(sys.argv[1])
         files = os.listdir(self.directory)
+        if len(sys.argv) > 2:
+            self.filter = sys.argv[2:]
+            print "Filtering tests to " + str(self.filter)
         for f in files:
             if self.fileMatcher.match(f):
                 m = re.compile("^\d{2}([A-Za-z]*)TestCase\.py").match(f)
+                if len(self.filter) > 0:
+                    if m is None or m.group(1) not in self.filter:
+                        continue
+
                 if m is not None:
-                    print "\nRunning tests for " + m.group(1) + "\n"
+                    print "\nRunning tests for " + m.group(1) + "\n"                    
                 else:
                     print "\nRunning tests in " + f + "\n"
                 tests = self.getSuitesFromFilename(f)



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message