Commit ccbe5c4d authored by Leonid Baraz's avatar Leonid Baraz Committed by Chromium LUCI CQ

Activate signature verification in client.

Signature is now mandatory in client when encryption is enabled.

Bug: b:170054326
Change-Id: I1b884b5b39d326446c24794c10cab1ced443312d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2615662
Commit-Queue: Leonid Baraz <lbaraz@chromium.org>
Reviewed-by: default avatarZach Trudo <zatrudo@google.com>
Cr-Commit-Position: refs/heads/master@{#841378}
parent 2355161c
...@@ -257,17 +257,14 @@ void RecordHandlerImpl::ReportUploader::HandleSuccessfulUpload() { ...@@ -257,17 +257,14 @@ void RecordHandlerImpl::ReportUploader::HandleSuccessfulUpload() {
signed_encryption_key_record->FindStringKey("publicKey"); signed_encryption_key_record->FindStringKey("publicKey");
const auto public_key_id_result = const auto public_key_id_result =
signed_encryption_key_record->FindIntKey("publicKeyId"); signed_encryption_key_record->FindIntKey("publicKeyId");
// TODO(b/170054326): Make signature mandatory too. const std::string* public_key_signature_str =
// const std::string* public_key_signature_str = signed_encryption_key_record->FindStringKey("publicKeySignature");
// signed_encryption_key_record->FindStringKey("publicKeySignature");
std::string public_key; std::string public_key;
std::string public_key_signature; std::string public_key_signature;
if (public_key_str != nullptr && if (public_key_str != nullptr &&
base::Base64Decode(*public_key_str, &public_key) && base::Base64Decode(*public_key_str, &public_key) &&
// TODO(b/170054326): Make signature mandatory too. public_key_signature_str != nullptr &&
// public_key_signature_str != nullptr base::Base64Decode(*public_key_signature_str, &public_key_signature) &&
// base::Base64Decode(*public_key_signature_str,
// &public_key_signature) &&
public_key_id_result.has_value()) { public_key_id_result.has_value()) {
SignedEncryptionInfo signed_encryption_key; SignedEncryptionInfo signed_encryption_key;
signed_encryption_key.set_public_asymmetric_key(public_key); signed_encryption_key.set_public_asymmetric_key(public_key);
......
...@@ -28,9 +28,13 @@ ...@@ -28,9 +28,13 @@
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
using ::testing::_; using ::testing::_;
using ::testing::AllOf;
using ::testing::Eq; using ::testing::Eq;
using ::testing::Gt;
using ::testing::Invoke; using ::testing::Invoke;
using ::testing::IsEmpty;
using ::testing::MockFunction; using ::testing::MockFunction;
using ::testing::Not;
using ::testing::Property; using ::testing::Property;
using ::testing::Return; using ::testing::Return;
using ::testing::StrictMock; using ::testing::StrictMock;
...@@ -132,7 +136,6 @@ base::Optional<base::Value> BuildEncryptionSettingsFromRequest( ...@@ -132,7 +136,6 @@ base::Optional<base::Value> BuildEncryptionSettingsFromRequest(
encryption_settings.SetStringKey("publicKey", public_key); encryption_settings.SetStringKey("publicKey", public_key);
encryption_settings.SetIntKey("publicKeyId", 12345); encryption_settings.SetIntKey("publicKeyId", 12345);
std::string public_key_signature; std::string public_key_signature;
// TODO(b/170054326): Generate signature.
base::Base64Encode("PUBLIC KEY SIG", &public_key_signature); base::Base64Encode("PUBLIC KEY SIG", &public_key_signature);
encryption_settings.SetStringKey("publicKeySignature", public_key_signature); encryption_settings.SetStringKey("publicKeySignature", public_key_signature);
return encryption_settings; return encryption_settings;
...@@ -249,7 +252,12 @@ TEST_P(RecordHandlerImplTest, ForwardsRecordsToCloudPolicyClient) { ...@@ -249,7 +252,12 @@ TEST_P(RecordHandlerImplTest, ForwardsRecordsToCloudPolicyClient) {
StrictMock<TestCompletionResponder> responder; StrictMock<TestCompletionResponder> responder;
TestCallbackWaiter responder_waiter; TestCallbackWaiter responder_waiter;
EXPECT_CALL(encryption_key_attached, Call(_)) EXPECT_CALL(
encryption_key_attached,
Call(AllOf(Property(&SignedEncryptionInfo::public_asymmetric_key,
Not(IsEmpty())),
Property(&SignedEncryptionInfo::public_key_id, Gt(0)),
Property(&SignedEncryptionInfo::signature, Not(IsEmpty())))))
.Times(need_encryption_key() ? 1 : 0); .Times(need_encryption_key() ? 1 : 0);
EXPECT_CALL( EXPECT_CALL(
...@@ -313,7 +321,12 @@ TEST_P(RecordHandlerImplTest, ReportsEarlyFailure) { ...@@ -313,7 +321,12 @@ TEST_P(RecordHandlerImplTest, ReportsEarlyFailure) {
.WillOnce(Invoke([&responder_waiter]() { responder_waiter.Signal(); })); .WillOnce(Invoke([&responder_waiter]() { responder_waiter.Signal(); }));
StrictMock<TestEncryptionKeyAttached> encryption_key_attached; StrictMock<TestEncryptionKeyAttached> encryption_key_attached;
EXPECT_CALL(encryption_key_attached, Call(_)) EXPECT_CALL(
encryption_key_attached,
Call(AllOf(Property(&SignedEncryptionInfo::public_asymmetric_key,
Not(IsEmpty())),
Property(&SignedEncryptionInfo::public_key_id, Gt(0)),
Property(&SignedEncryptionInfo::signature, Not(IsEmpty())))))
.Times(need_encryption_key() ? 1 : 0); .Times(need_encryption_key() ? 1 : 0);
auto encryption_key_attached_callback = auto encryption_key_attached_callback =
...@@ -389,7 +402,12 @@ TEST_P(RecordHandlerImplTest, UploadsGapRecordOnServerFailure) { ...@@ -389,7 +402,12 @@ TEST_P(RecordHandlerImplTest, UploadsGapRecordOnServerFailure) {
.WillOnce(Invoke([&responder_waiter]() { responder_waiter.Signal(); })); .WillOnce(Invoke([&responder_waiter]() { responder_waiter.Signal(); }));
StrictMock<TestEncryptionKeyAttached> encryption_key_attached; StrictMock<TestEncryptionKeyAttached> encryption_key_attached;
EXPECT_CALL(encryption_key_attached, Call(_)) EXPECT_CALL(
encryption_key_attached,
Call(AllOf(Property(&SignedEncryptionInfo::public_asymmetric_key,
Not(IsEmpty())),
Property(&SignedEncryptionInfo::public_key_id, Gt(0)),
Property(&SignedEncryptionInfo::signature, Not(IsEmpty())))))
.Times(need_encryption_key() ? 1 : 0); .Times(need_encryption_key() ? 1 : 0);
auto encryption_key_attached_callback = auto encryption_key_attached_callback =
base::BindRepeating(&TestEncryptionKeyAttached::Call, base::BindRepeating(&TestEncryptionKeyAttached::Call,
......
...@@ -33,9 +33,14 @@ namespace { ...@@ -33,9 +33,14 @@ namespace {
using ::policy::MockCloudPolicyClient; using ::policy::MockCloudPolicyClient;
using ::testing::_; using ::testing::_;
using ::testing::AllOf;
using ::testing::Gt;
using ::testing::Invoke; using ::testing::Invoke;
using ::testing::InvokeArgument; using ::testing::InvokeArgument;
using ::testing::IsEmpty;
using ::testing::MockFunction; using ::testing::MockFunction;
using ::testing::Not;
using ::testing::Property;
using ::testing::StrictMock; using ::testing::StrictMock;
using ::testing::WithArgs; using ::testing::WithArgs;
...@@ -154,7 +159,6 @@ base::Value ValueFromSucceededSequencingInfo( ...@@ -154,7 +159,6 @@ base::Value ValueFromSucceededSequencingInfo(
encryption_settings.SetStringKey("publicKey", public_key); encryption_settings.SetStringKey("publicKey", public_key);
encryption_settings.SetIntKey("publicKeyId", 12345); encryption_settings.SetIntKey("publicKeyId", 12345);
std::string public_key_signature; std::string public_key_signature;
// TODO(b/170054326): Generate signature.
base::Base64Encode("PUBLIC KEY SIG", &public_key_signature); base::Base64Encode("PUBLIC KEY SIG", &public_key_signature);
encryption_settings.SetStringKey("publicKeySignature", encryption_settings.SetStringKey("publicKeySignature",
public_key_signature); public_key_signature);
...@@ -240,7 +244,12 @@ TEST_P(UploadClientTest, CreateUploadClientAndUploadRecords) { ...@@ -240,7 +244,12 @@ TEST_P(UploadClientTest, CreateUploadClientAndUploadRecords) {
TestCallbackWaiterWithCounter waiter(kExpectedCallTimes); TestCallbackWaiterWithCounter waiter(kExpectedCallTimes);
StrictMock<TestEncryptionKeyAttached> encryption_key_attached; StrictMock<TestEncryptionKeyAttached> encryption_key_attached;
EXPECT_CALL(encryption_key_attached, Call(_)) EXPECT_CALL(
encryption_key_attached,
Call(AllOf(Property(&SignedEncryptionInfo::public_asymmetric_key,
Not(IsEmpty())),
Property(&SignedEncryptionInfo::public_key_id, Gt(0)),
Property(&SignedEncryptionInfo::signature, Not(IsEmpty())))))
.Times(need_encryption_key() ? 1 : 0); .Times(need_encryption_key() ? 1 : 0);
auto encryption_key_attached_cb = auto encryption_key_attached_cb =
base::BindRepeating(&TestEncryptionKeyAttached::Call, base::BindRepeating(&TestEncryptionKeyAttached::Call,
......
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