Skip to content

Commit cccf3b0

Browse files
committed
Documentation for twisted SSL context
1 parent cded2c1 commit cccf3b0

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

docs/cloud.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ Limitations
3434

3535
Event loops
3636
^^^^^^^^^^^
37-
Twisted and Evenlet aren't supported yet. These event loops are still using the old way to configure
37+
Evenlet isn't supported yet. Eventlet still uses the old way to configure
3838
SSL (ssl_options), which is not compatible with the secure connect bundle provided by Apollo.

docs/security.rst

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ SSL should be used when client encryption is enabled in Cassandra.
6161
To give you as much control as possible over your SSL configuration, our SSL
6262
API takes a user-created `SSLContext` instance from the Python standard library.
6363
These docs will include some examples for how to achieve common configurations,
64-
but the `ssl.SSLContext` documentation gives a more complete description of
65-
what is possible.
64+
but the `ssl.SSLContext <https://docs.python.org/3/library/ssl.html#ssl.SSLContext>`_ documentation
65+
gives a more complete description of what is possible.
6666

6767
To enable SSL with version 3.17.0 and higher, you will need to set :attr:`.Cluster.ssl_context` to a
6868
``ssl.SSLContext`` instance to enable SSL. Optionally, you can also set :attr:`.Cluster.ssl_options`
@@ -78,6 +78,15 @@ It might be also useful to learn about the different levels of identity verifica
7878

7979
* `Using SSL in DSE drivers <https://docs.datastax.com/en/dse/6.7/dse-dev/datastax_enterprise/appDevGuide/sslDrivers.html>`_
8080

81+
SSL with Twisted
82+
^^^^^^^^^^^^^^^^
83+
Twisted uses an alternative SSL implementation called pyOpenSSL, so if your `Cluster`'s connection class is
84+
:class:`~cassandra.io.twistedreactor.TwistedConnection`, you must pass a
85+
`pyOpenSSL context <https://www.pyopenssl.org/en/stable/api/ssl.html#context-objects>`_ instead.
86+
An example is provided in these docs, and more details can be found in the
87+
`documentation <https://www.pyopenssl.org/en/stable/api/ssl.html#context-objects>`_.
88+
pyOpenSSL is not installed by the driver and must be installed separately.
89+
8190
SSL Configuration Examples
8291
^^^^^^^^^^^^^^^^^^^^^^^^^^
8392
Here, we'll describe the server and driver configuration necessary to set up SSL to meet various goals, such as the client verifying the server and the server verifying the client. We'll also include Python code demonstrating how to use servers and drivers configured in these ways.
@@ -239,6 +248,28 @@ The following driver code specifies that the connection should use two-way verif
239248
The driver uses ``SSLContext`` directly to give you many other options in configuring SSL. Consider reading the `Python SSL documentation <https://docs.python.org/library/ssl.html#ssl.SSLContext>`_
240249
for more details about ``SSLContext`` configuration.
241250
251+
**Server verifies client and client verifies server using Twisted and pyOpenSSL**
252+
253+
.. code-block:: python
254+
255+
from OpenSSL import SSL, crypto
256+
from cassandra.cluster import Cluster
257+
from cassandra.io.twistedreactor import TwistedConnection
258+
259+
ssl_context = SSL.Context(SSL.TLSv1_METHOD)
260+
ssl_context.set_verify(SSL.VERIFY_PEER, callback=lambda _1, _2, _3, _4, ok: ok)
261+
ssl_context.use_certificate_file('/path/to/client.crt_signed')
262+
ssl_context.use_privatekey_file('/path/to/client.key')
263+
ssl_context.load_verify_locations('/path/to/rootca.crt')
264+
265+
cluster = Cluster(
266+
contact_points=['127.0.0.1'],
267+
connection_class=TwistedConnection,
268+
ssl_context=ssl_context,
269+
ssl_options={'check_hostname': True}
270+
)
271+
session = cluster.connect()
272+
242273
Versions 3.16.0 and lower
243274
^^^^^^^^^^^^^^^^^^^^^^^^^
244275

0 commit comments

Comments
 (0)