diff options
author | Marco Nelissen <marcone@google.com> | 2014-03-14 22:27:22 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-03-14 22:27:23 +0000 |
commit | 10a07a043f7fa47148ae2cc2fcd6b0edeb52190b (patch) | |
tree | ad9a666b09e1ba5a67bbaf5a591b1e2797ba9699 | |
parent | 09421fab0784bcfc6660a09d02faea7835c28e31 (diff) | |
parent | 7e435a011dd519f76a8ec1a8ed99a22bee5c3e26 (diff) | |
download | frameworks_base-10a07a043f7fa47148ae2cc2fcd6b0edeb52190b.zip frameworks_base-10a07a043f7fa47148ae2cc2fcd6b0edeb52190b.tar.gz frameworks_base-10a07a043f7fa47148ae2cc2fcd6b0edeb52190b.tar.bz2 |
Merge "Verify certificates" into klp-dev
-rw-r--r-- | media/java/android/media/AudioService.java | 43 | ||||
-rw-r--r-- | media/java/android/media/IAudioService.aidl | 3 |
2 files changed, 46 insertions, 0 deletions
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java index 17c4595..92474df 100644 --- a/media/java/android/media/AudioService.java +++ b/media/java/android/media/AudioService.java @@ -49,6 +49,8 @@ import android.database.ContentObserver; import android.media.MediaPlayer.OnCompletionListener; import android.media.MediaPlayer.OnErrorListener; import android.net.Uri; +import android.net.http.CertificateChainValidator; +import android.net.http.SslError; import android.os.Binder; import android.os.Build; import android.os.Bundle; @@ -81,10 +83,12 @@ import com.android.internal.util.XmlUtils; import org.xmlpull.v1.XmlPullParserException; +import java.io.ByteArrayInputStream; import java.io.FileDescriptor; import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.Field; +import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.concurrent.ConcurrentHashMap; import java.util.HashMap; @@ -116,6 +120,8 @@ public class AudioService extends IAudioService.Stub { protected static final boolean DEBUG_RC = false; /** Debug volumes */ protected static final boolean DEBUG_VOL = false; + /** Debug cert verification */ + private static final boolean DEBUG_CERTS = false; /** How long to delay before persisting a change in volume/ringer mode. */ private static final int PERSIST_DELAY = 500; @@ -4581,6 +4587,43 @@ public class AudioService extends IAudioService.Stub { } } + public int verifyX509CertChain(int numcerts, byte [] chain, String domain, String authType) { + + if (DEBUG_CERTS) { + Log.v(TAG, "java side verify for " + + numcerts + " certificates (" + chain.length + " bytes" + + ")for "+ domain + "/" + authType); + } + + byte[][] certChain = new byte[numcerts][]; + + ByteBuffer buf = ByteBuffer.wrap(chain); + for (int i = 0; i < numcerts; i++) { + int certlen = buf.getInt(); + if (DEBUG_CERTS) { + Log.i(TAG, "cert " + i +": " + certlen); + } + certChain[i] = new byte[certlen]; + buf.get(certChain[i]); + } + + try { + SslError err = CertificateChainValidator.verifyServerCertificates(certChain, + domain, authType); + if (DEBUG_CERTS) { + Log.i(TAG, "verified: " + err); + } + if (err == null) { + return -1; + } else { + return err.getPrimaryError(); + } + } catch (Exception e) { + Log.e(TAG, "failed to verify chain: " + e); + } + return SslError.SSL_INVALID; + } + //========================================================================================== // Camera shutter sound policy. diff --git a/media/java/android/media/IAudioService.aidl b/media/java/android/media/IAudioService.aidl index 2f08325..b5c3631 100644 --- a/media/java/android/media/IAudioService.aidl +++ b/media/java/android/media/IAudioService.aidl @@ -35,6 +35,8 @@ import android.view.KeyEvent; */ interface IAudioService { + int verifyX509CertChain(int chainsize, in byte[] chain, String host, String authtype); + void adjustVolume(int direction, int flags, String callingPackage); boolean isLocalOrRemoteMusicActive(); @@ -236,4 +238,5 @@ interface IAudioService { AudioRoutesInfo startWatchingRoutes(in IAudioRoutesObserver observer); boolean isCameraSoundForced(); + } |