diff options
-rw-r--r-- | src/auth/Crypto.cc | 47 | ||||
-rw-r--r-- | src/auth/Crypto.h | 32 | ||||
-rw-r--r-- | src/common/ceph_context.cc | 4 | ||||
-rw-r--r-- | src/common/ceph_context.h | 6 |
4 files changed, 53 insertions, 36 deletions
diff --git a/src/auth/Crypto.cc b/src/auth/Crypto.cc index e401c9605b1..f7ec93a2c93 100644 --- a/src/auth/Crypto.cc +++ b/src/auth/Crypto.cc @@ -64,6 +64,21 @@ uint64_t get_random(uint64_t min_val, uint64_t max_val) // --------------------------------------------------- +class CryptoNone : public CryptoHandler { +public: + CryptoNone() { } + ~CryptoNone() {} + int get_type() const { + return CEPH_CRYPTO_NONE; + } + int create(bufferptr& secret); + int validate_secret(bufferptr& secret); + void encrypt(const bufferptr& secret, const bufferlist& in, + bufferlist& out, std::string &error) const; + void decrypt(const bufferptr& secret, const bufferlist& in, + bufferlist& out, std::string &error) const; +}; + int CryptoNone::create(bufferptr& secret) { return 0; @@ -88,6 +103,23 @@ void CryptoNone::decrypt(const bufferptr& secret, const bufferlist& in, // --------------------------------------------------- + +class CryptoAES : public CryptoHandler { +public: + CryptoAES() { } + ~CryptoAES() {} + int get_type() const { + return CEPH_CRYPTO_AES; + } + int create(bufferptr& secret); + int validate_secret(bufferptr& secret); + void encrypt(const bufferptr& secret, const bufferlist& in, + bufferlist& out, std::string &error) const; + void decrypt(const bufferptr& secret, const bufferlist& in, + bufferlist& out, std::string &error) const; +}; + + #ifdef USE_CRYPTOPP # define AES_KEY_LEN ((size_t)CryptoPP::AES::DEFAULT_KEYLENGTH) # define AES_BLOCK_LEN ((size_t)CryptoPP::AES::BLOCKSIZE) @@ -396,3 +428,18 @@ void CryptoKey::encode_plaintext(bufferlist &bl) { bl.append(encode_base64()); } + + +// ------------------ + +CryptoHandler *CryptoHandler::create(int type) +{ + switch (type) { + case CEPH_CRYPTO_NONE: + return new CryptoNone; + case CEPH_CRYPTO_AES: + return new CryptoAES; + default: + return NULL; + } +} diff --git a/src/auth/Crypto.h b/src/auth/Crypto.h index c8112220aa6..1356b61f6c1 100644 --- a/src/auth/Crypto.h +++ b/src/auth/Crypto.h @@ -124,39 +124,11 @@ public: bufferlist& out, std::string &error) const = 0; virtual void decrypt(const bufferptr& secret, const bufferlist& in, bufferlist& out, std::string &error) const = 0; + + static CryptoHandler *create(int type); }; extern int get_random_bytes(char *buf, int len); extern uint64_t get_random(uint64_t min_val, uint64_t max_val); -class CryptoNone : public CryptoHandler { -public: - CryptoNone() { } - ~CryptoNone() {} - int get_type() const { - return CEPH_CRYPTO_NONE; - } - int create(bufferptr& secret); - int validate_secret(bufferptr& secret); - void encrypt(const bufferptr& secret, const bufferlist& in, - bufferlist& out, std::string &error) const; - void decrypt(const bufferptr& secret, const bufferlist& in, - bufferlist& out, std::string &error) const; -}; - -class CryptoAES : public CryptoHandler { -public: - CryptoAES() { } - ~CryptoAES() {} - int get_type() const { - return CEPH_CRYPTO_AES; - } - int create(bufferptr& secret); - int validate_secret(bufferptr& secret); - void encrypt(const bufferptr& secret, const bufferlist& in, - bufferlist& out, std::string &error) const; - void decrypt(const bufferptr& secret, const bufferlist& in, - bufferlist& out, std::string &error) const; -}; - #endif diff --git a/src/common/ceph_context.cc b/src/common/ceph_context.cc index 79aff8b8cf1..08e394cc613 100644 --- a/src/common/ceph_context.cc +++ b/src/common/ceph_context.cc @@ -407,8 +407,8 @@ CephContext::CephContext(uint32_t module_type_) _admin_socket->register_command("log dump", "log dump", _admin_hook, "dump recent log entries to log file"); _admin_socket->register_command("log reopen", "log reopen", _admin_hook, "reopen log file"); - _crypto_none = new CryptoNone; - _crypto_aes = new CryptoAES; + _crypto_none = CryptoHandler::create(CEPH_CRYPTO_NONE); + _crypto_aes = CryptoHandler::create(CEPH_CRYPTO_AES); } CephContext::~CephContext() diff --git a/src/common/ceph_context.h b/src/common/ceph_context.h index a8dfec55410..47aceb0f88e 100644 --- a/src/common/ceph_context.h +++ b/src/common/ceph_context.h @@ -32,8 +32,6 @@ class md_config_obs_t; struct md_config_t; class CephContextHook; class CephContextObs; -class CryptoNone; -class CryptoAES; class CryptoHandler; namespace ceph { @@ -165,8 +163,8 @@ private: std::map<std::string, AssociatedSingletonObject*> _associated_objs; // crypto - CryptoNone *_crypto_none; - CryptoAES *_crypto_aes; + CryptoHandler *_crypto_none; + CryptoHandler *_crypto_aes; // experimental CephContextObs *_cct_obs; |