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