How to use the federation.credentials.src.trustgcf.credential.Credential function in federation

To help you get started, we’ve selected a few federation examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github fp7-ofelia / ocf / federation / credentials / src / trustgcf / credential.py View on Github external
def filter_creds_by_caller(creds, caller_hrn_list):
        """
        Returns a list of creds who's gid caller matches the
        specified caller hrn
        """
        if not isinstance(creds, list): creds = [creds]
        if not isinstance(caller_hrn_list, list): 
            caller_hrn_list = [caller_hrn_list]
        caller_creds = []
        for cred in creds:
            try:
                tmp_cred = Credential(string=cred)
                if tmp_cred.get_cred_type() != Credential.SFA_CREDENTIAL_TYPE:
                    continue
                if tmp_cred.get_gid_caller().get_hrn() in caller_hrn_list:
                    caller_creds.append(cred)
            except: pass
        return caller_creds
github fp7-ofelia / ocf / federation / credentials / src / trustgcf / credential.py View on Github external
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("utf-8")
            if parent_xml is None or parent_xml.strip() == "":
                raise CredentialNotVerifiable("Malformed XML: Had parent tag but it is empty")
            self.parent = Credential(string=parent_xml)
            self.updateRefID()

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

            for cur_cred in self.get_credential_list():
                if cur_cred.get_refid() == Sig.get_refid():
                    cur_cred.set_signature(Sig)
github fp7-ofelia / ocf / federation / credentials / src / trustgcf / credential.py View on Github external
def __init__(self, create=False, subject=None, string=None, filename=None):
        self.gidCaller = None
        self.gidObject = None
        self.expiration = None
        self.privileges = None
        self.issuer_privkey = None
        self.issuer_gid = None
        self.issuer_pubkey = None
        self.parent = None
        self.signature = None
        self.xml = None
        self.refid = None
        self.legacy = None
        self.cred_type = Credential.SFA_CREDENTIAL_TYPE

        # Check if this is a legacy credential, translate it if so
        if string or filename:
            if string:                
                str = string
            elif filename:
                str = file(filename).read()
                
            if str.strip().startswith("-----"):
                self.legacy = CredentialLegacy(False,string=str)
                self.translate_legacy(str)
            else:
                self.xml = str
                self.decode()

        # Find an xmlsec1 path
github fp7-ofelia / ocf / federation / credentials / src / trustgcf / credential.py View on Github external
"""
        Return a delegated copy of this credential, delegated to the 
        specified gid's user.    
        """
        # get the gid of the object we are delegating
        object_gid = self.get_gid_object()
        object_hrn = object_gid.get_hrn()        
 
        # the hrn of the user who will be delegated to
        delegee_gid = GID(filename=delegee_gidfile)
        delegee_hrn = delegee_gid.get_hrn()
  
        #user_key = Keypair(filename=keyfile)
        #user_hrn = self.get_gid_caller().get_hrn()
        subject_string = "%s delegated to %s" % (object_hrn, delegee_hrn)
        dcred = Credential(subject=subject_string)
        dcred.set_gid_caller(delegee_gid)
        dcred.set_gid_object(object_gid)
        dcred.set_parent(self)
        dcred.set_expiration(self.get_expiration())
        dcred.set_privileges(self.get_privileges())
        dcred.get_privileges().delegate_all_privileges(True)
        #dcred.set_issuer_keys(keyfile, delegee_gidfile)
        dcred.set_issuer_keys(caller_keyfile, caller_gidfile)
        dcred.encode()
        dcred.sign()

        return dcred