From 1ae1cdb75235d6e603894400596fff024a61e7d5 Mon Sep 17 00:00:00 2001 From: Casey Bodley Date: Tue, 3 Oct 2017 16:02:44 -0400 Subject: [PATCH] common: add CryptoRandom to CephContext Signed-off-by: Casey Bodley --- src/auth/Crypto.cc | 2 +- src/auth/cephx/CephxKeyServer.cc | 2 +- src/common/ceph_context.cc | 1 + src/common/ceph_context.h | 5 +++++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index 22a53509d89..228a99b34c2 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -453,7 +453,7 @@ int CryptoKey::create(CephContext *cct, int t) return -EOPNOTSUPP; } bufferptr s; - int r = ch->create(nullptr, s); // fixme + int r = ch->create(cct->random(), s); delete ch; if (r < 0) return r; diff --git a/src/auth/cephx/CephxKeyServer.cc b/src/auth/cephx/CephxKeyServer.cc index db73266b8c9..b3a9dc8c8e2 100644 --- a/src/auth/cephx/CephxKeyServer.cc +++ b/src/auth/cephx/CephxKeyServer.cc @@ -264,7 +264,7 @@ bool KeyServer::generate_secret(CryptoKey& secret) if (!crypto) return false; - if (crypto->create(nullptr, bp) < 0) // fixme + if (crypto->create(cct->random(), bp) < 0) return false; secret.set_secret(CEPH_CRYPTO_AES, bp, ceph_clock_now()); diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index e82a9b2b122..2a5cb3be4ee 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -632,6 +632,7 @@ CephContext::CephContext(uint32_t module_type_, _crypto_none = CryptoHandler::create(CEPH_CRYPTO_NONE); _crypto_aes = CryptoHandler::create(CEPH_CRYPTO_AES); + _crypto_random.reset(new CryptoRandom()); MempoolObs *mempool_obs = 0; lookup_or_create_singleton_object(mempool_obs, "mempool_obs"); diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index fdbc06cacc5..9070cfb72e8 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -16,6 +16,7 @@ #define CEPH_CEPHCONTEXT_H #include +#include #include #include @@ -37,6 +38,7 @@ struct md_config_t; class CephContextHook; class CephContextObs; class CryptoHandler; +class CryptoRandom; namespace ceph { class PluginRegistry; @@ -146,6 +148,8 @@ public: */ CryptoHandler *get_crypto_handler(int type); + CryptoRandom* random() const { return _crypto_random.get(); } + /// check if experimental feature is enable, and emit appropriate warnings bool check_experimental_feature_enabled(const std::string& feature); bool check_experimental_feature_enabled(const std::string& feature, @@ -265,6 +269,7 @@ private: // crypto CryptoHandler *_crypto_none; CryptoHandler *_crypto_aes; + std::unique_ptr _crypto_random; // experimental CephContextObs *_cct_obs; -- 2.39.5