1 ### $Id: get_credential.py 15321 2009-10-15 05:01:21Z tmack $
2 ### $URL: https://svn.planet-lab.org/svn/sfa/trunk/sfa/methods/get_credential.py $
4 from sfa.trust.credential import *
5 from sfa.trust.rights import *
6 from sfa.util.faults import *
7 from sfa.util.method import Method
8 from sfa.util.parameter import Parameter, Mixed
9 from sfa.util.record import GeniRecord
10 from sfa.util.debug import log
12 class get_self_credential(Method):
14 Retrive a credential for an object
15 @param cert certificate string
16 @param type type of object (user | slice | sa | ma | node)
17 @param hrn human readable name of object
19 @return the string representation of a credential object
22 interfaces = ['registry']
25 Parameter(str, "certificate"),
26 Parameter(str, "Human readable name (hrn)"),
27 Mixed(Parameter(str, "Request hash"),
28 Parameter(None, "Request hash not specified"))
31 returns = Parameter(str, "String representation of a credential object")
33 def call(self, cert, type, hrn, request_hash=None):
35 get_self_credential a degenerate version of get_credential used by a client
36 to get his initial credential when de doesnt have one. This is the same as
37 get_credetial(..., cred = None, ...)
39 The registry ensures that the client is the principal that is named by
40 (type, name) by comparing the public key in the record's GID to the
41 private key used to encrypt the client side of the HTTPS connection. Thus
42 it is impossible for one principal to retrive another principal's
43 credential without having the appropriate private key.
45 @param type type of object (user | slice | sa | ma | node)
46 @param hrn human readable name of authority to list
47 @return string representation of a credential object
49 self.api.auth.verify_object_belongs_to_me(hrn)
51 # send the call to the right manager
52 manager_base = 'sfa.managers'
53 mgr_type = self.api.config.SFA_REGISTRY_TYPE
54 manager_module = manager_base + ".registry_manager_%s" % mgr_type
55 manager = __import__(manager_module, fromlist=[manager_base])
57 # authenticate the gid
58 records = manager.resolve(self.api, hrn, type)
60 raise RecordNotFound(hrn)
61 record = GeniRecord(dict=records[0])
62 gid = record.get_gid_object()
63 gid_str = gid.save_to_string(save_parents=True)
64 self.api.auth.authenticateGid(gid_str, [cert, type, hrn], request_hash)
65 # authenticate the certificate against the gid in the db
66 certificate = Certificate(string=cert)
67 if not certificate.is_pubkey(gid.get_pubkey()):
68 raise ConnectionKeyGIDMismatch(gid.get_subject())
70 return manager.get_credential(self.api, hrn, type, is_self=True)