summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-21 00:57:25 +0100
committerTao Bao <tbao@google.com>2017-03-28 01:13:01 +0200
commit7e61c6a8628bb72c90ca4d5c5b6a609323107d3b (patch)
treec9178556edab033548735c3a969440d4ca95d2f1 /tests
parentMerge "tests: Construct signature-boundary.zip at runtime." (diff)
downloadandroid_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar.gz
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar.bz2
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar.lz
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar.xz
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.tar.zst
android_bootable_recovery-7e61c6a8628bb72c90ca4d5c5b6a609323107d3b.zip
Diffstat (limited to '')
-rw-r--r--tests/component/verifier_test.cpp49
-rw-r--r--tests/testdata/alter-footer.zipbin4009 -> 0 bytes
-rw-r--r--tests/testdata/alter-metadata.zipbin4009 -> 0 bytes
3 files changed, 46 insertions, 3 deletions
diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp
index 4c0648714..4a3a981f7 100644
--- a/tests/component/verifier_test.cpp
+++ b/tests/component/verifier_test.cpp
@@ -117,6 +117,51 @@ TEST(VerifierTest, load_keys_invalid_keys) {
ASSERT_FALSE(load_keys(key_file5.path, certs));
}
+TEST(VerifierTest, BadPackage_AlteredFooter) {
+ std::string testkey_v3;
+ ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
+ TemporaryFile key_file1;
+ ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path));
+ std::vector<Certificate> certs;
+ ASSERT_TRUE(load_keys(key_file1.path, certs));
+
+ std::string package;
+ ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package));
+ ASSERT_EQ(std::string("\xc0\x06\xff\xff\xd2\x06", 6), package.substr(package.size() - 6, 6));
+
+ // Alter the footer.
+ package[package.size() - 5] = '\x05';
+ ASSERT_EQ(VERIFY_FAILURE,
+ verify_file(reinterpret_cast<const unsigned char*>(package.data()), package.size(),
+ certs));
+}
+
+TEST(VerifierTest, BadPackage_AlteredContent) {
+ std::string testkey_v3;
+ ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
+ TemporaryFile key_file1;
+ ASSERT_TRUE(android::base::WriteStringToFile(testkey_v3, key_file1.path));
+ std::vector<Certificate> certs;
+ ASSERT_TRUE(load_keys(key_file1.path, certs));
+
+ std::string package;
+ ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("otasigned_v3.zip"), &package));
+ ASSERT_GT(package.size(), static_cast<size_t>(100));
+
+ // Alter the content.
+ std::string altered1(package);
+ altered1[50] += 1;
+ ASSERT_EQ(VERIFY_FAILURE,
+ verify_file(reinterpret_cast<const unsigned char*>(altered1.data()), altered1.size(),
+ certs));
+
+ std::string altered2(package);
+ altered2[10] += 1;
+ ASSERT_EQ(VERIFY_FAILURE,
+ verify_file(reinterpret_cast<const unsigned char*>(altered2.data()), altered2.size(),
+ certs));
+}
+
TEST(VerifierTest, BadPackage_SignatureStartOutOfBounds) {
std::string testkey_v3;
ASSERT_TRUE(android::base::ReadFileToString(from_testdata_base("testkey_v3.txt"), &testkey_v3));
@@ -174,6 +219,4 @@ INSTANTIATE_TEST_CASE_P(WrongHash, VerifierFailureTest,
INSTANTIATE_TEST_CASE_P(BadPackage, VerifierFailureTest,
::testing::Values(
std::vector<std::string>({"random.zip", "v1"}),
- std::vector<std::string>({"fake-eocd.zip", "v1"}),
- std::vector<std::string>({"alter-metadata.zip", "v1"}),
- std::vector<std::string>({"alter-footer.zip", "v1"})));
+ std::vector<std::string>({"fake-eocd.zip", "v1"})));
diff --git a/tests/testdata/alter-footer.zip b/tests/testdata/alter-footer.zip
deleted file mode 100644
index f497ec000..000000000
--- a/tests/testdata/alter-footer.zip
+++ /dev/null
Binary files differ
diff --git a/tests/testdata/alter-metadata.zip b/tests/testdata/alter-metadata.zip
deleted file mode 100644
index 1c71fbc49..000000000
--- a/tests/testdata/alter-metadata.zip
+++ /dev/null
Binary files differ