|
13 | 13 | """Bitcoin Core RPC support""" |
14 | 14 |
|
15 | 15 | from __future__ import absolute_import, division, print_function, unicode_literals |
| 16 | +import ssl |
16 | 17 |
|
17 | 18 | try: |
18 | 19 | import http.client as httplib |
@@ -100,6 +101,22 @@ def __init__(self, service_url=None, |
100 | 101 | else: |
101 | 102 | raise ValueError('Unknown rpcssl value %r' % conf['rpcssl']) |
102 | 103 |
|
| 104 | + if conf['rpcssl'] and 'rpcsslcertificatechainfile' in conf and 'rpcsslprivatekeyfile' in conf: |
| 105 | + self.__ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2) |
| 106 | + if os.path.exists(conf['rpcsslcertificatechainfile']): |
| 107 | + certificate = conf['rpcsslcertificatechainfile'] |
| 108 | + elif os.path.exists(os.path.join(os.path.dirname(btc_conf_file), conf['rpcsslcertificatechainfile'])): |
| 109 | + certificate = os.path.join(os.path.dirname(btc_conf_file), conf['rpcsslcertificatechainfile']) |
| 110 | + else: |
| 111 | + raise ValueError('The value of rpcsslcertificatechainfile is not correctly specified in the configuration file: %s' % btc_conf_file) |
| 112 | + if os.path.exists(conf['rpcsslprivatekeyfile']): |
| 113 | + private_key = conf['rpcsslprivatekeyfile'] |
| 114 | + elif os.path.exists(os.path.join(os.path.dirname(btc_conf_file), conf['rpcsslprivatekeyfile'])): |
| 115 | + private_key = os.path.join(os.path.dirname(btc_conf_file), conf['rpcsslprivatekeyfile']) |
| 116 | + else: |
| 117 | + raise ValueError('The value of rpcsslprivatekeyfile is not correctly specified in the configuration file: %s' % btc_conf_file) |
| 118 | + self.__ssl_context.load_cert_chain(certificate, private_key) |
| 119 | + |
103 | 120 | if 'rpcpassword' not in conf: |
104 | 121 | raise ValueError('The value of rpcpassword not specified in the configuration file: %s' % btc_conf_file) |
105 | 122 |
|
@@ -128,7 +145,7 @@ def __init__(self, service_url=None, |
128 | 145 |
|
129 | 146 | if self.__url.scheme == 'https': |
130 | 147 | self.__conn = httplib.HTTPSConnection(self.__url.hostname, port=port, |
131 | | - key_file=None, cert_file=None, |
| 148 | + context=self.__ssl_context, |
132 | 149 | timeout=timeout) |
133 | 150 | else: |
134 | 151 | self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port, |
|
0 commit comments