Skip to content

Commit

Permalink
msg/async, v2: switch the pre-auth mechanism to HMAC-SHA256.
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Zarzynski <[email protected]>
  • Loading branch information
rzarzynski committed Mar 13, 2019
1 parent 39573a0 commit 8e324a5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/auth/Crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ class CryptoKey {
const bufferptr& get_secret() { return secret; }
const bufferptr& get_secret() const { return secret; }

bool empty() const { return ckh.get() == nullptr; }

void encode_base64(string& s) const {
bufferlist bl;
encode(bl);
Expand Down
14 changes: 9 additions & 5 deletions src/msg/async/ProtocolV2.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ ProtocolV2::ProtocolV2(AsyncConnection *connection)
bannerExchangeCallback(nullptr),
next_tag(static_cast<Tag>(0)),
keepalive(false) {
ceph::crypto::init(cct);
}

ProtocolV2::~ProtocolV2() {
Expand Down Expand Up @@ -1779,8 +1780,9 @@ CtPtr ProtocolV2::handle_auth_done(ceph::bufferlist &payload)

state = AUTH_CONNECTING_SIGN;

// FIXME, WIP: crc32 is just scaffolding
auto sig_frame = AuthSignatureFrame::Encode(pre_auth.rxbuf.crc32c(-1));
const auto sig = auth_meta->session_key.empty() ? sha256_digest_t() :
auth_meta->session_key.hmac_sha256(cct, pre_auth.rxbuf);
auto sig_frame = AuthSignatureFrame::Encode(sig);
pre_auth.enabled = false;
pre_auth.rxbuf.clear();
return WRITE(sig_frame, "auth signature", read_frame);
Expand Down Expand Up @@ -2188,8 +2190,9 @@ CtPtr ProtocolV2::finish_auth()
session_stream_handlers = \
ceph::crypto::onwire::rxtx_t::create_handler_pair(cct, *auth_meta, true);

// FIXME, WIP: crc32 is just scaffolding
auto sig_frame = AuthSignatureFrame::Encode(pre_auth.rxbuf.crc32c(-1));
const auto sig = auth_meta->session_key.empty() ? sha256_digest_t() :
auth_meta->session_key.hmac_sha256(cct, pre_auth.rxbuf);
auto sig_frame = AuthSignatureFrame::Encode(sig);
pre_auth.enabled = false;
pre_auth.rxbuf.clear();
return WRITE(sig_frame, "auth signature", read_frame);
Expand Down Expand Up @@ -2223,7 +2226,8 @@ CtPtr ProtocolV2::handle_auth_signature(ceph::bufferlist &payload)

auto sig_frame = AuthSignatureFrame::Decode(payload);

const auto actual_tx_sig = pre_auth.txbuf.crc32c(-1);
const auto actual_tx_sig = auth_meta->session_key.empty() ?
sha256_digest_t() : auth_meta->session_key.hmac_sha256(cct, pre_auth.txbuf);
if (sig_frame.signature() != actual_tx_sig) {
ldout(cct, 2) << __func__ << " pre-auth signature mismatch"
<< " actual_tx_sig=" << actual_tx_sig
Expand Down
5 changes: 2 additions & 3 deletions src/msg/async/frames_v2.h
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,12 @@ struct AuthDoneFrame : public ControlFrame<AuthDoneFrame,

struct AuthSignatureFrame
: public ControlFrame<AuthSignatureFrame,
// FIXME: using crc32 as scaffolding
uint32_t> {
sha256_digest_t> {
static const Tag tag = Tag::AUTH_SIGNATURE;
using ControlFrame::Encode;
using ControlFrame::Decode;

inline uint32_t &signature() { return get_val<0>(); }
inline sha256_digest_t &signature() { return get_val<0>(); }

protected:
using ControlFrame::ControlFrame;
Expand Down

0 comments on commit 8e324a5

Please sign in to comment.