diff options
author | Nathan Hourt <[email protected]> | 2016-10-03 15:55:13 -0500 |
---|---|---|
committer | GitHub <[email protected]> | 2016-10-03 15:55:13 -0500 |
commit | 467007928b2e929a67d68b22ff6d59a7a40b236a (patch) | |
tree | d3da7c9a3c39f915eb42fff323281717ee7ee1c0 /src | |
parent | ab2842d6f28680b1cac18d5ff6b70b395d1ffb65 (diff) |
Resolve #647
Implement a backoff approach to opening the system RNG: if opening read-write fails, try to open read-only. This will allow the RNG to be used, but attempts to add entropy will fail. If opening as read-only also fails, only then throw an exception.
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/rng/system_rng/system_rng.cpp | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/src/lib/rng/system_rng/system_rng.cpp b/src/lib/rng/system_rng/system_rng.cpp index 135f4fabd..1ea749327 100644 --- a/src/lib/rng/system_rng/system_rng.cpp +++ b/src/lib/rng/system_rng/system_rng.cpp @@ -75,6 +75,12 @@ System_RNG_Impl::System_RNG_Impl() #endif m_fd = ::open(BOTAN_SYSTEM_RNG_DEVICE, O_RDWR | O_NOCTTY); + + // Cannot open in read-write mode. Fall back to read-only + // Calls to add_entropy will fail, but randomize will work + if(m_fd < 0) + m_fd = ::open(BOTAN_SYSTEM_RNG_DEVICE, O_RDONLY | O_NOCTTY); + if(m_fd < 0) throw Exception("System_RNG failed to open RNG device"); #endif |