2 This module implements a general-purpose server layer for sfa.
3 The same basic server should be usable on the registry or
9 from sfa.server.threadedserver import ThreadedServer, SecureXMLRpcRequestHandler
11 from sfa.util.sfalogging import logger
12 from sfa.trust.certificate import Keypair, Certificate
15 # Implements an HTTPS XML-RPC server. Generally it is expected that SFA
16 # functions will take a credential string, which is passed to
17 # decode_authentication. Decode_authentication() will verify the validity of
18 # the credential, and verify that the user is using the key that matches the
19 # GID supplied in the credential.
22 class SfaServer(threading.Thread):
25 # Create a new SfaServer object.
27 # @param ip the ip address to listen on
28 # @param port the port to listen on
29 # @param key_file private key filename of registry
30 # @param cert_file certificate filename containing public key
31 # (could be a GID file)
33 def __init__(self, ip, port, key_file, cert_file, interface):
34 threading.Thread.__init__(self)
35 self.key = Keypair(filename=key_file)
36 self.cert = Certificate(filename=cert_file)
37 #self.server = SecureXMLRPCServer((ip, port), SecureXMLRpcRequestHandler, key_file, cert_file)
38 self.server = ThreadedServer(
39 (ip, int(port)), SecureXMLRpcRequestHandler, key_file, cert_file)
40 self.server.interface = interface
41 self.trusted_cert_list = None
42 self.register_functions()
43 logger.info("Starting SfaServer, interface=%s" % interface)
46 # Register functions that will be served by the XMLRPC server. This
47 # function should be overridden by each descendant class.
49 def register_functions(self):
50 self.server.register_function(self.noop)
53 # Sample no-op server function. The no-op function decodes the credential
54 # that was passed to it.
56 def noop(self, cred, anything):
60 # Execute the server, serving requests forever.
63 self.server.serve_forever()