source: TI12-security/trunk/python/Tests/xmlsec/WS-Security/wsClient.py @ 1508

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/xmlsec/WS-Security/wsClient.py@1510
Revision 1508, 2.6 KB checked in by pjkersha, 13 years ago (diff)

Working EncryptionHandler? encrypt method. Equivalent decrypt nearly complete. Moved calls to handler code in
wsServer.py from echo to _Dispatch because the latter needs to know what method to call and so must operate on
the decrypted message.

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3"""WS-Security test client
4
5NERC Data Grid Project
6
7P J Kershaw 01/09/06
8
9Copyright (C) 2006 CCLRC & NERC
10
11This software may be distributed under the terms of the Q Public License,
12version 1.0 or later.
13"""
14
15reposID = '$Id$'
16
17import sys, socket
18from ZSI import Binding, TCcompound, TC
19from wsInterface import *
20import wsSecurity
21
22MESSAGE = "Hello from Python!"
23
24def main():
25   
26    priKeyPwd = open('../../tmp2').read().strip()
27    certFilePath = '../../Junk-cert.pem'
28    priKeyFilePath = '../../Junk-key.pem'
29   
30    # Signature handler object is passed to binding
31    signatureHandler = wsSecurity.SignatureHandler(certFilePath=certFilePath,
32                                                priKeyFilePath=priKeyFilePath,
33                                                priKeyPwd=priKeyPwd)
34   
35    encryptionHandler = wsSecurity.EncryptionHandler(
36                                                certFilePath=certFilePath,
37                                                priKeyFilePath=priKeyFilePath,
38                                                priKeyPwd=priKeyPwd)
39
40    # Added in encr_handler keyword as a quick fudge - encr_handler.encrypt
41    # gets called after sig_handler.sign and encr_handler.decrypt gets called
42    # before sig_handler.verify
43    #
44    # Maybe there should be a generic handler keyword for signature and
45    # encryption so that it can customised - sign then encrypt or encrypt
46    # then sign or any other combination...
47    binding = Binding(url='http://localhost:8080/wsServer.py',
48                      #sig_handler=signatureHandler, [leave out whilst testing
49                      # encryption]
50                      encr_handler=encryptionHandler)
51                 
52    echoRequest = echoRequestWrapper()
53    echoRequest._message = MESSAGE
54   
55    import pdb;pdb.set_trace()
56    print ' Sending: %s' % MESSAGE
57   
58    try:
59        binding.Send(None, 
60                 'echo', 
61                 echoRequest,
62                 encodingStyle="http://schemas.xmlsoap.org/soap/encoding/")
63   
64        response = binding.Receive(echoResponseWrapper(), 
65                 encodingStyle="http://schemas.xmlsoap.org/soap/encoding/")
66
67    except socket.error, (errNum, errMsg):
68        print >>sys.stderr, "Socket error: %s" % errMsg
69        sys.exit(1)
70       
71    if not isinstance(response, echoResponse) and \
72       not issubclass(echoResponse, response.__class__):
73        print >>sys.stderr, "%s incorrect response type" % response.__class__
74        sys.exit(1)
75
76    print 'Response: %s' % response._message
77
78
79if __name__ == '__main__':
80    main()
Note: See TracBrowser for help on using the repository browser.