From 1396f237d19c5ea074ad705913e668f24433ec62 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Wed, 13 Jul 2022 20:44:22 +0000 Subject: [PATCH] Test that the password isn't truncated Test that Gatekeeper doesn't truncate passwords, either due to them containing NUL bytes or being long. Bug: 238919794 Test: atest VtsHalGatekeeperV1_0TargetTest # on Cuttlefish Change-Id: I8dd40c66bbe5cd8d309a6461053389b479fa0745 --- .../VtsHalGatekeeperV1_0TargetTest.cpp | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp b/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp index f3fa0b469e..e938b01be4 100644 --- a/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp +++ b/gatekeeper/1.0/vts/functional/VtsHalGatekeeperV1_0TargetTest.cpp @@ -243,6 +243,47 @@ TEST_P(GatekeeperHidlTest, VerifySuccess) { ALOGI("Testing Enroll+Verify done"); } +/** + * Ensure that passwords containing a NUL byte aren't truncated + */ +TEST_P(GatekeeperHidlTest, PasswordIsBinaryData) { + GatekeeperResponse enrollRsp; + GatekeeperResponse verifyRsp; + hidl_vec rightPassword = {'A', 'B', 'C', '\0', 'D', 'E', 'F'}; + hidl_vec wrongPassword = {'A', 'B', 'C', '\0', '\0', '\0', '\0'}; + + ALOGI("Testing Enroll+Verify of password with embedded NUL (expected success)"); + enrollNewPassword(rightPassword, enrollRsp, true); + verifyPassword(rightPassword, enrollRsp.data, 1, verifyRsp, true); + + ALOGI("Testing Verify of wrong password (expected failure)"); + verifyPassword(wrongPassword, enrollRsp.data, 1, verifyRsp, false); + + ALOGI("PasswordIsBinaryData test done"); +} + +/** + * Ensure that long passwords aren't truncated + */ +TEST_P(GatekeeperHidlTest, LongPassword) { + GatekeeperResponse enrollRsp; + GatekeeperResponse verifyRsp; + hidl_vec password; + + password.resize(64); // maximum length used by Android + memset(password.data(), 'A', password.size()); + + ALOGI("Testing Enroll+Verify of long password (expected success)"); + enrollNewPassword(password, enrollRsp, true); + verifyPassword(password, enrollRsp.data, 1, verifyRsp, true); + + ALOGI("Testing Verify of wrong password (expected failure)"); + password[password.size() - 1] ^= 1; + verifyPassword(password, enrollRsp.data, 1, verifyRsp, false); + + ALOGI("LongPassword test done"); +} + /** * Ensure we can securely update password (keep the same * secure user_id) if we prove we know old password