Alex Gaynor | af82d5e | 2013-10-29 17:07:24 -0700 | [diff] [blame] | 1 | .. hazmat:: |
Alex Gaynor | 0f7f781 | 2013-09-30 10:52:36 -0700 | [diff] [blame] | 2 | |
Alex Gaynor | 8f42fe4 | 2013-12-24 13:15:52 -0800 | [diff] [blame] | 3 | OpenSSL Backend |
| 4 | =============== |
Donald Stufft | e51fb93 | 2013-10-27 17:26:17 -0400 | [diff] [blame] | 5 | |
Alex Stapleton | c368ac2 | 2013-12-31 13:43:38 +0000 | [diff] [blame] | 6 | The `OpenSSL`_ C library. |
Alex Gaynor | 6d02e2d | 2013-09-30 10:37:22 -0700 | [diff] [blame] | 7 | |
Alex Gaynor | f8796b1 | 2013-12-13 20:28:55 -0800 | [diff] [blame] | 8 | .. data:: cryptography.hazmat.backends.openssl.backend |
Alex Gaynor | 6d02e2d | 2013-09-30 10:37:22 -0700 | [diff] [blame] | 9 | |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 10 | This is the exposed API for the OpenSSL backend. |
Paul Kehrer | 2502ce5 | 2014-01-18 09:32:47 -0600 | [diff] [blame] | 11 | |
Alex Gaynor | 031c2cb | 2014-01-31 11:44:53 -0800 | [diff] [blame] | 12 | 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` |
Alex Stapleton | 8f2250f | 2014-02-08 12:24:02 +0000 | [diff] [blame] | 18 | * :class:`~cryptography.hazmat.backends.interfaces.RSABackend` |
Alex Gaynor | 031c2cb | 2014-01-31 11:44:53 -0800 | [diff] [blame] | 19 | |
Paul Kehrer | e4acd5d | 2014-02-03 21:59:29 -0600 | [diff] [blame] | 20 | It also exposes the following: |
Paul Kehrer | 2502ce5 | 2014-01-18 09:32:47 -0600 | [diff] [blame] | 21 | |
Paul Kehrer | cfa2d62 | 2014-01-19 14:01:25 -0600 | [diff] [blame] | 22 | .. attribute:: name |
Paul Kehrer | 2502ce5 | 2014-01-18 09:32:47 -0600 | [diff] [blame] | 23 | |
Paul Kehrer | cfa2d62 | 2014-01-19 14:01:25 -0600 | [diff] [blame] | 24 | The string name of this backend: ``"openssl"`` |
Alex Gaynor | 6d02e2d | 2013-09-30 10:37:22 -0700 | [diff] [blame] | 25 | |
Paul Kehrer | d52b89b | 2014-01-31 10:57:17 -0600 | [diff] [blame] | 26 | .. method:: activate_osrandom_engine() |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 27 | |
Paul Kehrer | d52b89b | 2014-01-31 10:57:17 -0600 | [diff] [blame] | 28 | Activates the OS random engine. This will effectively disable OpenSSL's |
| 29 | default CSPRNG. |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 30 | |
Paul Kehrer | d258222 | 2014-02-05 16:21:19 -0600 | [diff] [blame] | 31 | .. method:: activate_builtin_random() |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 32 | |
Paul Kehrer | d258222 | 2014-02-05 16:21:19 -0600 | [diff] [blame] | 33 | This will activate the default OpenSSL CSPRNG. |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 34 | |
| 35 | OS Random Engine |
| 36 | ---------------- |
| 37 | |
Paul Kehrer | ae2138a | 2014-01-29 22:19:47 -0600 | [diff] [blame] | 38 | OpenSSL uses a user-space CSPRNG that is seeded from system random ( |
Paul Kehrer | 136ff17 | 2014-01-29 21:23:11 -0600 | [diff] [blame] | 39 | ``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded |
| 40 | automatically when a process calls ``fork()``. This can result in situations |
| 41 | where two different processes can return similar or identical keys and |
| 42 | compromise the security of the system. |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 43 | |
Paul Kehrer | 136ff17 | 2014-01-29 21:23:11 -0600 | [diff] [blame] | 44 | The approach this project has chosen to mitigate this vulnerability is to |
| 45 | include an engine that replaces the OpenSSL default CSPRNG with one that sources |
| 46 | its entropy from ``/dev/urandom`` on UNIX-like operating systems and uses |
| 47 | ``CryptGenRandom`` on Windows. This method of pulling from the system pool |
| 48 | allows us to avoid potential issues with `initializing the RNG`_ as well as |
| 49 | protecting us from the ``fork()`` weakness. |
| 50 | |
Paul Kehrer | 8042b29 | 2014-01-31 10:44:36 -0600 | [diff] [blame] | 51 | This engine is **active** by default when importing the OpenSSL backend. When |
| 52 | active this engine will be used to generate all the random data OpenSSL |
| 53 | requests. |
| 54 | |
Paul Kehrer | 8042b29 | 2014-01-31 10:44:36 -0600 | [diff] [blame] | 55 | When importing only the binding it is added to the engine list but |
| 56 | **not activated**. |
| 57 | |
Paul Kehrer | 3f17c7c | 2014-01-20 16:32:26 -0600 | [diff] [blame] | 58 | |
Paul Kehrer | 9967bc5 | 2014-01-29 21:39:13 -0600 | [diff] [blame] | 59 | OS Random Sources |
Paul Kehrer | 55809a1 | 2014-01-29 21:41:16 -0600 | [diff] [blame] | 60 | ----------------- |
Paul Kehrer | 9967bc5 | 2014-01-29 21:39:13 -0600 | [diff] [blame] | 61 | |
| 62 | On OS X and FreeBSD ``/dev/urandom`` is an alias for ``/dev/random`` and |
| 63 | utilizes the `Yarrow`_ algorithm. |
| 64 | |
Paul Kehrer | 012bfbc | 2014-02-11 23:37:51 -0600 | [diff] [blame] | 65 | On Windows the implementation of ``CryptGenRandom`` depends on which version of |
Paul Kehrer | 039b478 | 2014-02-11 23:50:56 -0600 | [diff] [blame] | 66 | the operation system you are using. See the `Microsoft documentation`_ for more |
Paul Kehrer | 012bfbc | 2014-02-11 23:37:51 -0600 | [diff] [blame] | 67 | details. |
Paul Kehrer | 9967bc5 | 2014-01-29 21:39:13 -0600 | [diff] [blame] | 68 | |
| 69 | Linux uses its own PRNG design. ``/dev/urandom`` is a non-blocking source seeded |
Paul Kehrer | 16e5e4d | 2014-01-30 09:43:30 -0600 | [diff] [blame] | 70 | from the same pool as ``/dev/random``. |
Paul Kehrer | 9967bc5 | 2014-01-29 21:39:13 -0600 | [diff] [blame] | 71 | |
| 72 | |
Alex Gaynor | 6d02e2d | 2013-09-30 10:37:22 -0700 | [diff] [blame] | 73 | .. _`OpenSSL`: https://www.openssl.org/ |
Paul Kehrer | 136ff17 | 2014-01-29 21:23:11 -0600 | [diff] [blame] | 74 | .. _`initializing the RNG`: http://en.wikipedia.org/wiki/OpenSSL#Vulnerability_in_the_Debian_implementation |
| 75 | .. _`Yarrow`: http://en.wikipedia.org/wiki/Yarrow_algorithm |
Paul Kehrer | b4f7d88 | 2014-02-11 23:29:51 -0600 | [diff] [blame] | 76 | .. _`Microsoft documentation`: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx |