The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 17 | #include "install.h" |
| 18 | |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 19 | #include <ctype.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 20 | #include <errno.h> |
| 21 | #include <fcntl.h> |
Alex Deymo | 4e29ce0 | 2016-08-12 13:43:04 -0700 | [diff] [blame] | 22 | #include <inttypes.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 23 | #include <limits.h> |
Elliott Hughes | 26dbad2 | 2015-01-28 12:09:05 -0800 | [diff] [blame] | 24 | #include <string.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 25 | #include <sys/stat.h> |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 26 | #include <sys/wait.h> |
| 27 | #include <unistd.h> |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 28 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 29 | #include <chrono> |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 30 | #include <limits> |
| 31 | #include <map> |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 32 | #include <string> |
Tao Bao | 71e3e09 | 2016-02-02 14:02:27 -0800 | [diff] [blame] | 33 | #include <vector> |
| 34 | |
Tianjie Xu | e16e799 | 2016-09-09 10:55:44 -0700 | [diff] [blame] | 35 | #include <android-base/file.h> |
| 36 | #include <android-base/logging.h> |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 37 | #include <android-base/parsedouble.h> |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 38 | #include <android-base/parseint.h> |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 39 | #include <android-base/stringprintf.h> |
| 40 | #include <android-base/strings.h> |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 41 | #include <cutils/properties.h> |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 42 | #include <ziparchive/zip_archive.h> |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 43 | |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 44 | #include "common.h" |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 45 | #include "error_code.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 46 | #include "minui/minui.h" |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 47 | #include "otautil/SysUtil.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 48 | #include "roots.h" |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 49 | #include "ui.h" |
Mattias Nissler | 452df6d | 2016-04-04 16:17:01 +0200 | [diff] [blame] | 50 | #include "verifier.h" |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 51 | |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 52 | #define ASSUMED_UPDATE_BINARY_NAME "META-INF/com/google/android/update-binary" |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 53 | static constexpr const char* AB_OTA_PAYLOAD_PROPERTIES = "payload_properties.txt"; |
| 54 | static constexpr const char* AB_OTA_PAYLOAD = "payload.bin"; |
Doug Zongker | d1b19b9 | 2009-04-01 15:48:46 -0700 | [diff] [blame] | 55 | #define PUBLIC_KEYS_FILE "/res/keys" |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 56 | static constexpr const char* METADATA_PATH = "META-INF/com/android/metadata"; |
Tianjie Xu | e16e799 | 2016-09-09 10:55:44 -0700 | [diff] [blame] | 57 | static constexpr const char* UNCRYPT_STATUS = "/cache/recovery/uncrypt_status"; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 58 | |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 59 | // Default allocation of progress bar segments to operations |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 60 | static constexpr int VERIFICATION_PROGRESS_TIME = 60; |
| 61 | static constexpr float VERIFICATION_PROGRESS_FRACTION = 0.25; |
| 62 | static constexpr float DEFAULT_FILES_PROGRESS_FRACTION = 0.4; |
| 63 | static constexpr float DEFAULT_IMAGE_PROGRESS_FRACTION = 0.1; |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 64 | |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 65 | // This function parses and returns the build.version.incremental |
Chih-Hung Hsieh | 8b23811 | 2016-08-26 14:54:29 -0700 | [diff] [blame] | 66 | static int parse_build_number(const std::string& str) { |
| 67 | size_t pos = str.find('='); |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 68 | if (pos != std::string::npos) { |
| 69 | std::string num_string = android::base::Trim(str.substr(pos+1)); |
| 70 | int build_number; |
| 71 | if (android::base::ParseInt(num_string.c_str(), &build_number, 0)) { |
| 72 | return build_number; |
| 73 | } |
| 74 | } |
| 75 | |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 76 | LOG(ERROR) << "Failed to parse build number in " << str; |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 77 | return -1; |
| 78 | } |
| 79 | |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 80 | bool read_metadata_from_package(ZipArchiveHandle zip, std::string* meta_data) { |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 81 | ZipString metadata_path(METADATA_PATH); |
| 82 | ZipEntry meta_entry; |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 83 | if (meta_data == nullptr) { |
| 84 | LOG(ERROR) << "string* meta_data can't be nullptr"; |
| 85 | return false; |
| 86 | } |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 87 | if (FindEntry(zip, metadata_path, &meta_entry) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 88 | LOG(ERROR) << "Failed to find " << METADATA_PATH << " in update package"; |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 89 | return false; |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 92 | meta_data->resize(meta_entry.uncompressed_length, '\0'); |
| 93 | if (ExtractToMemory(zip, &meta_entry, reinterpret_cast<uint8_t*>(&(*meta_data)[0]), |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 94 | meta_entry.uncompressed_length) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 95 | LOG(ERROR) << "Failed to read metadata in update package"; |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 96 | return false; |
| 97 | } |
| 98 | return true; |
| 99 | } |
| 100 | |
| 101 | // Read the build.version.incremental of src/tgt from the metadata and log it to last_install. |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 102 | static void read_source_target_build(ZipArchiveHandle zip, std::vector<std::string>& log_buffer) { |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 103 | std::string meta_data; |
| 104 | if (!read_metadata_from_package(zip, &meta_data)) { |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 105 | return; |
| 106 | } |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 107 | // Examples of the pre-build and post-build strings in metadata: |
| 108 | // pre-build-incremental=2943039 |
| 109 | // post-build-incremental=2951741 |
| 110 | std::vector<std::string> lines = android::base::Split(meta_data, "\n"); |
| 111 | for (const std::string& line : lines) { |
| 112 | std::string str = android::base::Trim(line); |
| 113 | if (android::base::StartsWith(str, "pre-build-incremental")){ |
| 114 | int source_build = parse_build_number(str); |
| 115 | if (source_build != -1) { |
| 116 | log_buffer.push_back(android::base::StringPrintf("source_build: %d", |
| 117 | source_build)); |
| 118 | } |
| 119 | } else if (android::base::StartsWith(str, "post-build-incremental")) { |
| 120 | int target_build = parse_build_number(str); |
| 121 | if (target_build != -1) { |
| 122 | log_buffer.push_back(android::base::StringPrintf("target_build: %d", |
| 123 | target_build)); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 129 | // Extract the update binary from the open zip archive |zip| located at |path| |
| 130 | // and store into |cmd| the command line that should be called. The |status_fd| |
| 131 | // is the file descriptor the child process should use to report back the |
| 132 | // progress of the update. |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 133 | static int |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 134 | update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 135 | int status_fd, std::vector<std::string>* cmd); |
Tianjie Xu | b0ddae5 | 2016-06-08 14:30:04 -0700 | [diff] [blame] | 136 | |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 137 | #ifdef AB_OTA_UPDATER |
| 138 | |
| 139 | // Parses the metadata of the OTA package in |zip| and checks whether we are |
| 140 | // allowed to accept this A/B package. Downgrading is not allowed unless |
| 141 | // explicitly enabled in the package and only for incremental packages. |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 142 | static int check_newer_ab_build(ZipArchiveHandle zip) |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 143 | { |
| 144 | std::string metadata_str; |
| 145 | if (!read_metadata_from_package(zip, &metadata_str)) { |
| 146 | return INSTALL_CORRUPT; |
| 147 | } |
| 148 | std::map<std::string, std::string> metadata; |
| 149 | for (const std::string& line : android::base::Split(metadata_str, "\n")) { |
| 150 | size_t eq = line.find('='); |
| 151 | if (eq != std::string::npos) { |
| 152 | metadata[line.substr(0, eq)] = line.substr(eq + 1); |
| 153 | } |
| 154 | } |
| 155 | char value[PROPERTY_VALUE_MAX]; |
| 156 | |
| 157 | property_get("ro.product.device", value, ""); |
| 158 | const std::string& pkg_device = metadata["pre-device"]; |
| 159 | if (pkg_device != value || pkg_device.empty()) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 160 | LOG(ERROR) << "Package is for product " << pkg_device << " but expected " << value; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 161 | return INSTALL_ERROR; |
| 162 | } |
| 163 | |
| 164 | // We allow the package to not have any serialno, but if it has a non-empty |
| 165 | // value it should match. |
| 166 | property_get("ro.serialno", value, ""); |
| 167 | const std::string& pkg_serial_no = metadata["serialno"]; |
| 168 | if (!pkg_serial_no.empty() && pkg_serial_no != value) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 169 | LOG(ERROR) << "Package is for serial " << pkg_serial_no; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 170 | return INSTALL_ERROR; |
| 171 | } |
| 172 | |
| 173 | if (metadata["ota-type"] != "AB") { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 174 | LOG(ERROR) << "Package is not A/B"; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 175 | return INSTALL_ERROR; |
| 176 | } |
| 177 | |
| 178 | // Incremental updates should match the current build. |
| 179 | property_get("ro.build.version.incremental", value, ""); |
| 180 | const std::string& pkg_pre_build = metadata["pre-build-incremental"]; |
| 181 | if (!pkg_pre_build.empty() && pkg_pre_build != value) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 182 | LOG(ERROR) << "Package is for source build " << pkg_pre_build << " but expected " << value; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 183 | return INSTALL_ERROR; |
| 184 | } |
| 185 | property_get("ro.build.fingerprint", value, ""); |
| 186 | const std::string& pkg_pre_build_fingerprint = metadata["pre-build"]; |
| 187 | if (!pkg_pre_build_fingerprint.empty() && |
| 188 | pkg_pre_build_fingerprint != value) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 189 | LOG(ERROR) << "Package is for source build " << pkg_pre_build_fingerprint |
| 190 | << " but expected " << value; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 191 | return INSTALL_ERROR; |
| 192 | } |
| 193 | |
| 194 | // Check for downgrade version. |
Tianjie Xu | 073451a | 2016-09-01 11:51:17 -0700 | [diff] [blame] | 195 | int64_t build_timestamp = property_get_int64( |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 196 | "ro.build.date.utc", std::numeric_limits<int64_t>::max()); |
Tianjie Xu | 073451a | 2016-09-01 11:51:17 -0700 | [diff] [blame] | 197 | int64_t pkg_post_timestamp = 0; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 198 | // We allow to full update to the same version we are running, in case there |
| 199 | // is a problem with the current copy of that version. |
| 200 | if (metadata["post-timestamp"].empty() || |
| 201 | !android::base::ParseInt(metadata["post-timestamp"].c_str(), |
Tianjie Xu | 073451a | 2016-09-01 11:51:17 -0700 | [diff] [blame] | 202 | &pkg_post_timestamp) || |
| 203 | pkg_post_timestamp < build_timestamp) { |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 204 | if (metadata["ota-downgrade"] != "yes") { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 205 | LOG(ERROR) << "Update package is older than the current build, expected a build " |
Tianjie Xu | 073451a | 2016-09-01 11:51:17 -0700 | [diff] [blame] | 206 | "newer than timestamp " << build_timestamp << " but package has " |
| 207 | "timestamp " << pkg_post_timestamp << " and downgrade not allowed."; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 208 | return INSTALL_ERROR; |
| 209 | } |
| 210 | if (pkg_pre_build_fingerprint.empty()) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 211 | LOG(ERROR) << "Downgrade package must have a pre-build version set, not allowed."; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 212 | return INSTALL_ERROR; |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | static int |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 220 | update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 221 | int status_fd, std::vector<std::string>* cmd) |
| 222 | { |
| 223 | int ret = check_newer_ab_build(zip); |
| 224 | if (ret) { |
| 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | // For A/B updates we extract the payload properties to a buffer and obtain |
| 229 | // the RAW payload offset in the zip file. |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 230 | ZipString property_name(AB_OTA_PAYLOAD_PROPERTIES); |
| 231 | ZipEntry properties_entry; |
| 232 | if (FindEntry(zip, property_name, &properties_entry) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 233 | LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD_PROPERTIES; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 234 | return INSTALL_CORRUPT; |
| 235 | } |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 236 | std::vector<uint8_t> payload_properties( |
| 237 | properties_entry.uncompressed_length); |
| 238 | if (ExtractToMemory(zip, &properties_entry, payload_properties.data(), |
| 239 | properties_entry.uncompressed_length) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 240 | LOG(ERROR) << "Can't extract " << AB_OTA_PAYLOAD_PROPERTIES; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 241 | return INSTALL_CORRUPT; |
| 242 | } |
| 243 | |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 244 | ZipString payload_name(AB_OTA_PAYLOAD); |
| 245 | ZipEntry payload_entry; |
| 246 | if (FindEntry(zip, payload_name, &payload_entry) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 247 | LOG(ERROR) << "Can't find " << AB_OTA_PAYLOAD; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 248 | return INSTALL_CORRUPT; |
| 249 | } |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 250 | long payload_offset = payload_entry.offset; |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 251 | *cmd = { |
| 252 | "/sbin/update_engine_sideload", |
| 253 | android::base::StringPrintf("--payload=file://%s", path), |
| 254 | android::base::StringPrintf("--offset=%ld", payload_offset), |
| 255 | "--headers=" + std::string(payload_properties.begin(), |
| 256 | payload_properties.end()), |
| 257 | android::base::StringPrintf("--status_fd=%d", status_fd), |
| 258 | }; |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | #else // !AB_OTA_UPDATER |
| 263 | |
| 264 | static int |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 265 | update_binary_command(const char* path, ZipArchiveHandle zip, int retry_count, |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 266 | int status_fd, std::vector<std::string>* cmd) |
| 267 | { |
| 268 | // On traditional updates we extract the update binary from the package. |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 269 | ZipString binary_name(ASSUMED_UPDATE_BINARY_NAME); |
| 270 | ZipEntry binary_entry; |
| 271 | if (FindEntry(zip, binary_name, &binary_entry) != 0) { |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 272 | return INSTALL_CORRUPT; |
| 273 | } |
| 274 | |
Doug Zongker | 10e418d | 2011-10-28 10:33:05 -0700 | [diff] [blame] | 275 | const char* binary = "/tmp/update_binary"; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 276 | unlink(binary); |
| 277 | int fd = creat(binary, 0755); |
| 278 | if (fd < 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 279 | PLOG(ERROR) << "Can't make " << binary; |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 280 | return INSTALL_ERROR; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 281 | } |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 282 | int error = ExtractEntryToFile(zip, &binary_entry, fd); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 283 | close(fd); |
| 284 | |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 285 | if (error != 0) { |
| 286 | LOG(ERROR) << "Can't copy " << ASSUMED_UPDATE_BINARY_NAME |
| 287 | << " : " << ErrorCodeString(error); |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 288 | return INSTALL_ERROR; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 291 | *cmd = { |
| 292 | binary, |
| 293 | EXPAND(RECOVERY_API_VERSION), // defined in Android.mk |
| 294 | std::to_string(status_fd), |
| 295 | path, |
| 296 | }; |
| 297 | if (retry_count > 0) |
| 298 | cmd->push_back("retry"); |
| 299 | return 0; |
| 300 | } |
| 301 | #endif // !AB_OTA_UPDATER |
| 302 | |
| 303 | // If the package contains an update binary, extract it and run it. |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 304 | static int try_update_binary(const char* path, ZipArchiveHandle zip, bool* wipe_cache, |
| 305 | std::vector<std::string>& log_buffer, int retry_count) { |
| 306 | read_source_target_build(zip, log_buffer); |
Alex Deymo | 4344d63 | 2016-08-03 21:03:53 -0700 | [diff] [blame] | 307 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 308 | int pipefd[2]; |
| 309 | pipe(pipefd); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 310 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 311 | std::vector<std::string> args; |
| 312 | int ret = update_binary_command(path, zip, retry_count, pipefd[1], &args); |
| 313 | if (ret) { |
| 314 | close(pipefd[0]); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 315 | close(pipefd[1]); |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 316 | return ret; |
| 317 | } |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 318 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 319 | // When executing the update binary contained in the package, the |
| 320 | // arguments passed are: |
| 321 | // |
| 322 | // - the version number for this interface |
| 323 | // |
| 324 | // - an FD to which the program can write in order to update the |
| 325 | // progress bar. The program can write single-line commands: |
| 326 | // |
| 327 | // progress <frac> <secs> |
| 328 | // fill up the next <frac> part of of the progress bar |
| 329 | // over <secs> seconds. If <secs> is zero, use |
| 330 | // set_progress commands to manually control the |
| 331 | // progress of this segment of the bar. |
| 332 | // |
| 333 | // set_progress <frac> |
| 334 | // <frac> should be between 0.0 and 1.0; sets the |
| 335 | // progress bar within the segment defined by the most |
| 336 | // recent progress command. |
| 337 | // |
| 338 | // ui_print <string> |
| 339 | // display <string> on the screen. |
| 340 | // |
| 341 | // wipe_cache |
| 342 | // a wipe of cache will be performed following a successful |
| 343 | // installation. |
| 344 | // |
| 345 | // clear_display |
| 346 | // turn off the text display. |
| 347 | // |
| 348 | // enable_reboot |
| 349 | // packages can explicitly request that they want the user |
| 350 | // to be able to reboot during installation (useful for |
| 351 | // debugging packages that don't exit). |
| 352 | // |
| 353 | // retry_update |
| 354 | // updater encounters some issue during the update. It requests |
| 355 | // a reboot to retry the same package automatically. |
| 356 | // |
| 357 | // log <string> |
| 358 | // updater requests logging the string (e.g. cause of the |
| 359 | // failure). |
| 360 | // |
| 361 | // - the name of the package zip file. |
| 362 | // |
| 363 | // - an optional argument "retry" if this update is a retry of a failed |
| 364 | // update attempt. |
| 365 | // |
Doug Zongker | d0181b8 | 2011-10-19 10:51:12 -0700 | [diff] [blame] | 366 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 367 | // Convert the vector to a NULL-terminated char* array suitable for execv. |
| 368 | const char* chr_args[args.size() + 1]; |
| 369 | chr_args[args.size()] = nullptr; |
| 370 | for (size_t i = 0; i < args.size(); i++) { |
| 371 | chr_args[i] = args[i].c_str(); |
| 372 | } |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 373 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 374 | pid_t pid = fork(); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 375 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 376 | if (pid == -1) { |
| 377 | close(pipefd[0]); |
| 378 | close(pipefd[1]); |
| 379 | PLOG(ERROR) << "Failed to fork update binary"; |
| 380 | return INSTALL_ERROR; |
| 381 | } |
| 382 | |
| 383 | if (pid == 0) { |
| 384 | umask(022); |
| 385 | close(pipefd[0]); |
| 386 | execv(chr_args[0], const_cast<char**>(chr_args)); |
| 387 | PLOG(ERROR) << "Can't run " << chr_args[0]; |
| 388 | _exit(-1); |
| 389 | } |
| 390 | close(pipefd[1]); |
| 391 | |
| 392 | *wipe_cache = false; |
| 393 | bool retry_update = false; |
| 394 | |
| 395 | char buffer[1024]; |
| 396 | FILE* from_child = fdopen(pipefd[0], "r"); |
| 397 | while (fgets(buffer, sizeof(buffer), from_child) != nullptr) { |
| 398 | std::string line(buffer); |
| 399 | size_t space = line.find_first_of(" \n"); |
| 400 | std::string command(line.substr(0, space)); |
| 401 | if (command.empty()) continue; |
| 402 | |
| 403 | // Get rid of the leading and trailing space and/or newline. |
| 404 | std::string args = space == std::string::npos ? "" : android::base::Trim(line.substr(space)); |
| 405 | |
| 406 | if (command == "progress") { |
| 407 | std::vector<std::string> tokens = android::base::Split(args, " "); |
| 408 | double fraction; |
| 409 | int seconds; |
| 410 | if (tokens.size() == 2 && android::base::ParseDouble(tokens[0].c_str(), &fraction) && |
| 411 | android::base::ParseInt(tokens[1], &seconds)) { |
| 412 | ui->ShowProgress(fraction * (1 - VERIFICATION_PROGRESS_FRACTION), seconds); |
| 413 | } else { |
| 414 | LOG(ERROR) << "invalid \"progress\" parameters: " << line; |
| 415 | } |
| 416 | } else if (command == "set_progress") { |
| 417 | std::vector<std::string> tokens = android::base::Split(args, " "); |
| 418 | double fraction; |
| 419 | if (tokens.size() == 1 && android::base::ParseDouble(tokens[0].c_str(), &fraction)) { |
| 420 | ui->SetProgress(fraction); |
| 421 | } else { |
| 422 | LOG(ERROR) << "invalid \"set_progress\" parameters: " << line; |
| 423 | } |
| 424 | } else if (command == "ui_print") { |
| 425 | if (!args.empty()) { |
| 426 | ui->PrintOnScreenOnly("%s", args.c_str()); |
| 427 | } else { |
| 428 | ui->PrintOnScreenOnly("\n"); |
| 429 | } |
| 430 | fflush(stdout); |
| 431 | } else if (command == "wipe_cache") { |
| 432 | *wipe_cache = true; |
| 433 | } else if (command == "clear_display") { |
| 434 | ui->SetBackground(RecoveryUI::NONE); |
| 435 | } else if (command == "enable_reboot") { |
| 436 | // packages can explicitly request that they want the user |
| 437 | // to be able to reboot during installation (useful for |
| 438 | // debugging packages that don't exit). |
| 439 | ui->SetEnableReboot(true); |
| 440 | } else if (command == "retry_update") { |
| 441 | retry_update = true; |
| 442 | } else if (command == "log") { |
| 443 | if (!args.empty()) { |
| 444 | // Save the logging request from updater and write to last_install later. |
| 445 | log_buffer.push_back(args); |
| 446 | } else { |
| 447 | LOG(ERROR) << "invalid \"log\" parameters: " << line; |
| 448 | } |
| 449 | } else { |
| 450 | LOG(ERROR) << "unknown command [" << command << "]"; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 451 | } |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 452 | } |
| 453 | fclose(from_child); |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 454 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 455 | int status; |
| 456 | waitpid(pid, &status, 0); |
| 457 | if (retry_update) { |
| 458 | return INSTALL_RETRY; |
| 459 | } |
| 460 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 461 | LOG(ERROR) << "Error in " << path << " (Status " << WEXITSTATUS(status) << ")"; |
| 462 | return INSTALL_ERROR; |
| 463 | } |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 464 | |
Tao Bao | 20c581e | 2016-12-28 20:55:51 -0800 | [diff] [blame] | 465 | return INSTALL_SUCCESS; |
Doug Zongker | b2ee920 | 2009-06-04 10:24:53 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 468 | static int |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 469 | really_install_package(const char *path, bool* wipe_cache, bool needs_mount, |
Tianjie Xu | 7ce287d | 2016-05-31 09:29:49 -0700 | [diff] [blame] | 470 | std::vector<std::string>& log_buffer, int retry_count) |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 471 | { |
Doug Zongker | 02ec6b8 | 2012-08-22 17:26:40 -0700 | [diff] [blame] | 472 | ui->SetBackground(RecoveryUI::INSTALLING_UPDATE); |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 473 | ui->Print("Finding update package...\n"); |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 474 | // Give verification half the progress bar... |
| 475 | ui->SetProgressType(RecoveryUI::DETERMINATE); |
| 476 | ui->ShowProgress(VERIFICATION_PROGRESS_FRACTION, VERIFICATION_PROGRESS_TIME); |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 477 | LOG(INFO) << "Update location: " << path; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 478 | |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 479 | // Map the update package into memory. |
| 480 | ui->Print("Opening update package...\n"); |
| 481 | |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 482 | if (path && needs_mount) { |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 483 | if (path[0] == '@') { |
| 484 | ensure_path_mounted(path+1); |
| 485 | } else { |
| 486 | ensure_path_mounted(path); |
| 487 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 488 | } |
| 489 | |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 490 | MemMapping map; |
| 491 | if (sysMapFile(path, &map) != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 492 | LOG(ERROR) << "failed to map file"; |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 493 | return INSTALL_CORRUPT; |
| 494 | } |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 495 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 496 | // Verify package. |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 497 | if (!verify_package(map.addr, map.length)) { |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 498 | log_buffer.push_back(android::base::StringPrintf("error: %d", kZipVerificationFailure)); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 499 | sysReleaseMap(&map); |
Doug Zongker | 60151a2 | 2009-08-12 18:30:03 -0700 | [diff] [blame] | 500 | return INSTALL_CORRUPT; |
| 501 | } |
| 502 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 503 | // Try to open the package. |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 504 | ZipArchiveHandle zip; |
Tianjie Xu | 8176cf2 | 2016-10-18 14:13:07 -0700 | [diff] [blame] | 505 | int err = OpenArchiveFromMemory(map.addr, map.length, path, &zip); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 506 | if (err != 0) { |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 507 | LOG(ERROR) << "Can't open " << path << " : " << ErrorCodeString(err); |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 508 | log_buffer.push_back(android::base::StringPrintf("error: %d", kZipOpenFailure)); |
| 509 | |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 510 | sysReleaseMap(&map); |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 511 | CloseArchive(zip); |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 512 | return INSTALL_CORRUPT; |
| 513 | } |
| 514 | |
Elliott Hughes | 8febafa | 2016-04-13 16:39:56 -0700 | [diff] [blame] | 515 | // Verify and install the contents of the package. |
Doug Zongker | 7440630 | 2011-10-28 15:13:10 -0700 | [diff] [blame] | 516 | ui->Print("Installing update...\n"); |
Tianjie Xu | 7ce287d | 2016-05-31 09:29:49 -0700 | [diff] [blame] | 517 | if (retry_count > 0) { |
| 518 | ui->Print("Retry attempt: %d\n", retry_count); |
| 519 | } |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 520 | ui->SetEnableReboot(false); |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 521 | int result = try_update_binary(path, zip, wipe_cache, log_buffer, retry_count); |
Doug Zongker | c704e06 | 2014-05-23 08:40:35 -0700 | [diff] [blame] | 522 | ui->SetEnableReboot(true); |
Doug Zongker | 075ad80 | 2014-06-26 15:35:51 -0700 | [diff] [blame] | 523 | ui->Print("\n"); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 524 | |
| 525 | sysReleaseMap(&map); |
Tianjie Xu | 8cf5c8f | 2016-09-08 20:10:11 -0700 | [diff] [blame] | 526 | CloseArchive(zip); |
Doug Zongker | 99916f0 | 2014-01-13 14:16:58 -0800 | [diff] [blame] | 527 | return result; |
The Android Open Source Project | c24a8e6 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 528 | } |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 529 | |
| 530 | int |
Tao Bao | 145d861 | 2015-03-25 15:51:15 -0700 | [diff] [blame] | 531 | install_package(const char* path, bool* wipe_cache, const char* install_file, |
Tianjie Xu | 1625583 | 2016-04-30 11:49:59 -0700 | [diff] [blame] | 532 | bool needs_mount, int retry_count) |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 533 | { |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 534 | modified_flash = true; |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 535 | auto start = std::chrono::system_clock::now(); |
Tao Bao | 682c34b | 2015-04-07 17:16:35 -0700 | [diff] [blame] | 536 | |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 537 | int result; |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 538 | std::vector<std::string> log_buffer; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 539 | if (setup_install_mounts() != 0) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 540 | LOG(ERROR) << "failed to set up expected mounts for install; aborting"; |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 541 | result = INSTALL_ERROR; |
| 542 | } else { |
Tianjie Xu | 7ce287d | 2016-05-31 09:29:49 -0700 | [diff] [blame] | 543 | result = really_install_package(path, wipe_cache, needs_mount, log_buffer, retry_count); |
Doug Zongker | 239ac6a | 2013-08-20 16:03:25 -0700 | [diff] [blame] | 544 | } |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 545 | |
Tao Bao | badaac4 | 2016-09-26 11:39:14 -0700 | [diff] [blame] | 546 | // Measure the time spent to apply OTA update in seconds. |
| 547 | std::chrono::duration<double> duration = std::chrono::system_clock::now() - start; |
| 548 | int time_total = static_cast<int>(duration.count()); |
Tianjie Xu | dd874b1 | 2016-05-13 12:13:15 -0700 | [diff] [blame] | 549 | |
Tao Bao | badaac4 | 2016-09-26 11:39:14 -0700 | [diff] [blame] | 550 | if (ensure_path_mounted(UNCRYPT_STATUS) != 0) { |
| 551 | LOG(WARNING) << "Can't mount " << UNCRYPT_STATUS; |
| 552 | } else { |
| 553 | std::string uncrypt_status; |
| 554 | if (!android::base::ReadFileToString(UNCRYPT_STATUS, &uncrypt_status)) { |
| 555 | PLOG(WARNING) << "failed to read uncrypt status"; |
Tianjie Xu | 68fc81e | 2016-09-24 15:31:34 -0700 | [diff] [blame] | 556 | } else if (!android::base::StartsWith(uncrypt_status, "uncrypt_")) { |
Tao Bao | 1709d22 | 2016-10-13 16:04:07 -0700 | [diff] [blame] | 557 | LOG(WARNING) << "corrupted uncrypt_status: " << uncrypt_status; |
Tianjie Xu | e16e799 | 2016-09-09 10:55:44 -0700 | [diff] [blame] | 558 | } else { |
Tao Bao | badaac4 | 2016-09-26 11:39:14 -0700 | [diff] [blame] | 559 | log_buffer.push_back(android::base::Trim(uncrypt_status)); |
Tianjie Xu | e16e799 | 2016-09-09 10:55:44 -0700 | [diff] [blame] | 560 | } |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 561 | } |
Tao Bao | badaac4 | 2016-09-26 11:39:14 -0700 | [diff] [blame] | 562 | |
| 563 | // The first two lines need to be the package name and install result. |
| 564 | std::vector<std::string> log_header = { |
| 565 | path, |
| 566 | result == INSTALL_SUCCESS ? "1" : "0", |
| 567 | "time_total: " + std::to_string(time_total), |
| 568 | "retry: " + std::to_string(retry_count), |
| 569 | }; |
| 570 | std::string log_content = android::base::Join(log_header, "\n") + "\n" + |
| 571 | android::base::Join(log_buffer, "\n"); |
| 572 | if (!android::base::WriteStringToFile(log_content, install_file)) { |
| 573 | PLOG(ERROR) << "failed to write " << install_file; |
| 574 | } |
| 575 | |
| 576 | // Write a copy into last_log. |
| 577 | LOG(INFO) << log_content; |
| 578 | |
Doug Zongker | 469243e | 2011-04-12 09:28:10 -0700 | [diff] [blame] | 579 | return result; |
| 580 | } |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 581 | |
| 582 | bool verify_package(const unsigned char* package_data, size_t package_size) { |
| 583 | std::vector<Certificate> loadedKeys; |
| 584 | if (!load_keys(PUBLIC_KEYS_FILE, loadedKeys)) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 585 | LOG(ERROR) << "Failed to load keys"; |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 586 | return false; |
| 587 | } |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 588 | LOG(INFO) << loadedKeys.size() << " key(s) loaded from " << PUBLIC_KEYS_FILE; |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 589 | |
| 590 | // Verify package. |
| 591 | ui->Print("Verifying update package...\n"); |
| 592 | auto t0 = std::chrono::system_clock::now(); |
| 593 | int err = verify_file(const_cast<unsigned char*>(package_data), package_size, loadedKeys); |
| 594 | std::chrono::duration<double> duration = std::chrono::system_clock::now() - t0; |
| 595 | ui->Print("Update package verification took %.1f s (result %d).\n", duration.count(), err); |
| 596 | if (err != VERIFY_SUCCESS) { |
Tianjie Xu | c21edd4 | 2016-08-05 18:00:04 -0700 | [diff] [blame] | 597 | LOG(ERROR) << "Signature verification failed"; |
| 598 | LOG(ERROR) << "error: " << kZipVerificationFailure; |
Yabin Cui | 6faf026 | 2016-06-09 14:09:39 -0700 | [diff] [blame] | 599 | return false; |
| 600 | } |
| 601 | return true; |
| 602 | } |