Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2008, The Android Open Source Project |
| 4 | ** |
| 5 | ** Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | ** you may not use this file except in compliance with the License. |
| 7 | ** You may obtain a copy of the License at |
| 8 | ** |
| 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | ** |
| 11 | ** Unless required by applicable law or agreed to in writing, software |
| 12 | ** distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | ** See the License for the specific language governing permissions and |
| 15 | ** limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | #include <stdint.h> |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 19 | #include <sys/limits.h> |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 20 | #include <sys/types.h> |
| 21 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 22 | #include <algorithm> |
| 23 | #include <limits> |
| 24 | |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 25 | #define LOG_TAG "KeystoreService" |
| 26 | #include <utils/Log.h> |
| 27 | |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 28 | #include <binder/IPCThreadState.h> |
| 29 | #include <binder/IServiceManager.h> |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 30 | #include <binder/Parcel.h> |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 31 | |
| 32 | #include <keystore/IKeystoreService.h> |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 33 | #include <keystore/keystore_hidl_support.h> |
| 34 | |
| 35 | #include "keystore_aidl_hidl_marshalling_utils.h" |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 36 | |
| 37 | namespace android { |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 38 | using namespace ::keystore; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 39 | |
Shawn Willden | 77d71ca | 2014-11-12 16:45:12 -0700 | [diff] [blame] | 40 | const ssize_t MAX_GENERATE_ARGS = 3; |
| 41 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 42 | KeystoreArg::KeystoreArg(const void* data, size_t len) : mData(data), mSize(len) {} |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 43 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 44 | KeystoreArg::~KeystoreArg() {} |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 45 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 46 | const void* KeystoreArg::data() const { |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 47 | return mData; |
| 48 | } |
| 49 | |
| 50 | size_t KeystoreArg::size() const { |
| 51 | return mSize; |
| 52 | } |
| 53 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 54 | OperationResult::OperationResult() : resultCode(), token(), handle(0), inputConsumed(0), data() {} |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 55 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 56 | OperationResult::~OperationResult() {} |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 57 | |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 58 | status_t OperationResult::readFromParcel(const Parcel* inn) { |
| 59 | const Parcel& in = *inn; |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 60 | resultCode = ErrorCode(in.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 61 | token = in.readStrongBinder(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 62 | handle = static_cast<uint64_t>(in.readInt64()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 63 | inputConsumed = in.readInt32(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 64 | data = readKeymasterBlob(in); |
| 65 | outParams = readParamSetFromParcel(in); |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 66 | return OK; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 69 | status_t OperationResult::writeToParcel(Parcel* out) const { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 70 | out->writeInt32(resultCode); |
| 71 | out->writeStrongBinder(token); |
Chad Brubaker | c3a1856 | 2015-03-17 18:21:35 -0700 | [diff] [blame] | 72 | out->writeInt64(handle); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 73 | out->writeInt32(inputConsumed); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 74 | writeKeymasterBlob(data, out); |
| 75 | writeParamSetToParcel(outParams, out); |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 76 | return OK; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 77 | } |
| 78 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 79 | ExportResult::ExportResult() : resultCode() {} |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 80 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 81 | ExportResult::~ExportResult() {} |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 82 | |
Bin Chen | 96d6271 | 2016-08-25 14:41:53 +1000 | [diff] [blame] | 83 | status_t ExportResult::readFromParcel(const Parcel* inn) { |
| 84 | const Parcel& in = *inn; |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 85 | resultCode = ErrorCode(in.readInt32()); |
| 86 | exportData = readKeymasterBlob(in); |
Bin Chen | 96d6271 | 2016-08-25 14:41:53 +1000 | [diff] [blame] | 87 | return OK; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Bin Chen | 96d6271 | 2016-08-25 14:41:53 +1000 | [diff] [blame] | 90 | status_t ExportResult::writeToParcel(Parcel* out) const { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 91 | out->writeInt32(resultCode); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 92 | writeKeymasterBlob(exportData, out); |
Bin Chen | 96d6271 | 2016-08-25 14:41:53 +1000 | [diff] [blame] | 93 | return OK; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 94 | } |
| 95 | |
Chad Brubaker | 6432df7 | 2015-03-20 16:23:04 -0700 | [diff] [blame] | 96 | /** |
| 97 | * Read a byte array from in. The data at *data is still owned by the parcel |
| 98 | */ |
| 99 | static void readByteArray(const Parcel& in, const uint8_t** data, size_t* length) { |
| 100 | ssize_t slength = in.readInt32(); |
| 101 | if (slength > 0) { |
| 102 | *data = reinterpret_cast<const uint8_t*>(in.readInplace(slength)); |
| 103 | if (*data) { |
| 104 | *length = static_cast<size_t>(slength); |
| 105 | } else { |
| 106 | *length = 0; |
| 107 | } |
| 108 | } else { |
| 109 | *data = NULL; |
| 110 | *length = 0; |
| 111 | } |
| 112 | } |
| 113 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 114 | class BpKeystoreService : public BpInterface<IKeystoreService> { |
| 115 | public: |
| 116 | explicit BpKeystoreService(const sp<IBinder>& impl) : BpInterface<IKeystoreService>(impl) {} |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 117 | |
| 118 | // test ping |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 119 | KeyStoreServiceReturnCode getState(int32_t userId) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 120 | Parcel data, reply; |
| 121 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 122 | data.writeInt32(userId); |
| 123 | status_t status = remote()->transact(BnKeystoreService::GET_STATE, data, &reply); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 124 | if (status != NO_ERROR) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 125 | ALOGD("getState() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 126 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 127 | } |
| 128 | int32_t err = reply.readExceptionCode(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 129 | ResponseCode ret = ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 130 | if (err < 0) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 131 | ALOGD("getState() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 132 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 133 | } |
| 134 | return ret; |
| 135 | } |
| 136 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 137 | KeyStoreServiceReturnCode get(const String16& name, int32_t uid, |
| 138 | hidl_vec<uint8_t>* item) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 139 | Parcel data, reply; |
| 140 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 141 | data.writeString16(name); |
Chad Brubaker | ad6a7f5 | 2015-09-09 14:55:22 -0700 | [diff] [blame] | 142 | data.writeInt32(uid); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 143 | status_t status = remote()->transact(BnKeystoreService::GET, data, &reply); |
| 144 | if (status != NO_ERROR) { |
| 145 | ALOGD("get() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 146 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 147 | } |
| 148 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 149 | if (err < 0) { |
| 150 | ALOGD("get() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 151 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 152 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 153 | auto resultItem = readBlobAsByteArray(reply); |
| 154 | if (item) *item = resultItem.value(); |
| 155 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 158 | KeyStoreServiceReturnCode insert(const String16& name, const hidl_vec<uint8_t>& item, int uid, |
| 159 | int32_t flags) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 160 | Parcel data, reply; |
| 161 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 162 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 163 | writeBlobAsByteArray(item, &data); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 164 | data.writeInt32(uid); |
Kenny Root | 0c540aa | 2013-04-03 09:22:15 -0700 | [diff] [blame] | 165 | data.writeInt32(flags); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 166 | status_t status = remote()->transact(BnKeystoreService::INSERT, data, &reply); |
| 167 | if (status != NO_ERROR) { |
| 168 | ALOGD("import() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 169 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 170 | } |
| 171 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 172 | if (err < 0) { |
| 173 | ALOGD("import() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 174 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 175 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 176 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 179 | KeyStoreServiceReturnCode del(const String16& name, int uid) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 180 | Parcel data, reply; |
| 181 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 182 | data.writeString16(name); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 183 | data.writeInt32(uid); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 184 | status_t status = remote()->transact(BnKeystoreService::DEL, data, &reply); |
| 185 | if (status != NO_ERROR) { |
| 186 | ALOGD("del() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 187 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 188 | } |
| 189 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 190 | if (err < 0) { |
| 191 | ALOGD("del() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 192 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 193 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 194 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 197 | KeyStoreServiceReturnCode exist(const String16& name, int uid) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 198 | Parcel data, reply; |
| 199 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 200 | data.writeString16(name); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 201 | data.writeInt32(uid); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 202 | status_t status = remote()->transact(BnKeystoreService::EXIST, data, &reply); |
| 203 | if (status != NO_ERROR) { |
| 204 | ALOGD("exist() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 205 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 206 | } |
| 207 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 208 | if (err < 0) { |
| 209 | ALOGD("exist() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 210 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 211 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 212 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 215 | KeyStoreServiceReturnCode list(const String16& prefix, int uid, |
| 216 | Vector<String16>* matches) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 217 | Parcel data, reply; |
| 218 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 219 | data.writeString16(prefix); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 220 | data.writeInt32(uid); |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 221 | status_t status = remote()->transact(BnKeystoreService::LIST, data, &reply); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 222 | if (status != NO_ERROR) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 223 | ALOGD("list() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 224 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 225 | } |
| 226 | int32_t err = reply.readExceptionCode(); |
| 227 | int32_t numMatches = reply.readInt32(); |
| 228 | for (int32_t i = 0; i < numMatches; i++) { |
| 229 | matches->push(reply.readString16()); |
| 230 | } |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 231 | if (err < 0) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 232 | ALOGD("list() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 233 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 234 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 235 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 238 | KeyStoreServiceReturnCode reset() override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 239 | Parcel data, reply; |
| 240 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 241 | status_t status = remote()->transact(BnKeystoreService::RESET, data, &reply); |
| 242 | if (status != NO_ERROR) { |
| 243 | ALOGD("reset() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 244 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 245 | } |
| 246 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 247 | if (err < 0) { |
| 248 | ALOGD("reset() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 249 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 250 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 251 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 254 | KeyStoreServiceReturnCode onUserPasswordChanged(int32_t userId, |
| 255 | const String16& password) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 256 | Parcel data, reply; |
| 257 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | 96d6d78 | 2015-05-07 10:19:40 -0700 | [diff] [blame] | 258 | data.writeInt32(userId); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 259 | data.writeString16(password); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 260 | status_t status = |
| 261 | remote()->transact(BnKeystoreService::ON_USER_PASSWORD_CHANGED, data, &reply); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 262 | if (status != NO_ERROR) { |
Chad Brubaker | 96d6d78 | 2015-05-07 10:19:40 -0700 | [diff] [blame] | 263 | ALOGD("onUserPasswordChanged() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 264 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 265 | } |
| 266 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 267 | if (err < 0) { |
Chad Brubaker | 96d6d78 | 2015-05-07 10:19:40 -0700 | [diff] [blame] | 268 | ALOGD("onUserPasswordChanged() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 269 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 270 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 271 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 272 | } |
| 273 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 274 | KeyStoreServiceReturnCode lock(int32_t userId) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 275 | Parcel data, reply; |
| 276 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 277 | data.writeInt32(userId); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 278 | status_t status = remote()->transact(BnKeystoreService::LOCK, data, &reply); |
| 279 | if (status != NO_ERROR) { |
| 280 | ALOGD("lock() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 281 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 282 | } |
| 283 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 284 | if (err < 0) { |
| 285 | ALOGD("lock() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 286 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 287 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 288 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 291 | KeyStoreServiceReturnCode unlock(int32_t userId, const String16& password) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 292 | Parcel data, reply; |
| 293 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | 96d6d78 | 2015-05-07 10:19:40 -0700 | [diff] [blame] | 294 | data.writeInt32(userId); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 295 | data.writeString16(password); |
| 296 | status_t status = remote()->transact(BnKeystoreService::UNLOCK, data, &reply); |
| 297 | if (status != NO_ERROR) { |
| 298 | ALOGD("unlock() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 299 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 300 | } |
| 301 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 302 | if (err < 0) { |
| 303 | ALOGD("unlock() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 304 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 305 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 306 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 309 | bool isEmpty(int32_t userId) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 310 | Parcel data, reply; |
| 311 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 312 | data.writeInt32(userId); |
| 313 | status_t status = remote()->transact(BnKeystoreService::IS_EMPTY, data, &reply); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 314 | if (status != NO_ERROR) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 315 | ALOGD("isEmpty() could not contact remote: %d\n", status); |
| 316 | return false; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 317 | } |
| 318 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 319 | if (err < 0) { |
Chad Brubaker | e6c3bfa | 2015-05-12 15:18:26 -0700 | [diff] [blame] | 320 | ALOGD("isEmpty() caught exception %d\n", err); |
| 321 | return false; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 322 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 323 | return reply.readInt32() != 0; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 326 | KeyStoreServiceReturnCode generate(const String16& name, int32_t uid, int32_t keyType, |
| 327 | int32_t keySize, int32_t flags, |
| 328 | Vector<sp<KeystoreArg>>* args) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 329 | Parcel data, reply; |
| 330 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 331 | data.writeString16(name); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 332 | data.writeInt32(uid); |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 333 | data.writeInt32(keyType); |
| 334 | data.writeInt32(keySize); |
Kenny Root | 0c540aa | 2013-04-03 09:22:15 -0700 | [diff] [blame] | 335 | data.writeInt32(flags); |
Chad Brubaker | 468fc69 | 2015-01-13 17:33:14 -0800 | [diff] [blame] | 336 | data.writeInt32(1); |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 337 | data.writeInt32(args->size()); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 338 | for (Vector<sp<KeystoreArg>>::iterator it = args->begin(); it != args->end(); ++it) { |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 339 | sp<KeystoreArg> item = *it; |
| 340 | size_t keyLength = item->size(); |
| 341 | data.writeInt32(keyLength); |
| 342 | void* buf = data.writeInplace(keyLength); |
| 343 | memcpy(buf, item->data(), keyLength); |
| 344 | } |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 345 | status_t status = remote()->transact(BnKeystoreService::GENERATE, data, &reply); |
| 346 | if (status != NO_ERROR) { |
| 347 | ALOGD("generate() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 348 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 349 | } |
| 350 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 351 | if (err < 0) { |
| 352 | ALOGD("generate() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 353 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 354 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 355 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 358 | KeyStoreServiceReturnCode import(const String16& name, const hidl_vec<uint8_t>& key, int uid, |
| 359 | int flags) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 360 | Parcel data, reply; |
| 361 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 362 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 363 | writeBlobAsByteArray(key, &data); |
Kenny Root | b88c3eb | 2013-02-13 14:43:43 -0800 | [diff] [blame] | 364 | data.writeInt32(uid); |
Kenny Root | 0c540aa | 2013-04-03 09:22:15 -0700 | [diff] [blame] | 365 | data.writeInt32(flags); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 366 | status_t status = remote()->transact(BnKeystoreService::IMPORT, data, &reply); |
| 367 | if (status != NO_ERROR) { |
| 368 | ALOGD("import() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 369 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 370 | } |
| 371 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 372 | if (err < 0) { |
| 373 | ALOGD("import() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 374 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 375 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 376 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 379 | KeyStoreServiceReturnCode sign(const String16& name, const hidl_vec<uint8_t>& in, |
| 380 | hidl_vec<uint8_t>* out) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 381 | Parcel data, reply; |
| 382 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 383 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 384 | writeBlobAsByteArray(in, &data); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 385 | status_t status = remote()->transact(BnKeystoreService::SIGN, data, &reply); |
| 386 | if (status != NO_ERROR) { |
| 387 | ALOGD("import() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 388 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 389 | } |
| 390 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 391 | if (err < 0) { |
| 392 | ALOGD("import() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 393 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 394 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 395 | auto outBlob = readBlobAsByteArray(reply); |
| 396 | if (out) { |
| 397 | // don't need to check outBlob.isOk() |
| 398 | // if !outBlob.isOk() the wrapped value is default constructed and therefore empty, |
| 399 | // as expected. |
| 400 | *out = outBlob.value(); |
| 401 | } |
| 402 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 403 | } |
| 404 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 405 | KeyStoreServiceReturnCode verify(const String16& name, const hidl_vec<uint8_t>& in, |
| 406 | const hidl_vec<uint8_t>& signature) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 407 | Parcel data, reply; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 408 | |
| 409 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 410 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 411 | writeBlobAsByteArray(in, &data); |
| 412 | writeBlobAsByteArray(signature, &data); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 413 | status_t status = remote()->transact(BnKeystoreService::VERIFY, data, &reply); |
| 414 | if (status != NO_ERROR) { |
| 415 | ALOGD("verify() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 416 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 417 | } |
| 418 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 419 | if (err < 0) { |
| 420 | ALOGD("verify() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 421 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 422 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 423 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 424 | } |
| 425 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 426 | KeyStoreServiceReturnCode get_pubkey(const String16& name, hidl_vec<uint8_t>* pubkey) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 427 | Parcel data, reply; |
| 428 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 429 | data.writeString16(name); |
| 430 | status_t status = remote()->transact(BnKeystoreService::GET_PUBKEY, data, &reply); |
| 431 | if (status != NO_ERROR) { |
| 432 | ALOGD("get_pubkey() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 433 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 434 | } |
| 435 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 436 | if (err < 0) { |
| 437 | ALOGD("get_pubkey() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 438 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 439 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 440 | auto resultKey = readBlobAsByteArray(reply); |
| 441 | if (pubkey) *pubkey = resultKey.value(); |
| 442 | return ResponseCode(reply.readInt32()); |
| 443 | } |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 444 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 445 | KeyStoreServiceReturnCode grant(const String16& name, int32_t granteeUid) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 446 | Parcel data, reply; |
| 447 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 448 | data.writeString16(name); |
| 449 | data.writeInt32(granteeUid); |
| 450 | status_t status = remote()->transact(BnKeystoreService::GRANT, data, &reply); |
| 451 | if (status != NO_ERROR) { |
| 452 | ALOGD("grant() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 453 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 454 | } |
| 455 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 456 | if (err < 0) { |
| 457 | ALOGD("grant() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 458 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 459 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 460 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 463 | KeyStoreServiceReturnCode ungrant(const String16& name, int32_t granteeUid) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 464 | Parcel data, reply; |
| 465 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 466 | data.writeString16(name); |
| 467 | data.writeInt32(granteeUid); |
| 468 | status_t status = remote()->transact(BnKeystoreService::UNGRANT, data, &reply); |
| 469 | if (status != NO_ERROR) { |
| 470 | ALOGD("ungrant() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 471 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 472 | } |
| 473 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 474 | if (err < 0) { |
| 475 | ALOGD("ungrant() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 476 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 477 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 478 | return ResponseCode(reply.readInt32()); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 481 | int64_t getmtime(const String16& name, int32_t uid) override { |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 482 | Parcel data, reply; |
| 483 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 484 | data.writeString16(name); |
Chad Brubaker | ad6a7f5 | 2015-09-09 14:55:22 -0700 | [diff] [blame] | 485 | data.writeInt32(uid); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 486 | status_t status = remote()->transact(BnKeystoreService::GETMTIME, data, &reply); |
| 487 | if (status != NO_ERROR) { |
| 488 | ALOGD("getmtime() could not contact remote: %d\n", status); |
| 489 | return -1; |
| 490 | } |
| 491 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 492 | if (err < 0) { |
| 493 | ALOGD("getmtime() caught exception %d\n", err); |
| 494 | return -1; |
| 495 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 496 | return reply.readInt64(); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 497 | } |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 498 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 499 | KeyStoreServiceReturnCode duplicate(const String16& srcKey, int32_t srcUid, |
| 500 | const String16& destKey, int32_t destUid) override { |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 501 | Parcel data, reply; |
| 502 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Kenny Root | d53bc92 | 2013-03-21 14:10:15 -0700 | [diff] [blame] | 503 | data.writeString16(srcKey); |
| 504 | data.writeInt32(srcUid); |
| 505 | data.writeString16(destKey); |
| 506 | data.writeInt32(destUid); |
| 507 | status_t status = remote()->transact(BnKeystoreService::DUPLICATE, data, &reply); |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 508 | if (status != NO_ERROR) { |
Kenny Root | d53bc92 | 2013-03-21 14:10:15 -0700 | [diff] [blame] | 509 | ALOGD("duplicate() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 510 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 511 | } |
| 512 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 513 | if (err < 0) { |
Kenny Root | d53bc92 | 2013-03-21 14:10:15 -0700 | [diff] [blame] | 514 | ALOGD("duplicate() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 515 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 516 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 517 | return ResponseCode(reply.readInt32()); |
Kenny Root | 0225407 | 2013-03-20 11:48:19 -0700 | [diff] [blame] | 518 | } |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 519 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 520 | int32_t is_hardware_backed(const String16& keyType) override { |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 521 | Parcel data, reply; |
| 522 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Kenny Root | 1b0e393 | 2013-09-05 13:06:32 -0700 | [diff] [blame] | 523 | data.writeString16(keyType); |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 524 | status_t status = remote()->transact(BnKeystoreService::IS_HARDWARE_BACKED, data, &reply); |
| 525 | if (status != NO_ERROR) { |
| 526 | ALOGD("is_hardware_backed() could not contact remote: %d\n", status); |
| 527 | return -1; |
| 528 | } |
| 529 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 530 | if (err < 0) { |
| 531 | ALOGD("is_hardware_backed() caught exception %d\n", err); |
| 532 | return -1; |
| 533 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 534 | return reply.readInt32(); |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 535 | } |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 536 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 537 | KeyStoreServiceReturnCode clear_uid(int64_t uid) override { |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 538 | Parcel data, reply; |
| 539 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 540 | data.writeInt64(uid); |
| 541 | status_t status = remote()->transact(BnKeystoreService::CLEAR_UID, data, &reply); |
| 542 | if (status != NO_ERROR) { |
| 543 | ALOGD("clear_uid() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 544 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 545 | } |
| 546 | int32_t err = reply.readExceptionCode(); |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 547 | if (err < 0) { |
| 548 | ALOGD("clear_uid() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 549 | return ResponseCode::SYSTEM_ERROR; |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 550 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 551 | return ResponseCode(reply.readInt32()); |
Kenny Root | 2ecc7a1 | 2013-04-01 16:29:11 -0700 | [diff] [blame] | 552 | } |
Robin Lee | 4e86575 | 2014-08-19 17:37:55 +0100 | [diff] [blame] | 553 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 554 | KeyStoreServiceReturnCode addRngEntropy(const hidl_vec<uint8_t>& entropy) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 555 | Parcel data, reply; |
| 556 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 557 | writeBlobAsByteArray(entropy, &data); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 558 | status_t status = remote()->transact(BnKeystoreService::ADD_RNG_ENTROPY, data, &reply); |
| 559 | if (status != NO_ERROR) { |
| 560 | ALOGD("addRngEntropy() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 561 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 562 | } |
| 563 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 564 | if (err < 0) { |
| 565 | ALOGD("addRngEntropy() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 566 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 567 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 568 | return ResponseCode(reply.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 569 | }; |
| 570 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 571 | KeyStoreServiceReturnCode generateKey(const String16& name, |
| 572 | const hidl_vec<KeyParameter>& params, |
| 573 | const hidl_vec<uint8_t>& entropy, int uid, int flags, |
| 574 | KeyCharacteristics* outCharacteristics) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 575 | Parcel data, reply; |
| 576 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 577 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 578 | nullable(writeParamSetToParcel, params, &data); |
| 579 | writeBlobAsByteArray(entropy, &data); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 580 | data.writeInt32(uid); |
| 581 | data.writeInt32(flags); |
| 582 | status_t status = remote()->transact(BnKeystoreService::GENERATE_KEY, data, &reply); |
| 583 | if (status != NO_ERROR) { |
| 584 | ALOGD("generateKey() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 585 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 586 | } |
| 587 | int32_t err = reply.readExceptionCode(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 588 | ResponseCode ret = ResponseCode(reply.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 589 | if (err < 0) { |
| 590 | ALOGD("generateKey() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 591 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 592 | } |
Bin Chen | 863f16f | 2016-08-25 15:13:51 +1000 | [diff] [blame] | 593 | if (outCharacteristics) { |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 594 | *outCharacteristics = nullable(readKeyCharacteristicsFromParcel, reply).value(); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 595 | } |
| 596 | return ret; |
| 597 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 598 | KeyStoreServiceReturnCode |
| 599 | getKeyCharacteristics(const String16& name, const hidl_vec<uint8_t>& clientId, |
| 600 | const hidl_vec<uint8_t>& appData, int32_t uid, |
| 601 | KeyCharacteristics* outCharacteristics) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 602 | Parcel data, reply; |
| 603 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 604 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 605 | writeBlobAsByteArray(clientId, &data); |
| 606 | writeBlobAsByteArray(appData, &data); |
Chad Brubaker | ad6a7f5 | 2015-09-09 14:55:22 -0700 | [diff] [blame] | 607 | data.writeInt32(uid); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 608 | status_t status = |
| 609 | remote()->transact(BnKeystoreService::GET_KEY_CHARACTERISTICS, data, &reply); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 610 | if (status != NO_ERROR) { |
| 611 | ALOGD("getKeyCharacteristics() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 612 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 613 | } |
| 614 | int32_t err = reply.readExceptionCode(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 615 | ResponseCode ret = ResponseCode(reply.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 616 | if (err < 0) { |
| 617 | ALOGD("getKeyCharacteristics() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 618 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 619 | } |
Bin Chen | 863f16f | 2016-08-25 15:13:51 +1000 | [diff] [blame] | 620 | if (outCharacteristics) { |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 621 | *outCharacteristics = nullable(readKeyCharacteristicsFromParcel, reply).value(); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 622 | } |
| 623 | return ret; |
| 624 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 625 | KeyStoreServiceReturnCode importKey(const String16& name, const hidl_vec<KeyParameter>& params, |
| 626 | KeyFormat format, const hidl_vec<uint8_t>& keyData, int uid, |
| 627 | int flags, |
| 628 | KeyCharacteristics* outCharacteristics) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 629 | Parcel data, reply; |
| 630 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 631 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 632 | nullable(writeParamSetToParcel, params, &data); |
| 633 | data.writeInt32(uint32_t(format)); |
| 634 | writeBlobAsByteArray(keyData, &data); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 635 | data.writeInt32(uid); |
| 636 | data.writeInt32(flags); |
| 637 | status_t status = remote()->transact(BnKeystoreService::IMPORT_KEY, data, &reply); |
| 638 | if (status != NO_ERROR) { |
| 639 | ALOGD("importKey() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 640 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 641 | } |
| 642 | int32_t err = reply.readExceptionCode(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 643 | ResponseCode ret = ResponseCode(reply.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 644 | if (err < 0) { |
| 645 | ALOGD("importKey() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 646 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 647 | } |
Bin Chen | 863f16f | 2016-08-25 15:13:51 +1000 | [diff] [blame] | 648 | if (outCharacteristics) { |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 649 | *outCharacteristics = nullable(readKeyCharacteristicsFromParcel, reply).value(); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 650 | } |
| 651 | return ret; |
| 652 | } |
| 653 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 654 | void exportKey(const String16& name, KeyFormat format, const hidl_vec<uint8_t>& clientId, |
| 655 | const hidl_vec<uint8_t>& appData, int32_t uid, ExportResult* result) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 656 | if (!result) { |
| 657 | return; |
| 658 | } |
| 659 | |
| 660 | Parcel data, reply; |
| 661 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 662 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 663 | data.writeInt32(int32_t(format)); |
| 664 | writeBlobAsByteArray(clientId, &data); |
| 665 | writeBlobAsByteArray(appData, &data); |
Chad Brubaker | ad6a7f5 | 2015-09-09 14:55:22 -0700 | [diff] [blame] | 666 | data.writeInt32(uid); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 667 | status_t status = remote()->transact(BnKeystoreService::EXPORT_KEY, data, &reply); |
| 668 | if (status != NO_ERROR) { |
| 669 | ALOGD("exportKey() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 670 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 671 | return; |
| 672 | } |
| 673 | int32_t err = reply.readExceptionCode(); |
| 674 | if (err < 0) { |
| 675 | ALOGD("exportKey() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 676 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 677 | return; |
| 678 | } |
Bin Chen | 96d6271 | 2016-08-25 14:41:53 +1000 | [diff] [blame] | 679 | |
| 680 | reply.readParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 683 | void begin(const sp<IBinder>& appToken, const String16& name, KeyPurpose purpose, |
| 684 | bool pruneable, const hidl_vec<KeyParameter>& params, |
| 685 | const hidl_vec<uint8_t>& entropy, int32_t uid, OperationResult* result) override { |
Chad Brubaker | 57e106d | 2015-06-01 12:59:00 -0700 | [diff] [blame] | 686 | if (!result) { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 687 | return; |
| 688 | } |
| 689 | Parcel data, reply; |
| 690 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 691 | data.writeStrongBinder(appToken); |
| 692 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 693 | data.writeInt32(int32_t(purpose)); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 694 | data.writeInt32(pruneable ? 1 : 0); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 695 | nullable(writeParamSetToParcel, params, &data); |
| 696 | writeBlobAsByteArray(entropy, &data); |
Chad Brubaker | ad6a7f5 | 2015-09-09 14:55:22 -0700 | [diff] [blame] | 697 | data.writeInt32(uid); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 698 | status_t status = remote()->transact(BnKeystoreService::BEGIN, data, &reply); |
| 699 | if (status != NO_ERROR) { |
| 700 | ALOGD("begin() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 701 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 702 | return; |
| 703 | } |
| 704 | int32_t err = reply.readExceptionCode(); |
| 705 | if (err < 0) { |
| 706 | ALOGD("begin() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 707 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 708 | return; |
| 709 | } |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 710 | |
| 711 | reply.readParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 712 | } |
| 713 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 714 | void update(const sp<IBinder>& token, const hidl_vec<KeyParameter>& params, |
| 715 | const hidl_vec<uint8_t>& opData, OperationResult* result) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 716 | if (!result) { |
| 717 | return; |
| 718 | } |
| 719 | Parcel data, reply; |
| 720 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 721 | data.writeStrongBinder(token); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 722 | nullable(writeParamSetToParcel, params, &data); |
| 723 | writeBlobAsByteArray(opData, &data); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 724 | status_t status = remote()->transact(BnKeystoreService::UPDATE, data, &reply); |
| 725 | if (status != NO_ERROR) { |
| 726 | ALOGD("update() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 727 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 728 | return; |
| 729 | } |
| 730 | int32_t err = reply.readExceptionCode(); |
| 731 | if (err < 0) { |
| 732 | ALOGD("update() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 733 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 734 | return; |
| 735 | } |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 736 | |
| 737 | reply.readParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 740 | void finish(const sp<IBinder>& token, const hidl_vec<KeyParameter>& params, |
| 741 | const hidl_vec<uint8_t>& signature, const hidl_vec<uint8_t>& entropy, |
| 742 | OperationResult* result) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 743 | if (!result) { |
| 744 | return; |
| 745 | } |
| 746 | Parcel data, reply; |
| 747 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 748 | data.writeStrongBinder(token); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 749 | nullable(writeParamSetToParcel, params, &data); |
| 750 | writeBlobAsByteArray(signature, &data); |
| 751 | writeBlobAsByteArray(entropy, &data); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 752 | status_t status = remote()->transact(BnKeystoreService::FINISH, data, &reply); |
| 753 | if (status != NO_ERROR) { |
| 754 | ALOGD("finish() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 755 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 756 | return; |
| 757 | } |
| 758 | int32_t err = reply.readExceptionCode(); |
| 759 | if (err < 0) { |
| 760 | ALOGD("finish() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 761 | result->resultCode = ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 762 | return; |
| 763 | } |
Bin Chen | 9ec9270 | 2016-08-25 14:25:05 +1000 | [diff] [blame] | 764 | |
| 765 | reply.readParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 766 | } |
| 767 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 768 | KeyStoreServiceReturnCode abort(const sp<IBinder>& token) override { |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 769 | Parcel data, reply; |
| 770 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 771 | data.writeStrongBinder(token); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 772 | status_t status = remote()->transact(BnKeystoreService::ABORT, data, &reply); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 773 | if (status != NO_ERROR) { |
| 774 | ALOGD("abort() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 775 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 776 | } |
| 777 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 778 | if (err < 0) { |
| 779 | ALOGD("abort() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 780 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 781 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 782 | return ResponseCode(reply.readInt32()); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 783 | } |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 784 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 785 | bool isOperationAuthorized(const sp<IBinder>& token) override { |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 786 | Parcel data, reply; |
| 787 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 788 | data.writeStrongBinder(token); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 789 | status_t status = |
| 790 | remote()->transact(BnKeystoreService::IS_OPERATION_AUTHORIZED, data, &reply); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 791 | if (status != NO_ERROR) { |
| 792 | ALOGD("isOperationAuthorized() could not contact remote: %d\n", status); |
| 793 | return false; |
| 794 | } |
| 795 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 796 | if (err < 0) { |
| 797 | ALOGD("isOperationAuthorized() caught exception %d\n", err); |
| 798 | return false; |
| 799 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 800 | return reply.readInt32() == 1; |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 803 | KeyStoreServiceReturnCode addAuthToken(const uint8_t* token, size_t length) override { |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 804 | Parcel data, reply; |
| 805 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 806 | data.writeByteArray(length, token); |
| 807 | status_t status = remote()->transact(BnKeystoreService::ADD_AUTH_TOKEN, data, &reply); |
| 808 | if (status != NO_ERROR) { |
| 809 | ALOGD("addAuthToken() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 810 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 811 | } |
| 812 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 813 | if (err < 0) { |
| 814 | ALOGD("addAuthToken() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 815 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 816 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 817 | return ResponseCode(reply.readInt32()); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 818 | }; |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 819 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 820 | KeyStoreServiceReturnCode onUserAdded(int32_t userId, int32_t parentId) override { |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 821 | Parcel data, reply; |
| 822 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 823 | data.writeInt32(userId); |
| 824 | data.writeInt32(parentId); |
| 825 | status_t status = remote()->transact(BnKeystoreService::ON_USER_ADDED, data, &reply); |
| 826 | if (status != NO_ERROR) { |
| 827 | ALOGD("onUserAdded() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 828 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 829 | } |
| 830 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 831 | if (err < 0) { |
| 832 | ALOGD("onUserAdded() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 833 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 834 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 835 | return ResponseCode(reply.readInt32()); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 838 | KeyStoreServiceReturnCode onUserRemoved(int32_t userId) override { |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 839 | Parcel data, reply; |
| 840 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 841 | data.writeInt32(userId); |
| 842 | status_t status = remote()->transact(BnKeystoreService::ON_USER_REMOVED, data, &reply); |
| 843 | if (status != NO_ERROR) { |
| 844 | ALOGD("onUserRemoved() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 845 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 846 | } |
| 847 | int32_t err = reply.readExceptionCode(); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 848 | if (err < 0) { |
| 849 | ALOGD("onUserRemoved() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 850 | return ResponseCode::SYSTEM_ERROR; |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 851 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 852 | return ResponseCode(reply.readInt32()); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 853 | } |
| 854 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 855 | KeyStoreServiceReturnCode attestKey(const String16& name, const hidl_vec<KeyParameter>& params, |
| 856 | hidl_vec<hidl_vec<uint8_t>>* outChain) override { |
| 857 | if (!outChain) return ErrorCode::OUTPUT_PARAMETER_NULL; |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 858 | |
| 859 | Parcel data, reply; |
| 860 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 861 | data.writeString16(name); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 862 | nullable(writeParamSetToParcel, params, &data); |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 863 | |
| 864 | status_t status = remote()->transact(BnKeystoreService::ATTEST_KEY, data, &reply); |
| 865 | if (status != NO_ERROR) { |
| 866 | ALOGD("attestkey() count not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 867 | return ResponseCode::SYSTEM_ERROR; |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 868 | } |
| 869 | int32_t err = reply.readExceptionCode(); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 870 | ResponseCode ret = ResponseCode(reply.readInt32()); |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 871 | if (err < 0) { |
| 872 | ALOGD("attestKey() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 873 | return ResponseCode::SYSTEM_ERROR; |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 874 | } |
| 875 | if (reply.readInt32() != 0) { |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 876 | *outChain = readCertificateChainFromParcel(reply); |
Shawn Willden | 50eb1b2 | 2016-01-21 12:41:23 -0700 | [diff] [blame] | 877 | } |
| 878 | return ret; |
| 879 | } |
| 880 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 881 | KeyStoreServiceReturnCode onDeviceOffBody() override { |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 882 | Parcel data, reply; |
| 883 | data.writeInterfaceToken(IKeystoreService::getInterfaceDescriptor()); |
| 884 | status_t status = remote()->transact(BnKeystoreService::ON_DEVICE_OFF_BODY, data, &reply); |
| 885 | if (status != NO_ERROR) { |
| 886 | ALOGD("onDeviceOffBody() could not contact remote: %d\n", status); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 887 | return ResponseCode::SYSTEM_ERROR; |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 888 | } |
| 889 | int32_t err = reply.readExceptionCode(); |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 890 | if (err < 0) { |
| 891 | ALOGD("onDeviceOffBody() caught exception %d\n", err); |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 892 | return ResponseCode::SYSTEM_ERROR; |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 893 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 894 | return ResponseCode(reply.readInt32()); |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 895 | } |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 896 | }; |
| 897 | |
Chad Brubaker | 468fc69 | 2015-01-13 17:33:14 -0800 | [diff] [blame] | 898 | IMPLEMENT_META_INTERFACE(KeystoreService, "android.security.IKeystoreService"); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 899 | |
| 900 | // ---------------------------------------------------------------------- |
| 901 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 902 | status_t BnKeystoreService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 903 | uint32_t flags) { |
| 904 | switch (code) { |
| 905 | case GET_STATE: { |
| 906 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 907 | int32_t userId = data.readInt32(); |
| 908 | int32_t ret = getState(userId); |
| 909 | reply->writeNoException(); |
| 910 | reply->writeInt32(ret); |
| 911 | return NO_ERROR; |
| 912 | } break; |
| 913 | case GET: { |
| 914 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 915 | String16 name = data.readString16(); |
| 916 | int32_t uid = data.readInt32(); |
| 917 | hidl_vec<uint8_t> out; |
| 918 | auto ret = get(name, uid, &out); |
| 919 | reply->writeNoException(); |
| 920 | if (ret.isOk()) { |
| 921 | writeBlobAsByteArray(out, reply); |
| 922 | } else { |
| 923 | reply->writeInt32(-1); |
| 924 | } |
| 925 | reply->writeInt32(ret); |
| 926 | return NO_ERROR; |
| 927 | } break; |
| 928 | case INSERT: { |
| 929 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 930 | String16 name = data.readString16(); |
| 931 | auto in = readBlobAsByteArray(data); |
| 932 | int uid = data.readInt32(); |
| 933 | int32_t flags = data.readInt32(); |
| 934 | int32_t ret = insert(name, in.value(), uid, flags); |
| 935 | reply->writeNoException(); |
| 936 | reply->writeInt32(ret); |
| 937 | return NO_ERROR; |
| 938 | } break; |
| 939 | case DEL: { |
| 940 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 941 | String16 name = data.readString16(); |
| 942 | int uid = data.readInt32(); |
| 943 | int32_t ret = del(name, uid); |
| 944 | reply->writeNoException(); |
| 945 | reply->writeInt32(ret); |
| 946 | return NO_ERROR; |
| 947 | } break; |
| 948 | case EXIST: { |
| 949 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 950 | String16 name = data.readString16(); |
| 951 | int uid = data.readInt32(); |
| 952 | int32_t ret = exist(name, uid); |
| 953 | reply->writeNoException(); |
| 954 | reply->writeInt32(ret); |
| 955 | return NO_ERROR; |
| 956 | } break; |
| 957 | case LIST: { |
| 958 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 959 | String16 prefix = data.readString16(); |
| 960 | int uid = data.readInt32(); |
| 961 | Vector<String16> matches; |
| 962 | int32_t ret = list(prefix, uid, &matches); |
| 963 | reply->writeNoException(); |
| 964 | reply->writeInt32(matches.size()); |
| 965 | Vector<String16>::const_iterator it = matches.begin(); |
| 966 | for (; it != matches.end(); ++it) { |
| 967 | reply->writeString16(*it); |
| 968 | } |
| 969 | reply->writeInt32(ret); |
| 970 | return NO_ERROR; |
| 971 | } break; |
| 972 | case RESET: { |
| 973 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 974 | int32_t ret = reset(); |
| 975 | reply->writeNoException(); |
| 976 | reply->writeInt32(ret); |
| 977 | return NO_ERROR; |
| 978 | } break; |
| 979 | case ON_USER_PASSWORD_CHANGED: { |
| 980 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 981 | int32_t userId = data.readInt32(); |
| 982 | String16 pass = data.readString16(); |
| 983 | int32_t ret = onUserPasswordChanged(userId, pass); |
| 984 | reply->writeNoException(); |
| 985 | reply->writeInt32(ret); |
| 986 | return NO_ERROR; |
| 987 | } break; |
| 988 | case LOCK: { |
| 989 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 990 | int32_t userId = data.readInt32(); |
| 991 | int32_t ret = lock(userId); |
| 992 | reply->writeNoException(); |
| 993 | reply->writeInt32(ret); |
| 994 | return NO_ERROR; |
| 995 | } break; |
| 996 | case UNLOCK: { |
| 997 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 998 | int32_t userId = data.readInt32(); |
| 999 | String16 pass = data.readString16(); |
| 1000 | int32_t ret = unlock(userId, pass); |
| 1001 | reply->writeNoException(); |
| 1002 | reply->writeInt32(ret); |
| 1003 | return NO_ERROR; |
| 1004 | } break; |
| 1005 | case IS_EMPTY: { |
| 1006 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1007 | int32_t userId = data.readInt32(); |
| 1008 | bool ret = isEmpty(userId); |
| 1009 | reply->writeNoException(); |
| 1010 | reply->writeInt32(ret ? 1 : 0); |
| 1011 | return NO_ERROR; |
| 1012 | } break; |
| 1013 | case GENERATE: { |
| 1014 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1015 | String16 name = data.readString16(); |
| 1016 | int32_t uid = data.readInt32(); |
| 1017 | int32_t keyType = data.readInt32(); |
| 1018 | int32_t keySize = data.readInt32(); |
| 1019 | int32_t flags = data.readInt32(); |
| 1020 | Vector<sp<KeystoreArg>> args; |
| 1021 | int32_t argsPresent = data.readInt32(); |
| 1022 | if (argsPresent == 1) { |
| 1023 | ssize_t numArgs = data.readInt32(); |
| 1024 | if (numArgs > MAX_GENERATE_ARGS) { |
| 1025 | return BAD_VALUE; |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 1026 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1027 | if (numArgs > 0) { |
| 1028 | for (size_t i = 0; i < (size_t)numArgs; i++) { |
| 1029 | ssize_t inSize = data.readInt32(); |
| 1030 | if (inSize >= 0 && (size_t)inSize <= data.dataAvail()) { |
| 1031 | sp<KeystoreArg> arg = new KeystoreArg(data.readInplace(inSize), inSize); |
| 1032 | args.push_back(arg); |
| 1033 | } else { |
| 1034 | args.push_back(NULL); |
Kenny Root | 96427ba | 2013-08-16 14:02:41 -0700 | [diff] [blame] | 1035 | } |
| 1036 | } |
| 1037 | } |
Kenny Root | 4306123 | 2013-03-29 11:15:50 -0700 | [diff] [blame] | 1038 | } |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1039 | int32_t ret = generate(name, uid, keyType, keySize, flags, &args); |
| 1040 | reply->writeNoException(); |
| 1041 | reply->writeInt32(ret); |
| 1042 | return NO_ERROR; |
| 1043 | } break; |
| 1044 | case IMPORT: { |
| 1045 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1046 | String16 name = data.readString16(); |
| 1047 | auto in = readBlobAsByteArray(data); |
| 1048 | int uid = data.readInt32(); |
| 1049 | int32_t flags = data.readInt32(); |
| 1050 | auto ret = import(name, in.value(), uid, flags); |
| 1051 | reply->writeNoException(); |
| 1052 | reply->writeInt32(ret); |
| 1053 | return NO_ERROR; |
| 1054 | } break; |
| 1055 | case SIGN: { |
| 1056 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1057 | String16 name = data.readString16(); |
| 1058 | auto in = readBlobAsByteArray(data); |
| 1059 | hidl_vec<uint8_t> out; |
| 1060 | auto ret = sign(name, in.value(), &out); |
| 1061 | reply->writeNoException(); |
| 1062 | writeBlobAsByteArray(out, reply); |
| 1063 | reply->writeInt32(ret); |
| 1064 | return NO_ERROR; |
| 1065 | } break; |
| 1066 | case VERIFY: { |
| 1067 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1068 | String16 name = data.readString16(); |
| 1069 | auto in = readBlobAsByteArray(data); |
| 1070 | auto signature = readBlobAsByteArray(data); |
| 1071 | auto ret = verify(name, in.value(), signature.value()); |
| 1072 | reply->writeNoException(); |
| 1073 | reply->writeInt32(ret); |
| 1074 | return NO_ERROR; |
| 1075 | } break; |
| 1076 | case GET_PUBKEY: { |
| 1077 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1078 | String16 name = data.readString16(); |
| 1079 | hidl_vec<uint8_t> out; |
| 1080 | auto ret = get_pubkey(name, &out); |
| 1081 | reply->writeNoException(); |
| 1082 | writeBlobAsByteArray(out, reply); |
| 1083 | reply->writeInt32(ret); |
| 1084 | return NO_ERROR; |
| 1085 | } break; |
| 1086 | case GRANT: { |
| 1087 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1088 | String16 name = data.readString16(); |
| 1089 | int32_t granteeUid = data.readInt32(); |
| 1090 | int32_t ret = grant(name, granteeUid); |
| 1091 | reply->writeNoException(); |
| 1092 | reply->writeInt32(ret); |
| 1093 | return NO_ERROR; |
| 1094 | } break; |
| 1095 | case UNGRANT: { |
| 1096 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1097 | String16 name = data.readString16(); |
| 1098 | int32_t granteeUid = data.readInt32(); |
| 1099 | int32_t ret = ungrant(name, granteeUid); |
| 1100 | reply->writeNoException(); |
| 1101 | reply->writeInt32(ret); |
| 1102 | return NO_ERROR; |
| 1103 | } break; |
| 1104 | case GETMTIME: { |
| 1105 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1106 | String16 name = data.readString16(); |
| 1107 | int32_t uid = data.readInt32(); |
| 1108 | int64_t ret = getmtime(name, uid); |
| 1109 | reply->writeNoException(); |
| 1110 | reply->writeInt64(ret); |
| 1111 | return NO_ERROR; |
| 1112 | } break; |
| 1113 | case DUPLICATE: { |
| 1114 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1115 | String16 srcKey = data.readString16(); |
| 1116 | int32_t srcUid = data.readInt32(); |
| 1117 | String16 destKey = data.readString16(); |
| 1118 | int32_t destUid = data.readInt32(); |
| 1119 | int32_t ret = duplicate(srcKey, srcUid, destKey, destUid); |
| 1120 | reply->writeNoException(); |
| 1121 | reply->writeInt32(ret); |
| 1122 | return NO_ERROR; |
| 1123 | } break; |
| 1124 | case IS_HARDWARE_BACKED: { |
| 1125 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1126 | String16 keyType = data.readString16(); |
| 1127 | int32_t ret = is_hardware_backed(keyType); |
| 1128 | reply->writeNoException(); |
| 1129 | reply->writeInt32(ret); |
| 1130 | return NO_ERROR; |
| 1131 | } |
| 1132 | case CLEAR_UID: { |
| 1133 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1134 | int64_t uid = data.readInt64(); |
| 1135 | int32_t ret = clear_uid(uid); |
| 1136 | reply->writeNoException(); |
| 1137 | reply->writeInt32(ret); |
| 1138 | return NO_ERROR; |
| 1139 | } |
| 1140 | case ADD_RNG_ENTROPY: { |
| 1141 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1142 | auto entropy = readBlobAsByteArray(data); |
| 1143 | auto ret = addRngEntropy(entropy.value()); |
| 1144 | reply->writeNoException(); |
| 1145 | reply->writeInt32(ret); |
| 1146 | return NO_ERROR; |
| 1147 | } |
| 1148 | case GENERATE_KEY: { |
| 1149 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1150 | String16 name = data.readString16(); |
| 1151 | auto params = nullable(readParamSetFromParcel, data); |
| 1152 | auto entropy = readBlobAsByteArray(data); |
| 1153 | int32_t uid = data.readInt32(); |
| 1154 | int32_t flags = data.readInt32(); |
| 1155 | KeyCharacteristics outCharacteristics; |
| 1156 | int32_t ret = |
| 1157 | generateKey(name, params.value(), entropy.value(), uid, flags, &outCharacteristics); |
| 1158 | reply->writeNoException(); |
| 1159 | reply->writeInt32(ret); |
| 1160 | nullable(writeKeyCharacteristicsToParcel, outCharacteristics, reply); |
| 1161 | return NO_ERROR; |
| 1162 | } |
| 1163 | case GET_KEY_CHARACTERISTICS: { |
| 1164 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1165 | String16 name = data.readString16(); |
| 1166 | auto clientId = nullable(readKeymasterBlob, data, true); |
| 1167 | auto appData = nullable(readKeymasterBlob, data, true); |
| 1168 | int32_t uid = data.readInt32(); |
| 1169 | KeyCharacteristics outCharacteristics; |
| 1170 | int ret = getKeyCharacteristics(name, clientId.value(), appData.value(), uid, |
| 1171 | &outCharacteristics); |
| 1172 | reply->writeNoException(); |
| 1173 | reply->writeInt32(ret); |
| 1174 | nullable(writeKeyCharacteristicsToParcel, outCharacteristics, reply); |
| 1175 | return NO_ERROR; |
| 1176 | } |
| 1177 | case IMPORT_KEY: { |
| 1178 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1179 | String16 name = data.readString16(); |
| 1180 | auto args = nullable(readParamSetFromParcel, data); |
| 1181 | KeyFormat format = static_cast<KeyFormat>(data.readInt32()); |
| 1182 | auto keyData = readBlobAsByteArray(data); |
| 1183 | int32_t uid = data.readInt32(); |
| 1184 | int32_t flags = data.readInt32(); |
| 1185 | KeyCharacteristics outCharacteristics; |
| 1186 | int32_t ret = |
| 1187 | importKey(name, args.value(), format, keyData.value(), uid, flags, &outCharacteristics); |
| 1188 | reply->writeNoException(); |
| 1189 | reply->writeInt32(ret); |
| 1190 | nullable(writeKeyCharacteristicsToParcel, outCharacteristics, reply); |
| 1191 | return NO_ERROR; |
| 1192 | } |
| 1193 | case EXPORT_KEY: { |
| 1194 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1195 | String16 name = data.readString16(); |
| 1196 | KeyFormat format = static_cast<KeyFormat>(data.readInt32()); |
| 1197 | auto clientId = nullable(readKeymasterBlob, data, true); |
| 1198 | auto appData = nullable(readKeymasterBlob, data, true); |
| 1199 | int32_t uid = data.readInt32(); |
| 1200 | ExportResult result; |
| 1201 | exportKey(name, format, clientId.value(), appData.value(), uid, &result); |
| 1202 | reply->writeNoException(); |
| 1203 | reply->writeParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 1204 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1205 | return NO_ERROR; |
| 1206 | } |
| 1207 | case BEGIN: { |
| 1208 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1209 | sp<IBinder> token = data.readStrongBinder(); |
| 1210 | String16 name = data.readString16(); |
| 1211 | KeyPurpose purpose = static_cast<KeyPurpose>(data.readInt32()); |
| 1212 | bool pruneable = data.readInt32() != 0; |
| 1213 | auto args = nullable(readParamSetFromParcel, data); |
| 1214 | auto entropy = readBlobAsByteArray(data); |
| 1215 | int32_t uid = data.readInt32(); |
| 1216 | OperationResult result; |
| 1217 | begin(token, name, purpose, pruneable, args.value(), entropy.value(), uid, &result); |
| 1218 | reply->writeNoException(); |
| 1219 | reply->writeParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 1220 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1221 | return NO_ERROR; |
| 1222 | } |
| 1223 | case UPDATE: { |
| 1224 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1225 | sp<IBinder> token = data.readStrongBinder(); |
| 1226 | auto args = nullable(readParamSetFromParcel, data); |
| 1227 | auto buf = readBlobAsByteArray(data); |
| 1228 | OperationResult result; |
| 1229 | update(token, args.value(), buf.value(), &result); |
| 1230 | reply->writeNoException(); |
| 1231 | reply->writeParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 1232 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1233 | return NO_ERROR; |
| 1234 | } |
| 1235 | case FINISH: { |
| 1236 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1237 | sp<IBinder> token = data.readStrongBinder(); |
| 1238 | auto args = nullable(readParamSetFromParcel, data); |
| 1239 | auto signature = readBlobAsByteArray(data); |
| 1240 | auto entropy = readBlobAsByteArray(data); |
| 1241 | OperationResult result; |
| 1242 | finish(token, args.value(), signature.value(), entropy.value(), &result); |
| 1243 | reply->writeNoException(); |
| 1244 | reply->writeParcelable(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 1245 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1246 | return NO_ERROR; |
| 1247 | } |
| 1248 | case ABORT: { |
| 1249 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1250 | sp<IBinder> token = data.readStrongBinder(); |
| 1251 | int32_t result = abort(token); |
| 1252 | reply->writeNoException(); |
| 1253 | reply->writeInt32(result); |
Chad Brubaker | 9899d6b | 2015-02-03 13:03:00 -0800 | [diff] [blame] | 1254 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1255 | return NO_ERROR; |
| 1256 | } |
| 1257 | case IS_OPERATION_AUTHORIZED: { |
| 1258 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1259 | sp<IBinder> token = data.readStrongBinder(); |
| 1260 | bool result = isOperationAuthorized(token); |
| 1261 | reply->writeNoException(); |
| 1262 | reply->writeInt32(result ? 1 : 0); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 1263 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1264 | return NO_ERROR; |
| 1265 | } |
| 1266 | case ADD_AUTH_TOKEN: { |
| 1267 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1268 | const uint8_t* token_bytes = NULL; |
| 1269 | size_t size = 0; |
| 1270 | readByteArray(data, &token_bytes, &size); |
| 1271 | int32_t result = addAuthToken(token_bytes, size); |
| 1272 | reply->writeNoException(); |
| 1273 | reply->writeInt32(result); |
Chad Brubaker | 2ed2baa | 2015-03-21 21:20:10 -0700 | [diff] [blame] | 1274 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1275 | return NO_ERROR; |
| 1276 | } |
| 1277 | case ON_USER_ADDED: { |
| 1278 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1279 | int32_t userId = data.readInt32(); |
| 1280 | int32_t parentId = data.readInt32(); |
| 1281 | int32_t result = onUserAdded(userId, parentId); |
| 1282 | reply->writeNoException(); |
| 1283 | reply->writeInt32(result); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 1284 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1285 | return NO_ERROR; |
| 1286 | } |
| 1287 | case ON_USER_REMOVED: { |
| 1288 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1289 | int32_t userId = data.readInt32(); |
| 1290 | int32_t result = onUserRemoved(userId); |
| 1291 | reply->writeNoException(); |
| 1292 | reply->writeInt32(result); |
Chad Brubaker | c0f031a | 2015-05-12 10:43:10 -0700 | [diff] [blame] | 1293 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1294 | return NO_ERROR; |
| 1295 | } |
| 1296 | case ATTEST_KEY: { |
| 1297 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1298 | String16 name = data.readString16(); |
| 1299 | auto params = nullable(readParamSetFromParcel, data); |
| 1300 | hidl_vec<hidl_vec<uint8_t>> chain; |
| 1301 | int ret = attestKey(name, params.value(), &chain); |
| 1302 | reply->writeNoException(); |
| 1303 | reply->writeInt32(ret); |
| 1304 | nullable(writeCertificateChainToParcel, chain, reply); |
Shawn Willden | 3976b6c | 2016-02-06 20:31:15 -0700 | [diff] [blame] | 1305 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1306 | return NO_ERROR; |
| 1307 | } |
| 1308 | case ON_DEVICE_OFF_BODY: { |
| 1309 | CHECK_INTERFACE(IKeystoreService, data, reply); |
| 1310 | int32_t ret = onDeviceOffBody(); |
| 1311 | reply->writeNoException(); |
| 1312 | reply->writeInt32(ret); |
Tucker Sylvestro | 0ab28b7 | 2016-08-05 18:02:47 -0400 | [diff] [blame] | 1313 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1314 | return NO_ERROR; |
| 1315 | } |
| 1316 | default: |
| 1317 | return BBinder::onTransact(code, data, reply, flags); |
Kenny Root | 07438c8 | 2012-11-02 15:41:02 -0700 | [diff] [blame] | 1318 | } |
| 1319 | } |
| 1320 | |
| 1321 | // ---------------------------------------------------------------------------- |
| 1322 | |
Janis Danisevskis | c7a9fa2 | 2016-10-13 18:43:45 +0100 | [diff] [blame^] | 1323 | }; // namespace android |