Skip to content

Commit 5a67077

Browse files
committed
Basic docs.
1 parent aaf5003 commit 5a67077

File tree

4 files changed

+109
-0
lines changed

4 files changed

+109
-0
lines changed

docs/source/index.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,23 @@
66
Certitude: Platform-Specific TLS Certificate Verification
77
=========================================================
88

9+
Certitude provides Python bindings to the Windows and OS X system-native TLS
10+
certificate libraries. This allows Python programs to validate TLS certificates
11+
using the exact same logic used by native browsers on those platforms (e.g.
12+
Safari and Internet Explorer/Edge).
13+
14+
This means that by combining Certitude with the OpenSSL used by default on most
15+
Linuxes and BSDs, it is possible for a Python program to perform certificate
16+
validation in a platform-native manner on all major operating systems. This
17+
lets a Python program behave like a full native citizen of whatever platform it
18+
is installed on.
19+
20+
This documentation discusses how to use Certitude.
21+
922
Contents:
1023

1124
.. toctree::
1225
:maxdepth: 2
26+
27+
installation
28+
using-certitude

docs/source/installation.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Installing Certitude
2+
====================
3+
4+
Certitude involves bindings to native-code libraries, and is a library that
5+
functions only on Windows and OS X. These two platforms traditionally have
6+
problems with native-code bindings from Python, due to their lack of compilers
7+
or fully-fledged dependency resolution.
8+
9+
For this reason, while Certitude is available as a source distribution, it also
10+
provides pre-compiled binary wheels for both Windows and OS X. For this reason
11+
it is *strongly preferred* that a recent pip is used for installing Certitude,
12+
as this will remove the need for a compiler toolchain that you may not have
13+
installed.
14+
15+
To install Certitude, the pip command is very simple:
16+
17+
.. code-block:: bash
18+
19+
$ pip install certitude
20+
21+
This should download and install a wheel that makes certitude available.

docs/source/using-certitude.rst

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
Using Certitude
2+
===============
3+
4+
Certitude has one job: validating the TLS certificates a server has sent you.
5+
To do that, you need to pass Certitude the TLS certificate chain sent by the
6+
server, and the hostname you're expecting to connect to.
7+
8+
Getting A Certificate Chain
9+
---------------------------
10+
11+
Certitude expects the TLS certificate chain as a list of TLS certificates
12+
stored in the DER representation. Unfortunately, the Python standard library's
13+
``ssl`` module is not capable of providing the entire certificate chain, only
14+
the leaf certificate. This means that to use Certitude you will need to use
15+
`pyopenssl`_ or something like it: it's just the only way to guarantee that
16+
you get the complete certificate chain.
17+
18+
To get a certificate chain from PyOpenSSL, you'll want to make the connection
19+
as normal and then call ``get_peer_cert_chain()``. This will get you your cert
20+
chain as a list of ``X509`` objects. These will need decoding.
21+
22+
Given an already existing connection ``cnx``, you can get your list of
23+
certificates like this:
24+
25+
.. code-block:: python
26+
27+
certs = cnx.get_peer_cert_chain()
28+
29+
encoded_certs = [
30+
OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, cert)
31+
for cert in certs
32+
]
33+
34+
Validating The Chain
35+
--------------------
36+
37+
Once you have the chain in place, it's simple enough to validate it. Simply
38+
pass the chain into ``certitude.validate_cert_chain`` along with a unicode
39+
string containing the expected hostname. For example:
40+
41+
.. code-block:: python
42+
43+
valid = validate_cert_chain(encoded_certs, u'http2bin.org')
44+
45+
46+
The ``validate_cert_chain`` function returns ``True`` if the cert chain is
47+
valid, and ``False`` in any other case.
48+
49+
Notes
50+
-----
51+
52+
When validating certificates using certitude you'll likely want to *disable*
53+
OpenSSL's certificate validation. This is because OpenSSL and the
54+
platform-specific TLS validation code will build their certificate chains
55+
differently. In particular, OpenSSL may be *unable* to validate a chain that
56+
the system library believes is valid. For that reason, put OpenSSL into the
57+
``VERIFY_NONE`` mode and then handle the validation manually, *after* the
58+
connection is made but **before you send any data on it**.
59+
60+
We cannot stress this enough: **you must validate the certificates before
61+
sending or receiving data on the connection**.
62+
63+
64+
.. _pyopenssl: https://pyopenssl.readthedocs.io/en/stable/

src/certitude/_certitude.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# auto-generated file
2+
import _cffi_backend
3+
4+
ffi = _cffi_backend.FFI('certitude._certitude',
5+
_version = 0x2601,
6+
_types = b'\x00\x00\x07\x0D\x00\x00\x08\x03\x00\x00\x03\x03\x00\x00\x1C\x01\x00\x00\x06\x03\x00\x00\x00\x0F\x00\x00\x02\x01\x00\x00\x16\x01\x00\x00\x09\x03\x00\x00\x12\x01',
7+
_globals = (b'\x00\x00\x00\x23validate_cert_chain',0,),
8+
)

0 commit comments

Comments
 (0)