summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorMaggie Benthall <mbenthall@google.com>2013-08-20 18:35:08 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-20 18:35:08 +0000
commit1cd230a552bcc4196b546321b670e084e643c8d5 (patch)
tree1bb3bf257066288dec0d0790c1ae017014b14739 /core/java/android
parentcf8e6778c28319b6c5357a43831ebf1a41b56e96 (diff)
parentda51e68e582ffa017543982297c831680d201a91 (diff)
downloadframeworks_base-1cd230a552bcc4196b546321b670e084e643c8d5.zip
frameworks_base-1cd230a552bcc4196b546321b670e084e643c8d5.tar.gz
frameworks_base-1cd230a552bcc4196b546321b670e084e643c8d5.tar.bz2
Merge "Add methods for managing CAs to DevicePolicyManager(Service)" into klp-dev
Diffstat (limited to 'core/java/android')
-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);
}