Commit aafd7633 authored by Minh X. Nguyen's avatar Minh X. Nguyen Committed by Commit Bot

Component unpacker: Generate public_key when verifying a crx package.

Bug: 722942
Change-Id: If2151274f2cfd1eaddd3a0cbeaf99636b8534a05
Reviewed-on: https://chromium-review.googlesource.com/726976
Commit-Queue: Minh Nguyen <mxnguyen@chromium.org>
Reviewed-by: default avatarSorin Jianu <sorin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#510216}
parent d04212e7
......@@ -285,6 +285,7 @@ TEST_F(ComponentInstallerTest, UnpackPathInstallSuccess) {
const auto unpack_path = result().unpack_path;
EXPECT_TRUE(base::DirectoryExists(unpack_path));
EXPECT_EQ(update_client::jebg_public_key, result().public_key);
base::ScopedPathOverride scoped_path_override(DIR_COMPONENT_USER);
base::FilePath base_dir;
......
......@@ -95,6 +95,7 @@ void InstallComplete(
void InstallOnBlockingTaskRunner(
const scoped_refptr<base::SingleThreadTaskRunner>& main_task_runner,
const base::FilePath& unpack_path,
const std::string& public_key,
const std::string& fingerprint,
const scoped_refptr<CrxInstaller>& installer,
const InstallOnBlockingTaskRunnerCompleteCallback& callback) {
......@@ -141,7 +142,8 @@ void UnpackCompleteOnBlockingTaskRunner(
base::PostTaskWithTraits(
FROM_HERE, kTaskTraits,
base::BindOnce(&InstallOnBlockingTaskRunner, main_task_runner,
result.unpack_path, fingerprint, installer, callback));
result.unpack_path, result.public_key, fingerprint,
installer, callback));
}
void StartInstallOnBlockingTaskRunner(
......
......@@ -61,9 +61,9 @@ bool ComponentUnpacker::Verify() {
return false;
}
const std::vector<std::vector<uint8_t>> required_keys = {pk_hash_};
const crx_file::VerifierResult result =
crx_file::Verify(path_, crx_file::VerifierFormat::CRX2_OR_CRX3,
required_keys, std::vector<uint8_t>(), nullptr, nullptr);
const crx_file::VerifierResult result = crx_file::Verify(
path_, crx_file::VerifierFormat::CRX2_OR_CRX3, required_keys,
std::vector<uint8_t>(), &public_key_, nullptr);
if (result != crx_file::VerifierResult::OK_FULL &&
result != crx_file::VerifierResult::OK_DELTA) {
error_ = UnpackerError::kInvalidFile;
......@@ -135,8 +135,10 @@ void ComponentUnpacker::EndUnpacking() {
Result result;
result.error = error_;
result.extended_error = extended_error_;
if (error_ == UnpackerError::kNone)
if (error_ == UnpackerError::kNone) {
result.unpack_path = unpack_path_;
result.public_key = public_key_;
}
base::SequencedTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(callback_, result));
......
......@@ -71,6 +71,9 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
// Path of the unpacked files if the unpacking was successful.
base::FilePath unpack_path;
// The extracted public key of the package if the unpacking was successful.
std::string public_key;
};
using Callback = base::Callback<void(const Result& result)>;
......@@ -127,6 +130,7 @@ class ComponentUnpacker : public base::RefCountedThreadSafe<ComponentUnpacker> {
scoped_refptr<OutOfProcessPatcher> oop_patcher_;
UnpackerError error_;
int extended_error_;
std::string public_key_;
DISALLOW_COPY_AND_ASSIGN(ComponentUnpacker);
};
......
......@@ -113,6 +113,7 @@ TEST_F(ComponentUnpackerTest, UnpackFullCrx) {
base::FilePath unpack_path = result_.unpack_path;
EXPECT_FALSE(unpack_path.empty());
EXPECT_TRUE(base::DirectoryExists(unpack_path));
EXPECT_EQ(jebg_public_key, result_.public_key);
int64_t file_size = 0;
EXPECT_TRUE(
......
......@@ -37,6 +37,11 @@ const uint8_t jebg_hash[] = {0x94, 0x16, 0x0b, 0x6d, 0x41, 0x75, 0xe9, 0xec,
0x8e, 0xd5, 0xfa, 0x54, 0xb0, 0xd2, 0xdd, 0xa5,
0x6e, 0x05, 0x6b, 0xe8, 0x73, 0x47, 0xf6, 0xc4,
0x11, 0x9f, 0xbc, 0xb3, 0x09, 0xb3, 0x5b, 0x40};
// component 1 public key (base64 encoded):
const std::string jebg_public_key =
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC68bW8i/RzSaeXOcNLuBw0SP9+1bdo5ysLqH"
"qfLqZs6XyJWEyL0U6f1axPR6LwViku21kgdc6PI524eb8Cr+a/iXGgZ8SdvZTcfQ/g/ukwlblF"
"mtqYfDoVpz03U8rDQ9b6DxeJBF4r48TNlFORggrAiNR26qbf1i178Au12AzWtwIDAQAB";
// component 2 has extension id "abagagagagagagagagagagagagagagag", and
// the RSA public key the following hash:
const uint8_t abag_hash[] = {0x01, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
......
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