private void loadKeys(ICordovaClientCertRequest request) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(cordova.getActivity()); final KeyChainAliasCallback callback = new AliasCallback(cordova.getActivity(), request); final String alias = sp.getString(SP_KEY_ALIAS, null); if (alias == null) { KeyChain.choosePrivateKeyAlias(cordova.getActivity(), callback, new String[]{"RSA"}, null, request.getHost(), request.getPort(), null); } else { ExecutorService threadPool = cordova.getThreadPool(); threadPool.submit(new Runnable() { @Override public void run() { callback.alias(alias); } }); } }
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH) @Override public boolean onReceivedClientCertRequest(CordovaWebView view, ICordovaClientCertRequest request) { if (mCertificates == null || mPrivateKey == null) { loadKeys(request); } else { proceedRequers(request); } return true; }
public AliasCallback(Context context, ICordovaClientCertRequest request) { mRequest = request; mContext = context; mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); }
public void proceedRequers(ICordovaClientCertRequest request) { request.proceed(mPrivateKey, mCertificates); }