Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 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 agree 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 | |
| 17 | #include <errno.h> |
| 18 | #include <fcntl.h> |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 21 | #include <sys/stat.h> |
Mattias Nissler | 452df6d | 2016-04-04 16:17:01 +0200 | [diff] [blame] | 22 | #include <sys/types.h> |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 23 | |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 24 | #include <string> |
| 25 | #include <vector> |
| 26 | |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 27 | #include <android-base/file.h> |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 28 | #include <android-base/stringprintf.h> |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 29 | #include <android-base/strings.h> |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 30 | #include <android-base/test_utils.h> |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 31 | #include <android-base/unique_fd.h> |
Tao Bao | 17054c0 | 2018-05-03 22:41:23 -0700 | [diff] [blame] | 32 | #include <gtest/gtest.h> |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 33 | #include <ziparchive/zip_writer.h> |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 34 | |
Jed Estep | b8a693b | 2016-03-09 17:51:34 -0800 | [diff] [blame] | 35 | #include "common/test_constants.h" |
Tao Bao | 17054c0 | 2018-05-03 22:41:23 -0700 | [diff] [blame] | 36 | #include "otautil/sysutil.h" |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 37 | #include "verifier.h" |
| 38 | |
Tao Bao | 056e2da | 2017-03-26 23:25:11 -0700 | [diff] [blame] | 39 | using namespace std::string_literals; |
| 40 | |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 41 | static void LoadKeyFromFile(const std::string& file_name, Certificate* cert) { |
| 42 | std::string testkey_string; |
| 43 | ASSERT_TRUE(android::base::ReadFileToString(file_name, &testkey_string)); |
| 44 | ASSERT_TRUE(LoadCertificateFromBuffer( |
| 45 | std::vector<uint8_t>(testkey_string.begin(), testkey_string.end()), cert)); |
| 46 | } |
| 47 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 48 | static void VerifyPackageWithCertificates(const std::string& name, |
| 49 | const std::vector<Certificate>& certs) { |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 50 | std::string package = from_testdata_base(name); |
| 51 | MemMapping memmap; |
| 52 | if (!memmap.MapFile(package)) { |
| 53 | FAIL() << "Failed to mmap " << package << ": " << strerror(errno) << "\n"; |
| 54 | } |
| 55 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 56 | ASSERT_EQ(VERIFY_SUCCESS, verify_file(memmap.addr, memmap.length, certs)); |
| 57 | } |
| 58 | |
| 59 | static void VerifyPackageWithSingleCertificate(const std::string& name, Certificate&& cert) { |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 60 | std::vector<Certificate> certs; |
| 61 | certs.emplace_back(std::move(cert)); |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 62 | VerifyPackageWithCertificates(name, certs); |
| 63 | } |
| 64 | |
| 65 | static void BuildCertificateArchive(const std::vector<std::string>& file_names, int fd) { |
| 66 | FILE* zip_file_ptr = fdopen(fd, "wb"); |
| 67 | ZipWriter zip_writer(zip_file_ptr); |
| 68 | |
| 69 | for (const auto& name : file_names) { |
| 70 | std::string content; |
| 71 | ASSERT_TRUE(android::base::ReadFileToString(name, &content)); |
| 72 | |
| 73 | // Makes sure the zip entry name has the correct suffix. |
| 74 | std::string entry_name = name; |
| 75 | if (!android::base::EndsWith(entry_name, "x509.pem")) { |
| 76 | entry_name += "x509.pem"; |
| 77 | } |
| 78 | ASSERT_EQ(0, zip_writer.StartEntry(entry_name.c_str(), ZipWriter::kCompress)); |
| 79 | ASSERT_EQ(0, zip_writer.WriteBytes(content.data(), content.size())); |
| 80 | ASSERT_EQ(0, zip_writer.FinishEntry()); |
| 81 | } |
| 82 | |
| 83 | ASSERT_EQ(0, zip_writer.Finish()); |
| 84 | ASSERT_EQ(0, fclose(zip_file_ptr)); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | TEST(VerifierTest, LoadCertificateFromBuffer_failure) { |
| 88 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 89 | std::string testkey_string; |
| 90 | ASSERT_TRUE( |
| 91 | android::base::ReadFileToString(from_testdata_base("testkey_v1.txt"), &testkey_string)); |
| 92 | ASSERT_FALSE(LoadCertificateFromBuffer( |
| 93 | std::vector<uint8_t>(testkey_string.begin(), testkey_string.end()), &cert)); |
| 94 | } |
| 95 | |
| 96 | TEST(VerifierTest, LoadCertificateFromBuffer_sha1_exponent3) { |
| 97 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 98 | LoadKeyFromFile(from_testdata_base("testkey_v1.x509.pem"), &cert); |
| 99 | |
| 100 | ASSERT_EQ(SHA_DIGEST_LENGTH, cert.hash_len); |
| 101 | ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type); |
| 102 | ASSERT_EQ(nullptr, cert.ec); |
| 103 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 104 | VerifyPackageWithSingleCertificate("otasigned_v1.zip", std::move(cert)); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | TEST(VerifierTest, LoadCertificateFromBuffer_sha1_exponent65537) { |
| 108 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 109 | LoadKeyFromFile(from_testdata_base("testkey_v2.x509.pem"), &cert); |
| 110 | |
| 111 | ASSERT_EQ(SHA_DIGEST_LENGTH, cert.hash_len); |
| 112 | ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type); |
| 113 | ASSERT_EQ(nullptr, cert.ec); |
| 114 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 115 | VerifyPackageWithSingleCertificate("otasigned_v2.zip", std::move(cert)); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | TEST(VerifierTest, LoadCertificateFromBuffer_sha256_exponent3) { |
| 119 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 120 | LoadKeyFromFile(from_testdata_base("testkey_v3.x509.pem"), &cert); |
| 121 | |
| 122 | ASSERT_EQ(SHA256_DIGEST_LENGTH, cert.hash_len); |
| 123 | ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type); |
| 124 | ASSERT_EQ(nullptr, cert.ec); |
| 125 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 126 | VerifyPackageWithSingleCertificate("otasigned_v3.zip", std::move(cert)); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | TEST(VerifierTest, LoadCertificateFromBuffer_sha256_exponent65537) { |
| 130 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 131 | LoadKeyFromFile(from_testdata_base("testkey_v4.x509.pem"), &cert); |
| 132 | |
| 133 | ASSERT_EQ(SHA256_DIGEST_LENGTH, cert.hash_len); |
| 134 | ASSERT_EQ(Certificate::KEY_TYPE_RSA, cert.key_type); |
| 135 | ASSERT_EQ(nullptr, cert.ec); |
| 136 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 137 | VerifyPackageWithSingleCertificate("otasigned_v4.zip", std::move(cert)); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | TEST(VerifierTest, LoadCertificateFromBuffer_sha256_ec256bits) { |
| 141 | Certificate cert(0, Certificate::KEY_TYPE_RSA, nullptr, nullptr); |
| 142 | LoadKeyFromFile(from_testdata_base("testkey_v5.x509.pem"), &cert); |
| 143 | |
| 144 | ASSERT_EQ(SHA256_DIGEST_LENGTH, cert.hash_len); |
| 145 | ASSERT_EQ(Certificate::KEY_TYPE_EC, cert.key_type); |
| 146 | ASSERT_EQ(nullptr, cert.rsa); |
| 147 | |
Tianjie Xu | 0dd9685 | 2018-10-15 11:44:14 -0700 | [diff] [blame] | 148 | VerifyPackageWithSingleCertificate("otasigned_v5.zip", std::move(cert)); |
| 149 | } |
| 150 | |
| 151 | TEST(VerifierTest, LoadKeysFromZipfile_empty_archive) { |
| 152 | TemporaryFile otacerts; |
| 153 | BuildCertificateArchive({}, otacerts.release()); |
| 154 | std::vector<Certificate> certs = LoadKeysFromZipfile(otacerts.path); |
| 155 | ASSERT_TRUE(certs.empty()); |
| 156 | } |
| 157 | |
| 158 | TEST(VerifierTest, LoadKeysFromZipfile_single_key) { |
| 159 | TemporaryFile otacerts; |
| 160 | BuildCertificateArchive({ from_testdata_base("testkey_v1.x509.pem") }, otacerts.release()); |
| 161 | std::vector<Certificate> certs = LoadKeysFromZipfile(otacerts.path); |
| 162 | ASSERT_EQ(1, certs.size()); |
| 163 | |
| 164 | VerifyPackageWithCertificates("otasigned_v1.zip", certs); |
| 165 | } |
| 166 | |
| 167 | TEST(VerifierTest, LoadKeysFromZipfile_corrupted_key) { |
| 168 | TemporaryFile corrupted_key; |
| 169 | std::string content; |
| 170 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v1.x509.pem"), &content)); |
| 171 | content = "random-contents" + content; |
| 172 | ASSERT_TRUE(android::base::WriteStringToFd(content, corrupted_key.release())); |
| 173 | |
| 174 | TemporaryFile otacerts; |
| 175 | BuildCertificateArchive({ from_testdata_base("testkey_v2.x509.pem"), corrupted_key.path }, |
| 176 | otacerts.release()); |
| 177 | std::vector<Certificate> certs = LoadKeysFromZipfile(otacerts.path); |
| 178 | ASSERT_EQ(0, certs.size()); |
| 179 | } |
| 180 | |
| 181 | TEST(VerifierTest, LoadKeysFromZipfile_multiple_key) { |
| 182 | TemporaryFile otacerts; |
| 183 | BuildCertificateArchive( |
| 184 | { |
| 185 | from_testdata_base("testkey_v3.x509.pem"), |
| 186 | from_testdata_base("testkey_v4.x509.pem"), |
| 187 | from_testdata_base("testkey_v5.x509.pem"), |
| 188 | |
| 189 | }, |
| 190 | otacerts.release()); |
| 191 | std::vector<Certificate> certs = LoadKeysFromZipfile(otacerts.path); |
| 192 | ASSERT_EQ(3, certs.size()); |
| 193 | |
| 194 | VerifyPackageWithCertificates("otasigned_v3.zip", certs); |
| 195 | VerifyPackageWithCertificates("otasigned_v4.zip", certs); |
| 196 | VerifyPackageWithCertificates("otasigned_v5.zip", certs); |
Tianjie Xu | 8256698 | 2018-10-10 15:44:17 -0700 | [diff] [blame] | 197 | } |
| 198 | |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 199 | class VerifierTest : public testing::TestWithParam<std::vector<std::string>> { |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 200 | protected: |
| 201 | void SetUp() override { |
| 202 | std::vector<std::string> args = GetParam(); |
| 203 | std::string package = from_testdata_base(args[0]); |
Tao Bao | b656a15 | 2017-04-18 23:54:29 -0700 | [diff] [blame] | 204 | if (!memmap.MapFile(package)) { |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 205 | FAIL() << "Failed to mmap " << package << ": " << strerror(errno) << "\n"; |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 206 | } |
| 207 | |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 208 | for (auto it = ++args.cbegin(); it != args.cend(); ++it) { |
| 209 | std::string public_key_file = from_testdata_base("testkey_" + *it + ".txt"); |
| 210 | ASSERT_TRUE(load_keys(public_key_file.c_str(), certs)); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 211 | } |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | MemMapping memmap; |
| 215 | std::vector<Certificate> certs; |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 216 | }; |
| 217 | |
| 218 | class VerifierSuccessTest : public VerifierTest { |
| 219 | }; |
| 220 | |
| 221 | class VerifierFailureTest : public VerifierTest { |
| 222 | }; |
| 223 | |
Tao Bao | 3116ce4 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 224 | TEST(VerifierTest, load_keys_multiple_keys) { |
| 225 | std::string testkey_v4; |
| 226 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v4.txt"), &testkey_v4)); |
| 227 | |
| 228 | std::string testkey_v3; |
| 229 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3)); |
| 230 | |
| 231 | std::string keys = testkey_v4 + "," + testkey_v3 + "," + testkey_v4; |
| 232 | TemporaryFile key_file1; |
| 233 | ASSERT_TRUE(android::base::WriteStringToFile(keys, key_file1.path)); |
| 234 | std::vector<Certificate> certs; |
| 235 | ASSERT_TRUE(load_keys(key_file1.path, certs)); |
| 236 | ASSERT_EQ(3U, certs.size()); |
| 237 | } |
| 238 | |
| 239 | TEST(VerifierTest, load_keys_invalid_keys) { |
| 240 | std::vector<Certificate> certs; |
| 241 | ASSERT_FALSE(load_keys("/doesntexist", certs)); |
| 242 | |
| 243 | // Empty file. |
| 244 | TemporaryFile key_file1; |
| 245 | ASSERT_FALSE(load_keys(key_file1.path, certs)); |
| 246 | |
| 247 | // Invalid contents. |
| 248 | ASSERT_TRUE(android::base::WriteStringToFile("invalid", key_file1.path)); |
| 249 | ASSERT_FALSE(load_keys(key_file1.path, certs)); |
| 250 | |
| 251 | std::string testkey_v4; |
| 252 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v4.txt"), &testkey_v4)); |
| 253 | |
| 254 | // Invalid key version: "v4 ..." => "v6 ...". |
| 255 | std::string invalid_key2(testkey_v4); |
| 256 | invalid_key2[1] = '6'; |
| 257 | TemporaryFile key_file2; |
| 258 | ASSERT_TRUE(android::base::WriteStringToFile(invalid_key2, key_file2.path)); |
| 259 | ASSERT_FALSE(load_keys(key_file2.path, certs)); |
| 260 | |
| 261 | // Invalid key content: inserted extra bytes ",2209831334". |
| 262 | std::string invalid_key3(testkey_v4); |
| 263 | invalid_key3.insert(invalid_key2.size() - 2, ",2209831334"); |
| 264 | TemporaryFile key_file3; |
| 265 | ASSERT_TRUE(android::base::WriteStringToFile(invalid_key3, key_file3.path)); |
| 266 | ASSERT_FALSE(load_keys(key_file3.path, certs)); |
| 267 | |
| 268 | // Invalid key: the last key must not end with an extra ','. |
| 269 | std::string invalid_key4 = testkey_v4 + ","; |
| 270 | TemporaryFile key_file4; |
| 271 | ASSERT_TRUE(android::base::WriteStringToFile(invalid_key4, key_file4.path)); |
| 272 | ASSERT_FALSE(load_keys(key_file4.path, certs)); |
| 273 | |
| 274 | // Invalid key separator. |
| 275 | std::string invalid_key5 = testkey_v4 + ";" + testkey_v4; |
| 276 | TemporaryFile key_file5; |
| 277 | ASSERT_TRUE(android::base::WriteStringToFile(invalid_key5, key_file5.path)); |
| 278 | ASSERT_FALSE(load_keys(key_file5.path, certs)); |
| 279 | } |
| 280 | |
Tao Bao | 7e61c6a | 2017-03-20 16:57:25 -0700 | [diff] [blame] | 281 | TEST(VerifierTest, BadPackage_AlteredFooter) { |
| 282 | std::string testkey_v3; |
| 283 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3)); |
| 284 | TemporaryFile key_file1; |
| 285 | ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path)); |
| 286 | std::vector<Certificate> certs; |
| 287 | ASSERT_TRUE(load_keys(key_file1.path, certs)); |
| 288 | |
| 289 | std::string package; |
| 290 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package)); |
| 291 | ASSERT_EQ(std::string("\xc0\x06\xff\xff\xd2\x06", 6), package.substr(package.size() - 6, 6)); |
| 292 | |
| 293 | // Alter the footer. |
| 294 | package[package.size() - 5] = '\x05'; |
| 295 | ASSERT_EQ(VERIFY_FAILURE, |
| 296 | verify_file(reinterpret_cast<const unsigned char*>(package.data()), package.size(), |
| 297 | certs)); |
| 298 | } |
| 299 | |
| 300 | TEST(VerifierTest, BadPackage_AlteredContent) { |
| 301 | std::string testkey_v3; |
| 302 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3)); |
| 303 | TemporaryFile key_file1; |
| 304 | ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path)); |
| 305 | std::vector<Certificate> certs; |
| 306 | ASSERT_TRUE(load_keys(key_file1.path, certs)); |
| 307 | |
| 308 | std::string package; |
| 309 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package)); |
| 310 | ASSERT_GT(package.size(), static_cast<size_t>(100)); |
| 311 | |
| 312 | // Alter the content. |
| 313 | std::string altered1(package); |
| 314 | altered1[50] += 1; |
| 315 | ASSERT_EQ(VERIFY_FAILURE, |
| 316 | verify_file(reinterpret_cast<const unsigned char*>(altered1.data()), altered1.size(), |
| 317 | certs)); |
| 318 | |
| 319 | std::string altered2(package); |
| 320 | altered2[10] += 1; |
| 321 | ASSERT_EQ(VERIFY_FAILURE, |
| 322 | verify_file(reinterpret_cast<const unsigned char*>(altered2.data()), altered2.size(), |
| 323 | certs)); |
| 324 | } |
| 325 | |
Tao Bao | 056e2da | 2017-03-26 23:25:11 -0700 | [diff] [blame] | 326 | TEST(VerifierTest, BadPackage_SignatureStartOutOfBounds) { |
| 327 | std::string testkey_v3; |
| 328 | ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3)); |
| 329 | |
| 330 | TemporaryFile key_file; |
| 331 | ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file.path)); |
| 332 | std::vector<Certificate> certs; |
| 333 | ASSERT_TRUE(load_keys(key_file.path, certs)); |
| 334 | |
| 335 | // Signature start is 65535 (0xffff) while comment size is 0 (Bug: 31914369). |
| 336 | std::string package = "\x50\x4b\x05\x06"s + std::string(12, '\0') + "\xff\xff\xff\xff\x00\x00"s; |
| 337 | ASSERT_EQ(VERIFY_FAILURE, verify_file(reinterpret_cast<const unsigned char*>(package.data()), |
| 338 | package.size(), certs)); |
| 339 | } |
| 340 | |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 341 | TEST_P(VerifierSuccessTest, VerifySucceed) { |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 342 | ASSERT_EQ(verify_file(memmap.addr, memmap.length, certs, nullptr), VERIFY_SUCCESS); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | TEST_P(VerifierFailureTest, VerifyFailure) { |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 346 | ASSERT_EQ(verify_file(memmap.addr, memmap.length, certs, nullptr), VERIFY_FAILURE); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | INSTANTIATE_TEST_CASE_P(SingleKeySuccess, VerifierSuccessTest, |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 350 | ::testing::Values( |
| 351 | std::vector<std::string>({"otasigned_v1.zip", "v1"}), |
| 352 | std::vector<std::string>({"otasigned_v2.zip", "v2"}), |
| 353 | std::vector<std::string>({"otasigned_v3.zip", "v3"}), |
| 354 | std::vector<std::string>({"otasigned_v4.zip", "v4"}), |
| 355 | std::vector<std::string>({"otasigned_v5.zip", "v5"}))); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 356 | |
| 357 | INSTANTIATE_TEST_CASE_P(MultiKeySuccess, VerifierSuccessTest, |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 358 | ::testing::Values( |
| 359 | std::vector<std::string>({"otasigned_v1.zip", "v1", "v2"}), |
| 360 | std::vector<std::string>({"otasigned_v2.zip", "v5", "v2"}), |
| 361 | std::vector<std::string>({"otasigned_v3.zip", "v5", "v1", "v3"}), |
| 362 | std::vector<std::string>({"otasigned_v4.zip", "v5", "v1", "v4"}), |
| 363 | std::vector<std::string>({"otasigned_v5.zip", "v4", "v1", "v5"}))); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 364 | |
| 365 | INSTANTIATE_TEST_CASE_P(WrongKey, VerifierFailureTest, |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 366 | ::testing::Values( |
| 367 | std::vector<std::string>({"otasigned_v1.zip", "v2"}), |
| 368 | std::vector<std::string>({"otasigned_v2.zip", "v1"}), |
| 369 | std::vector<std::string>({"otasigned_v3.zip", "v5"}), |
| 370 | std::vector<std::string>({"otasigned_v4.zip", "v5"}), |
| 371 | std::vector<std::string>({"otasigned_v5.zip", "v3"}))); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 372 | |
| 373 | INSTANTIATE_TEST_CASE_P(WrongHash, VerifierFailureTest, |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 374 | ::testing::Values( |
| 375 | std::vector<std::string>({"otasigned_v1.zip", "v3"}), |
| 376 | std::vector<std::string>({"otasigned_v2.zip", "v4"}), |
| 377 | std::vector<std::string>({"otasigned_v3.zip", "v1"}), |
| 378 | std::vector<std::string>({"otasigned_v4.zip", "v2"}))); |
Jed Estep | 4329186 | 2016-02-03 17:02:09 -0800 | [diff] [blame] | 379 | |
| 380 | INSTANTIATE_TEST_CASE_P(BadPackage, VerifierFailureTest, |
Tao Bao | 7b22c92 | 2017-03-16 17:37:38 -0700 | [diff] [blame] | 381 | ::testing::Values( |
| 382 | std::vector<std::string>({"random.zip", "v1"}), |
Tao Bao | 7e61c6a | 2017-03-20 16:57:25 -0700 | [diff] [blame] | 383 | std::vector<std::string>({"fake-eocd.zip", "v1"}))); |