chromium/device/fido/cable/fido_cable_handshake_handler_unittest.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "device/fido/cable/fido_cable_handshake_handler.h"

#include <array>
#include <cstdint>
#include <limits>
#include <memory>
#include <optional>
#include <string>
#include <string_view>
#include <utility>
#include <vector>

#include "base/containers/span.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
#include "base/task/sequenced_task_runner.h"
#include "base/test/task_environment.h"
#include "base/test/test_future.h"
#include "components/cbor/reader.h"
#include "components/cbor/values.h"
#include "crypto/hkdf.h"
#include "crypto/hmac.h"
#include "crypto/sha2.h"
#include "device/bluetooth/test/bluetooth_test.h"
#include "device/bluetooth/test/mock_bluetooth_adapter.h"
#include "device/fido/cable/fido_ble_frames.h"
#include "device/fido/cable/fido_cable_device.h"
#include "device/fido/cable/mock_fido_ble_connection.h"
#include "device/fido/fido_constants.h"
#include "device/fido/fido_parsing_utils.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace device {

namespace {

_;
Invoke;
Test;
TestDeviceFuture;
NiceMockBluetoothAdapter;

// Sufficiently large test control point length as we are not interested
// in testing fragmentations of BLE messages. All Cable messages are encrypted
// and decrypted per request frame, not fragment.
constexpr auto kControlPointLength =;

constexpr std::array<uint8_t, 16> kAuthenticatorSessionRandom =;

constexpr std::array<uint8_t, 32> kTestSessionPreKey =;

constexpr std::array<uint8_t, 32> kIncorrectSessionPreKey =;

constexpr std::array<uint8_t, 8> kTestNonce =;

constexpr std::array<uint8_t, 8> kIncorrectNonce =;

constexpr std::array<uint8_t, 50> kValidAuthenticatorHello =;

constexpr std::array<uint8_t, 43> kInvalidAuthenticatorHello =;

constexpr char kIncorrectHandshakeKey[] =;

// Returns the expected encryption key that should be constructed given that
// the client random nonce is |client_random_nonce| and other determining
// factors (i.e. authenticator session random, session pre key, and nonce) are
// |kAuthenticatorSessionRandom|, |kTestSessionPreKey|, and |kTestNonce|,
// respectively.
std::vector<uint8_t> GetExpectedEncryptionKey(
    base::span<const uint8_t> client_random_nonce) {}

// Given a hello message and handshake key from the authenticator, construct
// a handshake message by concatenating hello message and its mac message
// derived from |handshake_key|.
std::vector<uint8_t> ConstructAuthenticatorHelloReply(
    base::span<const uint8_t> hello_msg,
    std::string_view handshake_key) {}

// Constructs incoming handshake message from the authenticator into a BLE
// control fragment.
std::vector<uint8_t> ConstructSerializedOutgoingFragment(
    base::span<const uint8_t> data) {}

// Authenticator abstraction that handles logic related to validating handshake
// messages from the client and sending rely handshake message back to the
// client. Session key and nonce are assumed to be |kTestSessionPreKey| and
// |kTestNonce| respectively.
class FakeCableAuthenticator {};

}  // namespace

class FidoCableHandshakeHandlerTest : public Test {};

// Checks that outgoing handshake message from the client is a BLE frame with
// Control command type.
MATCHER(IsControlFrame, "") {}

TEST_F(FidoCableHandshakeHandlerTest, HandShakeSuccess) {}

TEST_F(FidoCableHandshakeHandlerTest, HandShakeWithIncorrectSessionPreKey) {}

TEST_F(FidoCableHandshakeHandlerTest, HandshakeFailWithIncorrectNonce) {}

TEST_F(FidoCableHandshakeHandlerTest,
       HandshakeFailWithIncorrectAuthenticatorResponse) {}

}  // namespace device