Certificate can now read protogeni style pems which have some text at the top of...
authorJosh Karlin <jkarlin@bbn.com>
Thu, 7 Oct 2010 14:20:00 +0000 (10:20 -0400)
committerJosh Karlin <jkarlin@bbn.com>
Thu, 7 Oct 2010 14:20:00 +0000 (10:20 -0400)
sfa/trust/certificate.py

index 64ac865..450f14d 100644 (file)
@@ -299,11 +299,18 @@ class Certificate:
         # load it (support for the ---parent--- tag as well as normal chained certs)
 
         string = string.strip()
-
-
-        if not string.startswith('-----'):
+        
+        # If it's not in proper PEM format, wrap it
+        if string.count('-----BEGIN CERTIFICATE') == 0:
             string = '-----BEGIN CERTIFICATE-----\n%s\n-----END CERTIFICATE-----' % string
 
+        # If there is a PEM cert in there, but there is some other text first
+        # such as the text of the certificate, skip the text
+        beg = string.find('-----BEGIN CERTIFICATE')
+        if beg > 0:
+            # skipping over non cert beginning                                                                                                              
+            string = string[beg:]
+
         parts = []
 
         if string.count('-----BEGIN CERTIFICATE-----') > 1 and \