from sfa.trust.credential_legacy import CredentialLegacy\r
from sfa.trust.rights import Right, Rights, determine_rights\r
from sfa.trust.gid import GID\r
-from sfa.util.xrn import urn_to_hrn\r
+from sfa.util.xrn import urn_to_hrn, hrn_authfor_hrn\r
\r
# 2 weeks, in seconds \r
DEFAULT_CREDENTIAL_LIFETIME = 86400 * 14\r
# . That the issuer of the credential is the authority in the target's urn\r
# . In the case of a delegated credential, this must be true of the root\r
# . That all of the gids presented in the credential are valid\r
+ # . Including verifying GID chains, and includ the issuer\r
# . The credential is not expired\r
#\r
# -- For Delegates (credentials with parents)\r
cert_args = " ".join(['--trusted-pem %s' % x for x in trusted_certs])\r
\r
# If caller explicitly passed in None that means skip cert chain validation.\r
- # Strange and not typical\r
+ # - Strange and not typical\r
if trusted_certs is not None:\r
# Verify the gids of this cred and of its parents\r
for cur_cred in self.get_credential_list():\r
if self.parent:\r
self.verify_parent(self.parent)\r
\r
- # Make sure the issuer is the target's authority\r
- self.verify_issuer()\r
+ # Make sure the issuer is the target's authority, and is\r
+ # itself a valid GID\r
+ self.verify_issuer(trusted_cert_objects)\r
return True\r
\r
##\r
return list\r
\r
##\r
- # Make sure the credential's target gid was signed by (or is the same) the entity that signed\r
- # the original credential or an authority over that namespace.\r
- def verify_issuer(self): \r
+ # Make sure the credential's target gid (a) was signed by or (b)\r
+ # is the same as the entity that signed the original credential,\r
+ # or (c) is an authority over the target's namespace.\r
+ # Also ensure that the credential issuer / signer itself has a valid\r
+ # GID signature chain (signed by an authority with namespace rights).\r
+ def verify_issuer(self, trusted_gids):\r
root_cred = self.get_credential_list()[-1]\r
root_target_gid = root_cred.get_gid_object()\r
root_cred_signer = root_cred.get_signature().get_issuer_gid()\r
\r
+ # Case 1:\r
+ # Allow non authority to sign target and cred about target.\r
+ #\r
+ # Why do we need to allow non authorities to sign?\r
+ # If in the target gid validation step we correctly\r
+ # checked that the target is only signed by an authority,\r
+ # then this is just a special case of case 3.\r
+ # This short-circuit is the common case currently -\r
+ # and cause GID validation doesn't check 'authority',\r
+ # this allows users to generate valid slice credentials.\r
if root_target_gid.is_signed_by_cert(root_cred_signer):\r
# cred signer matches target signer, return success\r
return\r
\r
- root_target_gid_str = root_target_gid.save_to_string()\r
- root_cred_signer_str = root_cred_signer.save_to_string()\r
- if root_target_gid_str == root_cred_signer_str:\r
- # cred signer is target, return success\r
- return\r
+ # Case 2:\r
+ # Allow someone to sign credential about themeselves. Used?\r
+ # If not, remove this.\r
+ #root_target_gid_str = root_target_gid.save_to_string()\r
+ #root_cred_signer_str = root_cred_signer.save_to_string()\r
+ #if root_target_gid_str == root_cred_signer_str:\r
+ # # cred signer is target, return success\r
+ # return\r
+\r
+ # Case 3:\r
\r
# root_cred_signer is not the target_gid\r
- # So this is a different gid that we have not verified\r
- # Did xmlsec1 verify the cert chain on this already?\r
- # Regardless, it hasn't verified that the gid meets the HRN namespace\r
- # requirements\r
-# FIXME: Uncomment once we verify this is right\r
-# root_cred_signer.verify_chain(trusted_cert_objects)\r
-\r
- # See if it the signer is an authority over the domain of the target\r
+ # So this is a different gid that we have not verified.\r
+ # xmlsec1 verified the cert chain on this already, but\r
+ # it hasn't verified that the gid meets the HRN namespace\r
+ # requirements.\r
+ # Below we'll ensure that it is an authority.\r
+ # But we haven't verified that it is _signed by_ an authority\r
+ # We also don't know if xmlsec1 requires that cert signers\r
+ # are marked as CAs.\r
+ root_cred_signer.verify_chain(trusted_gids)\r
+\r
+ # See if the signer is an authority over the domain of the target.\r
+ # There are multiple types of authority - accept them all here\r
# Maybe should be (hrn, type) = urn_to_hrn(root_cred_signer.get_urn())\r
root_cred_signer_type = root_cred_signer.get_type()\r
- if (root_cred_signer_type == 'authority'):\r
+ if (root_cred_signer_type.find('authority') == 0):\r
#logger.debug('Cred signer is an authority')\r
# signer is an authority, see if target is in authority's domain\r
- hrn = root_cred_signer.get_hrn()\r
- if root_target_gid.get_hrn().startswith(hrn):\r
+ signerhrn = root_cred_signer.get_hrn()\r
+ if hrn_authfor_hrn(signerhrn, root_target_gid.get_hrn()):\r
return\r
\r
# We've required that the credential be signed by an authority\r