1 /* 2 * Copyright (C) 2019 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 agreed 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 package android.appsecurity.cts; 18 19 import static org.junit.Assume.assumeTrue; 20 21 import com.android.tradefed.device.DeviceNotAvailableException; 22 import com.android.tradefed.testtype.DeviceJUnit4ClassRunner; 23 24 import java.io.FileNotFoundException; 25 26 import org.junit.After; 27 import org.junit.Before; 28 import org.junit.Test; 29 import org.junit.runner.RunWith; 30 31 /** 32 * Tests that verify some of the behaviors of Auth-Bound keys 33 */ 34 @RunWith(DeviceJUnit4ClassRunner.class) 35 public class AuthBoundKeyTest extends BaseAppSecurityTest { 36 static final String PKG = "com.android.cts.authboundkeyapp"; 37 static final String CLASS = PKG + ".AuthBoundKeyAppTest"; 38 static final String APK = "AuthBoundKeyApp.apk"; 39 40 @Before setUp()41 public void setUp() throws Exception { 42 Utils.prepareSingleUser(getDevice()); 43 getDevice().uninstallPackage(PKG); 44 } 45 46 @After tearDown()47 public void tearDown() throws Exception { 48 getDevice().uninstallPackage(PKG); 49 } 50 51 @Test useInvalidatedAuthBoundKey()52 public void useInvalidatedAuthBoundKey() 53 throws DeviceNotAvailableException, FileNotFoundException { 54 assumeTrue("Device does not support secure lock", 55 getDevice().hasFeature("android.software.secure_lock_screen")); 56 new InstallMultiple().addApk(APK).run(); 57 getDevice().executeShellCommand("cmd lock_settings set-pin 1234"); 58 runDeviceTests(PKG, CLASS, "testGenerateAuthBoundKey"); 59 getDevice().executeShellCommand("cmd lock_settings clear --old 1234"); 60 runDeviceTests(PKG, CLASS, "testUseKey"); 61 getDevice().executeShellCommand("cmd lock_settings set-pin 12345"); 62 getDevice().executeShellCommand("input keyevent 26"); // Screen on 63 getDevice().executeShellCommand("input keyevent 82"); // Bring up lock screen 64 getDevice().executeShellCommand("input text 12345"); // Input password 65 getDevice().executeShellCommand("input keyevent 66"); // Submit input 66 // try:finally clause to ensure the pin is wiped before testing continues 67 try { 68 runDeviceTests(PKG, CLASS, "testUseKey"); 69 } finally { 70 getDevice().executeShellCommand("cmd lock_settings clear --old 12345"); 71 } 72 } 73 } 74