From 031a9ce9319a88fab5b743e1578c1b69ef1fd54d Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 27 Oct 2009 12:38:43 -0700 Subject: [PATCH] authtool: print encoded CryptoKey in base64 --- src/auth/Crypto.h | 9 +++++++++ src/authtool.cc | 7 +++++-- src/common/buffer.cc | 11 +++++++++++ src/include/buffer.h | 2 ++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/auth/Crypto.h b/src/auth/Crypto.h index 7aff492747ec7..05875298a37a9 100644 --- a/src/auth/Crypto.h +++ b/src/auth/Crypto.h @@ -51,6 +51,15 @@ public: int set_secret(int type, bufferptr& s); bufferptr& get_secret() { return secret; } + void encode_base64(string& s) { + bufferlist bl; + encode(bl); + bufferlist e; + bl.encode_base64(e); + e.append('\0'); + s = e.c_str(); + } + // -- int create(int type); int encrypt(const bufferlist& in, bufferlist& out); diff --git a/src/authtool.cc b/src/authtool.cc index 1eef7d2fe8263..9b0950f8470e1 100644 --- a/src/authtool.cc +++ b/src/authtool.cc @@ -115,8 +115,11 @@ int main(int argc, const char **argv) } } } else if (print_key) { - if (keys_map.count(s)) - cout << keys_map[s].key << std::endl; + if (keys_map.count(s)) { + string a; + keys_map[s].key.encode_base64(a); + cout << a << std::endl; + } else cerr << "entity " << s << " not found" << std::endl; } diff --git a/src/common/buffer.cc b/src/common/buffer.cc index ea079ecdd1a07..6fbfa06a1f9a8 100644 --- a/src/common/buffer.cc +++ b/src/common/buffer.cc @@ -15,12 +15,23 @@ #include "config.h" #include "include/types.h" +#include "armor.h" #include #include atomic_t buffer_total_alloc; + +void buffer::list::encode_base64(buffer::list& o) +{ + bufferptr bp(length() * 4 / 3 + 1); + int l = ceph_armor(bp.c_str(), c_str(), c_str() + length()); + bp.set_length(l); + o.push_back(bp); +} + + int buffer::list::read_file(const char *fn, bool silent) { struct stat st; diff --git a/src/include/buffer.h b/src/include/buffer.h index c0720ace3edb6..08d87233fbdf8 100644 --- a/src/include/buffer.h +++ b/src/include/buffer.h @@ -1088,6 +1088,8 @@ public: }*/ } + void encode_base64(list& o); + void hexdump(std::ostream &out); int read_file(const char *fn, bool silent=false); int write_file(const char *fn); -- 2.39.5