GID now supports both xmlrpc formatted subjectAltName as well as the standard General...
authorJosh Karlin <jkarlin@bbn.com>
Tue, 9 Mar 2010 17:50:19 +0000 (17:50 +0000)
committerJosh Karlin <jkarlin@bbn.com>
Tue, 9 Mar 2010 17:50:19 +0000 (17:50 +0000)
CHANGES-GENI-API.txt
sfa/trust/certificate.py
sfa/trust/gid.py

index 9d37dd8..52bdb7e 100644 (file)
@@ -1,5 +1,8 @@
 2010-03-08  Josh Karlin  <jkarlin@localhost.localdomain>
 
+       * sfa/trust/gid.py (GID.encode): States URI and UUID explicitly without xml
+       (GID.decode): GIDs now encode/decode URI and UUID without the xml (but can still read it)
+
        * sfa/trust/certificate.py (Certificate.save_to_string): SaveParents defaults to true
        (Certificate.save_to_string): Saves without the parent tag.  
        (Certificate.set_data): Accepts optional field
index bcdd214..ce64dbe 100644 (file)
@@ -218,7 +218,6 @@ class Keypair:
 class Certificate:
    digest = "md5"
 
-   data = {}
    cert = None
    issuerKey = None
    issuerSubject = None
@@ -236,6 +235,7 @@ class Certificate:
    # @param filename If filename!=None, load the certficiate from the file.
 
    def __init__(self, create=False, subject=None, string=None, filename=None):
+       self.data = {}
        if create or subject:
            self.create()
        if subject:
@@ -419,7 +419,7 @@ class Certificate:
        if self.data.has_key(field):
           raise "cannot set ", field, " more than once"
        self.data[field] = str
-       self.add_extension(field, 0, "URI:http://" + str)
+       self.add_extension(field, 0, str)
 
    ##
    # Return the data string that was previously set with set_data
@@ -430,13 +430,10 @@ class Certificate:
 
        try:
            uri = self.get_extension(field)
+           self.data[field] = uri           
        except LookupError:
-           self.data.pop(field)
            return None
-
-       if not uri.startswith("URI:http://"):
-           raise "bad encoding in ", field       
-       self.data[field] = uri[11:]
+       
        return self.data[field]
 
    ##
index 7e9d40c..051168f 100644 (file)
@@ -18,7 +18,7 @@ def create_uuid():
     return str(uuid.uuid4().int)
 
 ##
-# GID is a tuplie:
+# GID is a tuple:
 #    (uuid, hrn, public_key)
 #
 # UUID is a unique identifier and is created by the python uuid module
@@ -101,11 +101,14 @@ class GID(Certificate):
             urn = self.urn
         else:
             urn = hrn_to_urn(self.hrn, None)
-        dict = {"uuid": self.uuid,
-                "urn": self.urn}
-        str = xmlrpclib.dumps((dict,))
-        self.set_data(str)
+            
+        szURN = "URI:" + urn
+        szUUID = "URI:" + uuid.UUID(int=self.uuid).urn
+        
+        
+        str = szURN + ", " + szUUID
+        self.set_data(str, 'subjectAltName')
+
 
     ##
     # Decode the subject-alt-name field of the X509 certificate into the
@@ -113,12 +116,19 @@ class GID(Certificate):
     # functions in this class.
 
     def decode(self):
-        data = self.get_data()
+        data = self.get_data('subjectAltName')
+        dict = {}
         if data:
-            dict = xmlrpclib.loads(self.get_data())[0][0]
-        else:
-            dict = {}
-
+            if data.lower().startswith('uri:http://<params>'):
+                dict = xmlrpclib.loads(data[11:])[0][0]
+            else:
+                spl = data.split(', ')
+                for val in spl:
+                    if val.lower().startswith('uri:urn:uuid:'):
+                        dict['uuid'] = uuid.UUID(val[4:]).int
+                    elif val.lower().startswith('uri:urn:publicid:idn+'):
+                        dict['urn'] = val[4:]
+                    
         self.uuid = dict.get("uuid", None)
         self.urn = dict.get("urn", None)
         self.hrn = dict.get("hrn", None)