diff --git a/internal/platform/implementation/BUILD b/internal/platform/implementation/BUILD index f905cb92..c69035da 100644 --- a/internal/platform/implementation/BUILD +++ b/internal/platform/implementation/BUILD @@ -70,6 +70,7 @@ cc_library( "//internal/platform:__pkg__", "//internal/platform/implementation:__subpackages__", "//third_party/nearby/presence:__pkg__", + "//third_party/nearby/presence/implementation:__pkg__", ], deps = [ "//connections/clients/windows:types", diff --git a/presence/implementation/BUILD b/presence/implementation/BUILD index 7e54592d..ab48918e 100644 --- a/presence/implementation/BUILD +++ b/presence/implementation/BUILD @@ -19,6 +19,7 @@ cc_library( hdrs = [ "broadcast_manager.h", "credential_manager.h", + "credential_manager_impl.h", "mock_service_controller.h", "scan_manager.h", "service_controller.h", @@ -28,9 +29,12 @@ cc_library( "//third_party/nearby/presence:__subpackages__", ], deps = [ - "//internal/platform:base", "//internal/platform:comm", + "//internal/platform/implementation:comm", "//third_party/nearby/presence:credential", "//third_party/nearby/presence/implementation/mediums", + "@com_google_absl//absl/status", + "@com_google_absl//absl/status:statusor", + "@com_google_absl//absl/strings", ], ) diff --git a/presence/implementation/credential_manager.h b/presence/implementation/credential_manager.h index 7137c7a7..02872195 100644 --- a/presence/implementation/credential_manager.h +++ b/presence/implementation/credential_manager.h @@ -19,15 +19,16 @@ #include #include -#include "internal/platform/credential_storage.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "internal/platform/implementation/credential_storage.h" #include "third_party/nearby/presence/credential.h" namespace nearby { namespace presence { struct GenerateCredentialsCallback { - std::function)> - credentials_generated_cb; + std::function)> credentials_generated_cb; }; struct UpdateRemotePublicCredentialsCallback { @@ -43,7 +44,7 @@ struct UpdateRemotePublicCredentialsCallback { class CredentialManager { public: CredentialManager() = default; - ~CredentialManager() = default; + virtual ~CredentialManager() = default; // Used to (re)generate user’s private and public credentials. // The generated private credentials will be saved to creds storage. @@ -51,28 +52,32 @@ class CredentialManager { // credentials_generated_cb for manager app to upload to web. // The user’s own public credentials won’t be saved on local credential // storage. - void GenerateCredentials( + virtual void GenerateCredentials( proto::DeviceMetadata device_metadata, std::vector trust_types, - GenerateCredentialsCallback credentials_generated_cb); + GenerateCredentialsCallback credentials_generated_cb) = 0; // Update remote public credentials. - void UpdateRemotePublicCredentials( + virtual void UpdateRemotePublicCredentials( std::string account_name, std::vector remote_public_creds, - UpdateRemotePublicCredentialsCallback credentials_updated_cb); + UpdateRemotePublicCredentialsCallback credentials_updated_cb) = 0; // Used to fetch private creds when broadcasting. - void GetPrivateCredentials( + virtual void GetPrivateCredentials( location::nearby::api::CredentialSelector credential_selector, - location::nearby::api::GetPrivateCredentialCallback callback); + location::nearby::api::GetPrivateCredentialCallback callback) = 0; // Used to fetch remote public creds when scanning. - void GetPublicCredentials( + virtual void GetPublicCredentials( location::nearby::api::CredentialSelector credential_selector, - location::nearby::api::GetPublicCredentialCallback callback); + location::nearby::api::GetPublicCredentialCallback callback) = 0; - private: - location::nearby::CredentialStorage* credential_storage_; + // Decrypts Data Elements from an NP advertisement. + // Returns an error if `metadata_key` is not associated with any known + // credentials (identity). + virtual absl::StatusOr DecryptDataElements( + absl::string_view metadata_key, absl::string_view salt, + absl::string_view data_elements) = 0; }; } // namespace presence diff --git a/presence/implementation/credential_manager_impl.h b/presence/implementation/credential_manager_impl.h new file mode 100644 index 00000000..2cbb7f60 --- /dev/null +++ b/presence/implementation/credential_manager_impl.h @@ -0,0 +1,67 @@ +// Copyright 2022 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_ +#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_ + +#include +#include + +#include "absl/status/status.h" +#include "absl/status/statusor.h" +#include "absl/strings/string_view.h" +#include "internal/platform/credential_storage.h" +#include "third_party/nearby/presence/credential.h" +#include "third_party/nearby/presence/implementation/credential_manager.h" + +namespace nearby { +namespace presence { + +class CredentialManagerImpl : public CredentialManager { + public: + CredentialManagerImpl() = default; + + void GenerateCredentials( + proto::DeviceMetadata device_metadata, std::vector trust_types, + GenerateCredentialsCallback credentials_generated_cb) override {} + + void UpdateRemotePublicCredentials( + std::string account_name, + std::vector remote_public_creds, + UpdateRemotePublicCredentialsCallback credentials_updated_cb) override{}; + + void GetPrivateCredentials( + location::nearby::api::CredentialSelector credential_selector, + location::nearby::api::GetPrivateCredentialCallback callback) override {} + + // Used to fetch remote public creds when scanning. + void GetPublicCredentials( + location::nearby::api::CredentialSelector credential_selector, + location::nearby::api::GetPublicCredentialCallback callback) override {} + + absl::StatusOr DecryptDataElements( + absl::string_view metadata_key, absl::string_view salt, + absl::string_view data_elements) override { + return absl::UnimplementedError("DecryptDataElements unimplemented"); + } + + private: + location::nearby::CredentialStorage* + credential_storage_; // NOLINT: further impl will use it. +}; + +} // namespace presence +} // namespace nearby + +#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_MANAGER_IMPL_H_ diff --git a/presence/implementation/service_controller_impl.h b/presence/implementation/service_controller_impl.h index f664079a..3a34f8e4 100644 --- a/presence/implementation/service_controller_impl.h +++ b/presence/implementation/service_controller_impl.h @@ -15,7 +15,7 @@ #ifndef THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_SERVICE_CONTROLLER_IMPL_H_ #define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_SERVICE_CONTROLLER_IMPL_H_ -#include "third_party/nearby/presence/implementation/credential_manager.h" +#include "third_party/nearby/presence/implementation/credential_manager_impl.h" #include "third_party/nearby/presence/implementation/mediums/mediums.h" #include "third_party/nearby/presence/implementation/service_controller.h" @@ -27,13 +27,10 @@ namespace nearby { namespace presence { class ServiceControllerImpl : public ServiceController { - public: - ServiceControllerImpl() = default; - ~ServiceControllerImpl() override = default; - private: Mediums mediums_; // NOLINT: further impl will use it. - CredentialManager credential_manager_; // NOLINT: further impl will use it. + CredentialManagerImpl + credential_manager_; // NOLINT: further impl will use it. }; } // namespace presence