labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dr...@apache.org
Subject svn commit: r602512 - in /labs/badca: BaDCA/Certificates.py tests/03CertTestCase.py tests/certs/ca1.pem
Date Sat, 08 Dec 2007 17:12:54 GMT
Author: dreid
Date: Sat Dec  8 09:12:53 2007
New Revision: 602512

URL: http://svn.apache.org/viewvc?rev=602512&view=rev
Log:
Add a sample CA certificate created using one of the sample keys
Add testing aimed at getting us towards being able to create a
certificate
Start adding in certificate creation code to Certificates

Added:
    labs/badca/tests/certs/ca1.pem
Modified:
    labs/badca/BaDCA/Certificates.py
    labs/badca/tests/03CertTestCase.py

Modified: labs/badca/BaDCA/Certificates.py
URL: http://svn.apache.org/viewvc/labs/badca/BaDCA/Certificates.py?rev=602512&r1=602511&r2=602512&view=diff
==============================================================================
--- labs/badca/BaDCA/Certificates.py (original)
+++ labs/badca/BaDCA/Certificates.py Sat Dec  8 09:12:53 2007
@@ -9,11 +9,11 @@
 class Certificate:
     filename = None
     cert = None
+    key = None
     
     def __init__(self, filename = None):
         if filename is not None:
-            self.cert = cert.read(filename)
-            self.filename = filename
+            self.readFromFile(filename)
 
     def readFromFile(self, filename = None):
         if filename is None:
@@ -27,7 +27,12 @@
     def getKey(self):
         if self.cert is None:
             return None
-        return cert.getPublicKey(self.cert)
+        return self.key
+
+    # should we store the path in the certificate object?
+    def addKeyPath(self, path):
+        if self.key is not None:
+            self.key.addSearchDirectory(path)
 
     # convenience function
     def getFingerprint(self):
@@ -66,5 +71,10 @@
             return None
 
     def processCertificate(self):
+        if self.cert is None:
+            return
         self.info = cert.parse(self.cert)
-        # todo - get public key!
+        key = cert.getPublicKey(self.cert)
+        if key is not None:
+            self.key = Keys.RSAKey(public = key)
+

Modified: labs/badca/tests/03CertTestCase.py
URL: http://svn.apache.org/viewvc/labs/badca/tests/03CertTestCase.py?rev=602512&r1=602511&r2=602512&view=diff
==============================================================================
--- labs/badca/tests/03CertTestCase.py (original)
+++ labs/badca/tests/03CertTestCase.py Sat Dec  8 09:12:53 2007
@@ -1,7 +1,7 @@
 import os
 import unittest
 
-from BaDCA import Keys, Certificates
+from BaDCA import Keys, CSRs, Certificates
 
 class BaDCAKeysTestCase(unittest.TestCase):
     obj = None
@@ -94,6 +94,29 @@
         errstr = "Purpose 'Any Purpose' was incorrectly reflected for CA"
         assert self.obj.checkPurpose('Any Purpose', 1) == 1, errstr
 
+    def test06(self):
+        """ Checking key object from certificate """
+        assert self.obj.readFromFile('tests/certs/test1.pem') == 1, \
+                                        "Failed to read the Certificate"
+
+        key = self.obj.getKey()
+        assert key is not None, "Failed to get key object"
+        assert key.hasPublic(), "Key object has not public key"
+        assert key.addSearchDirectory('tests/keys/private') == 1, \
+                                 "Unable to add certificate path to key"
+
+    def test07(self):
+        """ Create a certificate from a CSR """
+        csr = CSRs.CSR('tests/csr/test2.csr')
+        assert csr is not None, "Failed to get the CSR object"
+        assert self.obj.readFromFile('tests/certs/ca1.pem') == 1, \
+                                     "Failed to read the CA certificate"
+        self.obj.addKeyPath('tests/keys/private')
+        print str(self.obj.info)
+        key = self.obj.getKey()
+        assert key is not None, "Failed to get key object from certificate"
+        assert key.hasPublic(), "Not public key"
+        assert key.hasPrivate(), "No private key available!"
 
 if __name__ == "__main__":
     unittest.main()

Added: labs/badca/tests/certs/ca1.pem
URL: http://svn.apache.org/viewvc/labs/badca/tests/certs/ca1.pem?rev=602512&view=auto
==============================================================================
--- labs/badca/tests/certs/ca1.pem (added)
+++ labs/badca/tests/certs/ca1.pem Sat Dec  8 09:12:53 2007
@@ -0,0 +1,21 @@
+-----BEGIN CERTIFICATE-----
+MIIDbDCCAtWgAwIBAgIJANRKSSnXJty1MA0GCSqGSIb3DQEBBQUAMIGBMQswCQYD
+VQQGEwJHQjETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMYSW50ZXJuZXQg
+V2lkZ2l0cyBQdHkgTHRkMRkwFwYDVQQDExBCYURDQSBUZXN0aW5nIENBMR8wHQYJ
+KoZIhvcNAQkBFhBkcmVpZEBhcGFjaGUub3JnMB4XDTA3MTIwODE2NTkxMVoXDTA4
+MTIwNzE2NTkxMVowgYExCzAJBgNVBAYTAkdCMRMwEQYDVQQIEwpTb21lLVN0YXRl
+MSEwHwYDVQQKExhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQxGTAXBgNVBAMTEEJh
+RENBIFRlc3RpbmcgQ0ExHzAdBgkqhkiG9w0BCQEWEGRyZWlkQGFwYWNoZS5vcmcw
+gZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKfX5NEceId0PDZlmavBGJTkgFKw
+F7YQdH24iD1M6Yi/dgeyzJUxGOwS2dSBrB7f6lTrY6gG05pojf7X8/ckZ1n/Y9Oo
+/hGo+LH6rhkAKJ19iMg+dETUuqX0GMwcxuFI3ZhS7ls2ZTyQcXabbaurc85vqwNl
+LNg7g01YtQM4k40TAgMBAAGjgekwgeYwHQYDVR0OBBYEFLqX4iTV080MdtqLNAFN
+EWm+FDYUMIG2BgNVHSMEga4wgauAFLqX4iTV080MdtqLNAFNEWm+FDYUoYGHpIGE
+MIGBMQswCQYDVQQGEwJHQjETMBEGA1UECBMKU29tZS1TdGF0ZTEhMB8GA1UEChMY
+SW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMRkwFwYDVQQDExBCYURDQSBUZXN0aW5n
+IENBMR8wHQYJKoZIhvcNAQkBFhBkcmVpZEBhcGFjaGUub3JnggkA1EpJKdcm3LUw
+DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOBgQAJManNJecgeSUBjvb+Nory
+xmFeCu2jgO8+oZsXLTI2WpG8WDFQ9kUY/u5MxTnzu+4xIoz39EVT65spnBN9J61m
+K8/MCvMP4Hrp2RkgfjY0MLCQ6ikLes/DjAAHqICpJQ6L2AuQypgmAOik4ABz8HJD
+1DZIbwdc5VgBycjhJD84CA==
+-----END CERTIFICATE-----



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


Mime
View raw message