Index: net/android/java/src/org/chromium/net/AndroidKeyStoreRemoteImpl.java |
diff --git a/net/android/java/src/org/chromium/net/AndroidKeyStoreRemoteImpl.java b/net/android/java/src/org/chromium/net/AndroidKeyStoreRemoteImpl.java |
new file mode 100644 |
index 0000000000000000000000000000000000000000..69d03112aab8a718443fb03b00f68473e10066d4 |
--- /dev/null |
+++ b/net/android/java/src/org/chromium/net/AndroidKeyStoreRemoteImpl.java |
@@ -0,0 +1,139 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+package org.chromium.net; |
+ |
+import android.os.RemoteException; |
+import android.util.Log; |
+ |
+/** |
+ * Provides a remoted implementation of AndroidKeyStore where all calls are forwarded via |
+ * binder to an external process. |
+ */ |
+public class AndroidKeyStoreRemoteImpl implements AndroidKeyStore { |
+ |
+ private static class RemotePrivateKey implements AndroidPrivateKey { |
+ // Reference to the key on a remote store. |
+ final String mHandle; |
+ // Key store handling this key. |
+ final AndroidKeyStoreRemoteImpl mStore; |
+ |
+ RemotePrivateKey(String handle, AndroidKeyStoreRemoteImpl store) { |
+ mHandle = handle; |
+ mStore = store; |
+ } |
+ |
+ public String getHandle() { |
+ return mHandle; |
+ } |
+ |
+ @Override |
+ public AndroidKeyStore getKeyStore() { |
+ return mStore; |
+ } |
+ } |
+ |
+ private static final String TAG = "AndroidKeyStoreRemoteImpl"; |
Ryan Sleevi
2014/02/14 20:57:51
You ordering between the two classes is inconsiste
Yaron
2014/02/14 22:06:59
Done.
|
+ |
+ private final IAndroidKeyStoreRemote mRemoteManager; |
+ |
+ public AndroidKeyStoreRemoteImpl(IAndroidKeyStoreRemote manager) { |
+ mRemoteManager = manager; |
+ } |
+ |
+ @Override |
+ public byte[] getRSAKeyModulus(AndroidPrivateKey key) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "getRSAKeyModulus"); |
+ return mRemoteManager.getRSAKeyModulus(remoteKey.getHandle()); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return null; |
+ } |
+ } |
+ |
+ @Override |
+ public byte[] getDSAKeyParamQ(AndroidPrivateKey key) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "getDSAKeyParamQ"); |
+ return mRemoteManager.getDSAKeyParamQ(remoteKey.getHandle()); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return null; |
+ } |
+ } |
+ |
+ @Override |
+ public byte[] getECKeyOrder(AndroidPrivateKey key) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "getECKeyOrder"); |
+ return mRemoteManager.getECKeyOrder(remoteKey.getHandle()); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return null; |
+ } |
+ } |
+ |
+ @Override |
+ public byte[] rawSignDigestWithPrivateKey(AndroidPrivateKey key, byte[] message) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "rawSignDigestWithPrivateKey"); |
+ return mRemoteManager.rawSignDigestWithPrivateKey(remoteKey.getHandle(), message); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return null; |
+ } |
+ } |
+ |
+ @Override |
+ public int getPrivateKeyType(AndroidPrivateKey key) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "getPrivateKeyType"); |
+ return mRemoteManager.getPrivateKeyType(remoteKey.getHandle()); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return 0; |
+ } |
+ } |
+ |
+ @Override |
+ public byte[] getPrivateKeyEncodedBytes(AndroidPrivateKey key) { |
+ // This should not be called as it's only for older versions of Android. |
+ assert false; |
+ return null; |
+ } |
+ |
+ @Override |
+ public int getOpenSSLHandleForPrivateKey(AndroidPrivateKey privateKey) { |
Ryan Sleevi
2014/02/14 20:57:51
This seems like a real codesmell that you have to
Yaron
2014/02/14 22:06:59
True but it's sort of dead code anyway. See the in
|
+ // This should not be called as it's only for older versions of Android. |
+ assert false; |
Ryan Sleevi
2014/02/14 20:57:51
Your ordering within this class does not match the
Yaron
2014/02/14 22:06:59
Done.
|
+ return 0; |
+ } |
+ |
+ public AndroidPrivateKey createKey(String alias) { |
+ try { |
+ String handle = mRemoteManager.getPrivateKeyHandle(alias); |
+ return new RemotePrivateKey(handle, this); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ return null; |
+ } |
+ } |
+ |
+ @Override |
+ public void releaseKey(AndroidPrivateKey key) { |
+ RemotePrivateKey remoteKey = (RemotePrivateKey) key; |
+ try { |
+ Log.d(TAG, "releaseKey"); |
+ mRemoteManager.releaseKey(remoteKey.getHandle()); |
+ } catch (RemoteException e) { |
+ e.printStackTrace(); |
+ } |
+ } |
+} |