1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef REMOTING_PROTOCOL_SPAKE2_AUTHENTICATOR_H_
#define REMOTING_PROTOCOL_SPAKE2_AUTHENTICATOR_H_
#include <memory>
#include <string>
#include "base/compiler_specific.h"
#include "base/gtest_prod_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "remoting/protocol/authenticator.h"
#include "third_party/boringssl/src/include/openssl/base.h"
namespace remoting {
class RsaKeyPair;
namespace protocol {
// Authenticator that uses SPAKE2 implementation from BoringSSL. It
// implements SPAKE2 over Curve25519.
class Spake2Authenticator : public Authenticator {
public:
static std::unique_ptr<Authenticator> CreateForClient(
const std::string& local_id,
const std::string& remote_id,
const std::string& shared_secret,
State initial_state);
static std::unique_ptr<Authenticator> CreateForHost(
const std::string& local_id,
const std::string& remote_id,
const std::string& local_cert,
scoped_refptr<RsaKeyPair> key_pair,
const std::string& shared_secret,
State initial_state);
Spake2Authenticator(const Spake2Authenticator&) = delete;
Spake2Authenticator& operator=(const Spake2Authenticator&) = delete;
~Spake2Authenticator() override;
// Authenticator interface.
CredentialsType credentials_type() const override;
const Authenticator& implementing_authenticator() const override;
State state() const override;
bool started() const override;
RejectionReason rejection_reason() const override;
RejectionDetails rejection_details() const override;
void ProcessMessage(const jingle_xmpp::XmlElement* message,
base::OnceClosure resume_callback) override;
std::unique_ptr<jingle_xmpp::XmlElement> GetNextMessage() override;
const std::string& GetAuthKey() const override;
const SessionPolicies* GetSessionPolicies() const override;
std::unique_ptr<ChannelAuthenticator> CreateChannelAuthenticator()
const override;
private:
FRIEND_TEST_ALL_PREFIXES(Spake2AuthenticatorTest, InvalidSecret);
Spake2Authenticator(const std::string& local_id,
const std::string& remote_id,
const std::string& shared_secret,
bool is_host,
State initial_state);
virtual void ProcessMessageInternal(const jingle_xmpp::XmlElement* message);
std::string CalculateVerificationHash(bool from_host,
const std::string& local_id,
const std::string& remote_id);
const std::string local_id_;
const std::string remote_id_;
const std::string shared_secret_;
const bool is_host_;
// Used only for host authenticators.
std::string local_cert_;
scoped_refptr<RsaKeyPair> local_key_pair_;
// Used only for client authenticators.
std::string remote_cert_;
// Used for both host and client authenticators.
raw_ptr<SPAKE2_CTX, DanglingUntriaged> spake2_context_;
State state_;
bool started_ = false;
RejectionReason rejection_reason_ = RejectionReason::INVALID_CREDENTIALS;
RejectionDetails rejection_details_;
std::string local_spake_message_;
bool spake_message_sent_ = false;
std::string outgoing_verification_hash_;
std::string auth_key_;
std::string expected_verification_hash_;
};
} // namespace protocol
} // namespace remoting
#endif // REMOTING_PROTOCOL_SPAKE2_AUTHENTICATOR_H_
|