/thirdpart/Pyro-3.9.1/examples/ssl/server.py

https://github.com/xblaster/scrutator
Python | 61 lines | 33 code | 18 blank | 10 comment | 6 complexity | feb2bcf708609b3e65e3e27fc974d17b MD5 | raw file
  1. #!/usr/bin/env python
  2. import sys
  3. import Pyro.naming, Pyro.core, Pyro.util, Pyro.protocol
  4. from Pyro.errors import PyroError, NamingError
  5. from Pyro.protocol import getHostname
  6. ######## Custom connections validator.
  7. class printCertValidator(Pyro.protocol.BasicSSLValidator):
  8. def checkCertificate(self, cert):
  9. if cert is None:
  10. return (0, 3)
  11. print "Cert Subject: %s" % cert.get_subject()
  12. return (1, 0)
  13. ##### test object
  14. class testclass(Pyro.core.ObjBase):
  15. def passSecretMessage(self, arg):
  16. print 'I got a secret message: ', arg
  17. return "Elvis Presley isn't dead, he just went home"
  18. ##### main program.
  19. # initialize the server and set the default namespace group
  20. Pyro.core.initServer()
  21. Pyro.config.PYRO_TRACELEVEL = 3
  22. Pyro.config.PYRO_NS_DEFAULTGROUP = ':test'
  23. Pyro.config.PYRO_LOGFILE = 'server_log'
  24. print 'Check the logfile for messages: server_log'
  25. # Construct the Pyro Daemon with our own connection validator, using SSL
  26. daemon = Pyro.core.Daemon(prtcol='PYROSSL')
  27. daemon.setNewConnectionValidator(printCertValidator()) ### <<--- !!!
  28. # locate the NS
  29. locator = Pyro.naming.NameServerLocator()
  30. print 'searching for Naming Service...'
  31. ns = locator.getNS()
  32. print 'Naming Service found at', ns.URI.address, '(' + (Pyro.protocol.getHostname(ns.URI.address) or '??') + ') port', ns.URI.port
  33. # make sure our namespace group exists
  34. try: ns.createGroup(Pyro.config.PYRO_NS_DEFAULTGROUP)
  35. except NamingError: pass
  36. daemon.useNameServer(ns)
  37. # connect a new object implementation (first unregister previous one)
  38. try: ns.unregister('ssl')
  39. except NamingError: pass
  40. daemon.connect(testclass(), 'ssl')
  41. # enter the service loop.
  42. print 'Server object "ssl" ready.'
  43. daemon.requestLoop()