From bf20b9963add781a35de658f3228760015a163c9 Mon Sep 17 00:00:00 2001 From: Chung-yih Wang Date: Thu, 2 Jul 2009 23:42:12 +0800 Subject: [PATCH] Migrate to the CertTool library. Keystore is reimplemented and it is mainly for storing (key, value) pair generically. The certificate related APIs are moved to the class CertTool instead. Updates: Provide the getInstance() which gives the singleton. Fix the missing construction of the BIO in cert.c. --- core/java/android/webkit/JWebCoreJavaBridge.java | 6 +++--- core/java/android/webkit/LoadListener.java | 4 ++-- keystore/java/android/security/CertTool.java | 9 +++++++++ keystore/jni/cert.c | 3 +++ 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/java/android/webkit/JWebCoreJavaBridge.java b/core/java/android/webkit/JWebCoreJavaBridge.java index 5c0bd93251339..1dbd007886f13 100644 --- a/core/java/android/webkit/JWebCoreJavaBridge.java +++ b/core/java/android/webkit/JWebCoreJavaBridge.java @@ -18,7 +18,7 @@ package android.webkit; import android.os.Handler; import android.os.Message; -import android.security.Keystore; +import android.security.CertTool; import android.util.Log; final class JWebCoreJavaBridge extends Handler { @@ -188,12 +188,12 @@ final class JWebCoreJavaBridge extends Handler { } private String[] getKeyStrengthList() { - return Keystore.getInstance().getSupportedKeyStrenghs(); + return CertTool.getInstance().getSupportedKeyStrenghs(); } private String getSignedPublicKey(int index, String challenge, String url) { // generateKeyPair expects organizations which we don't have. Ignore url. - return Keystore.getInstance().generateKeyPair(index, challenge, null); + return CertTool.getInstance().generateKeyPair(index, challenge, null); } private native void nativeConstructor(); diff --git a/core/java/android/webkit/LoadListener.java b/core/java/android/webkit/LoadListener.java index 07e03ff8dcfae..39360cd72a23e 100644 --- a/core/java/android/webkit/LoadListener.java +++ b/core/java/android/webkit/LoadListener.java @@ -28,7 +28,7 @@ import android.net.http.SslError; import android.os.Handler; import android.os.Message; -import android.security.Keystore; +import android.security.CertTool; import android.util.Log; import android.webkit.CacheManager.CacheResult; import android.widget.Toast; @@ -999,7 +999,7 @@ class LoadListener extends Handler implements EventHandler { } mDataBuilder.releaseChunk(c); } - Keystore.getInstance().addCertificate(cert); + CertTool.getInstance().addCertificate(cert, mContext); Toast.makeText(mContext, R.string.certificateSaved, Toast.LENGTH_SHORT).show(); mBrowserFrame.stopLoading(); diff --git a/keystore/java/android/security/CertTool.java b/keystore/java/android/security/CertTool.java index 1dc575bccb881..531933007b309 100644 --- a/keystore/java/android/security/CertTool.java +++ b/keystore/java/android/security/CertTool.java @@ -63,6 +63,15 @@ public class CertTool { private native String getPrivateKeyPEM(int handle); private native void freeX509Certificate(int handle); + private static CertTool singleton = null; + + public static final CertTool getInstance() { + if (singleton == null) { + singleton = new CertTool(); + } + return singleton; + } + public String getUserPrivateKey(String key) { return USER_KEY + KEYNAME_DELIMITER + key; } diff --git a/keystore/jni/cert.c b/keystore/jni/cert.c index 07f0e860cf8e8..cc36b84e99a38 100644 --- a/keystore/jni/cert.c +++ b/keystore/jni/cert.c @@ -144,6 +144,9 @@ int is_pkcs12(const char *buf, int bufLen) if (!buf || bufLen < 1) goto err; + bp = BIO_new(BIO_s_mem()); + if (!bp) goto err; + if (buf[0] != 48) goto err; // it is not DER. if (!BIO_write(bp, buf, bufLen)) goto err;