Store raw payload hash blob in install plan.
We were using a custom sha256 pair in Omaha response, now that Omaha
has a standard hash_sha256 field in package, we should use that instead.
The difference is that hash_sha256 is encoded in hex instead of base64,
but the android payload property is still using base64, to be backward
compatible, we have to keep accepting base64 there, to avoid decoding
and then re-encoding to another encoding, we store the decoded raw hash.
Also removed the hash() related functions in HashCalculator, since it's
rarely used and the caller should encode it in whatever encoding they
want.
Also make use of RawHashOfBytes to simply code in a few places.
Bug: 36252799
Test: update_engine_unittests
Change-Id: Iaa02611b4c9cda3ead5de51e777e8caba6d99d93
(cherry picked from commit f14d51b6823522f6b2eb834f9e14d72c8363a3ad)
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index b06de09..94e615d 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -70,7 +70,6 @@
static const char* kTagMoreInfo = "MoreInfo";
// Deprecated: "NeedsAdmin"
static const char* kTagPrompt = "Prompt";
-static const char* kTagSha256 = "sha256";
static const char* kTagDisableP2PForDownloading = "DisableP2PForDownloading";
static const char* kTagDisableP2PForSharing = "DisableP2PForSharing";
static const char* kTagPublicKeyRsa = "PublicKeyRsa";
@@ -360,6 +359,7 @@
vector<string> url_codebase;
string package_name;
string package_size;
+ string package_hash;
string manifest_version;
map<string, string> action_postinstall_attrs;
};
@@ -420,6 +420,7 @@
// Only look at the first <package>.
data->package_name = attrs["name"];
data->package_size = attrs["size"];
+ data->package_hash = attrs["hash_sha256"];
} else if (data->current_path == "/response/app/updatecheck/manifest") {
// Get the version.
data->manifest_version = attrs[kTagVersion];
@@ -870,6 +871,13 @@
LOG(INFO) << "Payload size = " << output_object->size << " bytes";
+ output_object->hash = parser_data->package_hash;
+ if (output_object->hash.empty()) {
+ LOG(ERROR) << "Omaha Response has empty hash_sha256 value";
+ completer->set_code(ErrorCode::kOmahaResponseInvalid);
+ return false;
+ }
+
return true;
}
@@ -893,13 +901,6 @@
return false;
}
- output_object->hash = attrs[kTagSha256];
- if (output_object->hash.empty()) {
- LOG(ERROR) << "Omaha Response has empty sha256 value";
- completer->set_code(ErrorCode::kOmahaResponseInvalid);
- return false;
- }
-
// Get the optional properties one by one.
output_object->more_info_url = attrs[kTagMoreInfo];
output_object->metadata_size = ParseInt(attrs[kTagMetadataSize]);
@@ -1133,10 +1134,13 @@
next_data_offset + next_data_length;
}
- string file_id = utils::CalculateP2PFileId(response.hash, response.size);
+ brillo::Blob raw_hash;
+ if (!base::HexStringToBytes(response.hash, &raw_hash))
+ return;
+ string file_id = utils::CalculateP2PFileId(raw_hash, response.size);
if (system_state_->p2p_manager()) {
- LOG(INFO) << "Checking if payload is available via p2p, file_id="
- << file_id << " minimum_size=" << minimum_size;
+ LOG(INFO) << "Checking if payload is available via p2p, file_id=" << file_id
+ << " minimum_size=" << minimum_size;
system_state_->p2p_manager()->LookupUrlForFile(
file_id,
minimum_size,