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

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

ez_setup.py: keep for ndg generic egg install
Echo/EchoClient?.py, Echo/wsSecurity.py and Echo/EchoServer?.py: comments added and debugs cleaned up.

  • Property svn:executable set to *
Line 
1#!/usr/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                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
70#wsURL = "http://192.100.78.234:9081/EchoServiceWeb/services/EchoServer"
71wsURL = "http://localhost:7100"
72echoSrv = EchoServerSOAP(wsURL,
73                         sig_handler=wsseHandler,
74                         tracefile=sys.stdout)
75try:
76    #import pdb;pdb.set_trace()
77    print echoSrv.Echo("Test String")
78    #print echoSrv.EchoEncr("Test Secret")
79except Exception, e:
80    print "Failed to echo: ", e
81
Note: See TracBrowser for help on using the repository browser.