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 RemoteAndroidKeyStore implements AndroidKeyStore { |
| 15 |
| 16 private static final String TAG = "AndroidKeyStoreRemoteImpl"; |
| 17 |
| 18 private static class RemotePrivateKey implements AndroidPrivateKey { |
| 19 // Reference to the key on a remote store. |
| 20 final int mHandle; |
| 21 // Key store handling this key. |
| 22 final RemoteAndroidKeyStore mStore; |
| 23 |
| 24 RemotePrivateKey(int handle, RemoteAndroidKeyStore store) { |
| 25 mHandle = handle; |
| 26 mStore = store; |
| 27 } |
| 28 |
| 29 public int getHandle() { |
| 30 return mHandle; |
| 31 } |
| 32 |
| 33 @Override |
| 34 public AndroidKeyStore getKeyStore() { |
| 35 return mStore; |
| 36 } |
| 37 } |
| 38 |
| 39 private final IRemoteAndroidKeyStore mRemoteManager; |
| 40 |
| 41 public RemoteAndroidKeyStore(IRemoteAndroidKeyStore 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) { |
| 114 // This should not be called as it's only for older versions of Android. |
| 115 assert false; |
| 116 return 0; |
| 117 } |
| 118 |
| 119 public AndroidPrivateKey createKey(String alias) { |
| 120 try { |
| 121 int 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 |