blob: b7133deb2643a1144dd75e1663ebf937e9b61c08 [file] [log] [blame]
Alex Gaynoraf82d5e2013-10-29 17:07:24 -07001.. hazmat::
Alex Gaynor0f7f7812013-09-30 10:52:36 -07002
Alex Gaynor8f42fe42013-12-24 13:15:52 -08003OpenSSL Backend
4===============
Donald Stuffte51fb932013-10-27 17:26:17 -04005
Alex Stapletonc368ac22013-12-31 13:43:38 +00006The `OpenSSL`_ C library.
Alex Gaynor6d02e2d2013-09-30 10:37:22 -07007
Alex Gaynorf8796b12013-12-13 20:28:55 -08008.. data:: cryptography.hazmat.backends.openssl.backend
Alex Gaynor6d02e2d2013-09-30 10:37:22 -07009
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060010 This is the exposed API for the OpenSSL backend.
Paul Kehrer2502ce52014-01-18 09:32:47 -060011
Paul Kehrercfa2d622014-01-19 14:01:25 -060012 .. attribute:: name
Paul Kehrer2502ce52014-01-18 09:32:47 -060013
Paul Kehrercfa2d622014-01-19 14:01:25 -060014 The string name of this backend: ``"openssl"``
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070015
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060016 .. method:: register_osrandom_engine()
17
18 Registers the OS random engine as default. This will effectively
19 disable OpenSSL's default CSPRNG.
20
21 .. method:: unregister_osrandom_engine()
22
23 Unregisters the OS random engine if it is default. This will restore
24 the default OpenSSL CSPRNG. If the OS random engine is not the default
25 engine (e.g. if another engine is set as default) nothing will be
26 changed.
27
28OS Random Engine
29----------------
30
Paul Kehrer136ff172014-01-29 21:23:11 -060031OpenSSL uses a userspace CSPRNG that is seeded from system random (
32``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded
33automatically when a process calls ``fork()``. This can result in situations
34where two different processes can return similar or identical keys and
35compromise the security of the system.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060036
Paul Kehrer136ff172014-01-29 21:23:11 -060037The approach this project has chosen to mitigate this vulnerability is to
38include an engine that replaces the OpenSSL default CSPRNG with one that sources
39its entropy from ``/dev/urandom`` on UNIX-like operating systems and uses
40``CryptGenRandom`` on Windows. This method of pulling from the system pool
41allows us to avoid potential issues with `initializing the RNG`_ as well as
42protecting us from the ``fork()`` weakness.
43
44This engine is **active** by default when importing the OpenSSL backend. It is
45added to the engine list but **not activated** if you only import the binding.
46If you wish to deactivate it call ``unregister_osrandom_engine()`` on the
47backend object.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060048
Paul Kehrer9967bc52014-01-29 21:39:13 -060049OS Random Sources
Paul Kehrer55809a12014-01-29 21:41:16 -060050-----------------
Paul Kehrer9967bc52014-01-29 21:39:13 -060051
52On OS X and FreeBSD ``/dev/urandom`` is an alias for ``/dev/random`` and
53utilizes the `Yarrow`_ algorithm.
54
55On Windows ``CryptGenRandom`` is backed by `Fortuna`_.
56
57Linux uses its own PRNG design. ``/dev/urandom`` is a non-blocking source seeded
58from the ``/dev/random`` pool.
59
60
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070061.. _`OpenSSL`: https://www.openssl.org/
Paul Kehrer136ff172014-01-29 21:23:11 -060062.. _`initializing the RNG`: http://en.wikipedia.org/wiki/OpenSSL#Vulnerability_in_the_Debian_implementation
63.. _`Yarrow`: http://en.wikipedia.org/wiki/Yarrow_algorithm
64.. _`Fortuna`: http://en.wikipedia.org/wiki/Fortuna_(PRNG)