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.namespace import *
8 from sfa.util.method import Method
9 from sfa.util.parameter import Parameter, Mixed
10 from sfa.util.record import SfaRecord
11 from sfa.util.debug import log
12 from sfa.trust.certificate import Certificate
14 class GetSelfCredential(Method):
16 Retrive a credential for an object
17 @param cert certificate string
18 @param type type of object (user | slice | sa | ma | node)
19 @param hrn human readable name of object (hrn or urn)
21 @return the string representation of a credential object
24 interfaces = ['registry']
27 Parameter(str, "certificate"),
28 Parameter(str, "Human readable name (hrn or urn)"),
29 Mixed(Parameter(str, "Record type"),
30 Parameter(None, "Type not specified")),
33 returns = Parameter(str, "String representation of a credential object")
35 def call(self, cert, xrn, type):
37 get_self_credential a degenerate version of get_credential used by a client
38 to get his initial credential when de doesnt have one. This is the same as
39 get_credetial(..., cred = None, ...)
41 The registry ensures that the client is the principal that is named by
42 (type, name) by comparing the public key in the record's GID to the
43 private key used to encrypt the client side of the HTTPS connection. Thus
44 it is impossible for one principal to retrive another principal's
45 credential without having the appropriate private key.
47 @param type type of object (user | slice | sa | ma | node)
48 @param hrn human readable name of authority to list
49 @return string representation of a credential object
52 hrn = urn_to_hrn(xrn)[0]
54 hrn, type = urn_to_hrn(xrn)
55 self.api.auth.verify_object_belongs_to_me(hrn)
57 origin_hrn = Certificate(string=cert).get_subject()
58 self.api.logger.info("interface: %s\tcaller-hrn: %s\ttarget-hrn: %s\tmethod-name: %s"%(self.api.interface, origin_hrn, hrn, self.name))
60 manager = self.api.get_interface_manager()
62 # authenticate the gid
63 records = manager.resolve(self.api, xrn, type)
65 raise RecordNotFound(hrn)
66 record = SfaRecord(dict=records[0])
67 gid = record.get_gid_object()
68 gid_str = gid.save_to_string(save_parents=True)
69 self.api.auth.authenticateGid(gid_str, [cert, type, hrn])
70 # authenticate the certificate against the gid in the db
71 certificate = Certificate(string=cert)
72 if not certificate.is_pubkey(gid.get_pubkey()):
73 raise ConnectionKeyGIDMismatch(gid.get_subject())
75 return manager.get_credential(self.api, xrn, type, is_self=True)