Changeset 1510
- Timestamp:
- 12/09/06 12:02:22 (14 years ago)
- Location:
- TI12-security/trunk/python/Tests/xmlsec/WS-Security
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/Tests/xmlsec/WS-Security/wsSecurity.py
r1508 r1510 28 28 import ZSI 29 29 from ZSI.wstools.Namespaces import DSIG, ENCRYPTION, OASIS, WSU, WSA200403, \ 30 SOAP 30 SOAP, SCHEMA # last included for xsi 31 31 32 32 from ZSI.TC import ElementDeclaration,TypeDefinition … … 510 510 # Encrypt required elements 511 511 sharedKey = os.urandom(32) 512 print "Shared key = %s" % sharedKey513 512 encryptedData = AES.new(sharedKey, AES.MODE_ECB).encrypt(data) 514 513 dataCiphValue = base64.encodestring(encryptedData).strip() … … 628 627 629 628 # XPath reference - need to check for wsu namespace qualified? 630 # uriXPath = '//*[@wsu:Id="%s"]' % dataRefURI[1:]631 uriXPath = '//*[@Id="%s"]' % dataRefURI[1:]632 uriNode = xpath.Evaluate(uriXPath,633 contextNode=parsedSOAP.dom,634 context=ctxt)[0]629 #encrNodeXPath = '//*[@wsu:Id="%s"]' % dataRefURI[1:] 630 encrNodeXPath = '//*[@Id="%s"]' % dataRefURI[1:] 631 encrNode = xpath.Evaluate(encrNodeXPath, 632 contextNode=parsedSOAP.dom, 633 context=ctxt)[0] 635 634 636 dataEncrMethodNode = getElements( uriNode, 'EncryptionMethod')[0]635 dataEncrMethodNode = getElements(encrNode, 'EncryptionMethod')[0] 637 636 dataAlgorithm = dataEncrMethodNode.getAttributeNodeNS(None, 638 637 "Algorithm").value … … 643 642 644 643 # Get Data 645 dataCiphDataNode = getElements( uriNode, 'CipherData')[0]644 dataCiphDataNode = getElements(encrNode, 'CipherData')[0] 646 645 dataCiphValNode = getElements(dataCiphDataNode, 'CipherValue')[0] 647 646 … … 652 651 decryptedData = aes.decrypt(encryptedData) 653 652 654 # Parse the data and add to the EncryptedData parent 655 656 # Remove the EncryptedData Element 657 658 653 # Parse the encrypted data - inherit from Reader as a fudge to 654 # enable relevant namespaces to be added prior to parse 655 processorNss.update({'xsi': SCHEMA.XSI3}) 656 class _Reader(Reader): 657 def initState(self, ownerDoc=None): 658 Reader.initState(self, ownerDoc=ownerDoc) 659 self._namespaces.update(processorNss) 660 661 rdr = _Reader() 662 dataNode = rdr.fromString(decryptedData, ownerDoc=parsedSOAP.dom) 663 664 # Add decrypted element to parent and remove encrypted one 665 parentNode = encrNode._get_parentNode() 666 parentNode.appendChild(dataNode) 667 parentNode.removeChild(encrNode) 668 669 from xml.dom.ext import ReleaseNode 670 ReleaseNode(encrNode) 671 672 # Ensure body_root attribute is up to date in case it was 673 # previously encrypted 674 parsedSOAP.body_root = parsedSOAP.body.childNodes[0] 675 print decryptedData 659 676 import pdb;pdb.set_trace() 660 print decryptedData 661 662 677 663 678 664 679 -
TI12-security/trunk/python/Tests/xmlsec/WS-Security/wsServer.py
r1508 r1510 129 129 130 130 sw.serialize(result, tc, rpc=rpc) 131 132 signatureHandler = SignatureHandler(\ 131 132 # Test encryption handler independently of signature 133 # signatureHandler = SignatureHandler(\ 134 # certFilePath='../../Junk-cert.pem', 135 # priKeyFilePath='../../Junk-key.pem', 136 # priKeyPwd=open('../../tmp2').read().strip()) 137 # signatureHandler.sign(sw) 138 encryptionHandler = EncryptionHandler(\ 133 139 certFilePath='../../Junk-cert.pem', 134 140 priKeyFilePath='../../Junk-key.pem', 135 141 priKeyPwd=open('../../tmp2').read().strip()) 136 signatureHandler.sign(sw)142 encryptionHandler.encrypt(sw) 137 143 138 144 return SendResponse(str(sw), **kw)
Note: See TracChangeset
for help on using the changeset viewer.