Commit fdfc9245 authored by Jim Fulton's avatar Jim Fulton

client check-hostname by default

parent d5f44000
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</description> </description>
</key> </key>
<key name="check-hostname" datatype="boolean" required="no"> <key name="check-hostname" datatype="boolean" required="no" default="true">
<description> <description>
Verify the host name in the server certificate is as expected. Verify the host name in the server certificate is as expected.
</description> </description>
......
...@@ -60,6 +60,7 @@ class SSLConfigTest(ZEOConfigTest): ...@@ -60,6 +60,7 @@ class SSLConfigTest(ZEOConfigTest):
certificate {} certificate {}
key {} key {}
authenticate {} authenticate {}
server-hostname zodb.org
</ssl>""".format(client_cert, client_key, server_cert)) </ssl>""".format(client_cert, client_key, server_cert))
self._client_assertions(client, addr) self._client_assertions(client, addr)
client.close() client.close()
...@@ -200,6 +201,7 @@ class SSLConfigTest(ZEOConfigTest): ...@@ -200,6 +201,7 @@ class SSLConfigTest(ZEOConfigTest):
self.assert_context( self.assert_context(
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
capath=here, capath=here,
check_hostname=True,
) )
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
...@@ -215,6 +217,7 @@ class SSLConfigTest(ZEOConfigTest): ...@@ -215,6 +217,7 @@ class SSLConfigTest(ZEOConfigTest):
self.assert_context( self.assert_context(
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
cafile=server_cert, cafile=server_cert,
check_hostname=True,
) )
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
...@@ -231,8 +234,8 @@ class SSLConfigTest(ZEOConfigTest): ...@@ -231,8 +234,8 @@ class SSLConfigTest(ZEOConfigTest):
None) None)
self.assert_context( self.assert_context(
factory, context, (client_cert, client_key, pwfunc), factory, context, (client_cert, client_key, pwfunc),
check_hostname=False,
cafile=server_cert, cafile=server_cert,
check_hostname=True,
) )
@mock.patch('ssl.create_default_context') @mock.patch('ssl.create_default_context')
...@@ -259,14 +262,14 @@ class SSLConfigTest(ZEOConfigTest): ...@@ -259,14 +262,14 @@ class SSLConfigTest(ZEOConfigTest):
): ):
client = ssl_client( client = ssl_client(
certificate=client_cert, key=client_key, authenticate=server_cert, certificate=client_cert, key=client_key, authenticate=server_cert,
check_hostname=True) check_hostname=False)
context = ClientStorage.call_args[1]['ssl'] context = ClientStorage.call_args[1]['ssl']
self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'], self.assertEqual(ClientStorage.call_args[1]['ssl_server_hostname'],
None) None)
self.assert_context( self.assert_context(
factory, context, (client_cert, client_key, None), factory, context, (client_cert, client_key, None),
cafile=server_cert, cafile=server_cert,
check_hostname=True, check_hostname=False,
) )
def args(*a, **kw): def args(*a, **kw):
......
...@@ -30,9 +30,7 @@ def ssl_config(section, server): ...@@ -30,9 +30,7 @@ def ssl_config(section, server):
context.check_hostname = False context.check_hostname = False
return context return context
context.check_hostname = bool( context.check_hostname = section.check_hostname
section.check_hostname is None and (section.server_hostname or not auth)
or section.check_hostname)
return context, section.server_hostname return context, section.server_hostname
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment