Merge "Move install to separate module" am: a232d9dccb

am: 3f25d6bb07

Change-Id: I1b37d0263bbd383ba71c6025b7fb26b3651d7b8a
This commit is contained in:
Tianjie Xu
2019-03-29 14:54:00 -07:00
committed by android-build-merger
28 changed files with 194 additions and 183 deletions
+3 -70
View File
@@ -63,32 +63,18 @@ cc_defaults {
"libbootloader_message", "libbootloader_message",
"libcrypto", "libcrypto",
"libcutils", "libcutils",
"libext4_utils",
"libfs_mgr", "libfs_mgr",
"libfusesideload",
"libhidl-gen-utils",
"libhidlbase",
"libhidltransport",
"liblog", "liblog",
"libpng",
"libselinux",
"libtinyxml2",
"libutils",
"libz",
"libziparchive", "libziparchive",
], ],
static_libs: [ static_libs: [
"librecovery_fastboot", "librecovery_fastboot",
"libminui", "libminui",
"libpackage",
"libverifier",
"libotautil", "libotautil",
// external dependencies // external dependencies
"libhealthhalutils", "libhealthhalutils",
"libvintf_recovery",
"libvintf",
"libfstab", "libfstab",
], ],
} }
@@ -102,69 +88,14 @@ cc_library_static {
], ],
srcs: [ srcs: [
"adb_install.cpp",
"fsck_unshare_blocks.cpp", "fsck_unshare_blocks.cpp",
"fuse_sdcard_install.cpp",
"install.cpp",
"recovery.cpp", "recovery.cpp",
"roots.cpp",
], ],
shared_libs: [ shared_libs: [
"libinstall",
"librecovery_ui", "librecovery_ui",
], ],
include_dirs: [
"system/vold",
],
}
cc_library_static {
name: "libverifier",
recovery_available: true,
defaults: [
"recovery_defaults",
],
srcs: [
"asn1_decoder.cpp",
"verifier.cpp",
],
shared_libs: [
"libbase",
"libcrypto",
"libcrypto_utils",
"libziparchive",
],
static_libs: [
"libotautil",
],
}
cc_library_static {
name: "libpackage",
recovery_available: true,
defaults: [
"recovery_defaults",
],
srcs: [
"package.cpp",
],
shared_libs: [
"libbase",
"libcrypto",
"libziparchive",
],
static_libs: [
"libotautil",
],
} }
cc_binary { cc_binary {
@@ -172,6 +103,7 @@ cc_binary {
recovery: true, recovery: true,
defaults: [ defaults: [
"libinstall_defaults",
"librecovery_defaults", "librecovery_defaults",
], ],
@@ -181,6 +113,7 @@ cc_binary {
], ],
shared_libs: [ shared_libs: [
"libinstall",
"libminadbd_services", "libminadbd_services",
"librecovery_ui", "librecovery_ui",
], ],
-1
View File
@@ -31,7 +31,6 @@ struct selabel_handle;
extern struct selabel_handle* sehandle; extern struct selabel_handle* sehandle;
extern RecoveryUI* ui; extern RecoveryUI* ui;
extern bool modified_flash;
extern bool has_cache; extern bool has_cache;
// The current stage, e.g. "1/2". // The current stage, e.g. "1/2".
+1 -1
View File
@@ -36,7 +36,7 @@
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <fstab/fstab.h> #include <fstab/fstab.h>
#include "roots.h" #include "otautil/roots.h"
static constexpr const char* SYSTEM_E2FSCK_BIN = "/system/bin/e2fsck_static"; static constexpr const char* SYSTEM_E2FSCK_BIN = "/system/bin/e2fsck_static";
static constexpr const char* TMP_E2FSCK_BIN = "/tmp/e2fsck.bin"; static constexpr const char* TMP_E2FSCK_BIN = "/tmp/e2fsck.bin";
+78
View File
@@ -0,0 +1,78 @@
// Copyright (C) 2019 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
cc_defaults {
name: "libinstall_defaults",
defaults: [
"recovery_defaults",
],
shared_libs: [
"libbase",
"libbootloader_message",
"libcrypto",
"libext4_utils",
"libfs_mgr",
"libfusesideload",
"libhidl-gen-utils",
"libhidlbase",
"libhidltransport",
"liblog",
"libselinux",
"libtinyxml2",
"libutils",
"libz",
"libziparchive",
],
static_libs: [
"libotautil",
// external dependencies
"libvintf_recovery",
"libvintf",
"libfstab",
],
}
cc_library {
name: "libinstall",
recovery_available: true,
defaults: [
"libinstall_defaults",
],
srcs: [
"adb_install.cpp",
"asn1_decoder.cpp",
"fuse_sdcard_install.cpp",
"install.cpp",
"package.cpp",
"verifier.cpp",
],
shared_libs: [
"librecovery_ui",
],
export_include_dirs: [
"include",
],
export_shared_lib_headers: [
"librecovery_ui",
],
}
+9 -5
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "adb_install.h" #include "install/adb_install.h"
#include <errno.h> #include <errno.h>
#include <fcntl.h> #include <fcntl.h>
@@ -29,12 +29,16 @@
#include <android-base/logging.h> #include <android-base/logging.h>
#include <android-base/properties.h> #include <android-base/properties.h>
#include "common.h"
#include "fuse_sideload.h" #include "fuse_sideload.h"
#include "install.h" #include "install/install.h"
#include "recovery_ui/ui.h" #include "recovery_ui/ui.h"
int apply_from_adb(bool* wipe_cache) { static bool SetUsbConfig(const std::string& state) {
android::base::SetProperty("sys.usb.config", state);
return android::base::WaitForProperty("sys.usb.state", state);
}
int apply_from_adb(bool* wipe_cache, RecoveryUI* ui) {
// Save the usb state to restore after the sideload operation. // Save the usb state to restore after the sideload operation.
std::string usb_state = android::base::GetProperty("sys.usb.state", "none"); std::string usb_state = android::base::GetProperty("sys.usb.state", "none");
// Clean up state and stop adbd. // Clean up state and stop adbd.
@@ -85,7 +89,7 @@ int apply_from_adb(bool* wipe_cache) {
break; break;
} }
} }
result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0); result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0, ui);
break; break;
} }
@@ -14,9 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "asn1_decoder.h" #include "private/asn1_decoder.h"
#include <stdint.h>
int asn1_context::peek_byte() const { int asn1_context::peek_byte() const {
if (length_ == 0) { if (length_ == 0) {
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "fuse_sdcard_install.h" #include "install/fuse_sdcard_install.h"
#include <dirent.h> #include <dirent.h>
#include <signal.h> #include <signal.h>
@@ -35,8 +35,8 @@
#include "bootloader_message/bootloader_message.h" #include "bootloader_message/bootloader_message.h"
#include "fuse_provider.h" #include "fuse_provider.h"
#include "fuse_sideload.h" #include "fuse_sideload.h"
#include "install.h" #include "install/install.h"
#include "roots.h" #include "otautil/roots.h"
static constexpr const char* SDCARD_ROOT = "/sdcard"; static constexpr const char* SDCARD_ROOT = "/sdcard";
// How long (in seconds) we wait for the fuse-provided package file to // How long (in seconds) we wait for the fuse-provided package file to
@@ -184,7 +184,7 @@ int ApplyFromSdcard(Device* device, bool* wipe_cache, RecoveryUI* ui) {
} }
} }
result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0 /*retry_count*/); result = install_package(FUSE_SIDELOAD_HOST_PATHNAME, wipe_cache, false, 0 /*retry_count*/, ui);
break; break;
} }
@@ -14,9 +14,8 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _ADB_INSTALL_H #pragma once
#define _ADB_INSTALL_H
int apply_from_adb(bool* wipe_cache); #include <recovery_ui/ui.h>
#endif int apply_from_adb(bool* wipe_cache, RecoveryUI* ui);
@@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef RECOVERY_INSTALL_H_ #pragma once
#define RECOVERY_INSTALL_H_
#include <stddef.h> #include <stddef.h>
@@ -26,6 +25,7 @@
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
#include "package.h" #include "package.h"
#include "recovery_ui/ui.h"
enum InstallResult { enum InstallResult {
INSTALL_SUCCESS, INSTALL_SUCCESS,
@@ -45,12 +45,12 @@ enum class OtaType {
// Installs the given update package. If INSTALL_SUCCESS is returned and *wipe_cache is true on // Installs the given update package. If INSTALL_SUCCESS is returned and *wipe_cache is true on
// exit, caller should wipe the cache partition. // exit, caller should wipe the cache partition.
int install_package(const std::string& package, bool* wipe_cache, bool needs_mount, int install_package(const std::string& package, bool* wipe_cache, bool needs_mount, int retry_count,
int retry_count); RecoveryUI* ui);
// Verifies the package by ota keys. Returns true if the package is verified successfully, // Verifies the package by ota keys. Returns true if the package is verified successfully,
// otherwise returns false. // otherwise returns false.
bool verify_package(Package* package); bool verify_package(Package* package, RecoveryUI* ui);
// Reads meta data file of the package; parses each line in the format "key=value"; and writes the // Reads meta data file of the package; parses each line in the format "key=value"; and writes the
// result to |metadata|. Return true if succeed, otherwise return false. // result to |metadata|. Return true if succeed, otherwise return false.
@@ -67,5 +67,3 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip);
// Mandatory checks: ota-type, pre-device and serial number(if presents) // Mandatory checks: ota-type, pre-device and serial number(if presents)
// AB OTA specific checks: pre-build version, fingerprint, timestamp. // AB OTA specific checks: pre-build version, fingerprint, timestamp.
int CheckPackageMetadata(const std::map<std::string, std::string>& metadata, OtaType ota_type); int CheckPackageMetadata(const std::map<std::string, std::string>& metadata, OtaType ota_type);
#endif // RECOVERY_INSTALL_H_
@@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef _RECOVERY_VERIFIER_H #pragma once
#define _RECOVERY_VERIFIER_H
#include <stdint.h> #include <stdint.h>
@@ -44,25 +43,20 @@ struct ECKEYDeleter {
}; };
struct Certificate { struct Certificate {
typedef enum { typedef enum {
KEY_TYPE_RSA, KEY_TYPE_RSA,
KEY_TYPE_EC, KEY_TYPE_EC,
} KeyType; } KeyType;
Certificate(int hash_len_, Certificate(int hash_len_, KeyType key_type_, std::unique_ptr<RSA, RSADeleter>&& rsa_,
KeyType key_type_, std::unique_ptr<EC_KEY, ECKEYDeleter>&& ec_)
std::unique_ptr<RSA, RSADeleter>&& rsa_, : hash_len(hash_len_), key_type(key_type_), rsa(std::move(rsa_)), ec(std::move(ec_)) {}
std::unique_ptr<EC_KEY, ECKEYDeleter>&& ec_)
: hash_len(hash_len_),
key_type(key_type_),
rsa(std::move(rsa_)),
ec(std::move(ec_)) {}
// SHA_DIGEST_LENGTH (SHA-1) or SHA256_DIGEST_LENGTH (SHA-256) // SHA_DIGEST_LENGTH (SHA-1) or SHA256_DIGEST_LENGTH (SHA-256)
int hash_len; int hash_len;
KeyType key_type; KeyType key_type;
std::unique_ptr<RSA, RSADeleter> rsa; std::unique_ptr<RSA, RSADeleter> rsa;
std::unique_ptr<EC_KEY, ECKEYDeleter> ec; std::unique_ptr<EC_KEY, ECKEYDeleter> ec;
}; };
class VerifierInterface { class VerifierInterface {
@@ -103,7 +97,5 @@ bool LoadCertificateFromBuffer(const std::vector<uint8_t>& pem_content, Certific
// certificates. Returns an empty list if we fail to parse any of the entries. // certificates. Returns an empty list if we fail to parse any of the entries.
std::vector<Certificate> LoadKeysFromZipfile(const std::string& zip_name); std::vector<Certificate> LoadKeysFromZipfile(const std::string& zip_name);
#define VERIFY_SUCCESS 0 #define VERIFY_SUCCESS 0
#define VERIFY_FAILURE 1 #define VERIFY_FAILURE 1
#endif /* _RECOVERY_VERIFIER_H */
@@ -17,6 +17,7 @@
#ifndef ASN1_DECODER_H_ #ifndef ASN1_DECODER_H_
#define ASN1_DECODER_H_ #define ASN1_DECODER_H_
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
class asn1_context { class asn1_context {
+18 -14
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "install.h" #include "install/install.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
@@ -46,19 +46,22 @@
#include <android-base/unique_fd.h> #include <android-base/unique_fd.h>
#include <vintf/VintfObjectRecovery.h> #include <vintf/VintfObjectRecovery.h>
#include "common.h" #include "install/package.h"
#include "install/verifier.h"
#include "otautil/error_code.h" #include "otautil/error_code.h"
#include "otautil/paths.h" #include "otautil/paths.h"
#include "otautil/roots.h"
#include "otautil/sysutil.h" #include "otautil/sysutil.h"
#include "otautil/thermalutil.h" #include "otautil/thermalutil.h"
#include "package.h" #include "private/setup_commands.h"
#include "private/install.h"
#include "recovery_ui/ui.h" #include "recovery_ui/ui.h"
#include "roots.h"
#include "verifier.h"
using namespace std::chrono_literals; using namespace std::chrono_literals;
static constexpr int kRecoveryApiVersion = 3;
// Assert the version defined in code and in Android.mk are consistent.
static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions.");
// Default allocation of progress bar segments to operations // Default allocation of progress bar segments to operations
static constexpr int VERIFICATION_PROGRESS_TIME = 60; static constexpr int VERIFICATION_PROGRESS_TIME = 60;
static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25; static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25;
@@ -323,7 +326,7 @@ static void log_max_temperature(int* max_temperature, const std::atomic<bool>& l
// If the package contains an update binary, extract it and run it. // If the package contains an update binary, extract it and run it.
static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache, static int try_update_binary(const std::string& package, ZipArchiveHandle zip, bool* wipe_cache,
std::vector<std::string>* log_buffer, int retry_count, std::vector<std::string>* log_buffer, int retry_count,
int* max_temperature) { int* max_temperature, RecoveryUI* ui) {
std::map<std::string, std::string> metadata; std::map<std::string, std::string> metadata;
if (!ReadMetadataFromPackage(zip, &metadata)) { if (!ReadMetadataFromPackage(zip, &metadata)) {
LOG(ERROR) << "Failed to parse metadata in the zip file"; LOG(ERROR) << "Failed to parse metadata in the zip file";
@@ -569,7 +572,7 @@ bool verify_package_compatibility(ZipArchiveHandle package_zip) {
static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount, static int really_install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
std::vector<std::string>* log_buffer, int retry_count, std::vector<std::string>* log_buffer, int retry_count,
int* max_temperature) { int* max_temperature, RecoveryUI* ui) {
ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); ui->SetBackground(RecoveryUI::INSTALLING_UPDATE);
ui->Print("Finding update package...\n"); ui->Print("Finding update package...\n");
// Give verification half the progress bar... // Give verification half the progress bar...
@@ -596,7 +599,7 @@ static int really_install_package(const std::string& path, bool* wipe_cache, boo
} }
// Verify package. // Verify package.
if (!verify_package(package.get())) { if (!verify_package(package.get(), ui)) {
log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure)); log_buffer->push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure));
return INSTALL_CORRUPT; return INSTALL_CORRUPT;
} }
@@ -620,18 +623,19 @@ static int really_install_package(const std::string& path, bool* wipe_cache, boo
ui->Print("Retry attempt: %d\n", retry_count); ui->Print("Retry attempt: %d\n", retry_count);
} }
ui->SetEnableReboot(false); ui->SetEnableReboot(false);
int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature); int result =
try_update_binary(path, zip, wipe_cache, log_buffer, retry_count, max_temperature, ui);
ui->SetEnableReboot(true); ui->SetEnableReboot(true);
ui->Print("\n"); ui->Print("\n");
return result; return result;
} }
int install_package(const std::string& path, bool* wipe_cache, bool needs_mount, int retry_count) { int install_package(const std::string& path, bool* wipe_cache, bool needs_mount, int retry_count,
RecoveryUI* ui) {
CHECK(!path.empty()); CHECK(!path.empty());
CHECK(wipe_cache != nullptr); CHECK(wipe_cache != nullptr);
modified_flash = true;
auto start = std::chrono::system_clock::now(); auto start = std::chrono::system_clock::now();
int start_temperature = GetMaxValueFromThermalZone(); int start_temperature = GetMaxValueFromThermalZone();
@@ -644,7 +648,7 @@ int install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
result = INSTALL_ERROR; result = INSTALL_ERROR;
} else { } else {
result = really_install_package(path, wipe_cache, needs_mount, &log_buffer, retry_count, result = really_install_package(path, wipe_cache, needs_mount, &log_buffer, retry_count,
&max_temperature); &max_temperature, ui);
} }
// Measure the time spent to apply OTA update in seconds. // Measure the time spent to apply OTA update in seconds.
@@ -702,7 +706,7 @@ int install_package(const std::string& path, bool* wipe_cache, bool needs_mount,
return result; return result;
} }
bool verify_package(Package* package) { bool verify_package(Package* package, RecoveryUI* ui) {
static constexpr const char* CERTIFICATE_ZIP_FILE = "/system/etc/security/otacerts.zip"; static constexpr const char* CERTIFICATE_ZIP_FILE = "/system/etc/security/otacerts.zip";
std::vector<Certificate> loaded_keys = LoadKeysFromZipfile(CERTIFICATE_ZIP_FILE); std::vector<Certificate> loaded_keys = LoadKeysFromZipfile(CERTIFICATE_ZIP_FILE);
if (loaded_keys.empty()) { if (loaded_keys.empty()) {
+1 -1
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "package.h" #include "install/package.h"
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
+18 -19
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "verifier.h" #include "install/verifier.h"
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
@@ -36,8 +36,8 @@
#include <openssl/rsa.h> #include <openssl/rsa.h>
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
#include "asn1_decoder.h"
#include "otautil/print_sha1.h" #include "otautil/print_sha1.h"
#include "private/asn1_decoder.h"
/* /*
* Simple version of PKCS#7 SignedData extraction. This extracts the * Simple version of PKCS#7 SignedData extraction. This extracts the
@@ -82,10 +82,8 @@ static bool read_pkcs7(const uint8_t* pkcs7_der, size_t pkcs7_der_len,
} }
std::unique_ptr<asn1_context> signed_data_seq(signed_data_app->asn1_sequence_get()); std::unique_ptr<asn1_context> signed_data_seq(signed_data_app->asn1_sequence_get());
if (signed_data_seq == nullptr || if (signed_data_seq == nullptr || !signed_data_seq->asn1_sequence_next() ||
!signed_data_seq->asn1_sequence_next() || !signed_data_seq->asn1_sequence_next() || !signed_data_seq->asn1_sequence_next() ||
!signed_data_seq->asn1_sequence_next() ||
!signed_data_seq->asn1_sequence_next() ||
!signed_data_seq->asn1_constructed_skip_all()) { !signed_data_seq->asn1_constructed_skip_all()) {
return false; return false;
} }
@@ -96,11 +94,8 @@ static bool read_pkcs7(const uint8_t* pkcs7_der, size_t pkcs7_der_len,
} }
std::unique_ptr<asn1_context> sig_seq(sig_set->asn1_sequence_get()); std::unique_ptr<asn1_context> sig_seq(sig_set->asn1_sequence_get());
if (sig_seq == nullptr || if (sig_seq == nullptr || !sig_seq->asn1_sequence_next() || !sig_seq->asn1_sequence_next() ||
!sig_seq->asn1_sequence_next() || !sig_seq->asn1_sequence_next() || !sig_seq->asn1_sequence_next()) {
!sig_seq->asn1_sequence_next() ||
!sig_seq->asn1_sequence_next() ||
!sig_seq->asn1_sequence_next()) {
return false; return false;
} }
@@ -152,8 +147,8 @@ int verify_file(VerifierInterface* package, const std::vector<Certificate>& keys
<< " bytes from end"; << " bytes from end";
if (signature_start > comment_size) { if (signature_start > comment_size) {
LOG(ERROR) << "signature start: " << signature_start << " is larger than comment size: " LOG(ERROR) << "signature start: " << signature_start
<< comment_size; << " is larger than comment size: " << comment_size;
return VERIFY_FAILURE; return VERIFY_FAILURE;
} }
@@ -189,8 +184,8 @@ int verify_file(VerifierInterface* package, const std::vector<Certificate>& keys
return VERIFY_FAILURE; return VERIFY_FAILURE;
} }
for (size_t i = 4; i < eocd_size-3; ++i) { for (size_t i = 4; i < eocd_size - 3; ++i) {
if (eocd[i] == 0x50 && eocd[i+1] == 0x4b && eocd[i+2] == 0x05 && eocd[i+3] == 0x06) { if (eocd[i] == 0x50 && eocd[i + 1] == 0x4b && eocd[i + 2] == 0x05 && eocd[i + 3] == 0x06) {
// If the sequence $50 $4b $05 $06 appears anywhere after the real one, libziparchive will // If the sequence $50 $4b $05 $06 appears anywhere after the real one, libziparchive will
// find the later (wrong) one, which could be exploitable. Fail the verification if this // find the later (wrong) one, which could be exploitable. Fail the verification if this
// sequence occurs anywhere after the real one. // sequence occurs anywhere after the real one.
@@ -203,8 +198,12 @@ int verify_file(VerifierInterface* package, const std::vector<Certificate>& keys
bool need_sha256 = false; bool need_sha256 = false;
for (const auto& key : keys) { for (const auto& key : keys) {
switch (key.hash_len) { switch (key.hash_len) {
case SHA_DIGEST_LENGTH: need_sha1 = true; break; case SHA_DIGEST_LENGTH:
case SHA256_DIGEST_LENGTH: need_sha256 = true; break; need_sha1 = true;
break;
case SHA256_DIGEST_LENGTH:
need_sha256 = true;
break;
} }
} }
@@ -247,8 +246,8 @@ int verify_file(VerifierInterface* package, const std::vector<Certificate>& keys
const uint8_t* signature = eocd + eocd_size - signature_start; const uint8_t* signature = eocd + eocd_size - signature_start;
size_t signature_size = signature_start - FOOTER_SIZE; size_t signature_size = signature_start - FOOTER_SIZE;
LOG(INFO) << "signature (offset: " << std::hex << (length - signature_start) << ", length: " LOG(INFO) << "signature (offset: " << std::hex << (length - signature_start)
<< signature_size << "): " << print_hex(signature, signature_size); << ", length: " << signature_size << "): " << print_hex(signature, signature_size);
std::vector<uint8_t> sig_der; std::vector<uint8_t> sig_der;
if (!read_pkcs7(signature, signature_size, &sig_der)) { if (!read_pkcs7(signature, signature_size, &sig_der)) {
+1 -1
View File
@@ -33,7 +33,7 @@
#include "common.h" #include "common.h"
#include "otautil/dirutil.h" #include "otautil/dirutil.h"
#include "otautil/paths.h" #include "otautil/paths.h"
#include "roots.h" #include "otautil/roots.h"
static constexpr const char* LOG_FILE = "/cache/recovery/log"; static constexpr const char* LOG_FILE = "/cache/recovery/log";
static constexpr const char* LAST_INSTALL_FILE = "/cache/recovery/last_install"; static constexpr const char* LAST_INSTALL_FILE = "/cache/recovery/last_install";
+11
View File
@@ -42,12 +42,23 @@ cc_library_static {
"dirutil.cpp", "dirutil.cpp",
"mounts.cpp", "mounts.cpp",
"parse_install_logs.cpp", "parse_install_logs.cpp",
"roots.cpp",
"sysutil.cpp", "sysutil.cpp",
"thermalutil.cpp", "thermalutil.cpp",
], ],
include_dirs: [
"system/vold",
],
static_libs: [
"libfstab",
],
shared_libs: [ shared_libs: [
"libcutils", "libcutils",
"libext4_utils",
"libfs_mgr",
"libselinux", "libselinux",
], ],
}, },
+1 -4
View File
@@ -14,8 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#ifndef RECOVERY_ROOTS_H_ #pragma once
#define RECOVERY_ROOTS_H_
#include <string> #include <string>
@@ -58,5 +57,3 @@ int setup_install_mounts();
bool logical_partitions_mapped(); bool logical_partitions_mapped();
std::string get_system_root(); std::string get_system_root();
#endif // RECOVERY_ROOTS_H_
+3 -5
View File
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
#include "roots.h" #include "otautil/roots.h"
#include <ctype.h> #include <ctype.h>
#include <fcntl.h> #include <fcntl.h>
@@ -174,11 +174,9 @@ int format_volume(const std::string& volume, const std::string& directory) {
PLOG(ERROR) << "format_volume: failed to open " << v->blk_device; PLOG(ERROR) << "format_volume: failed to open " << v->blk_device;
return -1; return -1;
} }
length = length = get_file_size(fd.get(), v->length ? -v->length : CRYPT_FOOTER_OFFSET);
get_file_size(fd.get(), v->length ? -v->length : CRYPT_FOOTER_OFFSET);
if (length <= 0) { if (length <= 0) {
LOG(ERROR) << "get_file_size: invalid size " << length << " for " LOG(ERROR) << "get_file_size: invalid size " << length << " for " << v->blk_device;
<< v->blk_device;
return -1; return -1;
} }
} }
+11 -10
View File
@@ -50,20 +50,20 @@
#include <healthhalutils/HealthHalUtils.h> #include <healthhalutils/HealthHalUtils.h>
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
#include "adb_install.h"
#include "common.h" #include "common.h"
#include "fsck_unshare_blocks.h" #include "fsck_unshare_blocks.h"
#include "fuse_sdcard_install.h" #include "install/adb_install.h"
#include "install.h" #include "install/fuse_sdcard_install.h"
#include "install/install.h"
#include "install/package.h"
#include "logging.h" #include "logging.h"
#include "otautil/dirutil.h" #include "otautil/dirutil.h"
#include "otautil/error_code.h" #include "otautil/error_code.h"
#include "otautil/paths.h" #include "otautil/paths.h"
#include "otautil/roots.h"
#include "otautil/sysutil.h" #include "otautil/sysutil.h"
#include "package.h"
#include "recovery_ui/screen_ui.h" #include "recovery_ui/screen_ui.h"
#include "recovery_ui/ui.h" #include "recovery_ui/ui.h"
#include "roots.h"
static constexpr const char* CACHE_LOG_DIR = "/cache/recovery"; static constexpr const char* CACHE_LOG_DIR = "/cache/recovery";
static constexpr const char* COMMAND_FILE = "/cache/recovery/command"; static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
@@ -79,7 +79,7 @@ static constexpr const char* METADATA_ROOT = "/metadata";
// into target_files.zip. Assert the version defined in code and in Android.mk are consistent. // into target_files.zip. Assert the version defined in code and in Android.mk are consistent.
static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions."); static_assert(kRecoveryApiVersion == RECOVERY_API_VERSION, "Mismatching recovery API versions.");
bool modified_flash = false; static bool modified_flash = false;
std::string stage; std::string stage;
const char* reason = nullptr; const char* reason = nullptr;
@@ -439,7 +439,7 @@ static std::unique_ptr<Package> ReadWipePackage(size_t wipe_package_size) {
// 1. verify the package. // 1. verify the package.
// 2. check metadata (ota-type, pre-device and serial number if having one). // 2. check metadata (ota-type, pre-device and serial number if having one).
static bool CheckWipePackage(Package* wipe_package) { static bool CheckWipePackage(Package* wipe_package) {
if (!verify_package(wipe_package)) { if (!verify_package(wipe_package, ui)) {
LOG(ERROR) << "Failed to verify package"; LOG(ERROR) << "Failed to verify package";
return false; return false;
} }
@@ -693,7 +693,7 @@ static Device::BuiltinAction prompt_and_wait(Device* device, int status) {
modified_flash = true; modified_flash = true;
bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD); bool adb = (chosen_action == Device::APPLY_ADB_SIDELOAD);
if (adb) { if (adb) {
status = apply_from_adb(&should_wipe_cache); status = apply_from_adb(&should_wipe_cache, ui);
} else { } else {
status = ApplyFromSdcard(device, &should_wipe_cache, ui); status = ApplyFromSdcard(device, &should_wipe_cache, ui);
} }
@@ -1030,7 +1030,8 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri
set_retry_bootloader_message(retry_count + 1, args); set_retry_bootloader_message(retry_count + 1, args);
} }
status = install_package(update_package, &should_wipe_cache, true, retry_count); modified_flash = true;
status = install_package(update_package, &should_wipe_cache, true, retry_count, ui);
if (status == INSTALL_SUCCESS && should_wipe_cache) { if (status == INSTALL_SUCCESS && should_wipe_cache) {
wipe_cache(false, device); wipe_cache(false, device);
} }
@@ -1096,7 +1097,7 @@ Device::BuiltinAction start_recovery(Device* device, const std::vector<std::stri
if (!sideload_auto_reboot) { if (!sideload_auto_reboot) {
ui->ShowText(true); ui->ShowText(true);
} }
status = apply_from_adb(&should_wipe_cache); status = apply_from_adb(&should_wipe_cache, ui);
if (status == INSTALL_SUCCESS && should_wipe_cache) { if (status == INSTALL_SUCCESS && should_wipe_cache) {
if (!wipe_cache(false, device)) { if (!wipe_cache(false, device)) {
status = INSTALL_ERROR; status = INSTALL_ERROR;
+1 -1
View File
@@ -53,12 +53,12 @@
#include "logging.h" #include "logging.h"
#include "minadbd/minadbd.h" #include "minadbd/minadbd.h"
#include "otautil/paths.h" #include "otautil/paths.h"
#include "otautil/roots.h"
#include "otautil/sysutil.h" #include "otautil/sysutil.h"
#include "recovery.h" #include "recovery.h"
#include "recovery_ui/device.h" #include "recovery_ui/device.h"
#include "recovery_ui/stub_ui.h" #include "recovery_ui/stub_ui.h"
#include "recovery_ui/ui.h" #include "recovery_ui/ui.h"
#include "roots.h"
static constexpr const char* COMMAND_FILE = "/cache/recovery/command"; static constexpr const char* COMMAND_FILE = "/cache/recovery/command";
static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale"; static constexpr const char* LOCALE_FILE = "/cache/recovery/last_locale";
+3 -4
View File
@@ -76,9 +76,9 @@ libapplypatch_static_libs = [
librecovery_static_libs = [ librecovery_static_libs = [
"librecovery", "librecovery",
"librecovery_fastboot", "librecovery_fastboot",
"libinstall",
"librecovery_ui",
"libminui", "libminui",
"libpackage",
"libverifier",
"libotautil", "libotautil",
"libhealthhalutils", "libhealthhalutils",
@@ -116,10 +116,9 @@ cc_test {
], ],
static_libs: libapplypatch_static_libs + [ static_libs: libapplypatch_static_libs + [
"libinstall",
"librecovery_ui", "librecovery_ui",
"libminui", "libminui",
"libpackage",
"libverifier",
"libotautil", "libotautil",
"libupdater", "libupdater",
"libgtest_prod", "libgtest_prod",
+2 -2
View File
@@ -32,9 +32,9 @@
#include <ziparchive/zip_archive.h> #include <ziparchive/zip_archive.h>
#include <ziparchive/zip_writer.h> #include <ziparchive/zip_writer.h>
#include "install.h" #include "install/install.h"
#include "otautil/paths.h" #include "otautil/paths.h"
#include "private/install.h" #include "private/setup_commands.h"
static void BuildZipArchive(const std::map<std::string, std::string>& file_map, int fd, static void BuildZipArchive(const std::map<std::string, std::string>& file_map, int fd,
int compression_type) { int compression_type) {
+2 -2
View File
@@ -35,9 +35,9 @@
#include <ziparchive/zip_writer.h> #include <ziparchive/zip_writer.h>
#include "common/test_constants.h" #include "common/test_constants.h"
#include "install/package.h"
#include "install/verifier.h"
#include "otautil/sysutil.h" #include "otautil/sysutil.h"
#include "package.h"
#include "verifier.h"
using namespace std::string_literals; using namespace std::string_literals;
+1 -1
View File
@@ -20,7 +20,7 @@
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include "asn1_decoder.h" #include "private/asn1_decoder.h"
TEST(Asn1DecoderTest, Empty_Failure) { TEST(Asn1DecoderTest, Empty_Failure) {
uint8_t empty[] = {}; uint8_t empty[] = {};
+1 -1
View File
@@ -26,7 +26,7 @@
#include <ziparchive/zip_writer.h> #include <ziparchive/zip_writer.h>
#include "common/test_constants.h" #include "common/test_constants.h"
#include "package.h" #include "install/package.h"
class PackageTest : public ::testing::Test { class PackageTest : public ::testing::Test {
protected: protected: