mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-10-05 13:26:03 +00:00
1. Remove certificate file 'bindctl.pem'. 2. Add options -c(--certificate-chain) to bindctl. 3. Override class HTTPSConnection to support server certificate validation.
git-svn-id: svn://bind10.isc.org/svn/bind10/branches/trac127@2167 e5f2f494-b856-4b98-b285-d166d9295462
This commit is contained in:
@@ -58,10 +58,34 @@ Type \"<module_name> help\" for help on the specific module.
|
||||
Type \"<module_name> <command_name> help\" for help on the specific command.
|
||||
\nAvailable module names: """
|
||||
|
||||
class ValidatedHTTPSConnection(http.client.HTTPSConnection):
|
||||
'''Overrides HTTPSConnection to support certification
|
||||
validation. '''
|
||||
def __init__(self, host, ca_certs):
|
||||
http.client.HTTPSConnection.__init__(self, host)
|
||||
self.ca_certs = ca_certs
|
||||
|
||||
def connect(self):
|
||||
''' Overrides the connect() so that we do
|
||||
certificate validation. '''
|
||||
sock = socket.create_connection((self.host, self.port),
|
||||
self.timeout)
|
||||
if self._tunnel_host:
|
||||
self.sock = sock
|
||||
self._tunnel()
|
||||
|
||||
req_cert = ssl.CERT_NONE
|
||||
if self.ca_certs:
|
||||
req_cert = ssl.CERT_REQUIRED
|
||||
self.sock = ssl.wrap_socket(sock, self.key_file,
|
||||
self.cert_file,
|
||||
cert_reqs=req_cert,
|
||||
ca_certs=self.ca_certs)
|
||||
|
||||
class BindCmdInterpreter(Cmd):
|
||||
"""simple bindctl example."""
|
||||
|
||||
def __init__(self, server_port = 'localhost:8080', pem_file = "bindctl.pem"):
|
||||
def __init__(self, server_port = 'localhost:8080', pem_file = None):
|
||||
Cmd.__init__(self)
|
||||
self.location = ""
|
||||
self.prompt_end = '> '
|
||||
@@ -70,19 +94,10 @@ class BindCmdInterpreter(Cmd):
|
||||
self.modules = OrderedDict()
|
||||
self.add_module_info(ModuleInfo("help", desc = "Get help for bindctl"))
|
||||
self.server_port = server_port
|
||||
self.pem_file = pem_file
|
||||
self._connect_to_cmd_ctrld()
|
||||
self.conn = ValidatedHTTPSConnection(self.server_port,
|
||||
ca_certs=pem_file)
|
||||
self.session_id = self._get_session_id()
|
||||
|
||||
def _connect_to_cmd_ctrld(self):
|
||||
'''Connect to cmdctl in SSL context. '''
|
||||
try:
|
||||
self.conn = http.client.HTTPSConnection(self.server_port,
|
||||
cert_file=self.pem_file)
|
||||
except Exception as e:
|
||||
print(e, "can't connect to %s, please make sure cmd-ctrld is running" %
|
||||
self.server_port)
|
||||
|
||||
def _get_session_id(self):
|
||||
'''Generate one session id for the connection. '''
|
||||
rand = os.urandom(16)
|
||||
|
Reference in New Issue
Block a user