aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTao Bao2017-04-10 18:55:57 -0500
committerTao Bao2017-04-13 00:46:09 -0500
commit1d866050eba7614109a1edec42529d4d80b0998f (patch)
tree36905d2bd8d5121a9ecb6d87996bc32fa480c009 /install.cpp
parent1b28a27c33e3f60fce661ddf4f2f0c5abefb63bc (diff)
downloadplatform-bootable-recovery-1d866050eba7614109a1edec42529d4d80b0998f.tar.gz
platform-bootable-recovery-1d866050eba7614109a1edec42529d4d80b0998f.tar.xz
platform-bootable-recovery-1d866050eba7614109a1edec42529d4d80b0998f.zip
Verify the package compatibility with libvintf.
verify_package_compatibility() is added to parse the compatibility entry (compatibility.zip) in a given OTA package. If entry is present, the information is sent to libvintf to check the compatibility. This CL doesn't actually call libvintf, since the API there is not available yet. Bug: 36597505 Test: Doesn't break the install with existing packages (i.e. w/o the compatibility entry). Test: recovery_component_test Change-Id: I3903ffa5f6ba33a5c0d761602ade6290c6752596 (cherry picked from commit 62e0bc7586077b3bde82759fb34b51b982cea20f)
Diffstat (limited to 'install.cpp')
-rw-r--r--install.cpp73
1 files changed, 73 insertions, 0 deletions
diff --git a/install.cpp b/install.cpp
index 0a2fa3ca..b4b869b9 100644
--- a/install.cpp
+++ b/install.cpp
@@ -489,6 +489,70 @@ static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_
489 return INSTALL_SUCCESS; 489 return INSTALL_SUCCESS;
490} 490}
491 491
492// Verifes the compatibility info in a Treble-compatible package. Returns true directly if the
493// entry doesn't exist. Note that the compatibility info is packed in a zip file inside the OTA
494// package.
495bool verify_package_compatibility(ZipArchiveHandle package_zip) {
496 LOG(INFO) << "Verifying package compatibility...";
497
498 static constexpr const char* COMPATIBILITY_ZIP_ENTRY = "compatibility.zip";
499 ZipString compatibility_entry_name(COMPATIBILITY_ZIP_ENTRY);
500 ZipEntry compatibility_entry;
501 if (FindEntry(package_zip, compatibility_entry_name, &compatibility_entry) != 0) {
502 LOG(INFO) << "Package doesn't contain " << COMPATIBILITY_ZIP_ENTRY << " entry";
503 return true;
504 }
505
506 std::string zip_content(compatibility_entry.uncompressed_length, '\0');
507 int32_t ret;
508 if ((ret = ExtractToMemory(package_zip, &compatibility_entry,
509 reinterpret_cast<uint8_t*>(&zip_content[0]),
510 compatibility_entry.uncompressed_length)) != 0) {
511 LOG(ERROR) << "Failed to read " << COMPATIBILITY_ZIP_ENTRY << ": " << ErrorCodeString(ret);
512 return false;
513 }
514
515 ZipArchiveHandle zip_handle;
516 ret = OpenArchiveFromMemory(static_cast<void*>(const_cast<char*>(zip_content.data())),
517 zip_content.size(), COMPATIBILITY_ZIP_ENTRY, &zip_handle);
518 if (ret != 0) {
519 LOG(ERROR) << "Failed to OpenArchiveFromMemory: " << ErrorCodeString(ret);
520 return false;
521 }
522
523 // Iterate all the entries inside COMPATIBILITY_ZIP_ENTRY and read the contents.
524 void* cookie;
525 ret = StartIteration(zip_handle, &cookie, nullptr, nullptr);
526 if (ret != 0) {
527 LOG(ERROR) << "Failed to start iterating zip entries: " << ErrorCodeString(ret);
528 CloseArchive(zip_handle);
529 return false;
530 }
531 std::unique_ptr<void, decltype(&EndIteration)> guard(cookie, EndIteration);
532
533 std::vector<std::string> compatibility_info;
534 ZipEntry info_entry;
535 ZipString info_name;
536 while (Next(cookie, &info_entry, &info_name) == 0) {
537 std::string content(info_entry.uncompressed_length, '\0');
538 int32_t ret = ExtractToMemory(zip_handle, &info_entry, reinterpret_cast<uint8_t*>(&content[0]),
539 info_entry.uncompressed_length);
540 if (ret != 0) {
541 LOG(ERROR) << "Failed to read " << info_name.name << ": " << ErrorCodeString(ret);
542 CloseArchive(zip_handle);
543 return false;
544 }
545 compatibility_info.emplace_back(std::move(content));
546 }
547 EndIteration(cookie);
548 CloseArchive(zip_handle);
549
550 // TODO(b/36814503): Enable the actual verification when VintfObject::CheckCompatibility() lands.
551 // VintfObject::CheckCompatibility returns zero on success.
552 // return (android::vintf::VintfObject::CheckCompatibility(compatibility_info, true) == 0);
553 return true;
554}
555
492static int 556static int
493really_install_package(const char *path, bool* wipe_cache, bool needs_mount, 557really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
494 std::vector<std::string>& log_buffer, int retry_count, int* max_temperature) 558 std::vector<std::string>& log_buffer, int retry_count, int* max_temperature)
@@ -536,6 +600,15 @@ really_install_package(const char *path, bool* wipe_cache, bool needs_mount,
536 return INSTALL_CORRUPT; 600 return INSTALL_CORRUPT;
537 } 601 }
538 602
603 // Additionally verify the compatibility of the package.
604 if (!verify_package_compatibility(zip)) {
605 LOG(ERROR) << "Failed to verify package compatibility";
606 log_buffer.push_back(android::base::StringPrintf("error: %d", kPackageCompatibilityFailure));
607 sysReleaseMap(&map);
608 CloseArchive(zip);
609 return INSTALL_CORRUPT;
610 }
611
539 // Verify and install the contents of the package. 612 // Verify and install the contents of the package.
540 ui->Print("Installing update...\n"); 613 ui->Print("Installing update...\n");
541 if (retry_count > 0) { 614 if (retry_count > 0) {