Lines Matching +full:use +full:- +full:base +full:- +full:image
7 * restriction, including without limitation the rights to use, copy,
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 #include <base/files/file_util.h>
32 #include <base/strings/string_split.h>
33 #include <base/strings/string_util.h>
34 #include <base/strings/stringprintf.h>
59 base::FilePath* rootfs_path);
71 base::FilePath path = testdir_.Append("version.txt"); in TEST_F()
74 ASSERT_TRUE(base::ReadFileToString(path, &printed_version)); in TEST_F()
75 base::TrimWhitespaceASCII(printed_version, base::TRIM_ALL, &printed_version); in TEST_F()
86 base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
100 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
101 "--append_to_release_string \"Woot XYZ\""); in TEST_F()
119 EXPECT_GT(expected_str.size(), (size_t)(AVB_RELEASE_STRING_SIZE - 1)); in TEST_F()
120 expected_str.resize(AVB_RELEASE_STRING_SIZE - 1); in TEST_F()
126 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
127 std::string("--append_to_release_string \"") + append_str + "\""); in TEST_F()
145 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
146 "--internal_release_string \"\""); in TEST_F()
149 PublicKeyAVB(base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
168 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
169 "--prop foo:brillo " in TEST_F()
170 "--prop bar:chromeos " in TEST_F()
171 "--prop prisoner:24601 " in TEST_F()
172 "--prop hexnumber:0xcafe " in TEST_F()
173 "--prop hexnumber_capital:0xCAFE " in TEST_F()
174 "--prop large_hexnumber:0xfedcba9876543210 " in TEST_F()
175 "--prop larger_than_uint64:0xfedcba98765432101 " in TEST_F()
176 "--prop almost_a_number:423x " in TEST_F()
177 "--prop_from_file blob:test/data/small_blob.bin " in TEST_F()
178 "--internal_release_string \"\""); in TEST_F()
202 vbmeta_image_.data(), vbmeta_image_.size(), "non-existant", 0, &len); in TEST_F()
244 // Number-parsing failures. in TEST_F()
258 // test/data/small_blob.bin is 21 byte file full of NUL-bytes except in TEST_F()
274 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
275 "--internal_release_string \"\""); in TEST_F()
280 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
281 "--internal_release_string \"\" --padding_size 4096"); in TEST_F()
283 base::FilePath vbmeta_path = testdir_.Append("vbmeta.img"); in TEST_F()
284 base::FilePath vbmeta_padded_path = testdir_.Append("vbmeta_padded.img"); in TEST_F()
286 ASSERT_TRUE(base::GetFileSize(vbmeta_path, &vbmeta_size)); in TEST_F()
287 ASSERT_TRUE(base::GetFileSize(vbmeta_padded_path, &vbmeta_padded_size)); in TEST_F()
304 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
305 "--internal_release_string \"\""); in TEST_F()
320 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
321 "--internal_release_string \"\""); in TEST_F()
337 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
338 base::StringPrintf("--rollback_index_location %d", in TEST_F()
354 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
355 "--internal_release_string \"\""); in TEST_F()
381 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
382 "--prop foo:brillo " in TEST_F()
383 "--prop bar:chromeos " in TEST_F()
384 "--prop prisoner:24601 " in TEST_F()
385 "--prop hexnumber:0xcafe " in TEST_F()
386 "--prop hexnumber_capital:0xCAFE " in TEST_F()
387 "--prop large_hexnumber:0xfedcba9876543210 " in TEST_F()
388 "--prop larger_than_uint64:0xfedcba98765432101 " in TEST_F()
389 "--prop almost_a_number:423x " in TEST_F()
390 "--prop_from_file blob:test/data/small_blob.bin " in TEST_F()
391 "--prop_from_file large_blob:test/data/large_blob.bin " in TEST_F()
392 "--internal_release_string \"\""); in TEST_F()
406 " Prop: foo -> 'brillo'\n" in TEST_F()
407 " Prop: bar -> 'chromeos'\n" in TEST_F()
408 " Prop: prisoner -> '24601'\n" in TEST_F()
409 " Prop: hexnumber -> '0xcafe'\n" in TEST_F()
410 " Prop: hexnumber_capital -> '0xCAFE'\n" in TEST_F()
411 " Prop: large_hexnumber -> '0xfedcba9876543210'\n" in TEST_F()
412 " Prop: larger_than_uint64 -> '0xfedcba98765432101'\n" in TEST_F()
413 " Prop: almost_a_number -> '423x'\n" in TEST_F()
414 " Prop: blob -> '\\x00\\x00brillo " in TEST_F()
416 " Prop: large_blob -> (2048 bytes)\n", in TEST_F()
424 descriptors->push_back(descriptor); in collect_descriptors()
430 return base::StringPrintf( in AddHashFooterGetExpectedVBMetaInfo()
432 "Image size: %" PRIu64 in AddHashFooterGetExpectedVBMetaInfo()
434 "Original image size: 1052672 bytes\n" in AddHashFooterGetExpectedVBMetaInfo()
437 "--\n" in AddHashFooterGetExpectedVBMetaInfo()
450 " Image Size: 1052672 bytes\n" in AddHashFooterGetExpectedVBMetaInfo()
480 base::FilePath external_vbmeta_path = testdir_.Append("external_vbmeta.bin"); in AddHashFooterTest()
481 base::FilePath extracted_vbmeta_path = in AddHashFooterTest()
483 base::FilePath rootfs_path = testdir_.Append("rootfs.bin"); in AddHashFooterTest()
486 base::WriteFile(rootfs_path, in AddHashFooterTest()
499 EXPECT_COMMAND(0, "rm -f %s.unsparse", rootfs_path.value().c_str()); in AddHashFooterTest()
505 "./avbtool.py add_hash_footer --salt d00df00d " in AddHashFooterTest()
506 "--hash_algorithm sha256 --image %s " in AddHashFooterTest()
507 "--partition_size %d --partition_name foobar " in AddHashFooterTest()
508 "--algorithm SHA256_RSA2048 " in AddHashFooterTest()
509 "--key test/data/testkey_rsa2048.pem " in AddHashFooterTest()
510 "--output_vbmeta %s " in AddHashFooterTest()
511 "--internal_release_string \"\"", in AddHashFooterTest()
532 " Image Size: 1052672 bytes\n" in AddHashFooterTest()
544 "./avbtool.py extract_vbmeta_image --image %s " in AddHashFooterTest()
545 "--output %s", in AddHashFooterTest()
554 // Resize the image and check that the only thing that has changed in AddHashFooterTest()
560 "./avbtool.py resize_image --image %s " in AddHashFooterTest()
561 "--partition_size %d", in AddHashFooterTest()
563 (int)(rootfs_size - 16 * 1024)); in AddHashFooterTest()
565 "./avbtool.py resize_image --image %s " in AddHashFooterTest()
566 "--partition_size %d", in AddHashFooterTest()
582 EXPECT_COMMAND(0, "rm -f %s.sparse", rootfs_path.value().c_str()); in AddHashFooterTest()
597 ASSERT_TRUE(base::ReadFileToString(rootfs_path, &part_data)); in AddHashFooterTest()
604 part_data.data() + part_data.size() - AVB_FOOTER_SIZE), in AddHashFooterTest()
615 // Check that the vbmeta image at |f.vbmeta_offset| checks out. in AddHashFooterTest()
629 EXPECT_EQ(AVB_DESCRIPTOR_TAG_HASH, avb_be64toh(descriptors[0]->tag)); in AddHashFooterTest()
653 0, "./avbtool.py erase_footer --image %s", rootfs_path.value().c_str()); in AddHashFooterTest()
655 ASSERT_TRUE(base::GetFileSize(rootfs_path, &erased_footer_file_size)); in AddHashFooterTest()
658 // Check that --do_not_append_vbmeta_image works as intended. in AddHashFooterTest()
659 // In this case we don't modify the input image so it should work read-only. in AddHashFooterTest()
660 EXPECT_COMMAND(0, "chmod a-w %s", rootfs_path.value().c_str()); in AddHashFooterTest()
662 "./avbtool.py add_hash_footer --salt d00df00d " in AddHashFooterTest()
663 "--hash_algorithm sha256 --image %s " in AddHashFooterTest()
664 "--partition_size %d --partition_name foobar " in AddHashFooterTest()
665 "--algorithm SHA256_RSA2048 " in AddHashFooterTest()
666 "--key test/data/testkey_rsa2048.pem " in AddHashFooterTest()
667 "--output_vbmeta %s_2nd_run --do_not_append_vbmeta_image " in AddHashFooterTest()
668 "--internal_release_string \"\"", in AddHashFooterTest()
673 ASSERT_TRUE(base::GetFileSize(rootfs_path, &file_size)); in AddHashFooterTest()
694 lines = base::SplitString( in RemoveLinesStartingWith()
695 str, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); in RemoveLinesStartingWith()
697 if (!base::StartsWith(line, prefix, base::CompareCase::SENSITIVE)) { in RemoveLinesStartingWith()
705 // NOTE: make_ext4fs was removed and there is no replacement for how we use
713 // 0x00000000)" and not "Don't care". Instead, use make_ext4fs for in TEST_F()
716 base::FilePath partition_path = testdir_.Append("partition.bin"); in TEST_F()
718 "make_ext4fs -s -L test -l %zd %s", in TEST_F()
719 partition_size - metadata_size, in TEST_F()
723 "./avbtool.py add_hash_footer --salt d00df00d " in TEST_F()
724 "--hash_algorithm sha256 --image %s " in TEST_F()
725 "--partition_size %d --partition_name foobar " in TEST_F()
726 "--algorithm SHA256_RSA2048 " in TEST_F()
727 "--key test/data/testkey_rsa2048.pem " in TEST_F()
728 "--internal_release_string \"\"", in TEST_F()
734 // disk image may slightly change. It's enough to just remove the in TEST_F()
740 "Image size: 10485760 bytes\n" in TEST_F()
741 "Original image size: 10354688 bytes\n" in TEST_F()
744 "--\n" in TEST_F()
757 " Image Size: 10354688 bytes\n" in TEST_F()
772 EXPECT_COMMAND(0, "rm -f %s.sparse", partition_path.value().c_str()); in TEST_F()
777 base::FilePath output_path = testdir_.Append("max_size.txt"); in TEST_F()
781 "--partition_size %zd " in TEST_F()
782 "--calc_max_image_size > %s", in TEST_F()
786 EXPECT_TRUE(base::ReadFileToString(output_path, &max_image_size_data)); in TEST_F()
791 EXPECT_EQ(68 * 1024ULL, partition_size - max_image_size); in TEST_F()
793 // Check that we can add a hash footer for an image this size for in TEST_F()
795 base::FilePath boot_path = GenerateImage("boot", max_image_size); in TEST_F()
798 " --image %s" in TEST_F()
799 " --partition_name boot" in TEST_F()
800 " --partition_size %zd" in TEST_F()
801 " --salt deadbeef" in TEST_F()
802 " --algorithm SHA512_RSA4096 " in TEST_F()
803 " --key test/data/testkey_rsa4096.pem" in TEST_F()
804 " --internal_release_string \"\"", in TEST_F()
811 base::FilePath path = GenerateImage("digest_location", 1024); in TEST_F()
814 "--hash_algorithm sha256 --image %s " in TEST_F()
815 "--partition_size %d --partition_name foobar " in TEST_F()
816 "--algorithm SHA256_RSA2048 " in TEST_F()
817 "--key test/data/testkey_rsa2048.pem " in TEST_F()
818 "--internal_release_string \"\" " in TEST_F()
819 "--use_persistent_digest", in TEST_F()
824 // Hash descriptor -> Digest = (empty) in TEST_F()
827 "Image size: 1048576 bytes\n" in TEST_F()
828 "Original image size: 1024 bytes\n" in TEST_F()
831 "--\n" in TEST_F()
844 " Image Size: 1024 bytes\n" in TEST_F()
855 base::FilePath path = GenerateImage("digest_location", 1024); in TEST_F()
857 "./avbtool.py add_hash_footer --salt d00df00d " in TEST_F()
858 "--hash_algorithm sha256 --image %s " in TEST_F()
859 "--partition_size %d --partition_name foobar " in TEST_F()
860 "--algorithm SHA256_RSA2048 " in TEST_F()
861 "--key test/data/testkey_rsa2048.pem " in TEST_F()
862 "--internal_release_string \"\" " in TEST_F()
863 "--do_not_use_ab", in TEST_F()
868 // Hash descriptor -> Flags = 1 in TEST_F()
871 "Image size: 1048576 bytes\n" in TEST_F()
872 "Original image size: 1024 bytes\n" in TEST_F()
875 "--\n" in TEST_F()
888 " Image Size: 1024 bytes\n" in TEST_F()
900 base::FilePath path = GenerateImage("digest_location", 1024); in TEST_F()
903 "--hash_algorithm sha256 --image %s " in TEST_F()
904 "--partition_size %d --partition_name foobar " in TEST_F()
905 "--algorithm SHA256_RSA2048 " in TEST_F()
906 "--key test/data/testkey_rsa2048.pem " in TEST_F()
907 "--internal_release_string \"\" " in TEST_F()
908 "--use_persistent_digest --do_not_use_ab", in TEST_F()
913 // Hash descriptor -> Digest = (empty) in TEST_F()
914 // Hash descriptor -> Flags = 1 in TEST_F()
917 "Image size: 1048576 bytes\n" in TEST_F()
918 "Original image size: 1024 bytes\n" in TEST_F()
921 "--\n" in TEST_F()
934 " Image Size: 1024 bytes\n" in TEST_F()
947 base::FilePath* output_rootfs_path) { in CreateRootfsWithHashtreeFooter()
956 base::FilePath external_vbmeta_path = testdir_.Append("external_vbmeta.bin"); in CreateRootfsWithHashtreeFooter()
957 base::FilePath extracted_vbmeta_path = in CreateRootfsWithHashtreeFooter()
959 base::FilePath rootfs_path = testdir_.Append("rootfs.bin"); in CreateRootfsWithHashtreeFooter()
962 base::WriteFile(rootfs_path, in CreateRootfsWithHashtreeFooter()
975 EXPECT_COMMAND(0, "rm -f %s.unsparse", rootfs_path.value().c_str()); in CreateRootfsWithHashtreeFooter()
981 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in CreateRootfsWithHashtreeFooter()
982 "--hash_algorithm %s " in CreateRootfsWithHashtreeFooter()
983 "--partition_size %d --partition_name foobar " in CreateRootfsWithHashtreeFooter()
984 "--algorithm SHA256_RSA2048 " in CreateRootfsWithHashtreeFooter()
985 "--key test/data/testkey_rsa2048.pem " in CreateRootfsWithHashtreeFooter()
986 "--output_vbmeta_image %s " in CreateRootfsWithHashtreeFooter()
987 "--internal_release_string \"\" " in CreateRootfsWithHashtreeFooter()
988 "--do_not_generate_fec", in CreateRootfsWithHashtreeFooter()
994 ASSERT_EQ(base::StringPrintf("Footer version: 1.0\n" in CreateRootfsWithHashtreeFooter()
995 "Image size: 1572864 bytes\n" in CreateRootfsWithHashtreeFooter()
996 "Original image size: 1052672 bytes\n" in CreateRootfsWithHashtreeFooter()
999 "--\n" in CreateRootfsWithHashtreeFooter()
1013 " Version of dm-verity: 1\n" in CreateRootfsWithHashtreeFooter()
1014 " Image Size: 1052672 bytes\n" in CreateRootfsWithHashtreeFooter()
1033 ASSERT_EQ(base::StringPrintf("Minimum libavb version: 1.0\n" in CreateRootfsWithHashtreeFooter()
1046 " Version of dm-verity: 1\n" in CreateRootfsWithHashtreeFooter()
1047 " Image Size: 1052672 bytes\n" in CreateRootfsWithHashtreeFooter()
1067 "./avbtool.py extract_vbmeta_image --image %s " in CreateRootfsWithHashtreeFooter()
1068 "--output %s", in CreateRootfsWithHashtreeFooter()
1081 base::FilePath rootfs_path; in AddHashtreeFooterTest()
1087 /* Zero the hashtree on a copy of the image. */ in AddHashtreeFooterTest()
1093 "./avbtool.py zero_hashtree --image %s.zht ", in AddHashtreeFooterTest()
1105 EXPECT_COMMAND(0, "rm -f %s.sparse", rootfs_path.value().c_str()); in AddHashtreeFooterTest()
1115 EXPECT_COMMAND(0, "rm -f %s.zht.sparse", rootfs_path.value().c_str()); in AddHashtreeFooterTest()
1118 // To check that we generate the correct hashtree we can use in AddHashtreeFooterTest()
1119 // veritysetup(1) - another codebase for working with dm-verity in AddHashtreeFooterTest()
1120 // hashtrees - to verify it. in AddHashtreeFooterTest()
1126 "veritysetup --no-superblock --format=1 --hash=sha1 " in AddHashtreeFooterTest()
1127 "--data-block-size=4096 --hash-block-size=4096 " in AddHashtreeFooterTest()
1128 "--salt=d00df00d " in AddHashtreeFooterTest()
1129 "--data-blocks=257 " in AddHashtreeFooterTest()
1130 "--hash-offset=1052672 " in AddHashtreeFooterTest()
1139 ASSERT_TRUE(base::ReadFileToString(rootfs_path, &part_data)); in AddHashtreeFooterTest()
1141 // Also read the zeroed hash-tree version. in AddHashtreeFooterTest()
1143 ASSERT_TRUE(base::ReadFileToString( in AddHashtreeFooterTest()
1144 base::FilePath(rootfs_path.value() + ".zht"), &zht_part_data)); in AddHashtreeFooterTest()
1151 part_data.data() + part_data.size() - AVB_FOOTER_SIZE), in AddHashtreeFooterTest()
1162 // Check that the vbmeta image at |f.vbmeta_offset| checks out. in AddHashtreeFooterTest()
1176 EXPECT_EQ(AVB_DESCRIPTOR_TAG_HASHTREE, avb_be64toh(descriptors[0]->tag)); in AddHashtreeFooterTest()
1214 zht_fec_end - zht_ht_begin)); in AddHashtreeFooterTest()
1218 zht_part_data.size() - zht_fec_end)); in AddHashtreeFooterTest()
1230 // Check that we correctly generate dm-verity kernel cmdline in AddHashtreeFooterTest()
1232 base::FilePath vbmeta_dmv_path = testdir_.Append("vbmeta_dm_verity_desc.bin"); in AddHashtreeFooterTest()
1235 "--output %s " in AddHashtreeFooterTest()
1236 "--setup_rootfs_from_kernel %s " in AddHashtreeFooterTest()
1237 "--algorithm SHA256_RSA2048 " in AddHashtreeFooterTest()
1238 "--key test/data/testkey_rsa2048.pem " in AddHashtreeFooterTest()
1239 "--internal_release_string \"\"", in AddHashtreeFooterTest()
1260 "d00df00d 2 $(ANDROID_VERITY_MODE) ignore_zero_blocks\" root=/dev/dm-0'\n" in AddHashtreeFooterTest()
1268 // remains - see above for why the constant 1069056 is used. in AddHashtreeFooterTest()
1270 "./avbtool.py erase_footer --image %s --keep_hashtree", in AddHashtreeFooterTest()
1273 ASSERT_TRUE(base::GetFileSize(rootfs_path, &erased_footer_file_size)); in AddHashtreeFooterTest()
1278 base::FilePath external_vbmeta_path = testdir_.Append("external_vbmeta.bin"); in AddHashtreeFooterTest()
1279 // Check that --do_not_append_vbmeta_image works as intended. in AddHashtreeFooterTest()
1281 // For this we need to reset the size of the image to the original in AddHashtreeFooterTest()
1284 0, "truncate -s %d %s", (int)rootfs_size, rootfs_path.value().c_str()); in AddHashtreeFooterTest()
1286 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in AddHashtreeFooterTest()
1287 "--partition_size %d --partition_name foobar " in AddHashtreeFooterTest()
1288 "--algorithm SHA256_RSA2048 " in AddHashtreeFooterTest()
1289 "--key test/data/testkey_rsa2048.pem " in AddHashtreeFooterTest()
1290 "--output_vbmeta %s_2nd_run --do_not_append_vbmeta_image " in AddHashtreeFooterTest()
1291 "--internal_release_string \"\" " in AddHashtreeFooterTest()
1292 "--do_not_generate_fec", in AddHashtreeFooterTest()
1297 ASSERT_TRUE(base::GetFileSize(rootfs_path, &file_size)); in AddHashtreeFooterTest()
1314 base::FilePath rootfs_path; in TEST_F()
1317 "blake2b-256", in TEST_F()
1331 base::FilePath rootfs_path = testdir_.Append("rootfs.bin"); in AddHashtreeFooterFECTest()
1334 base::WriteFile(rootfs_path, in AddHashtreeFooterFECTest()
1347 EXPECT_COMMAND(0, "rm -f %s.unsparse", rootfs_path.value().c_str()); in AddHashtreeFooterFECTest()
1353 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in AddHashtreeFooterFECTest()
1354 "--partition_size %d --partition_name foobar " in AddHashtreeFooterFECTest()
1355 "--algorithm SHA256_RSA2048 " in AddHashtreeFooterFECTest()
1356 "--key test/data/testkey_rsa2048.pem " in AddHashtreeFooterFECTest()
1357 "--internal_release_string \"\"", in AddHashtreeFooterFECTest()
1361 ASSERT_EQ(base::StringPrintf("Footer version: 1.0\n" in AddHashtreeFooterFECTest()
1362 "Image size: 1572864 bytes\n" in AddHashtreeFooterFECTest()
1363 "Original image size: 1052672 bytes\n" in AddHashtreeFooterFECTest()
1366 "--\n" in AddHashtreeFooterFECTest()
1380 " Version of dm-verity: 1\n" in AddHashtreeFooterFECTest()
1381 " Image Size: 1052672 bytes\n" in AddHashtreeFooterFECTest()
1399 /* Zero the hashtree and FEC on a copy of the image. */ in AddHashtreeFooterFECTest()
1405 "./avbtool.py zero_hashtree --image %s.zht ", in AddHashtreeFooterFECTest()
1417 EXPECT_COMMAND(0, "rm -f %s.sparse", rootfs_path.value().c_str()); in AddHashtreeFooterFECTest()
1427 EXPECT_COMMAND(0, "rm -f %s.zht.sparse", rootfs_path.value().c_str()); in AddHashtreeFooterFECTest()
1434 ASSERT_TRUE(base::ReadFileToString(rootfs_path, &part_data)); in AddHashtreeFooterFECTest()
1436 // Also read the zeroed hash-tree version. in AddHashtreeFooterFECTest()
1438 ASSERT_TRUE(base::ReadFileToString( in AddHashtreeFooterFECTest()
1439 base::FilePath(rootfs_path.value() + ".zht"), &zht_part_data)); in AddHashtreeFooterFECTest()
1446 part_data.data() + part_data.size() - AVB_FOOTER_SIZE), in AddHashtreeFooterFECTest()
1457 // Check that the vbmeta image at |f.vbmeta_offset| checks out. in AddHashtreeFooterFECTest()
1471 EXPECT_EQ(AVB_DESCRIPTOR_TAG_HASHTREE, avb_be64toh(descriptors[0]->tag)); in AddHashtreeFooterFECTest()
1511 zht_fec_end - zht_ht_begin)); in AddHashtreeFooterFECTest()
1515 zht_part_data.size() - zht_fec_end)); in AddHashtreeFooterFECTest()
1527 // Check that we correctly generate dm-verity kernel cmdline in AddHashtreeFooterFECTest()
1529 base::FilePath vbmeta_dmv_path = testdir_.Append("vbmeta_dm_verity_desc.bin"); in AddHashtreeFooterFECTest()
1532 "--output %s " in AddHashtreeFooterFECTest()
1533 "--setup_rootfs_from_kernel %s " in AddHashtreeFooterFECTest()
1534 "--algorithm SHA256_RSA2048 " in AddHashtreeFooterFECTest()
1535 "--key test/data/testkey_rsa2048.pem " in AddHashtreeFooterFECTest()
1536 "--internal_release_string \"\"", in AddHashtreeFooterFECTest()
1560 "fec_start 261\" root=/dev/dm-0'\n" in AddHashtreeFooterFECTest()
1571 "./avbtool.py erase_footer --image %s --keep_hashtree", in AddHashtreeFooterFECTest()
1574 ASSERT_TRUE(base::GetFileSize(rootfs_path, &erased_footer_file_size)); in AddHashtreeFooterFECTest()
1588 base::FilePath output_path = testdir_.Append("max_size.txt"); in TEST_F()
1592 "--partition_size %zd --calc_max_image_size " in TEST_F()
1593 "--do_not_generate_fec > %s", in TEST_F()
1597 EXPECT_TRUE(base::ReadFileToString(output_path, &max_image_size_data)); in TEST_F()
1601 // Hashtree and metadata takes up 152 KiB - compare to below with in TEST_F()
1603 EXPECT_EQ(152 * 1024ULL, partition_size - max_image_size); in TEST_F()
1605 // Check that we can add a hashtree with an image this size for such in TEST_F()
1607 base::FilePath system_path = GenerateImage("system", max_image_size); in TEST_F()
1610 " --image %s" in TEST_F()
1611 " --partition_name system" in TEST_F()
1612 " --partition_size %zd" in TEST_F()
1613 " --salt deadbeef" in TEST_F()
1614 " --algorithm SHA512_RSA4096 " in TEST_F()
1615 " --key test/data/testkey_rsa4096.pem" in TEST_F()
1616 " --internal_release_string \"\" " in TEST_F()
1617 "--do_not_generate_fec", in TEST_F()
1624 base::FilePath output_path = testdir_.Append("max_size.txt"); in TEST_F()
1628 "--partition_size %zd --calc_max_image_size > %s", in TEST_F()
1632 EXPECT_TRUE(base::ReadFileToString(output_path, &max_image_size_data)); in TEST_F()
1636 // Hashtree, FEC codes, and metadata takes up 244 KiB - compare to in TEST_F()
1638 EXPECT_EQ(244 * 1024ULL, partition_size - max_image_size); in TEST_F()
1640 // Check that we can add a hashtree with an image this size for such in TEST_F()
1642 base::FilePath system_path = GenerateImage("system", max_image_size); in TEST_F()
1645 " --image %s" in TEST_F()
1646 " --partition_name system" in TEST_F()
1647 " --partition_size %zd" in TEST_F()
1648 " --salt deadbeef" in TEST_F()
1649 " --algorithm SHA512_RSA4096 " in TEST_F()
1650 " --key test/data/testkey_rsa4096.pem" in TEST_F()
1651 " --internal_release_string \"\"", in TEST_F()
1658 base::FilePath output_path = testdir_.Append("max_size.txt"); in TEST_F()
1662 "--no_hashtree " in TEST_F()
1663 "--partition_size %zd --calc_max_image_size > %s", in TEST_F()
1667 EXPECT_TRUE(base::ReadFileToString(output_path, &max_image_size_data)); in TEST_F()
1672 EXPECT_EQ(68 * 1024ULL, partition_size - max_image_size); in TEST_F()
1674 // Check that we can add a hashtree with an image this size for such in TEST_F()
1676 base::FilePath system_path = GenerateImage("system", max_image_size); in TEST_F()
1679 " --image %s" in TEST_F()
1680 " --no_hashtree" in TEST_F()
1681 " --partition_name system" in TEST_F()
1682 " --partition_size %zd" in TEST_F()
1683 " --salt deadbeef" in TEST_F()
1684 " --algorithm SHA512_RSA4096 " in TEST_F()
1685 " --key test/data/testkey_rsa4096.pem" in TEST_F()
1686 " --internal_release_string \"\"", in TEST_F()
1689 // with --no_hashtree, Tree/FEC sizes are 0 bytes in TEST_F()
1692 "Image size: 10485760 bytes\n" in TEST_F()
1693 "Original image size: 10416128 bytes\n" in TEST_F()
1696 "--\n" in TEST_F()
1709 " Version of dm-verity: 1\n" in TEST_F()
1710 " Image Size: 10416128 bytes\n" in TEST_F()
1728 base::FilePath path = GenerateImage("digest_location", partition_size / 2); in TEST_F()
1731 "--hash_algorithm sha256 --image %s " in TEST_F()
1732 "--partition_size %d --partition_name foobar " in TEST_F()
1733 "--algorithm SHA256_RSA2048 " in TEST_F()
1734 "--key test/data/testkey_rsa2048.pem " in TEST_F()
1735 "--internal_release_string \"\" " in TEST_F()
1736 "--use_persistent_digest", in TEST_F()
1739 // There are two important bits here specific to --use_persistent_digest: in TEST_F()
1741 // Hashtree descriptor -> Root Digest = (empty) in TEST_F()
1744 "Image size: 10485760 bytes\n" in TEST_F()
1745 "Original image size: 5242880 bytes\n" in TEST_F()
1748 "--\n" in TEST_F()
1761 " Version of dm-verity: 1\n" in TEST_F()
1762 " Image Size: 5242880 bytes\n" in TEST_F()
1780 base::FilePath path = GenerateImage("digest_location", partition_size / 2); in TEST_F()
1782 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
1783 "--hash_algorithm sha256 --image %s " in TEST_F()
1784 "--partition_size %d --partition_name foobar " in TEST_F()
1785 "--algorithm SHA256_RSA2048 " in TEST_F()
1786 "--key test/data/testkey_rsa2048.pem " in TEST_F()
1787 "--internal_release_string \"\" " in TEST_F()
1788 "--do_not_use_ab", in TEST_F()
1791 // There are two important bits here we're expecting with --do_not_use_ab: in TEST_F()
1793 // Hashtree descriptor -> Flags = 1 in TEST_F()
1796 "Image size: 10485760 bytes\n" in TEST_F()
1797 "Original image size: 5242880 bytes\n" in TEST_F()
1800 "--\n" in TEST_F()
1813 " Version of dm-verity: 1\n" in TEST_F()
1814 " Image Size: 5242880 bytes\n" in TEST_F()
1833 base::FilePath path = GenerateImage("digest_location", partition_size / 2); in TEST_F()
1836 "--hash_algorithm sha256 --image %s " in TEST_F()
1837 "--partition_size %d --partition_name foobar " in TEST_F()
1838 "--algorithm SHA256_RSA2048 " in TEST_F()
1839 "--key test/data/testkey_rsa2048.pem " in TEST_F()
1840 "--internal_release_string \"\" " in TEST_F()
1841 "--use_persistent_digest --do_not_use_ab", in TEST_F()
1846 // Hashtree descriptor -> Root Digest = (empty) in TEST_F()
1847 // Hashtree descriptor -> Flags = 1 in TEST_F()
1850 "Image size: 10485760 bytes\n" in TEST_F()
1851 "Original image size: 5242880 bytes\n" in TEST_F()
1854 "--\n" in TEST_F()
1867 " Version of dm-verity: 1\n" in TEST_F()
1868 " Image Size: 5242880 bytes\n" in TEST_F()
1887 base::FilePath path = GenerateImage("data.bin", file_size); in TEST_F()
1889 // Note how there is no --partition_size or --partition_name here. in TEST_F()
1891 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
1892 "--image %s " in TEST_F()
1893 "--algorithm SHA256_RSA2048 " in TEST_F()
1894 "--key test/data/testkey_rsa2048.pem " in TEST_F()
1895 "--internal_release_string \"\" ", in TEST_F()
1900 "Image size: 94208 bytes\n" in TEST_F()
1901 "Original image size: 73728 bytes\n" in TEST_F()
1904 "--\n" in TEST_F()
1917 " Version of dm-verity: 1\n" in TEST_F()
1918 " Image Size: 73728 bytes\n" in TEST_F()
1933 // Check that at least avbtool can verify the image and hashtree. in TEST_F()
1936 "--image %s ", in TEST_F()
1943 base::FilePath path = GenerateImage("data.bin", file_size); in TEST_F()
1945 // Note how there is no --partition_size or --partition_name here. in TEST_F()
1947 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
1948 "--image %s " in TEST_F()
1949 "--algorithm SHA256_RSA2048 " in TEST_F()
1950 "--key test/data/testkey_rsa2048.pem " in TEST_F()
1951 "--internal_release_string \"\" ", in TEST_F()
1956 "Image size: 20480 bytes\n" in TEST_F()
1957 "Original image size: 4096 bytes\n" in TEST_F()
1960 "--\n" in TEST_F()
1973 " Version of dm-verity: 1\n" in TEST_F()
1974 " Image Size: 4096 bytes\n" in TEST_F()
1989 // Check that at least avbtool can verify the image and hashtree. in TEST_F()
1992 "--image %s ", in TEST_F()
1999 base::FilePath path = GenerateImage("data.bin", file_size); in TEST_F()
2003 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
2004 "--image %s " in TEST_F()
2005 "--algorithm SHA256_RSA2048 " in TEST_F()
2006 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2007 "--internal_release_string \"\" ", in TEST_F()
2012 // Image size needs not to be a multiple of block size (4096 bytes) if in TEST_F()
2013 // --partition_size is specified. avbtool will round the image size being in TEST_F()
2016 base::FilePath path = GenerateImage("data.bin", image_size); in TEST_F()
2019 // Note that there is --partition_size here. in TEST_F()
2021 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
2022 "--image %s " in TEST_F()
2023 "--algorithm SHA256_RSA2048 " in TEST_F()
2024 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2025 "--partition_size %d --partition_name foobar " in TEST_F()
2026 "--internal_release_string \"\" ", in TEST_F()
2036 // Image size doesn't matter in this case. in TEST_F()
2038 base::FilePath path = GenerateImage("data.bin", image_size); in TEST_F()
2042 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
2043 "--image %s " in TEST_F()
2044 "--algorithm SHA256_RSA2048 " in TEST_F()
2045 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2046 "--partition_size %d --partition_name foobar " in TEST_F()
2047 "--internal_release_string \"\" ", in TEST_F()
2054 base::FilePath path = GenerateImage("digest_location", partition_size / 2); in TEST_F()
2056 "./avbtool.py add_hashtree_footer --salt d00df00d " in TEST_F()
2057 "--hash_algorithm sha256 --image %s " in TEST_F()
2058 "--partition_size %d --partition_name foobar " in TEST_F()
2059 "--algorithm SHA256_RSA2048 " in TEST_F()
2060 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2061 "--internal_release_string \"\" " in TEST_F()
2062 "--check_at_most_once", in TEST_F()
2065 // There are two important bits here we're expecting with --check_at_most_once: in TEST_F()
2067 // Hashtree descriptor -> Flags = 2 in TEST_F()
2070 "Image size: 10485760 bytes\n" in TEST_F()
2071 "Original image size: 5242880 bytes\n" in TEST_F()
2074 "--\n" in TEST_F()
2087 " Version of dm-verity: 1\n" in TEST_F()
2088 " Image Size: 5242880 bytes\n" in TEST_F()
2106 base::FilePath vbmeta_path = in TEST_F()
2111 "--output %s " in TEST_F()
2112 "--kernel_cmdline 'foo bar baz' " in TEST_F()
2113 "--kernel_cmdline 'second cmdline' " in TEST_F()
2114 "--algorithm SHA256_RSA2048 " in TEST_F()
2115 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2116 "--internal_release_string \"\"", in TEST_F()
2139 // Now check the VBMeta image. in TEST_F()
2141 ASSERT_TRUE(base::ReadFileToString(vbmeta_path, &image_data)); in TEST_F()
2154 // We should have two descriptors - check them. in TEST_F()
2158 avb_be64toh(descriptors[0]->tag)); in TEST_F()
2169 avb_be64toh(descriptors[1]->tag)); in TEST_F()
2182 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2185 "--output %s " in TEST_F()
2186 "--kernel_cmdline 'foo bar baz' " in TEST_F()
2187 "--kernel_cmdline 'second cmdline' " in TEST_F()
2188 "--algorithm SHA256_RSA2048 " in TEST_F()
2189 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2190 "--internal_release_string \"\"", in TEST_F()
2193 base::FilePath out_path = testdir_.Append("out.txt"); in TEST_F()
2196 "./avbtool.py calculate_kernel_cmdline --image %s > %s", in TEST_F()
2199 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
2207 base::FilePath pk_path = testdir_.Append("testkey_rsa2048.avbpubkey"); in TEST_F()
2212 // --hashtree_disabled option. in TEST_F()
2217 base::FilePath rootfs_path = testdir_.Append("rootfs.bin"); in TEST_F()
2220 base::WriteFile(rootfs_path, in TEST_F()
2226 "./avbtool.py extract_public_key --key test/data/testkey_rsa2048.pem" in TEST_F()
2227 " --output %s", in TEST_F()
2231 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
2232 "--partition_size %d --partition_name rootfs " in TEST_F()
2233 "--algorithm SHA256_RSA2048 " in TEST_F()
2234 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2235 "--internal_release_string \"\" " in TEST_F()
2236 "--setup_as_rootfs_from_kernel", in TEST_F()
2241 "Image size: 1572864 bytes\n" in TEST_F()
2242 "Original image size: 1052672 bytes\n" in TEST_F()
2245 "--\n" in TEST_F()
2258 " Version of dm-verity: 1\n" in TEST_F()
2259 " Image Size: 1052672 bytes\n" in TEST_F()
2279 "fec_blocks 261 fec_start 261\" root=/dev/dm-0'\n" in TEST_F()
2287 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2290 "--output %s " in TEST_F()
2291 "--kernel_cmdline 'foo bar baz' " in TEST_F()
2292 "--kernel_cmdline 'second cmdline' " in TEST_F()
2293 "--chain_partition rootfs:1:%s " in TEST_F()
2294 "--algorithm SHA256_RSA2048 " in TEST_F()
2295 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2296 "--internal_release_string \"\"", in TEST_F()
2325 base::FilePath out_path = testdir_.Append("out.txt"); in TEST_F()
2328 // First check the kernel cmdline without --hashtree_disabled - compare with in TEST_F()
2331 "./avbtool.py calculate_kernel_cmdline --image %s > %s", in TEST_F()
2334 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
2341 "fec_blocks 261 fec_start 261\" root=/dev/dm-0 foo bar baz second " in TEST_F()
2345 // Then check the kernel cmdline with --hashtree_disabled - compare with above in TEST_F()
2349 "./avbtool.py calculate_kernel_cmdline --image %s --hashtree_disabled > %s", in TEST_F()
2352 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
2362 std::vector<uint8_t> image(image_size, 0); in TEST_F() local
2364 image[n] = uint8_t(n); in TEST_F()
2367 base::FilePath ext_vbmeta_path = testdir_.Append("ext_vbmeta.bin"); in TEST_F()
2368 base::FilePath image_path = testdir_.Append("kernel.bin"); in TEST_F()
2371 base::WriteFile(image_path, in TEST_F()
2372 reinterpret_cast<const char*>(image.data()), in TEST_F()
2373 image.size()))); in TEST_F()
2375 "./avbtool.py add_hash_footer --salt d00df00d " in TEST_F()
2376 "--hash_algorithm sha256 --image %s " in TEST_F()
2377 "--partition_size %zu --partition_name kernel " in TEST_F()
2378 "--algorithm SHA256_RSA2048 " in TEST_F()
2379 "--key test/data/testkey_rsa2048.pem " in TEST_F()
2380 "--output_vbmeta %s " in TEST_F()
2381 "--do_not_append_vbmeta_image " in TEST_F()
2382 "--internal_release_string \"\"", in TEST_F()
2390 ASSERT_TRUE(base::GetFileSize(image_path, &file_size)); in TEST_F()
2395 base::FilePath vbmeta1_path = testdir_.Append("vbmeta_id1.bin"); in TEST_F()
2396 base::FilePath vbmeta2_path = testdir_.Append("vbmeta_id2.bin"); in TEST_F()
2397 base::FilePath vbmeta3_path = testdir_.Append("vbmeta_id3.bin"); in TEST_F()
2401 "--output %s " in TEST_F()
2402 "--kernel_cmdline 'something' " in TEST_F()
2403 "--prop name:value " in TEST_F()
2404 "--internal_release_string \"\"", in TEST_F()
2409 "--output %s " in TEST_F()
2410 "--prop name2:value2 " in TEST_F()
2411 "--prop name3:value3 " in TEST_F()
2412 "--internal_release_string \"\"", in TEST_F()
2417 "--output %s " in TEST_F()
2418 "--prop name4:value4 " in TEST_F()
2419 "--include_descriptors_from_image %s " in TEST_F()
2420 "--include_descriptors_from_image %s " in TEST_F()
2421 "--internal_release_string \"\"", in TEST_F()
2437 " Prop: name4 -> 'value4'\n" in TEST_F()
2438 " Prop: name -> 'value'\n" in TEST_F()
2442 " Prop: name2 -> 'value2'\n" in TEST_F()
2443 " Prop: name3 -> 'value3'\n", in TEST_F()
2448 base::FilePath vbmeta_path = testdir_.Append("vbmeta_cp.bin"); in TEST_F()
2450 base::FilePath pk_path = testdir_.Append("testkey_rsa2048.avbpubkey"); in TEST_F()
2454 "./avbtool.py extract_public_key --key test/data/testkey_rsa2048.pem" in TEST_F()
2455 " --output %s", in TEST_F()
2461 "--output %s " in TEST_F()
2462 "--chain_partition system:1:%s " in TEST_F()
2463 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2464 "--internal_release_string \"\"", in TEST_F()
2488 // Now check the VBMeta image. in TEST_F()
2490 ASSERT_TRUE(base::ReadFileToString(vbmeta_path, &image_data)); in TEST_F()
2503 // We should have one descriptor - check it. in TEST_F()
2507 ASSERT_TRUE(base::ReadFileToString(pk_path, &pk_data)); in TEST_F()
2511 avb_be64toh(descriptors[0]->tag)); in TEST_F()
2531 base::FilePath vbmeta_path = testdir_.Append("vbmeta_cp.bin"); in TEST_F()
2533 base::FilePath pk_path = testdir_.Append("testkey_rsa2048.avbpubkey"); in TEST_F()
2537 "./avbtool.py extract_public_key --key test/data/testkey_rsa2048.pem" in TEST_F()
2538 " --output %s", in TEST_F()
2544 "--output %s " in TEST_F()
2545 "--chain_partition_do_not_use_ab system:1:%s " in TEST_F()
2546 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2547 "--internal_release_string \"\"", in TEST_F()
2571 // Now check the VBMeta image. in TEST_F()
2573 ASSERT_TRUE(base::ReadFileToString(vbmeta_path, &image_data)); in TEST_F()
2586 // We should have one descriptor - check it. in TEST_F()
2590 ASSERT_TRUE(base::ReadFileToString(pk_path, &pk_data)); in TEST_F()
2594 avb_be64toh(descriptors[0]->tag)); in TEST_F()
2614 base::FilePath vbmeta_path = testdir_.Append("vbmeta_cp.bin"); in TEST_F()
2616 base::FilePath pk_path = testdir_.Append("testkey_rsa2048.avbpubkey"); in TEST_F()
2620 "./avbtool.py extract_public_key --key test/data/testkey_rsa2048.pem" in TEST_F()
2621 " --output %s", in TEST_F()
2629 "--output %s " in TEST_F()
2630 "--chain_partition system:1:%s " in TEST_F()
2631 "--chain_partition other:1:%s " in TEST_F()
2632 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2633 "--internal_release_string \"\"", in TEST_F()
2642 base::FilePath boot_path = GenerateImage("boot", boot_size); in TEST_F()
2647 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
2648 std::string("--append_to_release_string \"\" " in TEST_F()
2649 "--kernel_cmdline foo")); in TEST_F()
2653 "--image %s " in TEST_F()
2654 "--partition_size %d " in TEST_F()
2655 "--vbmeta_image %s ", in TEST_F()
2663 // Check that boot.img has the same vbmeta blob as from vbmeta.img - in TEST_F()
2685 "Image size: 33554432 bytes\n" in TEST_F()
2686 "Original image size: 5242880 bytes\n" in TEST_F()
2689 "--\n"; in TEST_F()
2693 base::File f = in TEST_F()
2694 base::File(boot_path, base::File::FLAG_OPEN | base::File::FLAG_READ); in TEST_F()
2705 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2706 base::FilePath signing_helper_test_path = in TEST_F()
2711 "--output %s " in TEST_F()
2712 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2713 "--signing_helper test/avbtool_signing_helper_test.py " in TEST_F()
2714 "--internal_release_string \"\"", in TEST_F()
2720 ASSERT_TRUE(base::ReadFileToString(signing_helper_test_path, &value)); in TEST_F()
2725 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2726 base::FilePath signing_helper_test_path = in TEST_F()
2731 "--output %s " in TEST_F()
2732 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2733 "--signing_helper_with_files " in TEST_F()
2735 "--internal_release_string \"\"", in TEST_F()
2741 ASSERT_TRUE(base::ReadFileToString(signing_helper_test_path, &value)); in TEST_F()
2746 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2750 "--output %s " in TEST_F()
2751 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2752 "--signing_helper test/avbtool_signing_helper_test.py " in TEST_F()
2753 "--internal_release_string \"\"", in TEST_F()
2758 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2762 "--output %s " in TEST_F()
2763 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2764 "--signing_helper_with_files " in TEST_F()
2766 "--internal_release_string \"\"", in TEST_F()
2774 base::FilePath()); in TEST_F()
2778 "--image %s ", in TEST_F()
2786 base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
2790 "--image %s ", in TEST_F()
2798 base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
2800 // Corrupt four bytes of data in the end of the image. Since the aux in TEST_F()
2805 ops_.avb_ops()->write_to_partition(ops_.avb_ops(), in TEST_F()
2807 -4, // offset from end in TEST_F()
2813 "--image %s ", in TEST_F()
2821 base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
2825 "--image %s --key test/data/testkey_rsa2048.pem", in TEST_F()
2833 base::FilePath("test/data/testkey_rsa2048.pem")); in TEST_F()
2837 "--image %s --key test/data/testkey_rsa4096.pem", in TEST_F()
2842 base::FilePath vbmeta_path = testdir_.Append("vbmeta.bin"); in TEST_F()
2843 base::FilePath signing_helper_test_path = in TEST_F()
2850 "--output %s " in TEST_F()
2851 "--algorithm SHA256_RSA2048 --key test/data/testkey_rsa2048.pem " in TEST_F()
2852 "--signing_helper test/avbtool_signing_helper_test.py " in TEST_F()
2853 "--internal_release_string \"\"", in TEST_F()
2858 "--image %s ", in TEST_F()
2866 base::FilePath boot_path = GenerateImage("boot.img", boot_image_size); in GenerateImageWithHashAndHashtreeSetup()
2869 " --image %s" in GenerateImageWithHashAndHashtreeSetup()
2870 " --rollback_index 0" in GenerateImageWithHashAndHashtreeSetup()
2871 " --partition_name boot" in GenerateImageWithHashAndHashtreeSetup()
2872 " --partition_size %zd" in GenerateImageWithHashAndHashtreeSetup()
2873 " --salt deadbeef" in GenerateImageWithHashAndHashtreeSetup()
2874 " --internal_release_string \"\"", in GenerateImageWithHashAndHashtreeSetup()
2880 base::FilePath system_path = GenerateImage("system.img", system_image_size); in GenerateImageWithHashAndHashtreeSetup()
2882 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in GenerateImageWithHashAndHashtreeSetup()
2883 "--partition_size %zd --partition_name system " in GenerateImageWithHashAndHashtreeSetup()
2884 "--internal_release_string \"\" ", in GenerateImageWithHashAndHashtreeSetup()
2891 base::FilePath("test/data/testkey_rsa2048.pem"), in GenerateImageWithHashAndHashtreeSetup()
2892 base::StringPrintf("--include_descriptors_from_image %s " in GenerateImageWithHashAndHashtreeSetup()
2893 "--include_descriptors_from_image %s", in GenerateImageWithHashAndHashtreeSetup()
2901 // Do two checks - one for system.img not sparse, and one where it in TEST_F()
2906 "--image %s ", in TEST_F()
2924 base::FilePath system_path = GenerateImage("system.img", system_image_size); in TEST_F()
2926 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
2927 "--partition_size %zd --partition_name system " in TEST_F()
2928 "--internal_release_string \"\" ", in TEST_F()
2935 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
2936 base::StringPrintf("--include_descriptors_from_image %s ", in TEST_F()
2940 "./avbtool.py verify_image --image %s --accept_zeroed_hashtree", in TEST_F()
2944 0, "./avbtool.py zero_hashtree --image %s", system_path.value().c_str()); in TEST_F()
2947 "./avbtool.py verify_image --image %s", in TEST_F()
2951 "./avbtool.py verify_image --image %s --accept_zeroed_hashtree", in TEST_F()
2958 base::FilePath system_path = GenerateImage("system.img", system_image_size); in TEST_F()
2960 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
2961 "--partition_size %zd --partition_name system " in TEST_F()
2962 "--no_hashtree " in TEST_F()
2963 "--internal_release_string \"\" ", in TEST_F()
2970 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
2971 base::StringPrintf("--include_descriptors_from_image %s ", in TEST_F()
2975 "./avbtool.py verify_image --image %s", in TEST_F()
2979 "./avbtool.py verify_image --image %s --accept_zeroed_hashtree", in TEST_F()
2989 ops_.avb_ops()->write_to_partition(ops_.avb_ops(), in TEST_F()
2997 "--image %s ", in TEST_F()
3007 ops_.avb_ops()->write_to_partition(ops_.avb_ops(), in TEST_F()
3013 // Do two checks - one for system.img not sparse, and one where it in TEST_F()
3018 "--image %s ", in TEST_F()
3034 base::FilePath pk4096_path = testdir_.Append("testkey_rsa4096.avbpubkey"); in TEST_F()
3037 "./avbtool.py extract_public_key --key test/data/testkey_rsa4096.pem" in TEST_F()
3038 " --output %s", in TEST_F()
3041 base::FilePath pk8192_path = testdir_.Append("testkey_rsa8192.avbpubkey"); in TEST_F()
3044 "./avbtool.py extract_public_key --key test/data/testkey_rsa8192.pem" in TEST_F()
3045 " --output %s", in TEST_F()
3051 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
3052 base::StringPrintf("--chain_partition system:1:%s ", in TEST_F()
3058 "--image %s " in TEST_F()
3059 "--expected_chain_partition system:1:%s", in TEST_F()
3063 // Should fail because we didn't use --expected_chain_partition. in TEST_F()
3066 "--image %s ", in TEST_F()
3072 "--image %s " in TEST_F()
3073 "--expected_chain_partition xyz:1:%s", in TEST_F()
3080 "--image %s " in TEST_F()
3081 "--expected_chain_partition system:2:%s", in TEST_F()
3088 "--image %s " in TEST_F()
3089 "--expected_chain_partition system:1:%s", in TEST_F()
3095 base::FilePath pk4096_path = testdir_.Append("testkey_rsa4096.avbpubkey"); in TEST_F()
3098 "./avbtool.py extract_public_key --key test/data/testkey_rsa4096.pem" in TEST_F()
3099 " --output %s", in TEST_F()
3105 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
3106 base::StringPrintf("--chain_partition system:1:%s ", in TEST_F()
3111 base::FilePath system_path = GenerateImage("system.img", system_image_size); in TEST_F()
3113 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
3114 "--partition_size %zd --partition_name system " in TEST_F()
3115 "--algorithm SHA256_RSA4096 " in TEST_F()
3116 "--key test/data/testkey_rsa4096.pem " in TEST_F()
3117 "--internal_release_string \"\" ", in TEST_F()
3121 // Even without --expected_chain_partition this shouldn't fail because we use in TEST_F()
3122 // --follow_chain_partitions and system.img exists... to avoid unstable paths in TEST_F()
3129 "--image vbmeta.img --follow_chain_partitions > out.txt)", in TEST_F()
3132 base::FilePath out_path = testdir_.Append("out.txt"); in TEST_F()
3134 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
3136 "Verifying image vbmeta.img using embedded public key\n" in TEST_F()
3141 "--\n" in TEST_F()
3142 "Verifying image system.img using embedded public key\n" in TEST_F()
3145 "system: Successfully verified sha1 hashtree of system.img for image of " in TEST_F()
3150 // --expect_chain_partition. The output is slightly different from above. in TEST_F()
3153 "--image vbmeta.img --expected_chain_partition system:1:%s " in TEST_F()
3154 "--follow_chain_partitions > out.txt)", in TEST_F()
3158 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
3160 "Verifying image vbmeta.img using embedded public key\n" in TEST_F()
3165 "--\n" in TEST_F()
3166 "Verifying image system.img using embedded public key\n" in TEST_F()
3169 "system: Successfully verified sha1 hashtree of system.img for image of " in TEST_F()
3175 base::FilePath pk4096_path = testdir_.Append("testkey_rsa4096.avbpubkey"); in TEST_F()
3178 "./avbtool.py extract_public_key --key test/data/testkey_rsa4096.pem" in TEST_F()
3179 " --output %s", in TEST_F()
3184 base::FilePath system_path = GenerateImage("system.img", system_image_size); in TEST_F()
3186 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
3187 "--partition_size %zd --partition_name system " in TEST_F()
3188 "--internal_release_string \"\" " in TEST_F()
3189 "--algorithm SHA256_RSA4096 " in TEST_F()
3190 "--key test/data/testkey_rsa4096.pem ", in TEST_F()
3199 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
3200 base::StringPrintf("--chain_partition vbmeta_google:1:%s ", in TEST_F()
3206 "--image %s " in TEST_F()
3207 "--expected_chain_partition vbmeta_google:1:%s", in TEST_F()
3211 // Should not fail (looks in system.img image). in TEST_F()
3214 "--image %s ", in TEST_F()
3220 base::FilePath vbmeta_google_path = GenerateImage("vbmeta_google.img", 0); in TEST_F()
3223 " --image %s" in TEST_F()
3224 " --output %s", in TEST_F()
3229 " --image %s --keep_hashtree", in TEST_F()
3232 // Should not fail - looks in system.img's detached vbmeta (vbmeta_google.img) in TEST_F()
3236 "--image %s ", in TEST_F()
3241 base::FilePath pk4096_path = testdir_.Append("testkey_rsa4096.avbpubkey"); in TEST_F()
3244 "./avbtool.py extract_public_key --key test/data/testkey_rsa4096.pem" in TEST_F()
3245 " --output %s", in TEST_F()
3250 base::FilePath boot_path = GenerateImage("boot.img", boot_image_size); in TEST_F()
3253 " --image %s" in TEST_F()
3254 " --rollback_index 0" in TEST_F()
3255 " --partition_name boot" in TEST_F()
3256 " --partition_size %zd" in TEST_F()
3257 " --salt deadbeef" in TEST_F()
3258 " --internal_release_string \"\"", in TEST_F()
3265 base::FilePath("test/data/testkey_rsa2048.pem"), in TEST_F()
3266 base::StringPrintf("--chain_partition system:1:%s " in TEST_F()
3267 "--include_descriptors_from_image %s", in TEST_F()
3273 base::FilePath system_path = GenerateImage("system.img", system_image_size); in TEST_F()
3275 "./avbtool.py add_hashtree_footer --salt d00df00d --image %s " in TEST_F()
3276 "--partition_size %zd --partition_name system " in TEST_F()
3277 "--algorithm SHA256_RSA4096 " in TEST_F()
3278 "--key test/data/testkey_rsa4096.pem " in TEST_F()
3279 "--internal_release_string \"\" ", in TEST_F()
3283 base::FilePath out_path = testdir_.Append("out.txt"); in TEST_F()
3288 "./avbtool.py print_partition_digests --image %s --output %s", in TEST_F()
3291 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
3301 "./avbtool.py print_partition_digests --image %s --json --output %s", in TEST_F()
3304 ASSERT_TRUE(base::ReadFileToString(out_path, &out)); in TEST_F()
3331 // The --do_not_use_ab option will require 1.1. in PrintWithAddHashFooter()
3332 extra_args = "--do_not_use_ab"; in PrintWithAddHashFooter()
3334 extra_args = "--rollback_index_location 2"; in PrintWithAddHashFooter()
3338 base::FilePath output_path = testdir_.Append(kOutputFile); in PrintWithAddHashFooter()
3341 " --rollback_index 0" in PrintWithAddHashFooter()
3342 " --partition_name boot" in PrintWithAddHashFooter()
3343 " --partition_size %zd" in PrintWithAddHashFooter()
3344 " --salt deadbeef" in PrintWithAddHashFooter()
3345 " --internal_release_string \"\"" in PrintWithAddHashFooter()
3347 " --print_required_libavb_version > %s", in PrintWithAddHashFooter()
3357 // The --do_not_use_ab option will require 1.1. in PrintWithAddHashtreeFooter()
3358 extra_args = "--do_not_use_ab --check_at_most_once"; in PrintWithAddHashtreeFooter()
3360 extra_args = "--rollback_index_location 2"; in PrintWithAddHashtreeFooter()
3363 base::FilePath output_path = testdir_.Append(kOutputFile); in PrintWithAddHashtreeFooter()
3365 "./avbtool.py add_hashtree_footer --salt d00df00d " in PrintWithAddHashtreeFooter()
3366 "--partition_size %zd --partition_name system " in PrintWithAddHashtreeFooter()
3367 "--internal_release_string \"\"" in PrintWithAddHashtreeFooter()
3369 " --print_required_libavb_version > %s", in PrintWithAddHashtreeFooter()
3381 base::FilePath image_path = GenerateImage("test_print_version", 1024); in PrintWithMakeVbmetaImage()
3383 "./avbtool.py add_hash_footer --salt d00df00d " in PrintWithMakeVbmetaImage()
3384 "--hash_algorithm sha256 --image %s " in PrintWithMakeVbmetaImage()
3385 "--partition_size %d --partition_name foobar " in PrintWithMakeVbmetaImage()
3386 "--algorithm SHA256_RSA2048 " in PrintWithMakeVbmetaImage()
3387 "--key test/data/testkey_rsa2048.pem " in PrintWithMakeVbmetaImage()
3388 "--internal_release_string \"\" " in PrintWithMakeVbmetaImage()
3389 "--do_not_use_ab", in PrintWithMakeVbmetaImage()
3392 extra_args = base::StringPrintf("--include_descriptors_from_image %s", in PrintWithMakeVbmetaImage()
3395 extra_args = "--rollback_index_location 2"; in PrintWithMakeVbmetaImage()
3398 base::FilePath output_path = testdir_.Append(kOutputFile); in PrintWithMakeVbmetaImage()
3401 "--algorithm SHA256_RSA2048 " in PrintWithMakeVbmetaImage()
3402 "--key test/data/testkey_rsa2048.pem " in PrintWithMakeVbmetaImage()
3403 "--internal_release_string \"\"" in PrintWithMakeVbmetaImage()
3405 " --print_required_libavb_version > %s", in PrintWithMakeVbmetaImage()
3412 base::FilePath output_path = testdir_.Append(kOutputFile); in CheckVersion()
3414 ASSERT_TRUE(base::ReadFileToString(output_path, &output)); in CheckVersion()
3416 base::StringPrintf("1.%d\n", expected_required_minor_version)); in CheckVersion()
3457 base::FilePath subject_path = testdir_.Append("tmp_subject"); in TEST_F()
3458 ASSERT_TRUE(base::WriteFile(subject_path, "fake PIK subject", 16)); in TEST_F()
3459 base::FilePath pubkey_path = testdir_.Append("tmp_pubkey.pem"); in TEST_F()
3462 "openssl pkey -pubout -in test/data/testkey_cert_pik.pem -out %s", in TEST_F()
3465 base::FilePath output_path = testdir_.Append("tmp_certificate.bin"); in TEST_F()
3468 " --subject %s" in TEST_F()
3469 " --subject_key %s" in TEST_F()
3470 " --subject_key_version 42" in TEST_F()
3471 " --subject_is_intermediate_authority" in TEST_F()
3472 " --authority_key test/data/testkey_cert_prk.pem" in TEST_F()
3473 " --output %s", in TEST_F()
3484 base::FilePath pubkey_path = testdir_.Append("tmp_pubkey.pem"); in TEST_F()
3487 "openssl pkey -pubout -in test/data/testkey_cert_psk.pem -out %s", in TEST_F()
3490 base::FilePath output_path = testdir_.Append("tmp_certificate.bin"); in TEST_F()
3493 " --subject test/data/cert_product_id.bin" in TEST_F()
3494 " --subject_key %s" in TEST_F()
3495 " --subject_key_version 42" in TEST_F()
3496 " --authority_key test/data/testkey_cert_pik.pem" in TEST_F()
3497 " --output %s", in TEST_F()
3507 base::FilePath pubkey_path = testdir_.Append("tmp_pubkey.pem"); in TEST_F()
3510 "openssl pkey -pubout -in test/data/testkey_cert_puk.pem -out %s", in TEST_F()
3513 base::FilePath output_path = testdir_.Append("tmp_certificate.bin"); in TEST_F()
3515 // Test with both legacy manual unlock --usage as well as --usage_for_unlock. in TEST_F()
3516 std::string usage_args[] = {"--usage com.google.android.things.vboot.unlock", in TEST_F()
3517 "--usage_for_unlock"}; in TEST_F()
3521 " --subject test/data/cert_product_id.bin" in TEST_F()
3522 " --subject_key %s" in TEST_F()
3523 " --subject_key_version 42" in TEST_F()
3525 " --authority_key test/data/testkey_cert_pik.pem" in TEST_F()
3526 " --output %s", in TEST_F()
3538 base::FilePath pubkey_path = testdir_.Append("tmp_pubkey.pem"); in TEST_F()
3541 "openssl pkey -pubout -in test/data/testkey_cert_prk.pem -out %s", in TEST_F()
3544 base::FilePath output_path = testdir_.Append("tmp_attributes.bin"); in TEST_F()
3547 " --root_authority_key %s" in TEST_F()
3548 " --product_id test/data/cert_product_id.bin" in TEST_F()
3549 " --output %s", in TEST_F()
3559 base::FilePath output_path = testdir_.Append("tmp_metadata.bin"); in TEST_F()
3564 " --intermediate_key_certificate test/data/cert_pik_certificate.bin" in TEST_F()
3565 " --product_key_certificate test/data/cert_psk_certificate.bin" in TEST_F()
3566 " --output %s", in TEST_F()
3574 base::FilePath output_path = testdir_.Append("tmp_credential.bin"); in TEST_F()
3579 " --intermediate_key_certificate test/data/cert_pik_certificate.bin" in TEST_F()
3580 " --unlock_key_certificate test/data/cert_puk_certificate.bin" in TEST_F()
3581 " --challenge test/data/cert_unlock_challenge.bin" in TEST_F()
3582 " --unlock_key test/data/testkey_cert_puk.pem" in TEST_F()
3583 " --output %s", in TEST_F()