mirror of
https://github.com/kidfromjupiter/nearby.git
synced 2026-09-14 14:46:12 -04:00
Move credentials related proto from Prensence to internal
Replace PresenceIdentityType with proto PiperOrigin-RevId: 467294239
This commit is contained in:
@@ -76,8 +76,8 @@ cc_library(
|
||||
"//internal/platform:base",
|
||||
"//internal/platform:cancellation_flag",
|
||||
"//internal/platform:uuid",
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"//presence:credential",
|
||||
"//presence/proto:credential_cc_proto",
|
||||
"@com_google_absl//absl/container:flat_hash_map",
|
||||
"@com_google_absl//absl/strings",
|
||||
],
|
||||
|
||||
@@ -21,25 +21,26 @@
|
||||
#include <vector>
|
||||
|
||||
#include "internal/platform/exception.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/proto/credential.pb.h"
|
||||
|
||||
namespace location {
|
||||
namespace nearby {
|
||||
namespace api {
|
||||
|
||||
using ::nearby::presence::PresenceIdentity;
|
||||
using ::nearby::presence::proto::PrivateCredential;
|
||||
using ::nearby::presence::proto::PublicCredential;
|
||||
using ::nearby::internal::IdentityType;
|
||||
using ::nearby::internal::PrivateCredential;
|
||||
using ::nearby::internal::PublicCredential;
|
||||
|
||||
enum class CredentialOperationStatus {
|
||||
kFailed = 0,
|
||||
kSucceeded = 1,
|
||||
kUnknown = 0,
|
||||
kFailed = 1,
|
||||
kSucceeded = 2,
|
||||
};
|
||||
|
||||
struct CredentialSelector {
|
||||
std::string account_name;
|
||||
PresenceIdentity::IdentityType identity_type;
|
||||
IdentityType identity_type;
|
||||
};
|
||||
|
||||
enum PublicCredentialType {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
syntax = "proto2";
|
||||
|
||||
package nearby.presence.proto;
|
||||
package nearby.internal;
|
||||
|
||||
import "presence/proto/device_metadata.proto";
|
||||
import "internal/proto/device_metadata.proto";
|
||||
|
||||
option java_package = "com.google.nearby.presence";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
syntax = "proto2";
|
||||
|
||||
package nearby.presence.proto;
|
||||
package nearby.internal;
|
||||
|
||||
// A proto to store the local device's metadata.
|
||||
message DeviceMetadata {
|
||||
+3
-2
@@ -61,7 +61,7 @@ cc_library(
|
||||
":credential",
|
||||
"//net/proto2/util/public:differencer",
|
||||
"//internal/platform:base",
|
||||
"//presence/proto:credential_cc_proto",
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"@com_google_absl//absl/strings",
|
||||
"@com_google_glog//:glog",
|
||||
],
|
||||
@@ -97,6 +97,7 @@ cc_test(
|
||||
deps = [
|
||||
":credential",
|
||||
":types",
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
@@ -114,7 +115,7 @@ cc_test(
|
||||
":credential",
|
||||
"//internal/platform:uuid",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"//presence/proto:credential_cc_proto",
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
|
||||
@@ -19,15 +19,17 @@
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
#include "presence/proto/credential.pb.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
namespace {
|
||||
using ::nearby::presence::proto::PrivateCredential;
|
||||
using ::nearby::presence::proto::PublicCredential;
|
||||
using ::nearby::presence::proto::IdentityType::IDENTITY_TYPE_PROVISIONED;
|
||||
using ::nearby::presence::proto::IdentityType::IDENTITY_TYPE_PUBLIC;
|
||||
using ::nearby::internal::DeviceMetadata;
|
||||
using ::nearby::internal::PrivateCredential;
|
||||
using ::nearby::internal::PublicCredential;
|
||||
using ::nearby::internal::IdentityType::IDENTITY_TYPE_PROVISIONED;
|
||||
using ::nearby::internal::IdentityType::IDENTITY_TYPE_PUBLIC;
|
||||
|
||||
using ::protobuf_matchers::EqualsProto;
|
||||
|
||||
TEST(CredentialsTest, NoDefaultConstructor) {
|
||||
@@ -61,7 +63,7 @@ TEST(CredentialsTest, CopyPrivateCredential) {
|
||||
auto salts = pc1.mutable_consumed_salts();
|
||||
salts->insert(std::pair<int32, bool>(15, true));
|
||||
pc1.mutable_device_metadata()->set_device_name("Android Phone");
|
||||
pc1.mutable_device_metadata()->set_device_type(proto::DeviceMetadata::PHONE);
|
||||
pc1.mutable_device_metadata()->set_device_type(DeviceMetadata::PHONE);
|
||||
PrivateCredential pc1_copy = {pc1};
|
||||
EXPECT_THAT(pc1, EqualsProto(pc1_copy));
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ cc_library(
|
||||
"//internal/platform:uuid",
|
||||
"//internal/platform/implementation:comm",
|
||||
"//internal/platform/implementation:types",
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"//presence:credential",
|
||||
"//presence:types",
|
||||
"//presence/implementation/mediums",
|
||||
"//presence/proto:credential_cc_proto",
|
||||
"//third_party/tink/cc/subtle",
|
||||
"@boringssl//:crypto",
|
||||
"@com_google_absl//absl/status",
|
||||
@@ -150,9 +150,9 @@ cc_test(
|
||||
deps = [
|
||||
":internal",
|
||||
"//net/proto2/contrib/parse_proto:testing",
|
||||
"//internal/crypto",
|
||||
"//internal/platform/implementation:types",
|
||||
"//internal/platform/implementation/g3", # build_cleaner: keep
|
||||
"//internal/proto:credential_cc_proto",
|
||||
"@com_github_protobuf_matchers//protobuf-matchers",
|
||||
"@com_google_googletest//:gtest_main",
|
||||
],
|
||||
|
||||
@@ -21,11 +21,14 @@
|
||||
#include "absl/types/variant.h"
|
||||
#include "internal/platform/logging.h"
|
||||
#include "internal/platform/uuid.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/data_element.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
using ::nearby::internal::IdentityType;
|
||||
|
||||
constexpr uint8_t kBaseVersion = 0;
|
||||
constexpr location::nearby::Uuid kServiceData(0xFCF1ULL << 32, 0);
|
||||
|
||||
@@ -56,15 +59,16 @@ absl::Status AppendDataElement(unsigned data_type,
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
uint8_t GetIdentityFieldType(PresenceIdentity::IdentityType type) {
|
||||
uint8_t GetIdentityFieldType(IdentityType type) {
|
||||
switch (type) {
|
||||
case PresenceIdentity::IdentityType::kPrivate:
|
||||
case IdentityType::IDENTITY_TYPE_PRIVATE:
|
||||
return DataElement::kPrivateIdentityFieldType;
|
||||
case PresenceIdentity::IdentityType::kTrusted:
|
||||
case IdentityType::IDENTITY_TYPE_TRUSTED:
|
||||
return DataElement::kTrustedIdentityFieldType;
|
||||
case PresenceIdentity::IdentityType::kPublic:
|
||||
case IdentityType::IDENTITY_TYPE_PUBLIC:
|
||||
return DataElement::kPublicIdentityFieldType;
|
||||
case PresenceIdentity::IdentityType::kProvisioned: // fall-through
|
||||
case IdentityType::IDENTITY_TYPE_PROVISIONED:
|
||||
ABSL_FALLTHROUGH_INTENDED;
|
||||
default:
|
||||
return DataElement::kProvisionedIdentityFieldType;
|
||||
}
|
||||
@@ -101,8 +105,7 @@ AdvertisementFactory::CreateBaseNpAdvertisement(
|
||||
if (!identity.ok()) {
|
||||
return identity.status();
|
||||
}
|
||||
uint8_t identity_type =
|
||||
GetIdentityFieldType(presence.identity.GetIdentityType());
|
||||
uint8_t identity_type = GetIdentityFieldType(presence.identity);
|
||||
result = AppendDataElement(identity_type, *identity, payload);
|
||||
if (!result.ok()) {
|
||||
return result;
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#include "internal/platform/implementation/ble_v2.h"
|
||||
#include "presence/implementation/base_broadcast_request.h"
|
||||
#include "presence/implementation/credential_manager.h"
|
||||
#include "presence/presence_identity.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace presence {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::nearby::internal::IdentityType;
|
||||
using ::testing::NiceMock;
|
||||
using ::testing::Return;
|
||||
using ::testing::status::StatusIs;
|
||||
@@ -38,9 +39,9 @@ using ::testing::status::StatusIs;
|
||||
class MockCredentialManager : public CredentialManagerImpl {
|
||||
public:
|
||||
MOCK_METHOD(absl::StatusOr<std::string>, GetBaseEncryptedMetadataKey,
|
||||
(const PresenceIdentity& identity), (override));
|
||||
(const IdentityType& identity), (override));
|
||||
MOCK_METHOD(absl::StatusOr<std::string>, EncryptDataElements,
|
||||
(const PresenceIdentity& identity, absl::string_view salt,
|
||||
(const IdentityType& identity, absl::string_view salt,
|
||||
absl::string_view data_elements),
|
||||
(override));
|
||||
};
|
||||
@@ -48,21 +49,21 @@ class MockCredentialManager : public CredentialManagerImpl {
|
||||
TEST(AdvertisementFactory, CreateAdvertisementFromPrivateIdentity) {
|
||||
std::string salt = "AB";
|
||||
NiceMock<MockCredentialManager> credential_manager;
|
||||
PresenceIdentity identity;
|
||||
constexpr IdentityType kIdentity = IdentityType::IDENTITY_TYPE_PRIVATE;
|
||||
std::vector<DataElement> data_elements;
|
||||
data_elements.emplace_back(DataElement::kActionFieldType,
|
||||
action::kActiveUnlockAction);
|
||||
Action action = ActionFactory::CreateAction(data_elements);
|
||||
BaseBroadcastRequest request =
|
||||
BaseBroadcastRequest(BasePresenceRequestBuilder(identity)
|
||||
BaseBroadcastRequest(BasePresenceRequestBuilder(kIdentity)
|
||||
.SetSalt(salt)
|
||||
.SetTxPower(5)
|
||||
.SetAction(action));
|
||||
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(identity))
|
||||
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(kIdentity))
|
||||
.WillOnce(Return(absl::HexStringToBytes("1011121314151617181920212223")));
|
||||
EXPECT_CALL(
|
||||
credential_manager,
|
||||
EncryptDataElements(identity, salt, absl::HexStringToBytes("1505260080")))
|
||||
EXPECT_CALL(credential_manager,
|
||||
EncryptDataElements(kIdentity, salt,
|
||||
absl::HexStringToBytes("1505260080")))
|
||||
.WillOnce(Return(absl::HexStringToBytes("5051525354")));
|
||||
|
||||
AdvertisementFactory factory(&credential_manager);
|
||||
@@ -82,17 +83,17 @@ TEST(AdvertisementFactory, CreateAdvertisementFromPrivateIdentity) {
|
||||
|
||||
TEST(AdvertisementFactory, CreateAdvertisementFailsWhenCredentialManagerFails) {
|
||||
NiceMock<MockCredentialManager> credential_manager;
|
||||
PresenceIdentity identity;
|
||||
constexpr IdentityType kIdentity = internal::IDENTITY_TYPE_PRIVATE;
|
||||
std::vector<DataElement> data_elements;
|
||||
data_elements.emplace_back(DataElement::kActionFieldType,
|
||||
action::kActiveUnlockAction);
|
||||
Action action = ActionFactory::CreateAction(data_elements);
|
||||
BaseBroadcastRequest request =
|
||||
BaseBroadcastRequest(BasePresenceRequestBuilder(identity)
|
||||
BaseBroadcastRequest(BasePresenceRequestBuilder(kIdentity)
|
||||
.SetSalt("AB")
|
||||
.SetTxPower(5)
|
||||
.SetAction(action));
|
||||
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(identity))
|
||||
EXPECT_CALL(credential_manager, GetBaseEncryptedMetadataKey(kIdentity))
|
||||
.WillOnce(Return(absl::UnimplementedError(
|
||||
"GetBaseEncryptedMetadataKey not implemented")));
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "absl/types/variant.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
@@ -36,7 +36,7 @@ struct Action {
|
||||
/** Defines a Nearby Presence broadcast request */
|
||||
struct BaseBroadcastRequest {
|
||||
struct BasePresence {
|
||||
PresenceIdentity identity;
|
||||
nearby::internal::IdentityType identity;
|
||||
Action action;
|
||||
};
|
||||
struct BaseFastPair {
|
||||
@@ -61,7 +61,8 @@ struct BaseBroadcastRequest {
|
||||
/** Builds a brodacast request variant with NP identity for BLE 4.2 */
|
||||
class BasePresenceRequestBuilder {
|
||||
public:
|
||||
explicit BasePresenceRequestBuilder(const PresenceIdentity& identity)
|
||||
explicit BasePresenceRequestBuilder(
|
||||
const nearby::internal::IdentityType& identity)
|
||||
: identity_(identity) {}
|
||||
BasePresenceRequestBuilder& SetSalt(absl::string_view salt);
|
||||
BasePresenceRequestBuilder& SetTxPower(int8_t tx_power);
|
||||
@@ -70,7 +71,7 @@ class BasePresenceRequestBuilder {
|
||||
explicit operator BaseBroadcastRequest() const;
|
||||
|
||||
private:
|
||||
PresenceIdentity identity_;
|
||||
nearby::internal::IdentityType identity_;
|
||||
std::string salt_;
|
||||
int8_t tx_power_ = kUnspecifiedTxPower;
|
||||
Action action_;
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace presence {
|
||||
namespace {
|
||||
|
||||
TEST(BroadcastRequestTest, CreateBasePresenceRequest) {
|
||||
PresenceIdentity identity;
|
||||
nearby::internal::IdentityType identity;
|
||||
constexpr int8_t kTxPower = -13;
|
||||
|
||||
BaseBroadcastRequest request = BaseBroadcastRequest(
|
||||
|
||||
@@ -22,15 +22,14 @@
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/implementation/credential_storage.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/proto/credential.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
using ::nearby::presence::PresenceIdentity;
|
||||
|
||||
struct GenerateCredentialsCallback {
|
||||
std::function<void(std::vector<proto::PublicCredential>)>
|
||||
std::function<void(std::vector<nearby::internal::PublicCredential>)>
|
||||
credentials_generated_cb;
|
||||
};
|
||||
|
||||
@@ -56,15 +55,15 @@ class CredentialManager {
|
||||
// The user’s own public credentials won’t be saved on local credential
|
||||
// storage.
|
||||
virtual void GenerateCredentials(
|
||||
proto::DeviceMetadata device_metadata,
|
||||
std::vector<proto::IdentityType> identity_types,
|
||||
nearby::internal::DeviceMetadata device_metadata,
|
||||
std::vector<nearby::internal::IdentityType> identity_types,
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsCallback credentials_generated_cb) = 0;
|
||||
|
||||
// Update remote public credentials.
|
||||
virtual void UpdateRemotePublicCredentials(
|
||||
std::string account_name,
|
||||
std::vector<proto::PublicCredential> remote_public_creds,
|
||||
std::vector<nearby::internal::PublicCredential> remote_public_creds,
|
||||
UpdateRemotePublicCredentialsCallback credentials_updated_cb) = 0;
|
||||
|
||||
// Used to fetch private creds when broadcasting.
|
||||
@@ -93,12 +92,12 @@ class CredentialManager {
|
||||
// Returns encrypted metadata key associated with `identity` for Base NP
|
||||
// advertisement.
|
||||
virtual absl::StatusOr<std::string> GetBaseEncryptedMetadataKey(
|
||||
const PresenceIdentity& identity) = 0;
|
||||
const nearby::internal::IdentityType& identity) = 0;
|
||||
|
||||
// Encrypts `data_elements` using certificate associated with `identity` and
|
||||
// `salt`.
|
||||
virtual absl::StatusOr<std::string> EncryptDataElements(
|
||||
const PresenceIdentity& identity, absl::string_view salt,
|
||||
const nearby::internal::IdentityType& identity, absl::string_view salt,
|
||||
absl::string_view data_elements) = 0;
|
||||
};
|
||||
|
||||
|
||||
@@ -32,8 +32,10 @@ namespace presence {
|
||||
namespace {
|
||||
using ::location::nearby::Base64Utils;
|
||||
using ::location::nearby::Crypto;
|
||||
using ::nearby::presence::proto::PrivateCredential;
|
||||
using ::nearby::presence::proto::PublicCredential;
|
||||
using ::nearby::internal::DeviceMetadata;
|
||||
using ::nearby::internal::IdentityType;
|
||||
using ::nearby::internal::PrivateCredential;
|
||||
using ::nearby::internal::PublicCredential;
|
||||
|
||||
// Key to retrieve local device's Private/Public Key Credentials from key store.
|
||||
constexpr char kPairedKeyAliasPrefix[] = "nearby_presence_paired_key_alias_";
|
||||
@@ -41,8 +43,7 @@ constexpr char kPairedKeyAliasPrefix[] = "nearby_presence_paired_key_alias_";
|
||||
} // namespace
|
||||
|
||||
void CredentialManagerImpl::GenerateCredentials(
|
||||
proto::DeviceMetadata device_metadata,
|
||||
std::vector<proto::IdentityType> identity_types,
|
||||
DeviceMetadata device_metadata, std::vector<IdentityType> identity_types,
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsCallback credentials_generated_cb) {
|
||||
std::vector<PublicCredential> public_credentials;
|
||||
@@ -71,9 +72,10 @@ void CredentialManagerImpl::GenerateCredentials(
|
||||
}
|
||||
|
||||
std::pair<std::unique_ptr<PrivateCredential>, std::unique_ptr<PublicCredential>>
|
||||
CredentialManagerImpl::CreatePrivateCredential(
|
||||
proto::DeviceMetadata device_metadata, proto::IdentityType identity_type,
|
||||
uint64_t start_time_ms, uint64_t end_time_ms) {
|
||||
CredentialManagerImpl::CreatePrivateCredential(DeviceMetadata device_metadata,
|
||||
IdentityType identity_type,
|
||||
uint64_t start_time_ms,
|
||||
uint64_t end_time_ms) {
|
||||
auto private_credential_ptr = std::make_unique<PrivateCredential>();
|
||||
private_credential_ptr->set_start_time_millis(start_time_ms);
|
||||
private_credential_ptr->set_end_time_millis(end_time_ms);
|
||||
@@ -127,10 +129,8 @@ CredentialManagerImpl::CreatePrivateCredential(
|
||||
std::move(private_credential_ptr), std::move(public_credential_ptr));
|
||||
}
|
||||
|
||||
std::unique_ptr<proto::PublicCredential>
|
||||
CredentialManagerImpl::CreatePublicCredential(
|
||||
proto::PrivateCredential* private_credential,
|
||||
std::vector<uint8_t>* public_key) {
|
||||
std::unique_ptr<PublicCredential> CredentialManagerImpl::CreatePublicCredential(
|
||||
PrivateCredential* private_credential, std::vector<uint8_t>* public_key) {
|
||||
auto public_credential_ptr = std::make_unique<PublicCredential>();
|
||||
|
||||
public_credential_ptr->set_identity_type(private_credential->identity_type());
|
||||
|
||||
@@ -24,9 +24,9 @@
|
||||
#include "absl/status/statusor.h"
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/platform/credential_storage.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/implementation/credential_manager.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/proto/credential.pb.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
@@ -45,14 +45,14 @@ class CredentialManagerImpl : public CredentialManager {
|
||||
static constexpr int kAesGcmIVSize = 12;
|
||||
|
||||
void GenerateCredentials(
|
||||
proto::DeviceMetadata device_metadata,
|
||||
std::vector<proto::IdentityType> identity_types,
|
||||
nearby::internal::DeviceMetadata device_metadata,
|
||||
std::vector<nearby::internal::IdentityType> identity_types,
|
||||
int credential_life_cycle_days, int contiguous_copy_of_credentials,
|
||||
GenerateCredentialsCallback credentials_generated_cb) override;
|
||||
|
||||
void UpdateRemotePublicCredentials(
|
||||
std::string account_name,
|
||||
std::vector<proto::PublicCredential> remote_public_creds,
|
||||
std::vector<nearby::internal::PublicCredential> remote_public_creds,
|
||||
UpdateRemotePublicCredentialsCallback credentials_updated_cb) override{};
|
||||
|
||||
void GetPrivateCredentials(
|
||||
@@ -77,13 +77,13 @@ class CredentialManagerImpl : public CredentialManager {
|
||||
}
|
||||
|
||||
absl::StatusOr<std::string> GetBaseEncryptedMetadataKey(
|
||||
const PresenceIdentity& identity) override {
|
||||
const nearby::internal::IdentityType& identity) override {
|
||||
return absl::UnimplementedError(
|
||||
"GetBaseEncryptedMetadataKey unimplemented");
|
||||
}
|
||||
|
||||
absl::StatusOr<std::string> EncryptDataElements(
|
||||
const PresenceIdentity& identity, absl::string_view salt,
|
||||
const nearby::internal::IdentityType& identity, absl::string_view salt,
|
||||
absl::string_view data_elements) override {
|
||||
return absl::UnimplementedError("EncryptDataElements unimplemented");
|
||||
}
|
||||
@@ -91,14 +91,14 @@ class CredentialManagerImpl : public CredentialManager {
|
||||
private:
|
||||
FRIEND_TEST(CredentialManagerImpl, CreateOneCredentialSuccessfully);
|
||||
|
||||
std::pair<std::unique_ptr<proto::PrivateCredential>,
|
||||
std::unique_ptr<proto::PublicCredential>>
|
||||
CreatePrivateCredential(proto::DeviceMetadata device_metadata,
|
||||
proto::IdentityType identity_type,
|
||||
std::pair<std::unique_ptr<nearby::internal::PrivateCredential>,
|
||||
std::unique_ptr<nearby::internal::PublicCredential>>
|
||||
CreatePrivateCredential(nearby::internal::DeviceMetadata device_metadata,
|
||||
nearby::internal::IdentityType identity_type,
|
||||
uint64_t start_time_ms, uint64_t end_time_ms);
|
||||
|
||||
std::unique_ptr<proto::PublicCredential> CreatePublicCredential(
|
||||
proto::PrivateCredential* private_credential_ptr,
|
||||
std::unique_ptr<nearby::internal::PublicCredential> CreatePublicCredential(
|
||||
nearby::internal::PrivateCredential* private_credential_ptr,
|
||||
std::vector<uint8_t>* public_key);
|
||||
|
||||
std::string EncryptDeviceMetadata(std::string device_metadata_encryption_key,
|
||||
|
||||
@@ -20,22 +20,24 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/crypto/aead.h"
|
||||
#include "internal/crypto/hkdf.h"
|
||||
#include "internal/platform/implementation/crypto.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/implementation/encryption.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
using ::location::nearby::Crypto;
|
||||
|
||||
using ::nearby::presence::proto::IdentityType::IDENTITY_TYPE_PRIVATE;
|
||||
using ::nearby::internal::DeviceMetadata;
|
||||
using ::nearby::internal::PrivateCredential;
|
||||
using ::nearby::internal::PublicCredential;
|
||||
using ::nearby::internal::IdentityType::IDENTITY_TYPE_PRIVATE;
|
||||
using ::proto2::contrib::parse_proto::ParseTestProto;
|
||||
using ::protobuf_matchers::EqualsProto;
|
||||
|
||||
// TODO(b/241926454): Make sure CredentialManager builds with Github.
|
||||
TEST(CredentialManagerImpl, CreateOneCredentialSuccessfully) {
|
||||
proto::DeviceMetadata device_metadata = ParseTestProto(R"pb(
|
||||
DeviceMetadata device_metadata = ParseTestProto(R"pb(
|
||||
stable_device_id: "test_device_id"
|
||||
;
|
||||
account_name: "test_account";
|
||||
@@ -50,8 +52,8 @@ TEST(CredentialManagerImpl, CreateOneCredentialSuccessfully) {
|
||||
device_metadata, IDENTITY_TYPE_PRIVATE, /* start_time_ms= */ 0,
|
||||
/* end_time_ms= */ 1000);
|
||||
|
||||
proto::PrivateCredential* private_credential = credentials.first.get();
|
||||
proto::PublicCredential* public_credential = credentials.second.get();
|
||||
PrivateCredential* private_credential = credentials.first.get();
|
||||
PublicCredential* public_credential = credentials.second.get();
|
||||
|
||||
// Verify the private credential.
|
||||
EXPECT_THAT(private_credential->device_metadata(),
|
||||
|
||||
@@ -19,10 +19,9 @@
|
||||
#include <vector>
|
||||
|
||||
#include "net/proto2/util/public/message_differencer.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/data_element.h"
|
||||
#include "presence/power_mode.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/proto/credential.pb.h"
|
||||
|
||||
using MD = proto2::util::MessageDifferencer;
|
||||
|
||||
@@ -64,7 +63,7 @@ struct LegacyPresenceScanFilter : public ScanFilter {
|
||||
|
||||
// Android T needs clients to provide remote public credentials in scan
|
||||
// requests.
|
||||
std::vector<proto::PublicCredential> remote_public_credentials;
|
||||
std::vector<nearby::internal::PublicCredential> remote_public_credentials;
|
||||
|
||||
// A list of presence actions for matching. Matching condition is met as
|
||||
// long as there’s one or more equal actions between Scan actions and
|
||||
@@ -118,7 +117,7 @@ struct ScanRequest {
|
||||
|
||||
// Used to specify which types of remote PublicCredential to use during the
|
||||
// scan. If empty, use all available types of remote PublicCredential.
|
||||
std::vector<PresenceIdentity::IdentityType> identity_types;
|
||||
std::vector<nearby::internal::IdentityType> identity_types;
|
||||
|
||||
// For new Nearby SDK client (like chromeOs and Android U), use
|
||||
// PresenceScanFilter; for Android T, use LegacyPresenceScanFilter.
|
||||
|
||||
@@ -19,6 +19,8 @@
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
using ::nearby::internal::IdentityType;
|
||||
|
||||
ScanRequestBuilder& ScanRequestBuilder::SetAccountName(
|
||||
absl::string_view account_name) {
|
||||
request_.account_name = account_name;
|
||||
@@ -36,13 +38,13 @@ ScanRequestBuilder& ScanRequestBuilder::SetScanType(ScanType scan_type) {
|
||||
}
|
||||
|
||||
ScanRequestBuilder& ScanRequestBuilder::AddIdentityType(
|
||||
PresenceIdentity::IdentityType identity_type) {
|
||||
IdentityType identity_type) {
|
||||
request_.identity_types.push_back(identity_type);
|
||||
return *this;
|
||||
}
|
||||
|
||||
ScanRequestBuilder& ScanRequestBuilder::SetIdentityTypes(
|
||||
std::vector<PresenceIdentity::IdentityType> types) {
|
||||
std::vector<IdentityType> types) {
|
||||
request_.identity_types = types;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
#include <vector>
|
||||
|
||||
#include "absl/strings/string_view.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/power_mode.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/presence_zone.h"
|
||||
#include "presence/scan_request.h"
|
||||
|
||||
@@ -34,9 +34,9 @@ class ScanRequestBuilder {
|
||||
ScanRequestBuilder& SetPowerMode(PowerMode power_mode);
|
||||
ScanRequestBuilder& SetScanType(ScanType scan_type);
|
||||
ScanRequestBuilder& AddIdentityType(
|
||||
PresenceIdentity::IdentityType identity_type);
|
||||
nearby::internal::IdentityType identity_type);
|
||||
ScanRequestBuilder& SetIdentityTypes(
|
||||
std::vector<PresenceIdentity::IdentityType> types);
|
||||
std::vector<nearby::internal::IdentityType> types);
|
||||
ScanRequestBuilder& AddScanFilter(ScanFilter scan_filter);
|
||||
ScanRequestBuilder& SetScanFilters(std::vector<ScanFilter> filters);
|
||||
ScanRequestBuilder& SetUseBle(bool use_ble);
|
||||
|
||||
@@ -19,20 +19,21 @@
|
||||
#include "gmock/gmock.h"
|
||||
#include "protobuf-matchers/protocol-buffer-matchers.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "internal/proto/credential.pb.h"
|
||||
#include "presence/power_mode.h"
|
||||
#include "presence/presence_identity.h"
|
||||
#include "presence/scan_request.h"
|
||||
|
||||
namespace nearby {
|
||||
namespace presence {
|
||||
|
||||
using ::nearby::internal::IdentityType;
|
||||
|
||||
constexpr char kAccountName[] = "Google User";
|
||||
constexpr bool kUseBle = true;
|
||||
constexpr bool kOnlyScreenOnScan = true;
|
||||
const PresenceIdentity::IdentityType kIdentity =
|
||||
PresenceIdentity::IdentityType::kPrivate;
|
||||
const ScanType kScanType = ScanType::kPresenceScan;
|
||||
const PowerMode kPowerMode = PowerMode::kLowLatency;
|
||||
constexpr IdentityType kIdentity = IdentityType::IDENTITY_TYPE_PRIVATE;
|
||||
constexpr ScanType kScanType = ScanType::kPresenceScan;
|
||||
constexpr PowerMode kPowerMode = PowerMode::kLowLatency;
|
||||
|
||||
std::vector<ScanFilter> MockFilters() {
|
||||
const LegacyPresenceScanFilter legacyFilter{{.scan_type = kScanType}};
|
||||
@@ -76,7 +77,7 @@ TEST(ScanRequestBuilderTest, TestAddIdentityType) {
|
||||
|
||||
TEST(ScanRequestBuilderTest, TestSetIdentityTypes) {
|
||||
ScanRequestBuilder builder;
|
||||
std::vector<PresenceIdentity::IdentityType> types = {kIdentity};
|
||||
std::vector<IdentityType> types = {kIdentity};
|
||||
builder.SetIdentityTypes(types);
|
||||
ScanRequest sr = builder.Build();
|
||||
EXPECT_EQ(sr.identity_types.size(), 1);
|
||||
|
||||
Reference in New Issue
Block a user