Commit 2a2103bf authored by Himanshu Jaju's avatar Himanshu Jaju Committed by Commit Bot

Integrate PairedKeyVerificationRunner in NearbyService.

Integrates PairedKeyVerificationRunner in NearbyServiceImpl to verify
remote device before receiving introduction and starting the transfer
flow.

Bug: 1085068
Change-Id: I73d42d9f85f3254007cdf3fdf46c6f5e05a48630
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2352799Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Commit-Queue: Himanshu Jaju <himanshujaju@chromium.org>
Cr-Commit-Position: refs/heads/master@{#798649}
parent d008c023
......@@ -52,6 +52,10 @@ std::vector<uint8_t> FakeNearbyConnection::GetWrittenData() {
return bytes;
}
bool FakeNearbyConnection::IsClosed() {
return closed_;
}
void FakeNearbyConnection::MaybeRunCallback() {
DCHECK(!closed_);
if (!callback_ || read_data_.empty())
......
......@@ -24,6 +24,8 @@ class FakeNearbyConnection : public NearbyConnection {
void AppendReadableData(std::vector<uint8_t> bytes);
std::vector<uint8_t> GetWrittenData();
bool IsClosed();
private:
void MaybeRunCallback();
......
......@@ -99,10 +99,20 @@ base::Optional<std::vector<uint8_t>>
FakeNearbyConnectionsManager::GetRawAuthenticationToken(
const std::string& endpoint_id) {
DCHECK(!IsShutdown());
// TODO(alexchau): Implement.
auto iter = endpoint_auth_tokens_.find(endpoint_id);
if (iter != endpoint_auth_tokens_.end())
return iter->second;
return base::nullopt;
}
void FakeNearbyConnectionsManager::SetRawAuthenticationToken(
const std::string& endpoint_id,
std::vector<uint8_t> token) {
endpoint_auth_tokens_[endpoint_id] = std::move(token);
}
void FakeNearbyConnectionsManager::UpgradeBandwidth(
const std::string& endpoint_id) {
upgrade_bandwidth_endpoint_ids_.insert(endpoint_id);
......
......@@ -51,6 +51,9 @@ class FakeNearbyConnectionsManager
const std::string& endpoint_id) override;
void UpgradeBandwidth(const std::string& endpoint_id) override;
void SetRawAuthenticationToken(const std::string& endpoint_id,
std::vector<uint8_t> token);
// mojom::EndpointDiscoveryListener:
void OnEndpointFound(
const std::string& endpoint_id,
......@@ -73,6 +76,7 @@ class FakeNearbyConnectionsManager
DataUsage advertising_data_usage_ = DataUsage::kUnknown;
PowerLevel advertising_power_level_ = PowerLevel::kUnknown;
std::set<std::string> upgrade_bandwidth_endpoint_ids_;
std::map<std::string, std::vector<uint8_t>> endpoint_auth_tokens_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_FAKE_NEARBY_CONNECTIONS_MANAGER_H_
......@@ -174,16 +174,21 @@ class NearbySharingServiceImpl
StatusCodes StopScanning();
void OnIncomingAdvertisementDecoded(
const std::string& endpoint_id,
NearbyConnection* connection,
ShareTarget placeholder_share_target,
sharing::mojom::AdvertisementPtr advertisement);
void OnIncomingTransferUpdate(const ShareTarget& share_target,
TransferMetadata metadata);
void CloseConnection(const ShareTarget& share_target);
void OnIncomingDecryptedCertificate(
const std::string& endpoint_id,
NearbyConnection* connection,
sharing::mojom::AdvertisementPtr advertisement,
ShareTarget placeholder_share_target,
base::Optional<NearbyShareDecryptedPublicCertificate> certificate);
void OnIncomingConnectionKeyVerificationDone(
ShareTarget share_target,
base::Optional<std::vector<uint8_t>> token,
PairedKeyVerificationRunner::PairedKeyVerificationResult result);
void RefreshUIOnDisconnection(ShareTarget share_target);
void ReceiveIntroduction(ShareTarget share_target,
base::Optional<std::string> token);
void OnReceivedIntroduction(ShareTarget share_target,
......
......@@ -11,6 +11,7 @@
#include "base/optional.h"
#include "chrome/browser/nearby_sharing/certificates/nearby_share_decrypted_public_certificate.h"
#include "chrome/browser/nearby_sharing/incoming_frames_reader.h"
#include "chrome/browser/nearby_sharing/paired_key_verification_runner.h"
class NearbyConnection;
......@@ -55,12 +56,22 @@ class ShareTargetInfo {
frames_reader_ = std::move(frames_reader);
}
PairedKeyVerificationRunner* key_verification_runner() {
return key_verification_runner_.get();
}
void set_key_verification_runner(
std::unique_ptr<PairedKeyVerificationRunner> key_verification_runner) {
key_verification_runner_ = std::move(key_verification_runner);
}
private:
base::Optional<std::string> endpoint_id_;
base::Optional<NearbyShareDecryptedPublicCertificate> certificate_;
NearbyConnection* connection_ = nullptr;
base::Optional<std::string> token_;
std::unique_ptr<IncomingFramesReader> frames_reader_;
std::unique_ptr<PairedKeyVerificationRunner> key_verification_runner_;
};
#endif // CHROME_BROWSER_NEARBY_SHARING_SHARE_TARGET_INFO_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment