blob: ea72af96e2301fcb0b4219b19981830e0bdc7ff2 [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
Alex Gaynor031c2cb2014-01-31 11:44:53 -080012 It implements the following interfaces:
13
14 * :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
15 * :class:`~cryptography.hazmat.backends.interfaces.HashBackend`
16 * :class:`~cryptography.hazmat.backends.interfaces.HMACBackend`
17 * :class:`~cryptography.hazmat.backends.interfaces.PBKDF2HMACBackend`
18
Paul Kehrere4acd5d2014-02-03 21:59:29 -060019 It also exposes the following:
Paul Kehrer2502ce52014-01-18 09:32:47 -060020
Paul Kehrercfa2d622014-01-19 14:01:25 -060021 .. attribute:: name
Paul Kehrer2502ce52014-01-18 09:32:47 -060022
Paul Kehrercfa2d622014-01-19 14:01:25 -060023 The string name of this backend: ``"openssl"``
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070024
Paul Kehrerd52b89b2014-01-31 10:57:17 -060025 .. method:: activate_osrandom_engine()
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060026
Paul Kehrerd52b89b2014-01-31 10:57:17 -060027 Activates the OS random engine. This will effectively disable OpenSSL's
28 default CSPRNG.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060029
Paul Kehrerd2582222014-02-05 16:21:19 -060030 .. method:: activate_builtin_random()
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060031
Paul Kehrerd2582222014-02-05 16:21:19 -060032 This will activate the default OpenSSL CSPRNG.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060033
34OS Random Engine
35----------------
36
Paul Kehrerae2138a2014-01-29 22:19:47 -060037OpenSSL uses a user-space CSPRNG that is seeded from system random (
Paul Kehrer136ff172014-01-29 21:23:11 -060038``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded
39automatically when a process calls ``fork()``. This can result in situations
40where two different processes can return similar or identical keys and
41compromise the security of the system.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060042
Paul Kehrer136ff172014-01-29 21:23:11 -060043The approach this project has chosen to mitigate this vulnerability is to
44include an engine that replaces the OpenSSL default CSPRNG with one that sources
45its entropy from ``/dev/urandom`` on UNIX-like operating systems and uses
46``CryptGenRandom`` on Windows. This method of pulling from the system pool
47allows us to avoid potential issues with `initializing the RNG`_ as well as
48protecting us from the ``fork()`` weakness.
49
Paul Kehrer8042b292014-01-31 10:44:36 -060050This engine is **active** by default when importing the OpenSSL backend. When
51active this engine will be used to generate all the random data OpenSSL
52requests.
53
Paul Kehrer8042b292014-01-31 10:44:36 -060054When importing only the binding it is added to the engine list but
55**not activated**.
56
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060057
Paul Kehrer9967bc52014-01-29 21:39:13 -060058OS Random Sources
Paul Kehrer55809a12014-01-29 21:41:16 -060059-----------------
Paul Kehrer9967bc52014-01-29 21:39:13 -060060
61On OS X and FreeBSD ``/dev/urandom`` is an alias for ``/dev/random`` and
62utilizes the `Yarrow`_ algorithm.
63
64On Windows ``CryptGenRandom`` is backed by `Fortuna`_.
65
66Linux uses its own PRNG design. ``/dev/urandom`` is a non-blocking source seeded
Paul Kehrer16e5e4d2014-01-30 09:43:30 -060067from the same pool as ``/dev/random``.
Paul Kehrer9967bc52014-01-29 21:39:13 -060068
69
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070070.. _`OpenSSL`: https://www.openssl.org/
Paul Kehrer136ff172014-01-29 21:23:11 -060071.. _`initializing the RNG`: http://en.wikipedia.org/wiki/OpenSSL#Vulnerability_in_the_Debian_implementation
72.. _`Yarrow`: http://en.wikipedia.org/wiki/Yarrow_algorithm
73.. _`Fortuna`: http://en.wikipedia.org/wiki/Fortuna_(PRNG)