Changeset 1962
- Timestamp:
- 05/01/07 17:12:42 (14 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg.security.common/ndg/security/common/XMLSec.py
r1959 r1962 92 92 of a signed document 93 93 @param encrCertFilePath: file path for X.509 cert used to encrypt 94 the document 94 the document - see note for __setCertFilePathList() method 95 95 @param encrPriKeyFilePath: file path for private key used to decrypt 96 96 previously encrypted document""" … … 138 138 139 139 def __setFilePath(self, filePath): 140 """Set file path for file to be signed/encrypted.""" 140 """Set file path for file to be signed/verified/encrypted/decrypted 141 142 @param filePath: file path of XML doc""" 141 143 142 144 if filePath is None or not isinstance(filePath, basestring): … … 176 178 def __setCertFilePathList(self, filePath): 177 179 """File path for certificate used to sign document / 178 list of certificates used to check the signature of a document""" 180 list of certificates used to check the signature of a document 181 182 @param filePath: file path or list of file paths to files used to 183 verify a signature. The first element should be the cert 184 corresponding to the proviate key used to make the signature. 185 Successive certs in the list correspond to the chain of trust e.g. 186 if a proxy cert/private key was used the list would be 187 188 proxy cert., 189 user cert which issued the proxy cert, 190 CA cert that issued the user cert 191 """ 179 192 180 193 if isinstance(filePath, basestring): … … 215 228 #_________________________________________________________________________ 216 229 def __setSigningKeyPwd(self, pwd): 217 """Set password to read private key from file""" 230 """Set password to read private key from file 231 232 @param pwd: password protecting private key file - set to None if no 233 password is set""" 218 234 219 235 if pwd is not None and not isinstance(pwd, basestring): … … 231 247 #_________________________________________________________________________ 232 248 def __setEncrCertFilePath(self, filePath): 233 """Set file path for certificate publiv key used to decrypt doc.""" 249 """Set file path for X.509 certificate file containing public 250 key used to decrypt doc. 251 252 @param filePath: path to X.509 Certificate file""" 234 253 235 254 if filePath is None or not isinstance(filePath, basestring): … … 246 265 #_________________________________________________________________________ 247 266 def __setEncrPriKeyFilePath(self, filePath): 248 """Set file path for certificate private key used to decrypt doc.""" 267 """Set file path for private key used to decrypt doc. 268 269 @param filePath: path to private key file""" 249 270 250 271 if filePath is None or not isinstance(filePath, basestring): … … 280 301 def parse(self, xmlTxt): 281 302 """Parse string containing XML into a DOM to allow signature or 282 signature validation""" 303 signature validation 304 305 @param xmlTxt: text to be parsed""" 306 283 307 self.__docNode = Reader().fromString(xmlTxt) 284 308 … … 286 310 #_________________________________________________________________________ 287 311 def read(self, stream=None): 288 """Read XML into a libxml2 document to allow signature validation""" 312 """Read XML into a libxml2 document to allow signature validation 313 314 @param stream: read from a file stream object instead of 315 self.__filePath""" 316 289 317 if stream is None: 290 318 stream = open(self.__filePath) … … 296 324 def write(self): 297 325 """Write XML document""" 298 open(self.__filePath, 'w').write(self.toString() )326 open(self.__filePath, 'w').write(self.toString() + os.linesep) 299 327 300 328 … … 308 336 """Make enveloped signature of XML document 309 337 310 @param xmlTxt: string buffer containing xml to be signed. If 311 not provided, calls XMLSecDoc.createXML(). 312 This is a virtual method so must be defined 313 in a derived class. 338 @param xmlTxt: string buffer containing xml to be signed. If not 339 provided, calls XMLSecDoc.createXML(). This is a virtual method so 340 must be defined in a derived class. 314 341 315 @param inclX509Cert: include MIME encoded content of X.509 316 certificate. This can be used by the 317 recipient of the XML in order to verify the 318 message 319 320 @param refC14nKw: Keywords for canonicalization of the reference 321 - for enveloped type signature this is the 322 parent element of the XML document""" 342 @param inclX509Cert: include MIME encoded content of X.509 343 certificate. This can be used by the recipient of the XML in order 344 to verify the message 345 346 @param refC14nKw: Keywords for canonicalization of the reference 347 - for enveloped type signature this is the parent element of the XML 348 document. If the key 'unsuppressedPrefixes' is set to a list of 349 element prefix strings, exclusive canonicalization will be applied. 350 To use inclusive canonicalization set 'unsuppressedPrefixes' to None 351 or set refC14nKw to None. 352 353 @param signedInfoC14nKw: keywords for canonicalization of the 354 SignedInfo section of the signature. See explanation for refC14nKw 355 keyword for options.""" 323 356 324 357 if xmlTxt: … … 502 535 InvalidSignature exception if the signature is invalid 503 536 504 xmlTxt: string buffer containing the text from the XML 505 file to be checked. If omitted, the 506 filePath argument is used instead. 507 508 filePath: file path to XML file to be checked. This 509 argument is used if no xmlTxt was provided. 510 If filePath itself is omitted the file set 511 by self.__filePath is read instead. 512 513 certFilePathList: Certificate used to sign the document.""" 537 @param xmlTxt: string buffer containing the text from the XML file to 538 be checked. If omitted, the filePath argument is used instead. 539 540 @param filePath: file path to XML file to be checked. This 541 argument is used if no xmlTxt was provided. If filePath itself is 542 omitted the file set by self.__filePath is read instead. 543 544 @param certFilePathList: Certificate used to sign the document.""" 514 545 515 546 # Check Certificate files for read access … … 674 705 calcSignedInfoDigestValue = sha(signedInfoC14n).digest() 675 706 676 import pdb;pdb.set_trace()677 707 678 708 # Try extracting X.509 Cert from ds:X509Certificate node in KeyInfo … … 735 765 xmlTxt=None, 736 766 filePath=None, 737 encrCertFilePath=None,738 767 inclX509SubjName=True, 739 inclX509IssSerial=True, 740 rtnAsString=False): 768 inclX509IssSerial=True): 741 769 """Encrypt a document using recipient's public key 742 770 … … 744 772 triple DES key and an RSA key from keys manager. 745 773 746 xmlTxt: string buffer containing the text from the XML 747 file to be encrypted. If omitted, the 748 filePath argument is used instead. 749 750 filePath: file path to XML file to be encrypted. This 751 argument is used if no xmlTxt was provided. 752 If filePath itself is omitted the file set 753 by self.__filePath is read instead. 774 @param xmlTxt: string buffer containing the text from the XML file to 775 be encrypted. If omitted, the filePath argument is used instead. 776 777 @param filePath: file path to XML file to be encrypted. This 778 argument is used if no xmlTxt was provided. If filePath itself is 779 omitted the file set by self.__filePath is read instead. 754 780 755 encrCertFilePath: file path to RSA public key file used to 756 encrypt the document. 757 758 inclX509SubjName: include subject name of signing X.509 759 certificate. 760 inclX509IssSerial: include issuer name and serial number in 761 signature 762 763 rtnAsString: This method returns None by default. Set to 764 True to override and return the encrypted 765 result instead as a string.""" 766 767 768 # Success 769 if rtnAsString: 770 return self.asString() 781 @param inclX509SubjName: include subject name of signing X.509 782 certificate. 783 784 @param inclX509IssSerial: include issuer name and serial number in 785 signature""" 786 787 raise NotImplementedError, \ 788 "Encryption algorithm not implemented in this version" 771 789 772 790 … … 774 792 def decrypt(self, 775 793 xmlTxt=None, 776 filePath=None, 777 encrPriKeyFilePath=None, 778 encrPriKeyPwd=None, 779 rtnAsString=False): 794 filePath=None): 780 795 """Decrypt a document using a private key of public/private key pair 781 796 782 xmlTxt: string buffer containing the text from the XML 783 file to be decrypted. If omitted, the 784 filePath argument is used instead. 785 786 filePath: file path to XML file to be decrypted. This 787 argument is used if no xmlTxt was provided. 788 If filePath itself is omitted the file set 789 by self.__filePath is read instead. 790 791 encrPriKeyFilePath: file path to private key file used to decrypt 792 793 encrPriKeyPwd: password for private key file. 794 795 rtnAsString: This method returns None by default. Set to 796 True to override and return the decrypted 797 result instead as a string.""" 798 799 if encrPriKeyFilePath: 800 self.__setEncrPriKeyFilePath(encrPriKeyFilePath) 801 802 # Success 803 if rtnAsString: 804 return self.asString() 797 @param xmlTxt: string buffer containing the text from the XML file to 798 be decrypted. If omitted, the filePath argument is used instead. 799 800 @param filePath: file path to XML file to be decrypted. This 801 argument is used if no xmlTxt was provided. If filePath itself is 802 omitted the file set by self.__filePath is read instead.""" 803 804 raise NotImplementedError, \ 805 "Encryption algorithm not implemented in this version" -
TI12-security/trunk/python/ndg.security.test/ndg/security/test/XMLSecDoc/xmlSecDocTest.py
r1959 r1962 88 88 self.xmlSecDoc.filePath = self.cfg['test3Write']['filepath'] 89 89 self.xmlSecDoc.write() 90 90 91 91 92 92 def test4Read(self):
Note: See TracChangeset
for help on using the changeset viewer.