]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
auth: introduce ceph::crypto::onwire interfaces.
authorRadoslaw Zarzynski <rzarzyns@redhat.com>
Tue, 5 Feb 2019 14:17:04 +0000 (15:17 +0100)
committerRadoslaw Zarzynski <rzarzyns@redhat.com>
Thu, 21 Feb 2019 20:54:18 +0000 (21:54 +0100)
Signed-off-by: Radoslaw Zarzynski <rzarzyns@redhat.com>
src/auth/AuthSessionHandler.h
src/msg/async/crypto_onwire.h [new file with mode: 0644]

index a334ee1eac4db40e5d60b0095f84fe2b9bc69d3e..2b0d952c411b179b13bf9c6aa4a92ee46a065fae 100644 (file)
@@ -59,13 +59,6 @@ struct SHA256SignatureError : public std::exception {
 
 struct DecryptionError : public std::exception {};
 
-// TODO: make this a static member of AuthSessionHandler.
-extern AuthSessionHandler *get_auth_session_handler(
-  CephContext *cct, int protocol,
-  const CryptoKey& key,
-  uint64_t features);
-
-
 struct AuthStreamHandler {
   virtual ~AuthStreamHandler() = default;
   //virtual ceph::bufferlist authenticated_encrypt(ceph::bufferlist& in) = 0;
@@ -86,4 +79,10 @@ struct AuthStreamHandler {
     const class AuthConnectionMeta& auth_meta);
 };
 
+// TODO: make this a static member of AuthSessionHandler.
+extern AuthSessionHandler *get_auth_session_handler(
+  CephContext *cct, int protocol,
+  const CryptoKey& key,
+  uint64_t features);
+
 #endif
diff --git a/src/msg/async/crypto_onwire.h b/src/msg/async/crypto_onwire.h
new file mode 100644 (file)
index 0000000..d65a85f
--- /dev/null
@@ -0,0 +1,111 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+ * Ceph - scalable distributed file system
+ *
+ * Copyright (C) 2004-2009 Sage Weil <sage@newdream.net>
+ *
+ * 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
+ * Foundation.  See file COPYING.
+ *
+ */
+
+
+#ifndef CEPH_CRYPTO_ONWIRE_H
+#define CEPH_CRYPTO_ONWIRE_H
+
+#include "include/types.h"
+
+
+namespace ceph::math {
+
+// TODO
+template <typename T>
+class always_aligned_t {
+  T val;
+
+  template <class... Args>
+  always_aligned_t(Args&&... args)
+    : val(std::forward<Args>(args)...) {
+  }
+};
+
+} // namespace ceph::math
+
+namespace ceph::crypto::onwire {
+
+struct TxHandler {
+  virtual ~TxHandler() = default;
+
+  virtual std::uint32_t calculate_segment_size(std::uint32_t size) = 0;
+
+  // Instance of TxHandler must be reset before doing any encrypt-update
+  // step. This applies also to situation when encrypt-final was already
+  // called and another round of update-...-update-final will take place.
+  //
+  // The input parameter informs implementation how the -update sequence
+  // is fragmented and allows to make concious decision about allocation
+  // or reusage of provided memory. One implementation could do in-place
+  // encryption while other might prefer one huge output buffer.
+  //
+  // It's undefined what will happen if client doesn't follow the order.
+  //
+  // TODO: switch to always_aligned_t
+  virtual void reset_tx_handler(
+    std::initializer_list<std::uint32_t> update_size_sequence) = 0;
+
+  // Reserve n bytes in the bufferlist being crafted by TxHandler.
+  // TODO: this will be dropped altogether with new frame format
+  virtual ceph::bufferlist::contiguous_filler reserve(std::uint32_t) = 0;
+
+  // Perform encryption. Client gives full ownership right to provided
+  // bufferlist. The method MUST NOT be called after _final() if there
+  // was no call to _reset().
+  virtual void authenticated_encrypt_update(
+    ceph::bufferlist&& plaintext) = 0;
+
+  // Generates authentication signature and returns bufferlist crafted
+  // basing on plaintext from preceding call to _update().
+  virtual ceph::bufferlist authenticated_encrypt_final() = 0;
+};
+
+class RxHandler {
+public:
+  virtual ~RxHandler() = default;
+
+  // Instance of RxHandler must be reset before doing any decrypt-update
+  // step. This applies also to situation when decrypt-final was already
+  // called and another round of update-...-update-final will take place.
+  virtual void reset_rx_handler() = 0;
+
+  // Perform decryption ciphertext must be ALWAYS aligned to 16 bytes.
+  // TODO: switch to always_aligned_t
+  virtual ceph::bufferlist authenticated_decrypt_update(
+    ceph::bufferlist&& ciphertext,
+    std::uint32_t alignment) = 0;
+
+  // Perform decryption of last cipertext's portion and verify signature
+  // for overall decryption sequence.
+  // Throws on integrity/authenticity checks
+  virtual ceph::bufferlist authenticated_decrypt_update_final(
+    ceph::bufferlist&& ciphertext,
+    std::uint32_t alignment) = 0;
+};
+
+struct rxtx_t {
+  //rxtx_t(rxtx_t&& r) : rx(std::move(rx)), tx(std::move(tx)) {}
+  // Each peer can use different handlers.
+  // Hmm, isn't that too much flexbility?
+  std::unique_ptr<RxHandler> rx;
+  std::unique_ptr<TxHandler> tx;
+};
+
+static rxtx_t create_stream_handler_pair(
+  CephContext* ctx,
+  const class AuthConnectionMeta& auth_meta);
+
+} // namespace ceph::crypto::onwire
+
+#endif // CEPH_CRYPTO_ONWIRE_H