aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-03-16 19:37:38 -0500
committerTao Bao2017-03-17 16:07:12 -0500
commit5e535014dd7961fbf812abeaa27f3339775031f1 (patch)
tree5b0df6618eb06633342242f917a2fcd020e8e78f /install.cpp
parentdd553d280f3dabf8b2bd01d63111206d4ccb098c (diff)
downloadplatform-bootable-recovery-5e535014dd7961fbf812abeaa27f3339775031f1.tar.gz
platform-bootable-recovery-5e535014dd7961fbf812abeaa27f3339775031f1.tar.xz
platform-bootable-recovery-5e535014dd7961fbf812abeaa27f3339775031f1.zip
Drop the dependency on 'ui' in verify_file().
verify_file() has a dependency on the global variable of 'ui' for posting the verification progress, which requires the users of libverifier to provide a UI instance. This CL adds an optional argument to verify_file() so that it can post the progress through the provided callback function. As a result, we can drop the MockUI class in verifier_test.cpp. Test: recovery_component_test passes. Test: verify_file() posts progress update when installing an OTA. Change-Id: I8b87d0f0d99777ea755d33d6dbbe2b6d44243bf1
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp40
1 files changed, 21 insertions, 19 deletions
diff --git a/install.cpp b/install.cpp
index ce89e0dc..9123fc27 100644
--- a/install.cpp
+++ b/install.cpp
@@ -27,6 +27,7 @@
27#include <unistd.h> 27#include <unistd.h>
28 28
29#include <chrono> 29#include <chrono>
30#include <functional>
30#include <limits> 31#include <limits>
31#include <map> 32#include <map>
32#include <string> 33#include <string>
@@ -578,23 +579,24 @@ install_package(const char* path, bool* wipe_cache, const char* install_file,
578} 579}
579 580
580bool verify_package(const unsigned char* package_data, size_t package_size) { 581bool verify_package(const unsigned char* package_data, size_t package_size) {
581 std::vector<Certificate> loadedKeys; 582 std::vector<Certificate> loadedKeys;
582 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { 583 if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) {
583 LOG(ERROR) << "Failed to load keys"; 584 LOG(ERROR) << "Failed to load keys";
584 return false; 585 return false;
585 } 586 }
586 LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; 587 LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE;
587 588
588 // Verify package. 589 // Verify package.
589 ui->Print("Verifying update package...\n"); 590 ui->Print("Verifying update package...\n");
590 auto t0 = std::chrono::system_clock::now(); 591 auto t0 = std::chrono::system_clock::now();
591 int err = verify_file(const_cast<unsigned char*>(package_data), package_size, loadedKeys); 592 int err = verify_file(const_cast<unsigned char*>(package_data), package_size, loadedKeys,
592 std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; 593 std::bind(&RecoveryUI::SetProgress, ui, std::placeholders::_1));
593 ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); 594 std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0;
594 if (err != VERIFY_SUCCESS) { 595 ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err);
595 LOG(ERROR) << "Signature verification failed"; 596 if (err != VERIFY_SUCCESS) {
596 LOG(ERROR) << "error: " << kZipVerificationFailure; 597 LOG(ERROR) << "Signature verification failed";
597 return false; 598 LOG(ERROR) << "error: " << kZipVerificationFailure;
598 } 599 return false;
599 return true; 600 }
601 return true;
600} 602}