11.. _https_connection:
22
33========================
4- HTTPS Connection support
4+ HTTPS connection support
55========================
66
7- The CrateDB Client is able to connect via https .
7+ The CrateDB client is able to connect via HTTPS .
88
9- .. note::
9+ A check against a specific CA certificate can be made by creating the client
10+ with the path to the CA certificate file using the keyword argument
11+ ``ca_cert``.
1012
11- By default, ssl server certificates are **NOT** verified.
13+ .. note::
1214
13- To enable verification, use the keyword argument ``verify_ssl_cert``.
14- If it is set to ``True``, the server certificate is validated, if set to
15- ``False`` or ommitted, no verification will be done whatsoever .
15+ By default, SSL server certificates are verified. To disable verification,
16+ use the keyword argument ``verify_ssl_cert``. If it is set to ``False``,
17+ server certificate validation will be skipped .
1618
17- One can check against a single CA certificate
18- by creating the client with the a path to a CA certificate file to check against
19- in keyword argument ``ca_cert``.
2019
2120.. rubric:: Table of Contents
2221
@@ -26,45 +25,44 @@ in keyword argument ``ca_cert``.
2625Examples
2726--------
2827
29- By default, certificates are not verified. This call is against a server with
30- a self signed certificate::
31-
32- >>> http_client = HttpClient([crate_host])
33- >>> http_client.server_infos(http_client._get_server())
34- ('https://localhost:65534', 'test', '0.0.0')
35-
3628When switching on verification without a ``ca_cert`` file provided, the
37- connection will fail::
29+ connection will fail because we are using a self-signed server certificate ::
3830
39- >>> verifying_client = HttpClient([crate_host], verify_ssl_cert=True )
31+ >>> verifying_client = HttpClient([crate_host])
4032 >>> verifying_client.server_infos(crate_host)
4133 Traceback (most recent call last):
4234 ...
4335 crate.client.exceptions.ConnectionError: Server not available, ...certificate verify failed...
4436
45- Also when providing an invalid ``ca_cert`` an error is raised::
37+ Also, when providing an invalid ``ca_cert`` an error is raised::
4638
47- >>> verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert, verify_ssl_cert=True )
39+ >>> verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert)
4840 >>> verifying_client.server_infos(crate_host)
4941 Traceback (most recent call last):
5042 ...
5143 crate.client.exceptions.ConnectionError: Server not available, ...certificate verify failed...
5244
53- Without verification, the given ``ca_cert`` is ignored and the connection will be
54- established, to Eves satisfaction.
45+ Connecting to a host whose certificate is verified with a valid CA certificate::
46+
47+ >>> verifying_valid_client = HttpClient([crate_host], ca_cert=valid_ca_cert)
48+ >>> verifying_valid_client.server_infos(verifying_valid_client._get_server())
49+ ('https://localhost:65534', 'test', '0.0.0')
5550
56- >>> non_verifying_client = HttpClient([crate_host], ca_cert=invalid_ca_cert, verify_ssl_cert=False)
51+ When turning off certificate verification, calling the server will succeed::
52+
53+ >>> non_verifying_client = HttpClient([crate_host], verify_ssl_cert=False)
5754 >>> non_verifying_client.server_infos(crate_host)
5855 ('https://localhost:65534', 'test', '0.0.0')
5956
60- Connecting to a host whose certificate is verified with a valid CA certificate::
57+ Without verification, calling the server will even work when using an invalid
58+ ``ca_cert``::
6159
62- >>> verifying_valid_client = HttpClient([crate_host], ca_cert=valid_ca_cert, verify_ssl_cert=True )
63- >>> verifying_valid_client .server_infos(verifying_valid_client._get_server() )
60+ >>> non_verifying_client = HttpClient([crate_host], verify_ssl_cert=False, ca_cert=invalid_ca_cert )
61+ >>> non_verifying_client .server_infos(crate_host )
6462 ('https://localhost:65534', 'test', '0.0.0')
6563
6664
67- Client Certificate
65+ Client certificate
6866------------------
6967
7068The client supports client certificates.
@@ -73,12 +71,11 @@ The ``HttpClient`` constructor takes two keyword arguments: ``cert_file`` and
7371``key_file``. Both should be a string pointing to the path of the client
7472certificate and key file.
7573
76- Below an example, in this case it fails because the supplied certificate is
74+ This example uses that options, however it fails because the certificate is
7775invalid::
7876
79- >>> client = HttpClient([crate_host], cert_file=invalid_ca_cert, key_file=invalid_ca_cert, verify_ssl_cert=True )
77+ >>> client = HttpClient([crate_host], cert_file=invalid_ca_cert, key_file=invalid_ca_cert, timeout=10 )
8078 >>> client.server_infos(crate_host)
8179 Traceback (most recent call last):
8280 ...
8381 crate.client.exceptions.ConnectionError: Server not available, exception: ...[SSL: ...
84-
0 commit comments