summaryrefslogtreecommitdiffstats
path: root/overlord/sslclient.py
blob: 0ddbf58fa632d75681abcc6f375a44782392ed35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python

import sys
import xmlrpclib
import urllib

from func import SSLCommon


class SSL_Transport(xmlrpclib.Transport):

    user_agent = "pyOpenSSL_XMLRPC/%s - %s" % ('0.1', xmlrpclib.Transport.user_agent)

    def __init__(self, ssl_context, timeout=None, use_datetime=0):
        if sys.version_info[:3] >= (2, 5, 0):
            xmlrpclib.Transport.__init__(self, use_datetime)
        self.ssl_ctx=ssl_context
        self._timeout = timeout

    def make_connection(self, host):
        # Handle username and password.
        try:
            host, extra_headers, x509 = self.get_host_info(host)
        except AttributeError:
            # Yay for Python 2.2
            pass
        _host, _port = urllib.splitport(host)
        return SSLCommon.HTTPS(_host, int(_port), ssl_context=self.ssl_ctx, timeout=self._timeout)


class SSLXMLRPCServerProxy(xmlrpclib.ServerProxy):
    def __init__(self, uri, pkey_file, cert_file, ca_cert_file, timeout=None):
        self.ctx = SSLCommon.CreateSSLContext(pkey_file, cert_file, ca_cert_file)
        xmlrpclib.ServerProxy.__init__(self, uri, SSL_Transport(ssl_context=self.ctx, timeout=timeout))


class FuncServer(SSLXMLRPCServerProxy):
    def __init__(self, uri, pem=None, crt=None, ca=None):
        self.pem = pem
        self.crt = crt
        self.ca = ca

        SSLXMLRPCServerProxy.__init__(self, uri,
                                      self.pem,
                                      self.crt,
                                      self.ca)
        

if __name__ == "__main__":
    s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.cert', '/etc/pki/func/ca/funcmaster.crt')
    f = s.ping(1, 2)
    print f