blob: b48e502d6ee0b87348e0ac80aea65f764a4e9411 [file] [log] [blame]
Alex Gaynoraf82d5e2013-10-29 17:07:24 -07001.. hazmat::
Alex Gaynor0f7f7812013-09-30 10:52:36 -07002
Alex Stapletonc5fffd32014-03-18 15:29:00 +00003OpenSSL backend
Alex Gaynor8f42fe42013-12-24 13:15:52 -08004===============
Donald Stuffte51fb932013-10-27 17:26:17 -04005
Paul Kehrer12649af2014-03-10 12:45:19 -04006The `OpenSSL`_ C library. Cryptography supports version ``0.9.8e`` (present in
7Red Hat Enterprise Linux 5) and greater. Earlier versions may work but are
8**not tested or supported**.
Alex Gaynor6d02e2d2013-09-30 10:37:22 -07009
Alex Gaynorf8796b12013-12-13 20:28:55 -080010.. data:: cryptography.hazmat.backends.openssl.backend
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070011
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060012 This is the exposed API for the OpenSSL backend.
Paul Kehrer2502ce52014-01-18 09:32:47 -060013
Alex Gaynor031c2cb2014-01-31 11:44:53 -080014 It implements the following interfaces:
15
16 * :class:`~cryptography.hazmat.backends.interfaces.CipherBackend`
Paul Kehrer3d754292014-05-01 09:09:34 -050017 * :class:`~cryptography.hazmat.backends.interfaces.CMACBackend`
Mohammed Attia59edb612014-04-25 22:44:40 +020018 * :class:`~cryptography.hazmat.backends.interfaces.DSABackend`
Alex Gaynor031c2cb2014-01-31 11:44:53 -080019 * :class:`~cryptography.hazmat.backends.interfaces.HashBackend`
20 * :class:`~cryptography.hazmat.backends.interfaces.HMACBackend`
21 * :class:`~cryptography.hazmat.backends.interfaces.PBKDF2HMACBackend`
Paul Kehrer286c7dc2014-05-31 12:05:38 -050022 * :class:`~cryptography.hazmat.backends.interfaces.PKCS8SerializationBackend`
Alex Stapleton8f2250f2014-02-08 12:24:02 +000023 * :class:`~cryptography.hazmat.backends.interfaces.RSABackend`
Paul Kehrer286c7dc2014-05-31 12:05:38 -050024 * :class:`~cryptography.hazmat.backends.interfaces.TraditionalOpenSSLSerializationBackend`
Alex Gaynor031c2cb2014-01-31 11:44:53 -080025
Paul Kehrere4acd5d2014-02-03 21:59:29 -060026 It also exposes the following:
Paul Kehrer2502ce52014-01-18 09:32:47 -060027
Paul Kehrercfa2d622014-01-19 14:01:25 -060028 .. attribute:: name
Paul Kehrer2502ce52014-01-18 09:32:47 -060029
Paul Kehrercfa2d622014-01-19 14:01:25 -060030 The string name of this backend: ``"openssl"``
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070031
Paul Kehrerd52b89b2014-01-31 10:57:17 -060032 .. method:: activate_osrandom_engine()
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060033
Paul Kehrerd52b89b2014-01-31 10:57:17 -060034 Activates the OS random engine. This will effectively disable OpenSSL's
35 default CSPRNG.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060036
Paul Kehrerd2582222014-02-05 16:21:19 -060037 .. method:: activate_builtin_random()
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060038
Paul Kehrerd2582222014-02-05 16:21:19 -060039 This will activate the default OpenSSL CSPRNG.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060040
Alex Stapletonc5fffd32014-03-18 15:29:00 +000041OS random engine
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060042----------------
43
Paul Kehrerae2138a2014-01-29 22:19:47 -060044OpenSSL uses a user-space CSPRNG that is seeded from system random (
Paul Kehrer136ff172014-01-29 21:23:11 -060045``/dev/urandom`` or ``CryptGenRandom``). This CSPRNG is not reseeded
46automatically when a process calls ``fork()``. This can result in situations
47where two different processes can return similar or identical keys and
48compromise the security of the system.
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060049
Paul Kehrer136ff172014-01-29 21:23:11 -060050The approach this project has chosen to mitigate this vulnerability is to
Alex Gaynor969f18e2014-05-17 20:07:35 -070051include an engine that replaces the OpenSSL default CSPRNG with one that
52sources its entropy from ``/dev/urandom`` on UNIX-like operating systems and
53uses ``CryptGenRandom`` on Windows. This method of pulling from the system pool
Paul Kehrer136ff172014-01-29 21:23:11 -060054allows us to avoid potential issues with `initializing the RNG`_ as well as
55protecting us from the ``fork()`` weakness.
56
Paul Kehrer8042b292014-01-31 10:44:36 -060057This engine is **active** by default when importing the OpenSSL backend. When
58active this engine will be used to generate all the random data OpenSSL
59requests.
60
Paul Kehrer8042b292014-01-31 10:44:36 -060061When importing only the binding it is added to the engine list but
62**not activated**.
63
Paul Kehrer3f17c7c2014-01-20 16:32:26 -060064
Alex Stapletonc5fffd32014-03-18 15:29:00 +000065OS random sources
Paul Kehrer55809a12014-01-29 21:41:16 -060066-----------------
Paul Kehrer9967bc52014-01-29 21:39:13 -060067
68On OS X and FreeBSD ``/dev/urandom`` is an alias for ``/dev/random`` and
69utilizes the `Yarrow`_ algorithm.
70
Paul Kehrer012bfbc2014-02-11 23:37:51 -060071On Windows the implementation of ``CryptGenRandom`` depends on which version of
Paul Kehrer039b4782014-02-11 23:50:56 -060072the operation system you are using. See the `Microsoft documentation`_ for more
Paul Kehrer012bfbc2014-02-11 23:37:51 -060073details.
Paul Kehrer9967bc52014-01-29 21:39:13 -060074
Alex Gaynor969f18e2014-05-17 20:07:35 -070075Linux uses its own PRNG design. ``/dev/urandom`` is a non-blocking source
76seeded from the same pool as ``/dev/random``.
Paul Kehrer9967bc52014-01-29 21:39:13 -060077
78
Alex Gaynor6d02e2d2013-09-30 10:37:22 -070079.. _`OpenSSL`: https://www.openssl.org/
Alex Gaynor2332c192014-04-23 08:07:27 -070080.. _`initializing the RNG`: https://en.wikipedia.org/wiki/OpenSSL#Predictable_keys_.28Debian-specific.29
Alex Gaynore9df2942014-12-12 10:56:26 -080081.. _`Yarrow`: https://en.wikipedia.org/wiki/Yarrow_algorithm
Paul Kehrerb4f7d882014-02-11 23:29:51 -060082.. _`Microsoft documentation`: http://msdn.microsoft.com/en-us/library/windows/desktop/aa379942(v=vs.85).aspx