Changeset 1967
- Timestamp:
- 08/01/07 14:39:00 (14 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 4 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/AttCert.py
r1964 r1967 23 23 from datetime import datetime, timedelta 24 24 25 # XML signature module based on xmlsec and libxml226 from XMLSec import XMLSecDoc 25 # XML signature module based on M2Crypto, ZSI Canonicalization and DOM 26 from XMLSec import XMLSecDoc, InvalidSignature, getParentNode 27 27 28 28 from X509 import X500DN … … 30 30 31 31 32 #_____________________________________________________________________________ 32 33 class AttCertError(Exception): 33 34 """Exception handling for NDG Attribute Certificate class.""" … … 77 78 # Provenance of certificate may be original or mapped from another 78 79 # certificate 79 __ provenance = (origProvenance, mappedProvenance)80 81 82 #_________________________________________________________________________ 83 def __init__(self, lifeTime=28800, **xmlSecDocKw):80 __validProvenanceSettings = ('original', 'mapped') 81 82 83 #_________________________________________________________________________ 84 def __init__(self, provenance='original', lifetime=28800, **xmlSecDocKw): 84 85 """Initialisation - Attribute Certificate file path may be specified. 85 86 Also, holder and issuer details and signing authority key and 86 87 certificate. 87 88 88 @param life Time: set the lifetime for the certificate in seconds.89 @param lifetime: set the lifetime for the certificate in seconds. 89 90 Defaults to 8 hours. 90 91 @param **xmlSecDocKw: see XMLSec.XMLSec class for an explanation. … … 118 119 119 120 # Certificate life time interval in seconds 120 self.__life Time = lifeTime121 self.__lifetime = lifetime 121 122 122 123 self.__dtNotBefore = None … … 140 141 #_________________________________________________________________________ 141 142 def __getitem__(self, key): 142 self.__class__.__name__ + """ behaves as data dictionary of Attribute 143 Certificate properties 144 145 Nb. also possible to apply keys belonging validity and attributes 146 sub dictionaries 143 """Get an item from the __dat, __dat['validity'] or 144 __dat['attributes'] dictionaries. This class behaves as data 145 dictionary of Attribute Certificate properties 146 147 @param key: name of key - key can be specified belonging to validity 148 or the attributes sub dictionaries 149 @param item: value to set dictionary item to 147 150 """ 148 151 149 152 # Check input key 150 if self.__dat.has_key(key):153 if key in self.__dat: 151 154 152 155 # key recognised 153 156 return self.__dat[key] 154 157 155 elif self.__dat['validity'].has_key(key):158 elif key in self.__dat['validity']: 156 159 157 160 # Allow indexing via validity keys - a shorthand way of … … 159 162 return self.__dat['validity'][key] 160 163 161 elif self.__dat['attributes'].has_key(key):164 elif key in self.__dat['attributes']: 162 165 163 166 # Allow indexing via attributes keys - a shorthand way of … … 173 176 #_________________________________________________________________________ 174 177 def __setitem__(self, key, item): 175 self.__class__.__name__ + """ behaves as data dictionary of Attribute 176 Certificate properties 177 178 Nb. also possible to apply keys belonging validity and attributes 179 sub dictionaries 178 """Set an item from the __dat, __dat['validity'] or 179 __dat['attributes'] dictionaries. This class behaves as data 180 dictionary of Attribute Certificate properties 181 182 @param key: name of key - key can be specified belonging to validity 183 or the attributes sub dictionaries 184 @param item: value to set dictionary item to 180 185 """ 181 186 182 187 # Check input key 183 if self.__dat.has_key(key):188 if key in self.__dat: 184 189 185 190 # key recognised - check if setting provenance 186 if key is "provenance" and not self.isValidProvenance(item): 187 raise AttCertError, "Provenance must be set to \"" + \ 188 "\" or \"".join(AttCert.__provenance) + "\"" 191 if key is "provenance": 192 self.setProvenance(item) 189 193 190 194 self.__dat[key] = item 191 195 192 elif self.__dat['attributes'].has_key(key):196 elif key in self.__dat['attributes']: 193 197 194 198 # Allow indexing via acInfo keys - a shorthand way of referencing … … 196 200 return self.__dat['attributes'][key] 197 201 198 elif self.__dat['validity'].has_key(key):202 elif key in self.__dat['validity']: 199 203 # Prevent setting of notBefore/notAfter - restrict to method 200 204 # setValidityTime … … 384 388 if not self.isValidProvenance(provenance): 385 389 raise AttCertError, "Provenance must be set to \"" + \ 386 "\" or \"".join(AttCert.__provenance) + "\""390 "\" or \"".join(AttCert.__validProvenanceSettings) + "\"" 387 391 388 392 self.__dat['provenance'] = provenance … … 413 417 provenance = self.__dat['provenance'] 414 418 415 return provenance in AttCert.__ provenance419 return provenance in AttCert.__validProvenanceSettings 416 420 417 421 … … 599 603 if not self.isValidProvenance(): 600 604 raise AttCertError, "Provenance must be set to \"" + \ 601 "\" or \"".join(AttCert.__ provenance) + "\""605 "\" or \"".join(AttCert.__validProvenanceSettings) + "\"" 602 606 603 607 604 608 # Create string of all XML content 605 xmlTxt = """<attributeCertificate >609 xmlTxt = """<attributeCertificate targetNamespace="urn:ndg:security"> 606 610 <acInfo> 607 611 <version>""" + self.__dat['version'] + """</version> … … 619 623 <attributes> 620 624 <roleSet> 621 """ + "".join([\622 """ 625 """ + "".join([\ 626 """ <role> 623 627 <name>""" + i['role']['name'] + """</name> 624 628 </role> … … 634 638 635 639 640 def applyEnvelopedSignature(self, **xmlSecDocKw): 641 '''Override super class version to ensure settings have been parsed 642 into a DOM object ready for signature 643 644 @param **xmlSecDocKw: keywords applying to 645 XMLSecDoc.applyEnvelopedSignature() 646 ''' 647 self.parse(self.createXML()) 648 super(AttCert, self).applyEnvelopedSignature(**xmlSecDocKw) 649 650 636 651 #_________________________________________________________________________ 637 652 def setValidityTime(self, 638 653 dtNotBefore=None, 639 654 dtNotAfter=None, 640 life Time=None,655 lifetime=None, 641 656 notBeforeOffset=None): 642 657 """Set the notBefore and notAfter times which determine the window for … … 645 660 ready for output. 646 661 647 Nb. use UTC time. life Time and notBeforeOffset are in seconds662 Nb. use UTC time. lifetime and notBeforeOffset are in seconds 648 663 649 664 @param dtNotBefore: not before time as datetime type. If omitted, … … 690 705 str(dtNotAfter) 691 706 692 self.__life Time = dtDeltaLifeTime.days*86400 + \707 self.__lifetime = dtDeltaLifeTime.days*86400 + \ 693 708 dtDeltaLifeTime.seconds 694 709 … … 697 712 else: 698 713 # Check for input certificate life time interval 699 if life Time is not None:700 self.__life Time = lifeTime714 if lifetime is not None: 715 self.__lifetime = lifetime 701 716 702 717 try: 703 718 # Make a time delta object from the lifetime expressed in 704 719 # seconds 705 dtDeltaLifeTime = timedelta(seconds=self.__life Time)720 dtDeltaLifeTime = timedelta(seconds=self.__lifetime) 706 721 except Exception, e: 707 722 raise AttCertError, "Invalid Certificate lifetime set %.3f" %\ 708 self.__life Time723 self.__lifetime 709 724 710 725 # Add certificate lifetime to calculate not after time … … 882 897 raise AttCertError, \ 883 898 "Attribute Certificate Provenance must be set to \"" + \ 884 "\" or \"".join(AttCert.__ provenance) + "\""899 "\" or \"".join(AttCert.__validProvenanceSettings) + "\"" 885 900 return False 886 901 -
TI12-security/trunk/python/ndg.security.common/ndg/security/common/XMLSec.py
r1964 r1967 126 126 """String representation of doc - only applies if doc had been read 127 127 or parsed""" 128 self.toString()128 return self.toString() 129 129 130 130 -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/AttAuthority/AttAuthorityClientTest.py
r1858 r1967 1 #!/usr/bin/e 1 #!/usr/bin/env python 2 2 """NDG Attribute Authority client unit tests 3 3 4 4 NERC Data Grid Project 5 5 6 P J Kershaw 05/05/056 @author P J Kershaw 05/05/05 7 7 8 Copyright (C) 2006 CCLRC & NERC8 @copyright (C) 2006 CCLRC & NERC 9 9 10 This software may be distributed under the terms of the Q Public License, 11 version 1.0 or later.10 @license This software may be distributed under the terms of the Q Public 11 License, version 1.0 or later. 12 12 """ 13 14 reposID = '$Id$' 15 13 16 import unittest 14 17 import os -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/MyProxy/MyProxyClientTest.py
r1945 r1967 4 4 NERC Data Grid Project 5 5 6 P J Kershaw 13/12/066 @author P J Kershaw 13/12/06 7 7 8 Copyright (C) 2006 CCLRC & NERC8 @copyright (C) 2006 CCLRC & NERC 9 9 10 This software may be distributed under the terms of the Q Public License, 11 version 1.0 or later.10 @license This software may be distributed under the terms of the Q Public 11 License, version 1.0 or later. 12 12 """ 13 14 reposID = '$Id$' 15 13 16 import unittest 14 17 import os
Note: See TracChangeset
for help on using the changeset viewer.