@@ -0,0 +1,2611 @@
+%0Apackage org.apache.cordova.plugin.clientcertificate;%0A%0Aimport android.annotation.TargetApi;%0Aimport android.content.Context;%0Aimport android.content.SharedPreferences;%0Aimport android.os.Build;%0Aimport android.preference.PreferenceManager;%0Aimport android.security.KeyChain;%0Aimport android.security.KeyChainAliasCallback;%0Aimport android.security.KeyChainException;%0Aimport android.util.Log;%0Aimport android.widget.Toast;%0Aimport org.apache.cordova.CordovaPlugin;%0Aimport org.apache.cordova.CordovaWebView;%0Aimport org.apache.cordova.ICordovaClientCertRequest;%0A%0Aimport java.security.PrivateKey;%0Aimport java.security.cert.X509Certificate;%0Aimport java.util.concurrent.ExecutorService;%0A%0A%0A@TargetApi(Build.VERSION_CODES.LOLLIPOP)%0Apublic class ClientCertificate extends CordovaPlugin %7B%0A%0A%0A    public String p12path = %22%22;%0A    public String p12password = %22%22;%0A%0A%0A    @Override%0A    public Boolean shouldAllowBridgeAccess(String url) %7B%0A        return super.shouldAllowBridgeAccess(url);%0A    %7D%0A%0A%0A    @TargetApi(Build.VERSION_CODES.LOLLIPOP)%0A    @Override%0A    public boolean onReceivedClientCertRequest(CordovaWebView view, ICordovaClientCertRequest request) %7B%0A      try %7B%0A                KeyStore keystore = KeyStore.getInstance(%22PKCS12%22);%0A               %0A                InputStream astream = getAssets().open(p12path);%0A                keystore.load(astream, p12password.toCharArray());%0A                astream.close();%0A                Enumeration e = keystore.aliases();%0A                if (e.hasMoreElements()) %7B%0A                    String ealias = (String) e.nextElement();%0A                    PrivateKey key = (PrivateKey) keystore.getKey(ealias, p12password.toCharArray());%0A                    CertificateFactory cf = CertificateFactory.getInstance(%22X.509%22);%0A                    InputStream bstream = getAssets().open(p12path);%0A                    Collection c = cf.generateCertificates(bstream);%0A                    bstream.close();%0A                    X509Certificate%5B%5D certs = (X509Certificate%5B%5D)(c.toArray(new X509Certificate%5Bc.size()%5D));%0A                    request.proceed(key,certs);%0A                %7D else%0A                %7B%0A                    request.ignore();%0A                %7D%0A%0A            %7D catch (Exception ex)%0A            %7B%0A                request.ignore();%0A            %7D%0A        return true;%0A    %7D%0A%0A    @Override%0A    public boolean execute(String action, JSONArray a, CallbackContext c) throws JSONException %7B%0A        if (action.equals(%22register%22))%0A        %7B%0A            p12path = %22www/%22 + a.getString(0);%0A            p12password = a.getString(1);%0A            return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A%0A%7D

add android initial commit