Chromium Code Reviews| Index: net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| diff --git a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| index 28208a76bdbdfb58be8baf453894798a362f66ff..8baeef4bc65ebcdf6f32cc118872a093469e467c 100644 |
| --- a/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| +++ b/net/android/java/src/org/chromium/net/AndroidNetworkLibrary.java |
| @@ -7,6 +7,7 @@ package org.chromium.net; |
| import android.content.ActivityNotFoundException; |
| import android.content.Context; |
| import android.content.Intent; |
| +import android.security.KeyChain; |
| import android.util.Log; |
| import org.chromium.base.CalledByNative; |
| @@ -30,24 +31,33 @@ class AndroidNetworkLibrary { |
| private static final String TAG = AndroidNetworkLibrary.class.getName(); |
| /** |
| - * Stores the key pair into the CertInstaller application. |
| + * Stores the key pair through the CertInstaller activity. |
| + * @param context: current activity context. |
|
joth
2012/10/24 19:40:28
question: I think native code normally passes over
digit1
2012/10/25 14:34:32
That's correct, updated.
|
| + * @param public_key: The public key bytes as DER-encoded SubjectPublicKeyInfo (X.509) |
| + * @param private_key: The private key as DER-encoded PrivateKeyInfo (PKCS#8). |
| + * @return: true on success, false on failure. |
| + * |
| + * Note that failure means that the function could not launch the CertInstaller |
| + * activity. Whether the keys are valid or properly installed will be indicated |
| + * by the CertInstaller UI itself. |
| */ |
| @CalledByNative |
| - static public boolean storeKeyPair(Context context, byte[] public_key, byte[] private_key) { |
| - // This is based on android.security.Credentials.install() |
| - // TODO(joth): Use KeyChain API instead of hard-coding constants here: |
| - // http://crbug.com/124660 |
| + static public boolean storeKeyPair(Context context, |
| + byte[] public_key, |
| + byte[] private_key) { |
|
joth
2012/10/24 19:40:28
nit: java style param wrap is double indent (not a
digit1
2012/10/25 14:34:32
Done.
|
| + // TODO(digit): Use KeyChain official extra values to pass the public and private |
| + // keys when they're available. The "KEY" and "PKEY" hard-coded constants were taken |
| + // from the platform sources, since there are no official KeyChain.EXTRA_XXX definitions |
| + // for them. b/5859651 |
| try { |
| - Intent intent = new Intent("android.credentials.INSTALL"); |
| - intent.setClassName("com.android.certinstaller", |
| - "com.android.certinstaller.CertInstallerMain"); |
| - intent.putExtra("KEY", private_key); |
| - intent.putExtra("PKEY", public_key); |
| + Intent intent = KeyChain.createInstallIntent(); |
| + intent.putExtra("PKEY", private_key); |
| + intent.putExtra("KEY", public_key); |
| intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| context.startActivity(intent); |
| return true; |
| } catch (ActivityNotFoundException e) { |
| - Log.w(TAG, "could not store certificate: " + e); |
| + Log.w(TAG, "could not store key pair: " + e); |
| } |
| return false; |
| } |