Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This changes add the FastPairHandshake class, a lookup class to manage instances of it and related test classes. The FastPairHandshake class performs the handshake logic that was previously in FastPairPairer. Moving the logic into this class enables sharing it between the Scanning and Pairing components. This CL is part of a chain of CLs to refactor this area to enable the handshake to be performed prior to showing the UX. Change-Id: I3295e5fad89f58c063e6e9d3dbe8a125a7b8e49f Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3312015 Reviewed-by: Jon Mann <jonmann@chromium.org> Commit-Queue: Shane Fitzpatrick <shanefitz@google.com> Auto-Submit: Shane Fitzpatrick <shanefitz@google.com> Cr-Commit-Position: refs/heads/main@{#949366}
- Loading branch information
Shane Fitzpatrick
authored and
Chromium LUCI CQ
committed
Dec 8, 2021
1 parent
4718751
commit 3b605ac
Showing
13 changed files
with
813 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
ash/quick_pair/fast_pair_handshake/fake_fast_pair_data_encryptor.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/quick_pair/fast_pair_handshake/fake_fast_pair_data_encryptor.h" | ||
|
||
namespace ash { | ||
namespace quick_pair { | ||
|
||
FakeFastPairDataEncryptor::FakeFastPairDataEncryptor() = default; | ||
|
||
FakeFastPairDataEncryptor::~FakeFastPairDataEncryptor() = default; | ||
|
||
const std::array<uint8_t, kBlockSizeBytes> | ||
FakeFastPairDataEncryptor::EncryptBytes( | ||
const std::array<uint8_t, kBlockSizeBytes>& bytes_to_encrypt) { | ||
return encrypted_bytes_; | ||
} | ||
|
||
const absl::optional<std::array<uint8_t, 64>>& | ||
FakeFastPairDataEncryptor::GetPublicKey() { | ||
return public_key_; | ||
} | ||
|
||
void FakeFastPairDataEncryptor::ParseDecryptedResponse( | ||
const std::vector<uint8_t>& encrypted_response_bytes, | ||
base::OnceCallback<void(const absl::optional<DecryptedResponse>&)> | ||
callback) { | ||
std::move(callback).Run(response_); | ||
} | ||
|
||
void FakeFastPairDataEncryptor::ParseDecryptedPasskey( | ||
const std::vector<uint8_t>& encrypted_passkey_bytes, | ||
base::OnceCallback<void(const absl::optional<DecryptedPasskey>&)> | ||
callback) { | ||
std::move(callback).Run(passkey_); | ||
} | ||
|
||
} // namespace quick_pair | ||
} // namespace ash |
60 changes: 60 additions & 0 deletions
60
ash/quick_pair/fast_pair_handshake/fake_fast_pair_data_encryptor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_DATA_ENCRYPTOR_H_ | ||
#define ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_DATA_ENCRYPTOR_H_ | ||
|
||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_data_encryptor.h" | ||
|
||
namespace ash { | ||
namespace quick_pair { | ||
|
||
class FakeFastPairDataEncryptor : public FastPairDataEncryptor { | ||
public: | ||
FakeFastPairDataEncryptor(); | ||
FakeFastPairDataEncryptor(const FakeFastPairDataEncryptor&) = delete; | ||
FakeFastPairDataEncryptor& operator=(const FakeFastPairDataEncryptor&) = | ||
delete; | ||
~FakeFastPairDataEncryptor() override; | ||
|
||
void public_key(absl::optional<std::array<uint8_t, 64>> public_key) { | ||
public_key_ = std::move(public_key); | ||
} | ||
|
||
void encrypted_bytes(std::array<uint8_t, kBlockSizeBytes> encrypted_bytes) { | ||
encrypted_bytes_ = std::move(encrypted_bytes); | ||
} | ||
|
||
void response(absl::optional<DecryptedResponse> response) { | ||
response_ = std::move(response); | ||
} | ||
|
||
void passkey(absl::optional<DecryptedPasskey> passkey) { | ||
passkey_ = std::move(passkey); | ||
} | ||
|
||
// FastPairDataEncryptor: | ||
const std::array<uint8_t, kBlockSizeBytes> EncryptBytes( | ||
const std::array<uint8_t, kBlockSizeBytes>& bytes_to_encrypt) override; | ||
const absl::optional<std::array<uint8_t, 64>>& GetPublicKey() override; | ||
void ParseDecryptedResponse( | ||
const std::vector<uint8_t>& encrypted_response_bytes, | ||
base::OnceCallback<void(const absl::optional<DecryptedResponse>&)> | ||
callback) override; | ||
void ParseDecryptedPasskey( | ||
const std::vector<uint8_t>& encrypted_passkey_bytes, | ||
base::OnceCallback<void(const absl::optional<DecryptedPasskey>&)> | ||
callback) override; | ||
|
||
private: | ||
absl::optional<std::array<uint8_t, 64>> public_key_ = absl::nullopt; | ||
std::array<uint8_t, kBlockSizeBytes> encrypted_bytes_ = {}; | ||
absl::optional<DecryptedResponse> response_ = absl::nullopt; | ||
absl::optional<DecryptedPasskey> passkey_ = absl::nullopt; | ||
}; | ||
|
||
} // namespace quick_pair | ||
} // namespace ash | ||
|
||
#endif // ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_DATA_ENCRYPTOR_H_ |
42 changes: 42 additions & 0 deletions
42
ash/quick_pair/fast_pair_handshake/fake_fast_pair_handshake.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/quick_pair/fast_pair_handshake/fake_fast_pair_handshake.h" | ||
|
||
#include <cstdint> | ||
#include <memory> | ||
#include <utility> | ||
|
||
#include "ash/quick_pair/common/device.h" | ||
#include "ash/quick_pair/common/pair_failure.h" | ||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_data_encryptor.h" | ||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client.h" | ||
#include "base/callback.h" | ||
#include "device/bluetooth/bluetooth_adapter.h" | ||
|
||
namespace ash { | ||
namespace quick_pair { | ||
|
||
FakeFastPairHandshake::FakeFastPairHandshake( | ||
scoped_refptr<device::BluetoothAdapter> adapter, | ||
scoped_refptr<Device> device, | ||
OnCompleteCallback on_complete, | ||
std::unique_ptr<FastPairDataEncryptor> data_encryptor, | ||
std::unique_ptr<FastPairGattServiceClient> gatt_service_client) | ||
: FastPairHandshake(std::move(adapter), | ||
std::move(device), | ||
std::move(on_complete), | ||
std::move(data_encryptor), | ||
std::move(gatt_service_client)) {} | ||
|
||
FakeFastPairHandshake::~FakeFastPairHandshake() = default; | ||
|
||
void FakeFastPairHandshake::InvokeCallback( | ||
absl::optional<PairFailure> failure) { | ||
std::move(on_complete_callback_).Run(device_, std::move(failure)); | ||
completed_successfully_ = !failure.has_value(); | ||
} | ||
|
||
} // namespace quick_pair | ||
} // namespace ash |
35 changes: 35 additions & 0 deletions
35
ash/quick_pair/fast_pair_handshake/fake_fast_pair_handshake.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_HANDSHAKE_H_ | ||
#define ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_HANDSHAKE_H_ | ||
|
||
#include <memory> | ||
|
||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_handshake.h" | ||
|
||
#include "base/memory/scoped_refptr.h" | ||
|
||
namespace ash { | ||
namespace quick_pair { | ||
|
||
class FakeFastPairHandshake : public FastPairHandshake { | ||
public: | ||
FakeFastPairHandshake( | ||
scoped_refptr<device::BluetoothAdapter> adapter, | ||
scoped_refptr<Device> device, | ||
OnCompleteCallback on_complete, | ||
std::unique_ptr<FastPairDataEncryptor> data_encryptor = nullptr, | ||
std::unique_ptr<FastPairGattServiceClient> gatt_service_client = nullptr); | ||
FakeFastPairHandshake(const FakeFastPairHandshake&) = delete; | ||
FakeFastPairHandshake& operator=(const FakeFastPairHandshake&) = delete; | ||
~FakeFastPairHandshake(); | ||
|
||
void InvokeCallback(absl::optional<PairFailure> failure = absl::nullopt); | ||
}; | ||
|
||
} // namespace quick_pair | ||
} // namespace ash | ||
|
||
#endif // ASH_QUICK_PAIR_FAST_PAIR_HANDSHAKE_FAKE_FAST_PAIR_HANDSHAKE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2021 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_handshake.h" | ||
|
||
#include <cstdint> | ||
|
||
#include "ash/quick_pair/common/device.h" | ||
#include "ash/quick_pair/common/pair_failure.h" | ||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_data_encryptor_impl.h" | ||
#include "ash/quick_pair/fast_pair_handshake/fast_pair_gatt_service_client_impl.h" | ||
#include "base/callback.h" | ||
#include "device/bluetooth/bluetooth_adapter.h" | ||
|
||
namespace ash { | ||
namespace quick_pair { | ||
|
||
FastPairHandshake::FastPairHandshake( | ||
scoped_refptr<device::BluetoothAdapter> adapter, | ||
scoped_refptr<Device> device, | ||
OnCompleteCallback on_complete, | ||
std::unique_ptr<FastPairDataEncryptor> data_encryptor, | ||
std::unique_ptr<FastPairGattServiceClient> gatt_service_client) | ||
: adapter_(std::move(adapter)), | ||
device_(std::move(device)), | ||
on_complete_callback_(std::move(on_complete)), | ||
fast_pair_data_encryptor_(std::move(data_encryptor)), | ||
fast_pair_gatt_service_client_(std::move(gatt_service_client)) {} | ||
|
||
FastPairHandshake::~FastPairHandshake() = default; | ||
|
||
} // namespace quick_pair | ||
} // namespace ash |
Oops, something went wrong.