Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.net; | |
| 6 | |
| 7 import android.os.RemoteException; | |
| 8 import android.util.Log; | |
| 9 | |
| 10 /** | |
| 11 * Provides a remoted implementation of AndroidKeyStore where all calls are forw arded via | |
| 12 * binder to an external process. | |
| 13 */ | |
| 14 public class AndroidKeyStoreRemoteImpl implements AndroidKeyStore { | |
| 15 | |
| 16 private static class RemotePrivateKey implements AndroidPrivateKey { | |
| 17 // Reference to the key on a remote store. | |
| 18 final String mHandle; | |
| 19 // Key store handling this key. | |
| 20 final AndroidKeyStoreRemoteImpl mStore; | |
| 21 | |
| 22 RemotePrivateKey(String handle, AndroidKeyStoreRemoteImpl store) { | |
| 23 mHandle = handle; | |
| 24 mStore = store; | |
| 25 } | |
| 26 | |
| 27 public String getHandle() { | |
| 28 return mHandle; | |
| 29 } | |
| 30 | |
| 31 @Override | |
| 32 public AndroidKeyStore getKeyStore() { | |
| 33 return mStore; | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 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.
| |
| 38 | |
| 39 private final IAndroidKeyStoreRemote mRemoteManager; | |
| 40 | |
| 41 public AndroidKeyStoreRemoteImpl(IAndroidKeyStoreRemote manager) { | |
| 42 mRemoteManager = manager; | |
| 43 } | |
| 44 | |
| 45 @Override | |
| 46 public byte[] getRSAKeyModulus(AndroidPrivateKey key) { | |
| 47 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 48 try { | |
| 49 Log.d(TAG, "getRSAKeyModulus"); | |
| 50 return mRemoteManager.getRSAKeyModulus(remoteKey.getHandle()); | |
| 51 } catch (RemoteException e) { | |
| 52 e.printStackTrace(); | |
| 53 return null; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 @Override | |
| 58 public byte[] getDSAKeyParamQ(AndroidPrivateKey key) { | |
| 59 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 60 try { | |
| 61 Log.d(TAG, "getDSAKeyParamQ"); | |
| 62 return mRemoteManager.getDSAKeyParamQ(remoteKey.getHandle()); | |
| 63 } catch (RemoteException e) { | |
| 64 e.printStackTrace(); | |
| 65 return null; | |
| 66 } | |
| 67 } | |
| 68 | |
| 69 @Override | |
| 70 public byte[] getECKeyOrder(AndroidPrivateKey key) { | |
| 71 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 72 try { | |
| 73 Log.d(TAG, "getECKeyOrder"); | |
| 74 return mRemoteManager.getECKeyOrder(remoteKey.getHandle()); | |
| 75 } catch (RemoteException e) { | |
| 76 e.printStackTrace(); | |
| 77 return null; | |
| 78 } | |
| 79 } | |
| 80 | |
| 81 @Override | |
| 82 public byte[] rawSignDigestWithPrivateKey(AndroidPrivateKey key, byte[] mess age) { | |
| 83 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 84 try { | |
| 85 Log.d(TAG, "rawSignDigestWithPrivateKey"); | |
| 86 return mRemoteManager.rawSignDigestWithPrivateKey(remoteKey.getHandl e(), message); | |
| 87 } catch (RemoteException e) { | |
| 88 e.printStackTrace(); | |
| 89 return null; | |
| 90 } | |
| 91 } | |
| 92 | |
| 93 @Override | |
| 94 public int getPrivateKeyType(AndroidPrivateKey key) { | |
| 95 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 96 try { | |
| 97 Log.d(TAG, "getPrivateKeyType"); | |
| 98 return mRemoteManager.getPrivateKeyType(remoteKey.getHandle()); | |
| 99 } catch (RemoteException e) { | |
| 100 e.printStackTrace(); | |
| 101 return 0; | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 @Override | |
| 106 public byte[] getPrivateKeyEncodedBytes(AndroidPrivateKey key) { | |
| 107 // This should not be called as it's only for older versions of Android. | |
| 108 assert false; | |
| 109 return null; | |
| 110 } | |
| 111 | |
| 112 @Override | |
| 113 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
| |
| 114 // This should not be called as it's only for older versions of Android. | |
| 115 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.
| |
| 116 return 0; | |
| 117 } | |
| 118 | |
| 119 public AndroidPrivateKey createKey(String alias) { | |
| 120 try { | |
| 121 String handle = mRemoteManager.getPrivateKeyHandle(alias); | |
| 122 return new RemotePrivateKey(handle, this); | |
| 123 } catch (RemoteException e) { | |
| 124 e.printStackTrace(); | |
| 125 return null; | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 @Override | |
| 130 public void releaseKey(AndroidPrivateKey key) { | |
| 131 RemotePrivateKey remoteKey = (RemotePrivateKey) key; | |
| 132 try { | |
| 133 Log.d(TAG, "releaseKey"); | |
| 134 mRemoteManager.releaseKey(remoteKey.getHandle()); | |
| 135 } catch (RemoteException e) { | |
| 136 e.printStackTrace(); | |
| 137 } | |
| 138 } | |
| 139 } | |
| OLD | NEW |