summaryrefslogtreecommitdiffstats
path: root/core/java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/admin/DevicePolicyManager.java71
-rw-r--r--core/java/android/app/admin/IDevicePolicyManager.aidl3
2 files changed, 74 insertions, 0 deletions
diff --git a/core/java/android/app/admin/DevicePolicyManager.java b/core/java/android/app/admin/DevicePolicyManager.java
index be831d7..e0b1c00 100644
--- a/core/java/android/app/admin/DevicePolicyManager.java
+++ b/core/java/android/app/admin/DevicePolicyManager.java
@@ -32,10 +32,17 @@ import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;
+import com.android.org.conscrypt.TrustedCertificateStore;
+
+import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Proxy;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
import java.util.List;
+import java.util.Set;
/**
* Public interface for managing policies enforced on a device. Most clients
@@ -1328,6 +1335,70 @@ public class DevicePolicyManager {
}
/**
+ * Installs the given certificate as a User CA.
+ *
+ * @return false if the certBuffer cannot be parsed or installation is
+ * interrupted, otherwise true
+ * @hide
+ */
+ public boolean installCaCert(byte[] certBuffer) {
+ if (mService != null) {
+ try {
+ return mService.installCaCert(certBuffer);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed talking with device policy service", e);
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Uninstalls the given certificate from the list of User CAs, if present.
+ *
+ * @hide
+ */
+ public void uninstallCaCert(byte[] certBuffer) {
+ if (mService != null) {
+ try {
+ mService.uninstallCaCert(certBuffer);
+ } catch (RemoteException e) {
+ Log.w(TAG, "Failed talking with device policy service", e);
+ }
+ }
+ }
+
+ /**
+ * Returns whether there are any user-installed CA certificates.
+ *
+ * @hide
+ */
+ public boolean hasAnyCaCertsInstalled() {
+ TrustedCertificateStore certStore = new TrustedCertificateStore();
+ Set<String> aliases = certStore.userAliases();
+ return aliases != null && !aliases.isEmpty();
+ }
+
+ /**
+ * Returns whether this certificate has been installed as a User CA.
+ *
+ * @hide
+ */
+ public boolean hasCaCertInstalled(byte[] certBuffer) {
+ TrustedCertificateStore certStore = new TrustedCertificateStore();
+ String alias;
+ byte[] pemCert;
+ try {
+ CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
+ X509Certificate cert = (X509Certificate) certFactory.generateCertificate(
+ new ByteArrayInputStream(certBuffer));
+ return certStore.getCertificateAlias(cert) != null;
+ } catch (CertificateException ce) {
+ Log.w(TAG, "Could not parse certificate", ce);
+ }
+ return false;
+ }
+
+ /**
* Called by an application that is administering the device to disable all cameras
* on the device. After setting this, no applications will be able to access any cameras
* on the device.
diff --git a/core/java/android/app/admin/IDevicePolicyManager.aidl b/core/java/android/app/admin/IDevicePolicyManager.aidl
index 9659a91..172c47c 100644
--- a/core/java/android/app/admin/IDevicePolicyManager.aidl
+++ b/core/java/android/app/admin/IDevicePolicyManager.aidl
@@ -102,4 +102,7 @@ interface IDevicePolicyManager {
boolean isDeviceOwner(String packageName);
String getDeviceOwner();
String getDeviceOwnerName();
+
+ boolean installCaCert(in byte[] certBuffer);
+ void uninstallCaCert(in byte[] certBuffer);
}