Initial header files showing class dependency and ownership.

No detailed function signatures nor impl included yet.

PiperOrigin-RevId: 460300058
This commit is contained in:
hais
2022-07-11 14:26:26 -07:00
committed by Copybara-Service
parent 1a9e4a2aff
commit b6f817274e
18 changed files with 767 additions and 0 deletions
+3
View File
@@ -30,6 +30,7 @@ cc_library(
"bluetooth_utils.h",
"byte_array.h",
"callable.h",
"credential.h",
"exception.h",
"feature_flags.h",
"input_stream.h",
@@ -343,6 +344,7 @@ cc_library(
"ble_v2.h",
"bluetooth_adapter.h",
"bluetooth_classic.h",
"credential_storage.h",
"wifi.h",
"wifi_hotspot.h",
"wifi_lan.h",
@@ -356,6 +358,7 @@ cc_library(
"//internal/analytics:__subpackages__",
"//internal/platform:__pkg__",
"//internal/platform/implementation:__subpackages__",
"//third_party/nearby/presence:__subpackages__",
],
deps = [
":logging",
+131
View File
@@ -0,0 +1,131 @@
// Copyright 2020 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_INTERNAL_PLATFORM_CREDENTIAL_H_
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_CREDENTIAL_H_
#include <set>
#include <string>
#include <vector>
namespace location {
namespace nearby {
enum class TrustType {
kUnspecified = 0,
// The same user itself.
kPrivate = 1,
// The user selects the contact from its contact list.
kTrusted = 2,
// For offline credentials and without dependence on Gaia account
kProvisioned = 3,
// For offline public identities and without dependence on Gaia account
kPublic = 4,
};
enum class DeviceType {
kUnspecified = 0,
kPhone = 1,
kTablet = 2,
kDisplay = 3,
kLaptop = 4,
kTV = 5,
kWatch = 6,
};
struct DeviceMetadata {
// Stable device identifier that does not rotate for a few months.
std::string stable_device_id;
// The account name which created the certificate.
std::string account_name;
// The name of the local device when the certificate is created.
std::string device_name;
// The icon url of the user whose device created the certificate.
std::string icon_url;
// The Bluetooth MAC address of the device which created the certificate.
std::string bluetooth_mac_address;
DeviceType device_type;
};
struct PrivateCredential {
TrustType trust_type;
// The unique id of (and hashed based on) a pair of secret
// key (PrivateCredential.verification_key) and X509Certificate's public
// key (PublicCredential.verification_key).
std::vector<uint8_t> secret_id;
// The aes key to encrypt personal fields in public certificates.
// A bytes representation of a Secret Key owned by contact, to decrypt the
// encrypted DeviceMetadata bytes stored within the advertisement.
std::vector<uint8_t> authenticity_key;
// Bytes representation of a public key of X509Certificate, used in
// handshake during contact verification phase.
std::vector<uint8_t> verification_key;
// The time in millis from epoch when this credential becomes effective.
int start_time;
// The time in millis from epoch when this credential expires.
int end_time;
// The set of 2-byte salts already used to encrypt the metadata key.
std::set<std::vector<uint8_t>> consumed_salts;
// The aes key to encrypt DeviceMetadata in public credential.
std::vector<uint8_t> metadata_encryption_key;
DeviceMetadata device_metadata;
};
struct PublicCredential {
TrustType trust_type;
// The unique id of (and hashed based on) a pair of secret
// key (PrivateCredential.verification_key) and X509Certificate's public
// key (PublicCredential.verification_key).
std::vector<uint8_t> secret_id;
// Bytes representation of a Secret Key owned by contact, to decrypt the
// metadata_key stored within the advertisement.
std::vector<uint8_t> authenticity_key;
// Bytes representation of a public key of X509Certificate, used in
// handshake during contact verification phase.
std::vector<uint8_t> verification_key;
// The time in millis from epoch when this credential becomes effective.
int start_time;
// The time in millis from epoch when this credential expires.
int end_time;
// The encrypted DeviceMetadata in bytes, contains personal information of the
// device/user who created this certificate. Needs to be decrypted into bytes,
// and converted back to DeviceMetadata instance to access fields.
std::vector<uint8_t> encrypted_metadata_bytes;
// The tag for verifying metadata_encryption_key.
std::vector<uint8_t> metadata_encryption_key_tag;
};
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_CREDENTIAL_H_
+39
View File
@@ -0,0 +1,39 @@
// Copyright 2020 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_STORAGE_H_
#define THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
#include "internal/platform/implementation/credential_storage.h"
namespace location {
namespace nearby {
/*
* The instance of CredentialStorage is owned by {@code CredentialManager}.
* It's a wrapper on top of implementation/credential_storage.h to providing
* credential storage operations for Nearby logic layer to invoke.
*/
class CredentialStorage {
public:
CredentialStorage() = default;
~CredentialStorage() = default;
private:
api::CredentialStorage credential_storage_;
};
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_PRESENCE_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
+1
View File
@@ -57,6 +57,7 @@ cc_library(
"ble_v2.h",
"bluetooth_adapter.h",
"bluetooth_classic.h",
"credential_storage.h",
"server_sync.h",
"wifi.h",
"wifi_hotspot.h",
@@ -0,0 +1,89 @@
// Copyright 2020 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_INTERNAL_PLATFORM_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
#define THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_CREDENTIAL_STORAGE_H_
#include <functional>
#include <set>
#include <string>
#include <vector>
#include "internal/platform/credential.h"
#include "internal/platform/exception.h"
namespace location {
namespace nearby {
namespace api {
enum class CredentialOperationStatus {
kFailed = 0,
kSucceeded = 1,
};
struct CredentialSelector {
std::string account_name;
TrustType trust_type;
};
struct SaveCredentialCallback {
std::function<void(CredentialOperationStatus)> credentials_saved_cb;
};
struct GetPrivateCredentialCallback {
std::function<void(ExceptionOr<std::vector<PrivateCredential>>)>
credentials_fetched_cb;
};
struct GetPublicCredentialCallback {
std::function<void(ExceptionOr<std::vector<PublicCredential>>)>
credentials_fetched_cb;
};
/*
* This class specifies the virtual functions for native platforms to implement.
*/
class CredentialStorage {
public:
CredentialStorage() = default;
virtual ~CredentialStorage() = default;
// Used for
// 1. Save/update private creds after (re)generate credentials invoked by
// manager app. (public_credentials will be empty for this case); Or
// 2. Update remote public creds after manager app downloaded a new batch of
// remote public creds and save to local storage. (private_credentials will
// be empty for this case).
// account_name will be used as the key in both options, and both would
// overwrite the previous credentials if there already exists credentials for
// that given account_name.
virtual void SaveCredentials(
std::string account_name,
std::vector<PrivateCredential> private_credentials,
std::vector<PublicCredential> public_credentials,
SaveCredentialCallback callback);
// Used to fetch private creds when broadcasting.
virtual void GetPrivateCredentials(CredentialSelector credential_selector,
GetPrivateCredentialCallback callback);
// Used to fetch remote public creds when scanning.
virtual void GetPublicCredentials(CredentialSelector credential_selector,
GetPublicCredentialCallback callback);
};
} // namespace api
} // namespace nearby
} // namespace location
#endif // THIRD_PARTY_NEARBY_INTERNAL_PLATFORM_IMPLEMENTATION_CREDENTIAL_STORAGE_H_