labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject svn commit: r601798 - in /labs/badca: BaDCA/ openssl/ tests/ tests/keys/ tests/keys/private/ tests/keys/public/
Date Thu, 06 Dec 2007 18:08:03 GMT
Author: dreid
Date: Thu Dec  6 10:08:01 2007
New Revision: 601798

URL: http://svn.apache.org/viewvc?rev=601798&view=rev
Log:
Fix the carnage that resulted from my last change to the Keys module :-)
Add start of certificate unit tests
Fix the position of some of the test files
Remove uneeded test files
Add certificate test case file

Move the test files to follow the "numbered" filename pattern so they
may run in the correct order. Still need to figure out how to get them
suitably ordered, but at least it gives us the direct control of the
ordering.

Added:
    labs/badca/tests/01KeysTestCase.py
      - copied unchanged from r601628, labs/badca/tests/KeysTestCase.py
    labs/badca/tests/02CSRTestCase.py
      - copied, changed from r601691, labs/badca/tests/CSRTestCase.py
    labs/badca/tests/03CertTestCase.py
    labs/badca/tests/keys/private/7c51d0ac629a02cf64429bc8677428189c4be60d.key
      - copied unchanged from r601350, labs/badca/tests/keys/7c51d0ac629a02cf64429bc8677428189c4be60d.key
Removed:
    labs/badca/tests/CSRTestCase.py
    labs/badca/tests/KeysTestCase.py
    labs/badca/tests/keys/7c51d0ac629a02cf64429bc8677428189c4be60d.key
    labs/badca/tests/keys/7c51d0ac629a02cf64429bc8677428189c4be60d.public.key
Modified:
    labs/badca/BaDCA/Certificates.py
    labs/badca/BaDCA/Keys.py
    labs/badca/openssl/certmodule.c
    labs/badca/tests/keys/public/test3.public.key

Modified: labs/badca/BaDCA/Certificates.py
URL: http://svn.apache.org/viewvc/labs/badca/BaDCA/Certificates.py?rev=601798&r1=601797&r2=601798&view=diff
==============================================================================
--- labs/badca/BaDCA/Certificates.py (original)
+++ labs/badca/BaDCA/Certificates.py Thu Dec  6 10:08:01 2007
@@ -2,7 +2,6 @@
 
 from BaDCA.Utils import getSHA1
 
-
 import cert
 
 from BaDCA import CSRs, Keys
@@ -15,6 +14,14 @@
         if filename is not None:
             self.cert = cert.read(filename)
             self.filename = filename
+
+    def readFromFile(self, filename = None):
+        if filename is None:
+            return 0
+        self.cert = cert.read(filename);
+        if self.cert:
+            return 1
+        return 0
 
     def getPublicKey(self):
         if self.cert is None:

Modified: labs/badca/BaDCA/Keys.py
URL: http://svn.apache.org/viewvc/labs/badca/BaDCA/Keys.py?rev=601798&r1=601797&r2=601798&view=diff
==============================================================================
--- labs/badca/BaDCA/Keys.py (original)
+++ labs/badca/BaDCA/Keys.py Thu Dec  6 10:08:01 2007
@@ -42,7 +42,6 @@
     sha1 = ''
     
     avail = KEY_NONE
-    directory = None
     directories = []
 
     def __init__(self, public = None, private = None):
@@ -76,10 +75,10 @@
         return 1
 
     def hasPrivate(self):
-        return (self.avail & KEY_PRIVATE) == KEY_PRIVATE
+        return ((self.avail & KEY_PRIVATE) == KEY_PRIVATE)
 
     def hasPublic(self):
-        return (self.avail & KEY_PUBLIC) == KEY_PUBLIC
+        return ((self.avail & KEY_PUBLIC) == KEY_PUBLIC)
 
     def create(self, bits = 2048):
         self.privRSA = rsa.genrsa(bits)
@@ -101,10 +100,7 @@
 
     def writeToDirectory(self, dir = None):
         if dir is None:
-            if self.directory is None:
-                baseDir = ''
-            else:
-                baseDir = self.directory
+            baseDir = '.'
         else:
             baseDir = dir
 
@@ -148,13 +144,14 @@
             return 0
         if not os.path.exists(filename):
             return 0
-        self.addSearchDirectory(os.path.dirname(filename))
         if internal == 0:
             self.Reset()
+            self.addSearchDirectory(os.path.dirname(filename))
         self.privRSA = rsa.read(filename)
         if self.privRSA:
             self.privFn = filename
             self.avail |= KEY_PRIVATE
+
             if internal == 0:
                 self.processKeys()
             return 1
@@ -168,7 +165,8 @@
         if not os.path.exists(filename):
             # Should we throw an exception here?
             return 0
-        self.Reset()
+        if self.privRSA is not None:
+            self.Reset()
         self.pubRSA = rsa.readPublic(filename)
         if self.pubRSA is None:
             return 0
@@ -209,6 +207,7 @@
         self.pubKey = ''
         self.sha1 = ''
         self.avail = KEY_NONE
+        self.directories[:] = []
 
     # assuming we have a public key, do we have a private key available
     # in the same directory or in a configured directory to search?
@@ -218,5 +217,6 @@
         for d in self.directories:
             ckFn = os.path.join(d, self.sha1 + '.key')
             if os.path.exists(ckFn):
-                self.readPrivateKey(ckFn, 1)
+                if self.readPrivateKey(ckFn, 1) == 1:
+                    break
 

Modified: labs/badca/openssl/certmodule.c
URL: http://svn.apache.org/viewvc/labs/badca/openssl/certmodule.c?rev=601798&r1=601797&r2=601798&view=diff
==============================================================================
--- labs/badca/openssl/certmodule.c (original)
+++ labs/badca/openssl/certmodule.c Thu Dec  6 10:08:01 2007
@@ -26,19 +26,25 @@
 
     if (!PyArg_ParseTuple(args, "z", &fn))
         return NULL;
-    if (!fn)
+
+    if (!fn) {
+        PyErr_SetString(PyExc_ValueError, "Filename MUST be supplied");
         return NULL;
+    }
 
     in = BIO_new(BIO_s_file());
-    if (!in)
+    if (!in) {
+        PyErr_SetString(PyExc_MemoryError, "failed to create a BIO");
         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 PyCObject_FromVoidPtr(cert, delcert);
 
+    PyErr_SetString(PyExc_IOError, "Failed to read certificate file");
     return rv;
 }
 

Copied: labs/badca/tests/02CSRTestCase.py (from r601691, labs/badca/tests/CSRTestCase.py)
URL: http://svn.apache.org/viewvc/labs/badca/tests/02CSRTestCase.py?p2=labs/badca/tests/02CSRTestCase.py&p1=labs/badca/tests/CSRTestCase.py&r1=601691&r2=601798&rev=601798&view=diff
==============================================================================
--- labs/badca/tests/CSRTestCase.py (original)
+++ labs/badca/tests/02CSRTestCase.py Thu Dec  6 10:08:01 2007
@@ -60,9 +60,9 @@
         key = self.obj.getKey()
         assert key is not None, "Unable to get key object from CSR"
         assert key.hasPublic(), "No public key found!"
-        assert key.addSearchDirectory('tests/keys') == 1, \
+        assert key.addSearchDirectory('tests/keys/private') == 1, \
                                  "Unable to add search directory to key"
-        assert key.hasPrivate(), "Unable to find private key"
+        assert key.hasPrivate() == 1, "Unable to find private key"
         assert key.hasPublic(), "No public key found!"
         self.subjectCheck('C', 'GB')
         self.subjectCheck('CN', "david reid")

Added: labs/badca/tests/03CertTestCase.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/03CertTestCase.py?rev=601798&view=auto
==============================================================================
--- labs/badca/tests/03CertTestCase.py (added)
+++ labs/badca/tests/03CertTestCase.py Thu Dec  6 10:08:01 2007
@@ -0,0 +1,22 @@
+import os
+import unittest
+
+from BaDCA import Keys, Certificates
+
+class BaDCAKeysTestCase(unittest.TestCase):
+    obj = None
+
+    def setUp(self):
+        """ Called prior to every test """
+        if self.obj is None:
+            self.obj = Certificates.Certificate()
+        else:
+            self.Reset()
+
+    def test01Read(self):
+        """ Test reading of a CSR from a file """
+        assert self.obj.readFromFile('tests/certs/test1.pem') == 1, \
+                                        "Failed to read the Certificate"
+
+if __name__ == "__main__":
+    unittest.main()

Modified: labs/badca/tests/keys/public/test3.public.key
URL: http://svn.apache.org/viewvc/labs/badca/tests/keys/public/test3.public.key?rev=601798&r1=601797&r2=601798&view=diff
==============================================================================
--- labs/badca/tests/keys/public/test3.public.key (original)
+++ labs/badca/tests/keys/public/test3.public.key Thu Dec  6 10:08:01 2007
@@ -1,6 +1,6 @@
 -----BEGIN PUBLIC KEY-----
-MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCZCnzWB7kZpl12IotutL3vJOET
-DaSAsEz8tr2jVjjY+JSXhZ88sjrseqrgFY9LYJ43GS36ZIbCNPmL62jG07wuuZ9a
-zX0ePmnlCG/9E2QkJgh4/cmar325ZpIxLVc4j+n6JVFrHGzFpPHDZqwRCS7Iw5aq
-/bmR2qdw5t65f+4x7wIDAQAB
+MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCn1+TRHHiHdDw2ZZmrwRiU5IBS
+sBe2EHR9uIg9TOmIv3YHssyVMRjsEtnUgawe3+pU62OoBtOaaI3+1/P3JGdZ/2PT
+qP4RqPix+q4ZACidfYjIPnRE1Lql9BjMHMbhSN2YUu5bNmU8kHF2m22rq3POb6sD
+ZSzYO4NNWLUDOJONEwIDAQAB
 -----END PUBLIC KEY-----



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


Mime
View raw message