Do not move versions backward
[certmaster.git] / certmaster / overlord / sslclient.py
1 import sys
2 import xmlrpclib
3 import urllib
4
5 from func import SSLCommon
6
7
8 class SSL_Transport(xmlrpclib.Transport):
9
10 user_agent = "pyOpenSSL_XMLRPC/%s - %s" % ('0.1', xmlrpclib.Transport.user_agent)
11
12 def __init__(self, ssl_context, timeout=None, use_datetime=0):
13 if sys.version_info[:3] >= (2, 5, 0):
14 xmlrpclib.Transport.__init__(self, use_datetime)
15 self.ssl_ctx=ssl_context
16 self._timeout = timeout
17
18 def make_connection(self, host):
19 # Handle username and password.
20 try:
21 host, extra_headers, x509 = self.get_host_info(host)
22 except AttributeError:
23 # Yay for Python 2.2
24 pass
25 _host, _port = urllib.splitport(host)
26 return SSLCommon.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout)
27
28
29 class SSLXMLRPCServerProxy(xmlrpclib.ServerProxy):
30 def __init__(self, uri, pkey_file, cert_file, ca_cert_file, timeout=None):
31 self.ctx = SSLCommon.CreateSSLContext(pkey_file, cert_file, ca_cert_file)
32 xmlrpclib.ServerProxy.__init__(self, uri, SSL_Transport(ssl_context=self.ctx, timeout=timeout))
33
34
35 class FuncServer(SSLXMLRPCServerProxy):
36 def __init__(self, uri, pem=None, crt=None, ca=None):
37 self.pem = pem
38 self.crt = crt
39 self.ca = ca
40
41 SSLXMLRPCServerProxy.__init__(self, uri,
42 self.pem,
43 self.crt,
44 self.ca)
45
46
47 if __name__ == "__main__":
48 s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.cert', '/etc/pki/func/ca/funcmaster.crt')
49 f = s.ping(1, 2)
50 print f