]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cephx: add sign bufferlist method
authorRicardo Dias <rdias@suse.com>
Fri, 16 Nov 2018 17:17:03 +0000 (17:17 +0000)
committerRicardo Dias <rdias@suse.com>
Wed, 23 Jan 2019 13:59:25 +0000 (13:59 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/auth/AuthSessionHandler.h
src/auth/cephx/CephxSessionHandler.cc
src/auth/cephx/CephxSessionHandler.h

index 6689f03052a096aea5ceea7a91080df9ebe0ae8b..8c58aaa89efbb4ba9fb11f80d0f6bae7bd57a208 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 /*
  * Ceph - scalable distributed file system
@@ -7,9 +7,9 @@
  *
  * This is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
+ * License version 2.1, as published by the Free Software
  * Foundation.  See file COPYING.
- * 
+ *
  */
 
 
@@ -35,7 +35,7 @@ protected:
 public:
   explicit AuthSessionHandler(CephContext *cct_) : cct(cct_), protocol(CEPH_AUTH_UNKNOWN) {}
 
-  AuthSessionHandler(CephContext *cct_, int protocol_, CryptoKey key_) : cct(cct_), 
+  AuthSessionHandler(CephContext *cct_, int protocol_, CryptoKey key_) : cct(cct_),
     protocol(protocol_), key(key_) {}
   virtual ~AuthSessionHandler() { }
 
@@ -44,6 +44,9 @@ public:
   virtual int check_message_signature(Message *message) = 0;
   virtual int encrypt_message(Message *message) = 0;
   virtual int decrypt_message(Message *message) = 0;
+  virtual int sign_bufferlist(bufferlist &in, bufferlist &out) {
+    return 0;
+  };
 
   int get_protocol() {return protocol;}
   CryptoKey get_key() {return key;}
index 802b93cda52dec609f7a18ae55550ee2cc2d9297..f931ac4447a591d9a244733242841212eaaabeb2 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 /*
  * Ceph - scalable distributed file system
@@ -7,9 +7,9 @@
  *
  * This is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
+ * License version 2.1, as published by the Free Software
  * Foundation.  See file COPYING.
- * 
+ *
  */
 
 #include "CephxSessionHandler.h"
@@ -21,7 +21,7 @@
 #include "common/config.h"
 #include "include/ceph_features.h"
 #include "msg/Message.h"
+
 #define dout_subsys ceph_subsys_auth
 
 int CephxSessionHandler::_calc_signature(Message *m, uint64_t *psig)
@@ -181,3 +181,25 @@ int CephxSessionHandler::check_message_signature(Message *m)
   return 0;
 }
 
+int CephxSessionHandler::sign_bufferlist(bufferlist &in, bufferlist &out)
+{
+  char exp_buf[CryptoKey::get_max_outbuf_size(in.length())];
+
+  try {
+    const CryptoKey::in_slice_t sin{in.length(),
+        reinterpret_cast<const unsigned char *>(in.c_str())};
+    const CryptoKey::out_slice_t sout{
+        sizeof(exp_buf),
+        reinterpret_cast<unsigned char *>(&exp_buf)};
+    key.encrypt(cct, sin, sout);
+  }
+  catch (std::exception &e) {
+    lderr(cct) << __func__ << " failed to encrypt signature block" << dendl;
+    return -1;
+  }
+
+
+  out.append(exp_buf, sizeof(exp_buf));
+
+  return 0;
+}
index 6a19630bffecbe6bf400d14e91991fb527fdf417..35930f34676a85f0fe1ce20cfd5925f6c6f24d75 100644 (file)
@@ -1,4 +1,4 @@
-// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 /*
  * Ceph - scalable distributed file system
@@ -7,9 +7,9 @@
  *
  * This is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
- * License version 2.1, as published by the Free Software 
+ * License version 2.1, as published by the Free Software
  * Foundation.  See file COPYING.
- * 
+ *
  */
 
 
@@ -27,7 +27,7 @@ public:
     : AuthSessionHandler(cct_, CEPH_AUTH_CEPHX, session_key),
       features(features) {}
   ~CephxSessionHandler() override {}
-  
+
   bool no_security() override {
     return false;
   }
@@ -37,6 +37,8 @@ public:
   int sign_message(Message *m) override;
   int check_message_signature(Message *m) override ;
 
+  int sign_bufferlist(bufferlist &in, bufferlist &out) override;
+
   // Cephx does not currently encrypt messages, so just return 0 if called.  PLR
 
   int encrypt_message(Message *m) override {