Changeset 540
- Timestamp:
- 30/01/06 16:45:50 (15 years ago)
- Location:
- security/trunk/python/NDG
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
security/trunk/python/NDG/AttAuthorityIO.py
r539 r540 81 81 raise AuthorisationRespError(\ 82 82 'Expecting "credential" or "errMsg" keywords') 83 83 84 85 #_________________________________________________________________________ 86 def update(self, credential=None, **xmlTags): 87 """Override base class implementation to include extra code 88 to allow setting of extAttCertList tag""" 89 90 if credential is not None: 91 if isinstance(credential, basestring): 92 attCert = AttCertParse(credential) 93 94 elif isinstance(credential, AttCert): 95 attCert = credential 96 else: 97 raise TypeError(\ 98 "credential keyword must contain string or AttCert type") 99 100 else: 101 attCert = None 102 103 # Call super class update with revised attribute certificate list 104 super(self.__class__, self).update(credential=attCert, **xmlTags) 105 106 84 107 #_________________________________________________________________________ 85 108 def updateXML(self, **xmlTags): … … 93 116 # Create XML formatted string ready for encryption 94 117 try: 95 rootNode = ElementTree.Element(self.__class__.__name__) 96 rootNode.tail = os.linesep 118 xmlTxt = self.xmlHdr + os.linesep + \ 119 "<" + self.__class__.__name__ + ">" + os.linesep 120 121 for tag, val in xmlTags.items(): 122 if tag == "credential": 123 # Remove any XML header - 124 # update() call will have converted val to AttCert type 125 val = val.asString(stripXMLhdr=True) 126 127 xmlTxt += " <%s>%s</%s>%s" % (tag, val, tag, os.linesep) 128 129 xmlTxt += "</" + self.__class__.__name__ + ">" + os.linesep 130 self.xmlTxt = xmlTxt 97 131 98 for tag in xmlTags: 99 # ElementTree tostring doesn't like bool types 100 elem = ElementTree.SubElement(rootNode, tag) 101 elem.tail = os.linesep 102 103 if isinstance(self[tag], bool): 104 elem.text = "%d" % self[tag] 105 106 elif tag == 'credential': 107 108 # str() will convert self[tag] correctly if it is an 109 # AttCert type 110 attCertElem = ElementTree.XML(str(self[tag])) 111 attCertElem.tail = os.linesep 112 elem.append(attCertElem) 113 else: 114 elem.text = self[tag] 115 116 self.xmlTxt = self.xmlHdr + os.linesep + \ 117 ElementTree.tostring(rootNode) 132 # rootNode = ElementTree.Element(self.__class__.__name__) 133 # rootNode.tail = os.linesep 134 # 135 # for tag in xmlTags: 136 # # ElementTree tostring doesn't like bool types 137 # elem = ElementTree.SubElement(rootNode, tag) 138 # elem.tail = os.linesep 139 # 140 # if isinstance(self[tag], bool): 141 # elem.text = "%d" % self[tag] 142 # 143 # elif tag == 'credential': 144 # 145 # # str() will convert self[tag] correctly if it is an 146 # # AttCert type 147 # attCertElem = ElementTree.XML(str(self[tag])) 148 # attCertElem.tail = os.linesep 149 # elem.append(attCertElem) 150 # else: 151 # elem.text = self[tag] 152 # 153 # self.xmlTxt = self.xmlHdr + os.linesep + \ 154 # ElementTree.tostring(rootNode) 118 155 except Exception, e: 119 156 raise XMLMsgError("Creating XML: %s" % e) … … 130 167 # Convert attribute certificate to AttCert instance 131 168 try: 132 self['credential'] = AttCertParse(self['credential']) 169 attCertPat = re.compile(\ 170 '<attributeCertificate>.*</attributeCertificate>', re.S) 171 attCertTxt = attCertPat.findall(self.xmlTxt)[0] 172 173 self['credential'] = AttCertParse(attCertTxt) 133 174 134 175 except Exception, e: -
security/trunk/python/NDG/CredWallet.py
r539 r540 589 589 raise CredWalletError("No CA certificate has been set") 590 590 591 attCert. filePath= self.__caCertFilePath591 attCert.certFilePathList = self.__caCertFilePath 592 592 593 593 … … 742 742 in self.__mapFromTrustedHosts is used 743 743 744 setExtAttCertList: make a list ofof certificates744 setExtAttCertList: make a list of certificates 745 745 from other Attribute Authorities. If 746 746 mapFromTrustedHosts is set True this flag is -
security/trunk/python/NDG/SessionMgrIO.py
r539 r540 295 295 296 296 #_________________________________________________________________________ 297 def update(self, extAttCertList=None, **xmlTags):297 def update(self, attCert=None, extAttCertList=None, **xmlTags): 298 298 """Override base class implementation to include extra code 299 299 to allow setting of extAttCertList tag""" 300 300 301 if extAttCertList: 301 def setAttCert(attCert=None): 302 if isinstance(attCert, basestring): 303 return AttCertParse(attCert) 304 305 elif isinstance(attCert, AttCert): 306 return attCert 307 308 elif attCert is not None: 309 raise TypeError(\ 310 "extAttCertList must contain string or AttCert types") 311 312 if extAttCertList is not None: 302 313 if not isinstance(extAttCertList, list): 303 314 raise TypeError(\ … … 306 317 307 318 # Join into single string and filter out XML headers as 308 # ElementTree doesn't like these nested into a doc 309 def setAttCert(attCert): 310 if isinstance(attCert, basestring): 311 return AttCertParse(attCert) 312 313 elif isinstance(attCert, AttCert): 314 return attCert 315 else: 316 raise TypeError(\ 317 "extAttCertList must contain string or AttCert types") 318 319 # ElementTree doesn't like these nested into a doc 319 320 attCertList = map(setAttCert, extAttCertList) 320 321 else: … … 322 323 323 324 # Call super class update with revised attribute certificate list 324 super(self.__class__, self).update(extAttCertList=attCertList, 325 super(self.__class__, self).update(attCert=setAttCert(attCert), 326 extAttCertList=attCertList, 325 327 **xmlTags) 326 328 … … 336 338 # Create XML formatted string ready for encryption 337 339 try: 338 rootNode = ElementTree.Element(self.__class__.__name__)339 rootNode.tail =os.linesep340 340 xmlTxt = self.xmlHdr + os.linesep + \ 341 "<" + self.__class__.__name__ + ">" + os.linesep 342 341 343 for tag in xmlTags: 342 # ElementTree tostring doesn't like bool types 343 elem = ElementTree.SubElement(rootNode, tag) 344 elem.tail = os.linesep 344 if isinstance(self[tag], AttCert): 345 # Attribute Certificate received from Attribute Authority 346 # 347 # Remove any XML header - 348 # update() call will have converted val to AttCert type 349 text = self[tag].asString(stripXMLhdr=True) 350 351 elif isinstance(self[tag], list): 352 # List of Attribute Certificates from other trusted hosts 353 # 354 # Call AttCert parse and return as Element type to append 355 # as branches 356 text = os.linesep.join([ac.asString(stripXMLhdr=True) \ 357 for ac in self[tag]]) 345 358 346 if isinstance(self[tag], bool): 347 elem.text = "%d" % self[tag] 359 elif isinstance(self[tag], bool): 360 text = "%d" % self[tag] 361 else: 362 text = self[tag] 363 364 xmlTxt += " <%s>%s</%s>%s" % (tag, text, tag, os.linesep) 348 365 349 elif isinstance(self[tag], list): 350 351 # Call AttCert parse and return as Element type to append 352 # as branches 353 for attCert in self[tag]: 354 attCertElem = ElementTree.XML(str(attCert)) 355 attCertElem.tail = os.linesep 356 elem.append(attCertElem) 357 else: 358 elem.text = self[tag] 359 360 self.xmlTxt = self.xmlHdr + os.linesep + \ 361 ElementTree.tostring(rootNode) 366 xmlTxt += "</" + self.__class__.__name__ + ">" + os.linesep 367 self.xmlTxt = xmlTxt 368 362 369 except Exception, e: 363 370 raise XMLMsgError("Creating XML: %s" % e) -
security/trunk/python/NDG/XMLSecDoc.py
r539 r540 365 365 #_________________________________________________________________________ 366 366 def __setCertFilePathList(self, filePath): 367 """ Set file path for certificate(s) used to sign/encrypt document as368 list of certificates to check the signature of a document"""367 """File path for certificate used to sign document / 368 list of certificates used to check the signature of a document""" 369 369 370 370 if isinstance(filePath, basestring): … … 380 380 381 381 # Publish attribute as write only 382 filePathList = property(fset=__setCertFilePathList, 383 doc="File Path for XML document to apply security to") 382 certFilePathList = property(fset=__setCertFilePathList, 383 doc="File Path of certificate used to sign document / " + \ 384 "list of certificates used to check the signature of a doc") 384 385 385 386 … … 747 748 748 749 # Check Certificate files for read access 749 for certFilePath in self.__certFilePathList: 750 if not os.access(certFilePath, os.R_OK): 751 raise XMLSecDocError(\ 752 "Signing certificate file path is invalid: \"%s\": %s" % \ 753 (certFilePath + str(e))) 750 if not self.__certFilePathList: 751 raise XMLSecDocError("No certificate files set for check") 754 752 755 753 -
security/trunk/python/NDG/attAuthority_services_server.py
r539 r540 87 87 88 88 authorisationResp = AuthorisationResp(\ 89 credential= str(attCert),89 credential=attCert, 90 90 statCode=AuthorisationResp.accessGranted) 91 91
Note: See TracChangeset
for help on using the changeset viewer.