1 /* 2 * Copyright (C) 2022 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.security.cts.CVE_2022_20230; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.ComponentName; 21 import android.content.Context; 22 23 import java.security.PrivateKey; 24 import java.security.cert.Certificate; 25 26 public class PocPolicyManager { 27 private Context mContext; 28 private DevicePolicyManager mDevicePolicyManager; 29 private ComponentName mComponentName; 30 PocPolicyManager(Context context)31 public PocPolicyManager(Context context) { 32 this.mContext = context; 33 mDevicePolicyManager = mContext.getSystemService(DevicePolicyManager.class); 34 mComponentName = new ComponentName(PocDeviceAdminReceiver.class.getPackage().getName(), 35 PocDeviceAdminReceiver.class.getName()); 36 } 37 clearDeviceOwner()38 public void clearDeviceOwner() { 39 mDevicePolicyManager.clearDeviceOwnerApp(mContext.getPackageName()); 40 } 41 installKeyPair(PrivateKey pkey, Certificate cert, String alias)42 public boolean installKeyPair(PrivateKey pkey, Certificate cert, String alias) { 43 return mDevicePolicyManager.installKeyPair(mComponentName, pkey, cert, alias); 44 } 45 removeKeyPair(String alias)46 public boolean removeKeyPair(String alias) { 47 return mDevicePolicyManager.removeKeyPair(mComponentName, alias); 48 } 49 } 50