Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bf20b996 authored by Chung-yih Wang's avatar Chung-yih Wang
Browse files

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.
parent 24ad29c6
Loading
Loading
Loading
Loading
+3 −3
Original line number Original line Diff line number Diff line
@@ -18,7 +18,7 @@ package android.webkit;


import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.security.Keystore;
import android.security.CertTool;
import android.util.Log;
import android.util.Log;


final class JWebCoreJavaBridge extends Handler {
final class JWebCoreJavaBridge extends Handler {
@@ -188,12 +188,12 @@ final class JWebCoreJavaBridge extends Handler {
    }
    }


    private String[] getKeyStrengthList() {
    private String[] getKeyStrengthList() {
        return Keystore.getInstance().getSupportedKeyStrenghs();
        return CertTool.getInstance().getSupportedKeyStrenghs();
    }
    }


    private String getSignedPublicKey(int index, String challenge, String url) {
    private String getSignedPublicKey(int index, String challenge, String url) {
        // generateKeyPair expects organizations which we don't have. Ignore 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();
    private native void nativeConstructor();
+2 −2
Original line number Original line Diff line number Diff line
@@ -28,7 +28,7 @@ import android.net.http.SslError;


import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
import android.security.Keystore;
import android.security.CertTool;
import android.util.Log;
import android.util.Log;
import android.webkit.CacheManager.CacheResult;
import android.webkit.CacheManager.CacheResult;
import android.widget.Toast;
import android.widget.Toast;
@@ -999,7 +999,7 @@ class LoadListener extends Handler implements EventHandler {
                }
                }
                mDataBuilder.releaseChunk(c);
                mDataBuilder.releaseChunk(c);
            }
            }
            Keystore.getInstance().addCertificate(cert);
            CertTool.getInstance().addCertificate(cert, mContext);
            Toast.makeText(mContext, R.string.certificateSaved,
            Toast.makeText(mContext, R.string.certificateSaved,
                    Toast.LENGTH_SHORT).show();
                    Toast.LENGTH_SHORT).show();
            mBrowserFrame.stopLoading();
            mBrowserFrame.stopLoading();
+9 −0
Original line number Original line Diff line number Diff line
@@ -63,6 +63,15 @@ public class CertTool {
    private native String getPrivateKeyPEM(int handle);
    private native String getPrivateKeyPEM(int handle);
    private native void freeX509Certificate(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) {
    public String getUserPrivateKey(String key) {
        return USER_KEY + KEYNAME_DELIMITER + key;
        return USER_KEY + KEYNAME_DELIMITER + key;
    }
    }
+3 −0
Original line number Original line Diff line number Diff line
@@ -144,6 +144,9 @@ int is_pkcs12(const char *buf, int bufLen)


    if (!buf || bufLen < 1) goto err;
    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 (buf[0] != 48) goto err; // it is not DER.


    if (!BIO_write(bp, buf, bufLen)) goto err;
    if (!BIO_write(bp, buf, bufLen)) goto err;