Ejemplo n.º 1
0
 def __init__(self, create=False, subject=None, string=None, filename=None, uuid=None, hrn=None, urn=None, lifeDays=1825):
     
     Certificate.__init__(self, lifeDays, create, subject, string, filename)
     if subject:
         logger.debug("Creating GID for subject: %s" % subject)
     if uuid:
         self.uuid = int(uuid)
     if hrn:
         self.hrn = hrn
         self.urn = hrn_to_urn(hrn, 'unknown')
     if urn:
         self.urn = urn
         self.hrn, type = urn_to_hrn(urn)
Ejemplo n.º 2
0
    def __init__(self,
                 create=False,
                 subject=None,
                 string=None,
                 filename=None,
                 uuid=None,
                 hrn=None,
                 urn=None,
                 lifeDays=1825):

        Certificate.__init__(self, lifeDays, create, subject, string, filename)
        if subject:
            logger.debug("Creating GID for subject: %s" % subject)
        if uuid:
            self.uuid = int(uuid)
        if hrn:
            self.hrn = hrn
            self.urn = hrn_to_urn(hrn, 'unknown')
        if urn:
            self.urn = urn
            self.hrn, type = urn_to_hrn(urn)
Ejemplo n.º 3
0
 def decode(self):
     data = self.get_data('subjectAltName')
     dict = {}
     if data:
         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:]
                 elif val.lower().startswith('email:'):
                     # FIXME: Ensure there isn't cruft in that address...
                     # EG look for email:copy,....
                     dict['email'] = val[6:]
                 
     self.uuid = dict.get("uuid", None)
     self.urn = dict.get("urn", None)
     self.hrn = dict.get("hrn", None)
     self.email = dict.get("email", None)
     if self.urn:
         self.hrn = urn_to_hrn(self.urn)[0]
Ejemplo n.º 4
0
    def decode(self):
        data = self.get_data('subjectAltName')
        dict = {}
        if data:
            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:]
                    elif val.lower().startswith('email:'):
                        # FIXME: Ensure there isn't cruft in that address...
                        # EG look for email:copy,....
                        dict['email'] = val[6:]

        self.uuid = dict.get("uuid", None)
        self.urn = dict.get("urn", None)
        self.hrn = dict.get("hrn", None)
        self.email = dict.get("email", None)
        if self.urn:
            self.hrn = urn_to_hrn(self.urn)[0]
Ejemplo n.º 5
0
    def decode(self):
        if not self.xml:
            return
        doc = parseString(self.xml)
        sigs = []
        signed_cred = doc.getElementsByTagName("signed-credential")

        # Is this a signed-cred or just a cred?
        if len(signed_cred) > 0:
            creds = signed_cred[0].getElementsByTagName("credential")
            signatures = signed_cred[0].getElementsByTagName("signatures")
            if len(signatures) > 0:
                sigs = signatures[0].getElementsByTagName("Signature")
        else:
            creds = doc.getElementsByTagName("credential")

        if creds is None or len(creds) == 0:
            # malformed cred file
            raise CredentialNotVerifiable(
                "Malformed XML: No credential tag found")

        # Just take the first cred if there are more than one
        cred = creds[0]

        self.set_refid(cred.getAttribute("xml:id"))
        self.set_expiration(utcparse(getTextNode(cred, "expires")))
        self.gidCaller = GID(string=getTextNode(cred, "owner_gid"))
        self.gidObject = GID(string=getTextNode(cred, "target_gid"))

        # Process privileges
        privs = cred.getElementsByTagName("privileges")[0]
        rlist = Rights()
        for priv in privs.getElementsByTagName("privilege"):
            kind = getTextNode(priv, "name")
            deleg = str2bool(getTextNode(priv, "can_delegate"))
            if kind == '*':
                # Convert * into the default privileges for the credential's type
                # Each inherits the delegatability from the * above
                _, type = urn_to_hrn(self.gidObject.get_urn())
                rl = determine_rights(type, self.gidObject.get_urn())
                for r in rl.rights:
                    r.delegate = deleg
                    rlist.add(r)
            else:
                rlist.add(Right(kind.strip(), deleg))
        self.set_privileges(rlist)

        # Is there a parent?
        parent = cred.getElementsByTagName("parent")
        if len(parent) > 0:
            parent_doc = parent[0].getElementsByTagName("credential")[0]
            parent_xml = parent_doc.toxml()
            self.parent = Credential(string=parent_xml)
            self.updateRefID()

        # Assign the signatures to the credentials
        for sig in sigs:
            Sig = Signature(string=sig.toxml())

            for cur_cred in self.get_credential_list():
                if cur_cred.get_refid() == Sig.get_refid():
                    cur_cred.set_signature(Sig)
Ejemplo n.º 6
0
 def get_type(self):
     if not self.urn:
         self.decode()
     _, t = urn_to_hrn(self.urn)
     return t
Ejemplo n.º 7
0
 def set_urn(self, urn):
     self.urn = urn
     self.hrn, type = urn_to_hrn(urn)
Ejemplo n.º 8
0
 def get_type(self):
     if not self.urn:
         self.decode()
     _, t = urn_to_hrn(self.urn)
     return t
Ejemplo n.º 9
0
 def set_urn(self, urn):
     self.urn = urn
     self.hrn, type = urn_to_hrn(urn)
Ejemplo n.º 10
0
    def decode(self):
        if not self.xml:
            return
        doc = parseString(self.xml)
        sigs = []
        signed_cred = doc.getElementsByTagName("signed-credential")

        # Is this a signed-cred or just a cred?
        if len(signed_cred) > 0:
            creds = signed_cred[0].getElementsByTagName("credential")
            signatures = signed_cred[0].getElementsByTagName("signatures")
            if len(signatures) > 0:
                sigs = signatures[0].getElementsByTagName("Signature")
        else:
            creds = doc.getElementsByTagName("credential")
        
        if creds is None or len(creds) == 0:
            # malformed cred file
            raise CredentialNotVerifiable("Malformed XML: No credential tag found")

        # Just take the first cred if there are more than one
        cred = creds[0]

        self.set_refid(cred.getAttribute("xml:id"))
        self.set_expiration(utcparse(getTextNode(cred, "expires")))
        self.gidCaller = GID(string=getTextNode(cred, "owner_gid"))
        self.gidObject = GID(string=getTextNode(cred, "target_gid"))   


        # Process privileges
        privs = cred.getElementsByTagName("privileges")[0]
        rlist = Rights()
        for priv in privs.getElementsByTagName("privilege"):
            kind = getTextNode(priv, "name")
            deleg = str2bool(getTextNode(priv, "can_delegate"))
            if kind == '*':
                # Convert * into the default privileges for the credential's type
                # Each inherits the delegatability from the * above
                _ , type = urn_to_hrn(self.gidObject.get_urn())
                rl = determine_rights(type, self.gidObject.get_urn())
                for r in rl.rights:
                    r.delegate = deleg
                    rlist.add(r)
            else:
                rlist.add(Right(kind.strip(), deleg))
        self.set_privileges(rlist)


        # Is there a parent?
        parent = cred.getElementsByTagName("parent")
        if len(parent) > 0:
            parent_doc = parent[0].getElementsByTagName("credential")[0]
            parent_xml = parent_doc.toxml()
            self.parent = Credential(string=parent_xml)
            self.updateRefID()

        # Assign the signatures to the credentials
        for sig in sigs:
            Sig = Signature(string=sig.toxml())

            for cur_cred in self.get_credential_list():
                if cur_cred.get_refid() == Sig.get_refid():
                    cur_cred.set_signature(Sig)