You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

testclient.py 3.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Bernd Zeimetz"
  4. __contact__ = "bzed@debian.org"
  5. __license__ = """
  6. Copyright (C) 2010-2012 Bernd Zeimetz <bzed@debian.org>
  7. Copyright (C) 2012 Bernd Zeimetz <b.zeimetz@conova.com>
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are
  10. met:
  11. 1. Redistributions of source code must retain the above copyright
  12. notice, this list of conditions and the following disclaimer.
  13. 2. Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the following
  15. disclaimer in the documentation and/or other materials provided
  16. with the distribution.
  17. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
  18. WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  19. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  21. ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  23. GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  24. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  25. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  26. OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  27. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. """
  29. import xmlrpclib
  30. server = xmlrpclib.ServerProxy('http://localhost:5000/')
  31. #for i in range(5):
  32. # print server.generate_password(40)
  33. from monkeystore import web
  34. import gnupg
  35. gpg=gnupg.GPG()
  36. def __encrypt_data__(data, keys, passphrase=None, symmetric=False):
  37. gpg_data = gpg.encrypt(data, keys, passphrase=passphrase, symmetric=symmetric, always_trust=True)
  38. if not gpg_data.ok:
  39. raise Exception("Failed to encrypt: \n%s" %(gpg_data.stderr,))
  40. return gpg_data.data
  41. def __decrypt_data__(gpg_data, passphrase=None):
  42. data = gpg.decrypt(gpg_data, passphrase=passphrase, always_trust=True)
  43. if not data.ok:
  44. raise Exception("Failed to encrypt: \n%s" %(data.stderr,))
  45. return data.data
  46. token=__decrypt_data__(server.retrieve_token('zebe'))
  47. print server.list_categories('zebe', token)
  48. token=__decrypt_data__(server.retrieve_token('zebe'))
  49. print "1 " + token
  50. password_crypt=__encrypt_data__('f00bar!', None, passphrase=token, symmetric=True)
  51. print password_crypt
  52. description_crypt=__encrypt_data__('das ist eine beschreibung!', None, passphrase=token, symmetric=True)
  53. print description_crypt
  54. print server.add_password('zebe', 'linux', 'zebe001', 'ssh', 'root',
  55. password_crypt, description_crypt)
  56. token=__decrypt_data__(server.retrieve_token('zebe'))
  57. print "1 " + token
  58. password_crypt=__encrypt_data__('f00bar!', None, passphrase=token, symmetric=True)
  59. print password_crypt
  60. description_crypt=__encrypt_data__('das ist eine beschreibung!', None, passphrase=token, symmetric=True)
  61. print description_crypt
  62. print server.add_password('zebe', 'linux', 'zebe001', 'sshasd', 'root',
  63. password_crypt, description_crypt)
  64. print __decrypt_data__(server.get_url('zebe', 'linux', 'zebe001', 'sshasd', 'root'))
  65. token=__decrypt_data__(server.retrieve_token('zebe'))
  66. server.delete_password('zebe', token, 'linux', 'zebe001', 'ssh', 'root')