diff --git a/sharing/certificates/nearby_share_decrypted_public_certificate.cc b/sharing/certificates/nearby_share_decrypted_public_certificate.cc index 02c8d9c5..bf52033d 100644 --- a/sharing/certificates/nearby_share_decrypted_public_certificate.cc +++ b/sharing/certificates/nearby_share_decrypted_public_certificate.cc @@ -188,7 +188,7 @@ NearbyShareDecryptedPublicCertificate::DecryptPublicCertificate( return NearbyShareDecryptedPublicCertificate( not_before, not_after, std::move(secret_key), std::move(public_key), std::move(id), std::move(unencrypted_metadata), - public_certificate.for_self_share()); + public_certificate.for_self_share(), public_certificate.binding_id()); } NearbyShareDecryptedPublicCertificate::NearbyShareDecryptedPublicCertificate( @@ -196,14 +196,15 @@ NearbyShareDecryptedPublicCertificate::NearbyShareDecryptedPublicCertificate( std::unique_ptr secret_key, std::vector public_key, std::vector id, nearby::sharing::proto::EncryptedMetadata unencrypted_metadata, - bool for_self_share) + bool for_self_share, std::string binding_id) : not_before_(not_before), not_after_(not_after), secret_key_(std::move(secret_key)), public_key_(std::move(public_key)), id_(std::move(id)), unencrypted_metadata_(std::move(unencrypted_metadata)), - for_self_share_(for_self_share) {} + for_self_share_(for_self_share), + binding_id_(std::move(binding_id)) {} NearbyShareDecryptedPublicCertificate::NearbyShareDecryptedPublicCertificate( const NearbyShareDecryptedPublicCertificate& other) { @@ -223,6 +224,7 @@ NearbyShareDecryptedPublicCertificate::operator=( id_ = other.id_; unencrypted_metadata_ = other.unencrypted_metadata_; for_self_share_ = other.for_self_share_; + binding_id_ = other.binding_id_; return *this; } diff --git a/sharing/certificates/nearby_share_decrypted_public_certificate.h b/sharing/certificates/nearby_share_decrypted_public_certificate.h index 58e4a137..23818b02 100644 --- a/sharing/certificates/nearby_share_decrypted_public_certificate.h +++ b/sharing/certificates/nearby_share_decrypted_public_certificate.h @@ -19,6 +19,7 @@ #include #include +#include #include #include "absl/time/time.h" @@ -68,6 +69,8 @@ class NearbyShareDecryptedPublicCertificate { bool for_self_share() const { return for_self_share_; } + const std::string& binding_id() const { return binding_id_; } + // Verifies the |signature| of the signed |payload| using |public_key_|. // Returns true if verification was successful. bool VerifySignature(absl::Span payload, @@ -85,7 +88,7 @@ class NearbyShareDecryptedPublicCertificate { std::unique_ptr secret_key, std::vector public_key, std::vector id, nearby::sharing::proto::EncryptedMetadata unencrypted_metadata, - bool for_self_share); + bool for_self_share, std::string binding_id); // The start and end times of the certificate's validity period. To avoid // issues with clock skew, these times may be offset compared to the @@ -111,6 +114,10 @@ class NearbyShareDecryptedPublicCertificate { // Indicates if this public certificate is from another device owned by the // same user. bool for_self_share_ = false; + + // The binding id of device pair binding. If multiple bindings exist + // between two devices, it will return the newest binding_id. + std::string binding_id_; }; } // namespace sharing diff --git a/sharing/certificates/nearby_share_decrypted_public_certificate_test.cc b/sharing/certificates/nearby_share_decrypted_public_certificate_test.cc index ec650da6..19dab6aa 100644 --- a/sharing/certificates/nearby_share_decrypted_public_certificate_test.cc +++ b/sharing/certificates/nearby_share_decrypted_public_certificate_test.cc @@ -50,6 +50,7 @@ TEST(NearbyShareDecryptedPublicCertificateTest, Decrypt) { PublicCertificate proto_cert = GetNearbyShareTestPublicCertificate(kTestPublicCertificateVisibility); proto_cert.set_for_self_share(true); + proto_cert.set_binding_id("binding_id"); std::optional cert = NearbyShareDecryptedPublicCertificate::DecryptPublicCertificate( @@ -65,6 +66,7 @@ TEST(NearbyShareDecryptedPublicCertificateTest, Decrypt) { EXPECT_EQ(GetNearbyShareTestMetadata().SerializeAsString(), cert->unencrypted_metadata().SerializeAsString()); EXPECT_EQ(proto_cert.for_self_share(), cert->for_self_share()); + EXPECT_EQ(proto_cert.binding_id(), cert->binding_id()); } TEST(NearbyShareDecryptedPublicCertificateTest, Decrypt_IncorrectKeyFailure) { diff --git a/sharing/proto/rpc_resources.proto b/sharing/proto/rpc_resources.proto index 59c9d756..95f1435b 100644 --- a/sharing/proto/rpc_resources.proto +++ b/sharing/proto/rpc_resources.proto @@ -27,7 +27,7 @@ option optimize_for = LITE_RUNTIME; // How a Certificate is distributed is determined by who is on a user's contact // list. For example, if Will adds Ryan to his contact list, Ryan will have a // ShareTarget with Will's Certificate attached to it. -// NextId=11 +// NextId=13 message PublicCertificate { // The secret (symmetric) identifier used when identifying the ShareTarget's // BLE advertisement. @@ -66,6 +66,12 @@ message PublicCertificate { // Indicates if this public certificate corresponds to a device owned by the // current user. bool for_self_share = 10; + + reserved 11; + + // The binding id of device pair binding. If multiple bindings exist + // between two devices, it will return the newest binding_id. + string binding_id = 12; } // A member of a contact list. This is not inlined on the recommendation of @@ -159,4 +165,6 @@ message Device { // The public certificates generated and uploaded from local device, to be // shared with contacts. repeated PublicCertificate public_certificates = 4; + + reserved 5; }