source: TI12-security/trunk/python/Tests/Echo/EchoClient.py @ 1664

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/Echo/EchoClient.py@1664
Revision 1664, 2.7 KB checked in by pjkersha, 13 years ago (diff)

Modified version working for sig generation with WebSphere?. Verify of
WebSphere? incoming message still to resolve.

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