1 /* 2 * Copyright (C) 2018 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 com.android.cts.deviceandprofileowner; 18 19 import static android.app.admin.DevicePolicyManager.DELEGATION_CERT_INSTALL; 20 import static android.app.admin.DevicePolicyManager.DELEGATION_CERT_SELECTION; 21 22 import android.keystore.cts.KeyGenerationUtils; 23 24 import java.util.Arrays; 25 import java.util.List; 26 27 /** 28 * A helper class for setting the DelegatedCertInstaller to the desired package. 29 * Does not actually contain any tests. 30 */ 31 public class DelegatedCertInstallerHelper extends BaseDeviceAdminTest { 32 private static final String CERT_INSTALLER_PACKAGE = "com.android.cts.certinstaller"; 33 34 private static final List<String> CERT_INSTALL_SCOPES = Arrays.asList( 35 DELEGATION_CERT_INSTALL, DELEGATION_CERT_SELECTION); 36 37 // MUST match the alias in PreSelectedKeyAccessTest 38 private static final String PRE_SELECTED_ALIAS = "pre-selected-rsa"; 39 testManualSetCertInstallerDelegate()40 public void testManualSetCertInstallerDelegate() { 41 setDelegatedScopes(CERT_INSTALLER_PACKAGE, CERT_INSTALL_SCOPES); 42 assertTrue(mDevicePolicyManager.getDelegatePackages(ADMIN_RECEIVER_COMPONENT, 43 DELEGATION_CERT_INSTALL).contains(CERT_INSTALLER_PACKAGE)); 44 assertTrue(mDevicePolicyManager.getDelegatePackages(ADMIN_RECEIVER_COMPONENT, 45 DELEGATION_CERT_SELECTION).contains(CERT_INSTALLER_PACKAGE)); 46 } 47 testManualClearCertInstallerDelegate()48 public void testManualClearCertInstallerDelegate() { 49 setDelegatedScopes(CERT_INSTALLER_PACKAGE, Arrays.asList()); 50 assertFalse(mDevicePolicyManager.getDelegatePackages(ADMIN_RECEIVER_COMPONENT, 51 DELEGATION_CERT_INSTALL).contains(CERT_INSTALLER_PACKAGE)); 52 assertFalse(mDevicePolicyManager.getDelegatePackages(ADMIN_RECEIVER_COMPONENT, 53 DELEGATION_CERT_SELECTION).contains(CERT_INSTALLER_PACKAGE)); 54 } 55 testManualGenerateKeyAndGrantAccess()56 public void testManualGenerateKeyAndGrantAccess() { 57 KeyGenerationUtils.generateRsaKey(mDevicePolicyManager, ADMIN_RECEIVER_COMPONENT, 58 PRE_SELECTED_ALIAS); 59 assertTrue(mDevicePolicyManager.grantKeyPairToApp(ADMIN_RECEIVER_COMPONENT, 60 PRE_SELECTED_ALIAS, CERT_INSTALLER_PACKAGE)); 61 } 62 testManualRemoveKeyGrant()63 public void testManualRemoveKeyGrant() { 64 assertTrue(mDevicePolicyManager.revokeKeyPairFromApp(ADMIN_RECEIVER_COMPONENT, 65 PRE_SELECTED_ALIAS, CERT_INSTALLER_PACKAGE)); 66 } 67 testManualClearGeneratedKey()68 public void testManualClearGeneratedKey() { 69 assertTrue(mDevicePolicyManager 70 .removeKeyPair(ADMIN_RECEIVER_COMPONENT, PRE_SELECTED_ALIAS)); 71 } 72 } 73