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
class Certificate:
digest = "md5"
- data = {}
cert = None
issuerKey = None
issuerSubject = None
# @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:
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
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]
##
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
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
# 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)