summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTao Bao <tbao@google.com>2017-03-29 03:14:51 +0200
committerandroid-build-merger <android-build-merger@google.com>2017-03-29 03:14:51 +0200
commitfa617cdf97a1979c741a276d2220200a00372e4d (patch)
treeff985d706e8f40dc61927e26e0e06585d5573069 /tests
parentMerge "Add the missing sr-Latn into png files and rename the png locale header" am: 713d915636 am: dc235b5ab9 am: 5ec12126f0 am: 0a599567ce (diff)
parentresolve merge conflicts of 39ef2d7f to oc-dev-plus-aosp (diff)
downloadandroid_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar.gz
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar.bz2
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar.lz
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar.xz
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.tar.zst
android_bootable_recovery-fa617cdf97a1979c741a276d2220200a00372e4d.zip
Diffstat (limited to 'tests')
-rw-r--r--tests/component/verifier_test.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/component/verifier_test.cpp b/tests/component/verifier_test.cpp
index 4a3a981f7..ce5b075cf 100644
--- a/tests/component/verifier_test.cpp
+++ b/tests/component/verifier_test.cpp
@@ -177,6 +177,51 @@ TEST(VerifierTest, BadPackage_SignatureStartOutOfBounds) {
package.size(), 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_P(VerifierSuccessTest, VerifySucceed) {
ASSERT_EQ(verify_file(memmap.addr, memmap.length, certs, nullptr), VERIFY_SUCCESS);
}