1 | #!/usr/bin/env python |
---|
2 | # |
---|
3 | # Exampe echo client, to show extended code generation in ZSI |
---|
4 | # |
---|
5 | # Import the client proxy object |
---|
6 | from EchoServer_client import EchoServerSOAP |
---|
7 | import sys |
---|
8 | |
---|
9 | import wsSecurity |
---|
10 | |
---|
11 | # Lambda used by WS-Security handler to check which operation has been |
---|
12 | # invoked |
---|
13 | isEchoRequest = lambda sw: sw.body.node.childNodes[0].localName=='Echo' |
---|
14 | isEchoEncrRequest = lambda sw: sw.body.node.childNodes[0].localName=='EchoEncr' |
---|
15 | |
---|
16 | isEchoResponse = lambda ps: \ |
---|
17 | ps.dom.childNodes[1].childNodes[1].childNodes[0].localName == 'EchoResponse' |
---|
18 | isEchoEncrResponse = lambda ps: \ |
---|
19 | ps.dom.childNodes[1].childNodes[1].childNodes[0].localName=='EchoEncrResponse' |
---|
20 | |
---|
21 | class WSSEhandler: |
---|
22 | def __init__(self, sigHandler=None, encrHandler=None): |
---|
23 | self.sigHandler = sigHandler |
---|
24 | self.encrHandler = encrHandler |
---|
25 | |
---|
26 | def sign(self, sw): |
---|
27 | if self.sigHandler: |
---|
28 | self.sigHandler.sign(sw) |
---|
29 | |
---|
30 | def verify(self, ps): |
---|
31 | if self.sigHandler: |
---|
32 | self.sigHandler.verify(ps) |
---|
33 | |
---|
34 | def encrypt(self, sw): |
---|
35 | if self.encrHandler: |
---|
36 | self.encrHandler.encrypt(sw) |
---|
37 | |
---|
38 | def decrypt(self, ps): |
---|
39 | if self.encrHandler: |
---|
40 | self.encrHandler.decrypt(ps) |
---|
41 | |
---|
42 | |
---|
43 | #priKeyPwd = open('../tmp2').read().strip() |
---|
44 | #certFilePath = '../Junk-cert.pem' |
---|
45 | #priKeyFilePath = '../Junk-key.pem' |
---|
46 | priKeyPwd = None |
---|
47 | certFilePath = '../webSphereTestcert.pem' |
---|
48 | priKeyFilePath = '../webSphereTestkey.pem' |
---|
49 | |
---|
50 | # Signature handler object is passed to binding |
---|
51 | sigHandler = wsSecurity.SignatureHandler(certFilePath=certFilePath, |
---|
52 | priKeyFilePath=priKeyFilePath, |
---|
53 | priKeyPwd=priKeyPwd) |
---|
54 | |
---|
55 | encrHandler = wsSecurity.EncryptionHandler(certFilePath=certFilePath, |
---|
56 | priKeyFilePath=priKeyFilePath, |
---|
57 | priKeyPwd=priKeyPwd) |
---|
58 | |
---|
59 | # Test encryption only |
---|
60 | #wsseHandler = WSSEhandler(sigHandler, encrHandler) |
---|
61 | wsseHandler = WSSEhandler(encrHandler=encrHandler) |
---|
62 | |
---|
63 | |
---|
64 | # Instantiate a client proxy object, then call it |
---|
65 | #wsURL = "http://192.100.78.234:9081/EchoServiceWeb/services/EchoServer" |
---|
66 | #wsURL = "http://localhost:7000" |
---|
67 | wsURL = "http://192.100.78.135:7000" |
---|
68 | echoSrv = EchoServerSOAP(wsURL, |
---|
69 | sig_handler=sigHandler, |
---|
70 | encr_handler=encrHandler, |
---|
71 | tracefile=sys.stdout) |
---|
72 | try: |
---|
73 | import pdb;pdb.set_trace() |
---|
74 | print echoSrv.Echo("Test String") |
---|
75 | #print echoSrv.EchoEncr("Test Secret") |
---|
76 | except Exception, e: |
---|
77 | print "Failed to echo: ", e |
---|
78 | |
---|