Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017, The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "KeymasterDevice.h" |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 18 | #include "proto_utils.h" |
| 19 | |
nagendra modadugu | 9e8c856 | 2017-09-18 18:58:54 -0700 | [diff] [blame] | 20 | #include <Keymaster.client.h> |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 21 | #include <nos/NuggetClient.h> |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 22 | |
| 23 | #include <android-base/logging.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace hardware { |
| 27 | namespace keymaster { |
| 28 | |
nagendra modadugu | 8a88337 | 2017-09-18 22:29:00 -0700 | [diff] [blame] | 29 | // std |
| 30 | using std::string; |
| 31 | |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 32 | // libhidl |
| 33 | using ::android::hardware::Void; |
| 34 | |
| 35 | // HAL |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 36 | using ::android::hardware::keymaster::V3_0::Algorithm; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 37 | using ::android::hardware::keymaster::V3_0::KeyCharacteristics; |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 38 | using ::android::hardware::keymaster::V3_0::KeyFormat; |
| 39 | using ::android::hardware::keymaster::V3_0::Tag; |
| 40 | |
| 41 | // nos |
| 42 | using nos::NuggetClient; |
| 43 | |
| 44 | // Keymaster app |
| 45 | using ::nugget::app::keymaster::AddRngEntropyRequest; |
| 46 | using ::nugget::app::keymaster::AddRngEntropyResponse; |
| 47 | using ::nugget::app::keymaster::GenerateKeyRequest; |
| 48 | using ::nugget::app::keymaster::GenerateKeyResponse; |
| 49 | using ::nugget::app::keymaster::GetKeyCharacteristicsRequest; |
| 50 | using ::nugget::app::keymaster::GetKeyCharacteristicsResponse; |
| 51 | using ::nugget::app::keymaster::ImportKeyRequest; |
| 52 | using ::nugget::app::keymaster::ImportKeyResponse; |
| 53 | using ::nugget::app::keymaster::ExportKeyRequest; |
| 54 | using ::nugget::app::keymaster::ExportKeyResponse; |
| 55 | using ::nugget::app::keymaster::AttestKeyRequest; |
| 56 | using ::nugget::app::keymaster::AttestKeyResponse; |
| 57 | using ::nugget::app::keymaster::UpgradeKeyRequest; |
| 58 | using ::nugget::app::keymaster::UpgradeKeyResponse; |
| 59 | using ::nugget::app::keymaster::DeleteKeyRequest; |
| 60 | using ::nugget::app::keymaster::DeleteKeyResponse; |
| 61 | using ::nugget::app::keymaster::DeleteAllKeysRequest; |
| 62 | using ::nugget::app::keymaster::DeleteAllKeysResponse; |
| 63 | using ::nugget::app::keymaster::DestroyAttestationIdsRequest; |
| 64 | using ::nugget::app::keymaster::DestroyAttestationIdsResponse; |
| 65 | using ::nugget::app::keymaster::BeginOperationRequest; |
| 66 | using ::nugget::app::keymaster::BeginOperationResponse; |
| 67 | using ::nugget::app::keymaster::UpdateOperationRequest; |
| 68 | using ::nugget::app::keymaster::UpdateOperationResponse; |
| 69 | using ::nugget::app::keymaster::FinishOperationRequest; |
| 70 | using ::nugget::app::keymaster::FinishOperationResponse; |
| 71 | using ::nugget::app::keymaster::AbortOperationRequest; |
| 72 | using ::nugget::app::keymaster::AbortOperationResponse; |
| 73 | |
| 74 | static ErrorCode status_to_error_code(uint32_t status) |
| 75 | { |
| 76 | switch (status) { |
| 77 | case APP_SUCCESS: |
| 78 | return ErrorCode::OK; |
| 79 | break; |
| 80 | case APP_ERROR_BOGUS_ARGS: |
| 81 | return ErrorCode::INVALID_ARGUMENT; |
| 82 | break; |
| 83 | case APP_ERROR_INTERNAL: |
| 84 | return ErrorCode::UNKNOWN_ERROR; |
| 85 | break; |
| 86 | case APP_ERROR_TOO_MUCH: |
| 87 | return ErrorCode::INSUFFICIENT_BUFFER_SPACE; |
| 88 | break; |
| 89 | case APP_ERROR_RPC: |
| 90 | return ErrorCode::SECURE_HW_COMMUNICATION_FAILED; |
| 91 | break; |
| 92 | // TODO: app specific error codes go here. |
| 93 | default: |
| 94 | return ErrorCode::UNKNOWN_ERROR; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | #define KM_CALL(meth) { \ |
| 100 | const uint32_t status = _keymaster. meth (request, response); \ |
| 101 | if (status != APP_SUCCESS) { \ |
| 102 | LOG(ERROR) << #meth << " : request failed with status: " \ |
| 103 | << NuggetClient::StatusCodeString(status); \ |
| 104 | return status_to_error_code(status); \ |
| 105 | } \ |
| 106 | if ((ErrorCode)response.error_code() != ErrorCode::OK) { \ |
| 107 | LOG(ERROR) << #meth << " : device response error code: " \ |
| 108 | << response.error_code(); \ |
| 109 | return (ErrorCode)response.error_code(); \ |
| 110 | } \ |
| 111 | } |
| 112 | |
| 113 | #define KM_CALLV(meth, ...) { \ |
| 114 | const uint32_t status = _keymaster. meth (request, response); \ |
| 115 | if (status != APP_SUCCESS) { \ |
| 116 | LOG(ERROR) << #meth << " : request failed with status: " \ |
| 117 | << NuggetClient::StatusCodeString(status); \ |
| 118 | _hidl_cb(status_to_error_code(status), __VA_ARGS__); \ |
| 119 | return Void(); \ |
| 120 | } \ |
| 121 | if ((ErrorCode)response.error_code() != ErrorCode::OK) { \ |
| 122 | LOG(ERROR) << #meth << " : device response error code: " \ |
| 123 | << response.error_code(); \ |
| 124 | _hidl_cb((ErrorCode)response.error_code(), __VA_ARGS__); \ |
| 125 | return Void(); \ |
| 126 | } \ |
| 127 | } |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 128 | |
| 129 | // Methods from ::android::hardware::keymaster::V3_0::IKeymasterDevice follow. |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 130 | |
nagendra modadugu | 8a88337 | 2017-09-18 22:29:00 -0700 | [diff] [blame] | 131 | Return<void> KeymasterDevice::getHardwareFeatures( |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 132 | getHardwareFeatures_cb _hidl_cb) |
| 133 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 134 | LOG(VERBOSE) << "Running KeymasterDevice::getHardwareFeatures"; |
| 135 | |
nagendra modadugu | 8a88337 | 2017-09-18 22:29:00 -0700 | [diff] [blame] | 136 | (void)_keymaster; |
| 137 | _hidl_cb(true, true, true, true, |
| 138 | true, string("CitadelKeymaster"), string("Google")); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 139 | return Void(); |
| 140 | } |
| 141 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 142 | Return<ErrorCode> KeymasterDevice::addRngEntropy(const hidl_vec<uint8_t>& data) |
| 143 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 144 | LOG(VERBOSE) << "Running KeymasterDevice::addRngEntropy"; |
| 145 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 146 | if (!data.size()) return ErrorCode::OK; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 147 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 148 | AddRngEntropyRequest request; |
| 149 | AddRngEntropyResponse response; |
| 150 | request.set_data(&data[0], data.size()); |
| 151 | |
| 152 | // Call device. |
| 153 | KM_CALL(AddRngEntropy); |
| 154 | |
| 155 | return (ErrorCode)response.error_code(); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 156 | } |
| 157 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 158 | Return<void> KeymasterDevice::generateKey( |
| 159 | const hidl_vec<KeyParameter>& keyParams, |
| 160 | generateKey_cb _hidl_cb) |
| 161 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 162 | LOG(VERBOSE) << "Running KeymasterDevice::generateKey"; |
| 163 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 164 | GenerateKeyRequest request; |
| 165 | GenerateKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 166 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 167 | hidl_params_to_pb(keyParams, request.mutable_params()); |
| 168 | |
| 169 | // Call device. |
| 170 | KM_CALLV(GenerateKey, hidl_vec<uint8_t>{}, KeyCharacteristics()); |
| 171 | |
| 172 | hidl_vec<uint8_t> blob; |
| 173 | KeyCharacteristics characteristics; |
| 174 | blob.setToExternal( |
| 175 | reinterpret_cast<uint8_t*>( |
| 176 | const_cast<char*>(response.blob().blob().data())), |
| 177 | response.blob().blob().size(), false); |
| 178 | pb_to_hidl_params(response.characteristics().tee_enforced(), |
| 179 | &characteristics.teeEnforced); |
| 180 | |
| 181 | _hidl_cb((ErrorCode)response.error_code(), blob, characteristics); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 182 | return Void(); |
| 183 | } |
| 184 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 185 | Return<void> KeymasterDevice::getKeyCharacteristics( |
| 186 | const hidl_vec<uint8_t>& keyBlob, |
| 187 | const hidl_vec<uint8_t>& clientId, |
| 188 | const hidl_vec<uint8_t>& appData, |
| 189 | getKeyCharacteristics_cb _hidl_cb) |
| 190 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 191 | LOG(VERBOSE) << "Running KeymasterDevice::getKeyCharacteristics"; |
| 192 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 193 | GetKeyCharacteristicsRequest request; |
| 194 | GetKeyCharacteristicsResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 195 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 196 | request.mutable_blob()->set_blob(&keyBlob[0], keyBlob.size()); |
| 197 | request.set_client_id(&clientId[0], clientId.size()); |
| 198 | request.set_app_data(&appData[0], appData.size()); |
| 199 | |
| 200 | // Call device. |
| 201 | KM_CALLV(GetKeyCharacteristics, KeyCharacteristics()); |
| 202 | |
| 203 | KeyCharacteristics characteristics; |
| 204 | pb_to_hidl_params(response.characteristics().tee_enforced(), |
| 205 | &characteristics.teeEnforced); |
| 206 | |
| 207 | _hidl_cb((ErrorCode)response.error_code(), characteristics); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 208 | return Void(); |
| 209 | } |
| 210 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 211 | Return<void> KeymasterDevice::importKey( |
| 212 | const hidl_vec<KeyParameter>& params, KeyFormat keyFormat, |
| 213 | const hidl_vec<uint8_t>& keyData, importKey_cb _hidl_cb) |
| 214 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 215 | LOG(VERBOSE) << "Running KeymasterDevice::importKey"; |
| 216 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 217 | ImportKeyRequest request; |
| 218 | ImportKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 219 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 220 | hidl_params_to_pb(params, request.mutable_params()); |
| 221 | // TODO: serialize into ImportKeyRequest proto. |
| 222 | (void)keyFormat; |
| 223 | (void)keyData; |
| 224 | |
| 225 | KM_CALLV(ImportKey, hidl_vec<uint8_t>{}, KeyCharacteristics{}); |
| 226 | |
| 227 | hidl_vec<uint8_t> blob; |
| 228 | blob.setToExternal( |
| 229 | reinterpret_cast<uint8_t*>( |
| 230 | const_cast<char*>(response.blob().blob().data())), |
| 231 | response.blob().blob().size(), false); |
| 232 | |
| 233 | KeyCharacteristics characteristics; |
| 234 | pb_to_hidl_params(response.characteristics().tee_enforced(), |
| 235 | &characteristics.teeEnforced); |
| 236 | |
| 237 | _hidl_cb(ErrorCode::OK, blob, characteristics); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 238 | return Void(); |
| 239 | } |
| 240 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 241 | Return<void> KeymasterDevice::exportKey( |
| 242 | KeyFormat exportFormat, const hidl_vec<uint8_t>& keyBlob, |
| 243 | const hidl_vec<uint8_t>& clientId, |
| 244 | const hidl_vec<uint8_t>& appData, exportKey_cb _hidl_cb) |
| 245 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 246 | LOG(VERBOSE) << "Running KeymasterDevice::exportKey"; |
| 247 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 248 | ExportKeyRequest request; |
| 249 | ExportKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 250 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 251 | request.set_format((::nugget::app::keymaster::KeyFormat)exportFormat); |
| 252 | request.mutable_blob()->set_blob(&keyBlob[0], keyBlob.size()); |
| 253 | request.set_client_id(&clientId[0], clientId.size()); |
| 254 | request.set_app_data(&appData[0], appData.size()); |
| 255 | |
| 256 | KM_CALLV(ExportKey, hidl_vec<uint8_t>{}); |
| 257 | |
| 258 | hidl_vec<uint8_t> blob; |
| 259 | blob.setToExternal( |
| 260 | reinterpret_cast<uint8_t*>( |
| 261 | const_cast<char*>(response.key_material().data())), |
| 262 | response.key_material().size(), false); |
| 263 | |
| 264 | _hidl_cb((ErrorCode)response.error_code(), blob); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 265 | return Void(); |
| 266 | } |
| 267 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 268 | Return<void> KeymasterDevice::attestKey( |
| 269 | const hidl_vec<uint8_t>& keyToAttest, |
| 270 | const hidl_vec<KeyParameter>& attestParams, |
| 271 | attestKey_cb _hidl_cb) |
| 272 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 273 | LOG(VERBOSE) << "Running KeymasterDevice::attestKey"; |
| 274 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 275 | AttestKeyRequest request; |
| 276 | AttestKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 277 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 278 | request.mutable_blob()->set_blob(&keyToAttest[0], keyToAttest.size()); |
| 279 | hidl_params_to_pb(attestParams, request.mutable_params()); |
| 280 | |
| 281 | KM_CALLV(AttestKey, hidl_vec<hidl_vec<uint8_t> >{}); |
| 282 | |
| 283 | vector<hidl_vec<uint8_t> > chain; |
| 284 | for (int i = 0; i < response.chain().certificates_size(); i++) { |
| 285 | hidl_vec<uint8_t> blob; |
| 286 | blob.setToExternal( |
| 287 | reinterpret_cast<uint8_t*>( |
| 288 | const_cast<char*>( |
| 289 | response.chain().certificates(i).data().data())), |
| 290 | response.chain().certificates(i).data().size(), false); |
| 291 | chain.push_back(blob); |
| 292 | } |
| 293 | |
| 294 | _hidl_cb((ErrorCode)response.error_code(), |
| 295 | hidl_vec<hidl_vec<uint8_t> >(chain)); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 296 | return Void(); |
| 297 | } |
| 298 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 299 | Return<void> KeymasterDevice::upgradeKey( |
| 300 | const hidl_vec<uint8_t>& keyBlobToUpgrade, |
| 301 | const hidl_vec<KeyParameter>& upgradeParams, |
| 302 | upgradeKey_cb _hidl_cb) |
| 303 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 304 | LOG(VERBOSE) << "Running KeymasterDevice::upgradeKey"; |
| 305 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 306 | UpgradeKeyRequest request; |
| 307 | UpgradeKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 308 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 309 | request.mutable_blob()->set_blob(&keyBlobToUpgrade[0], |
| 310 | keyBlobToUpgrade.size()); |
| 311 | hidl_params_to_pb(upgradeParams, request.mutable_params()); |
| 312 | |
| 313 | KM_CALLV(UpgradeKey, hidl_vec<uint8_t>{}); |
| 314 | |
| 315 | hidl_vec<uint8_t> blob; |
| 316 | blob.setToExternal( |
| 317 | reinterpret_cast<uint8_t*>( |
| 318 | const_cast<char*>(response.blob().blob().data())), |
| 319 | response.blob().blob().size(), false); |
| 320 | |
| 321 | _hidl_cb((ErrorCode)response.error_code(), blob); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 322 | return Void(); |
| 323 | } |
| 324 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 325 | Return<ErrorCode> KeymasterDevice::deleteKey(const hidl_vec<uint8_t>& keyBlob) |
| 326 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 327 | LOG(VERBOSE) << "Running KeymasterDevice::deleteKey"; |
| 328 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 329 | DeleteKeyRequest request; |
| 330 | DeleteKeyResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 331 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 332 | request.mutable_blob()->set_blob(&keyBlob[0], keyBlob.size()); |
| 333 | |
| 334 | KM_CALL(DeleteKey); |
| 335 | |
| 336 | return (ErrorCode)response.error_code(); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 337 | } |
| 338 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 339 | Return<ErrorCode> KeymasterDevice::deleteAllKeys() |
| 340 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 341 | LOG(VERBOSE) << "Running KeymasterDevice::deleteAllKeys"; |
| 342 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 343 | DeleteAllKeysRequest request; |
| 344 | DeleteAllKeysResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 345 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 346 | KM_CALL(DeleteAllKeys); |
| 347 | |
| 348 | return (ErrorCode)response.error_code(); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 349 | } |
| 350 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 351 | Return<ErrorCode> KeymasterDevice::destroyAttestationIds() |
| 352 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 353 | LOG(VERBOSE) << "Running KeymasterDevice::destroyAttestationIds"; |
| 354 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 355 | DestroyAttestationIdsRequest request; |
| 356 | DestroyAttestationIdsResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 357 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 358 | KM_CALL(DestroyAttestationIds); |
| 359 | |
| 360 | return (ErrorCode)response.error_code(); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 361 | } |
| 362 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 363 | Return<void> KeymasterDevice::begin( |
| 364 | KeyPurpose purpose, const hidl_vec<uint8_t>& key, |
| 365 | const hidl_vec<KeyParameter>& inParams, begin_cb _hidl_cb) |
| 366 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 367 | LOG(VERBOSE) << "Running KeymasterDevice::begin"; |
| 368 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 369 | BeginOperationRequest request; |
| 370 | BeginOperationResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 371 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 372 | request.set_purpose((::nugget::app::keymaster::KeyPurpose)purpose); |
| 373 | request.mutable_blob()->set_blob(&key[0], key.size()); |
| 374 | hidl_params_to_pb(inParams, request.mutable_params()); |
| 375 | |
| 376 | KM_CALLV(BeginOperation, hidl_vec<KeyParameter>{}, 0); |
| 377 | |
| 378 | hidl_vec<KeyParameter> params; |
| 379 | pb_to_hidl_params(response.params(), ¶ms); |
| 380 | |
| 381 | _hidl_cb((ErrorCode)response.error_code(), params, |
| 382 | response.handle().handle()); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 383 | return Void(); |
| 384 | } |
| 385 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 386 | Return<void> KeymasterDevice::update( |
| 387 | uint64_t operationHandle, |
| 388 | const hidl_vec<KeyParameter>& inParams, |
| 389 | const hidl_vec<uint8_t>& input, update_cb _hidl_cb) |
| 390 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 391 | LOG(VERBOSE) << "Running KeymasterDevice::update"; |
| 392 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 393 | UpdateOperationRequest request; |
| 394 | UpdateOperationResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 395 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 396 | request.mutable_handle()->set_handle(operationHandle); |
| 397 | hidl_params_to_pb(inParams, request.mutable_params()); |
| 398 | request.set_input(&input[0], input.size()); |
| 399 | |
| 400 | KM_CALLV(UpdateOperation, 0, hidl_vec<KeyParameter>{}, hidl_vec<uint8_t>{}); |
| 401 | |
| 402 | hidl_vec<KeyParameter> params; |
| 403 | hidl_vec<uint8_t> output; |
| 404 | pb_to_hidl_params(response.params(), ¶ms); |
| 405 | output.setToExternal( |
| 406 | reinterpret_cast<uint8_t*>(const_cast<char*>(response.output().data())), |
| 407 | response.output().size(), false); |
| 408 | |
| 409 | _hidl_cb(ErrorCode::OK, response.consumed(), params, output); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 410 | return Void(); |
| 411 | } |
| 412 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 413 | Return<void> KeymasterDevice::finish( |
| 414 | uint64_t operationHandle, |
| 415 | const hidl_vec<KeyParameter>& inParams, |
| 416 | const hidl_vec<uint8_t>& input, |
| 417 | const hidl_vec<uint8_t>& signature, finish_cb _hidl_cb) |
| 418 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 419 | LOG(VERBOSE) << "Running KeymasterDevice::finish"; |
| 420 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 421 | FinishOperationRequest request; |
| 422 | FinishOperationResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 423 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 424 | request.mutable_handle()->set_handle(operationHandle); |
| 425 | hidl_params_to_pb(inParams, request.mutable_params()); |
| 426 | request.set_input(&input[0], input.size()); |
| 427 | request.set_signature(&signature[0], signature.size()); |
| 428 | |
| 429 | KM_CALLV(FinishOperation, hidl_vec<KeyParameter>{}, hidl_vec<uint8_t>{}); |
| 430 | |
| 431 | hidl_vec<KeyParameter> params; |
| 432 | pb_to_hidl_params(response.params(), ¶ms); |
| 433 | hidl_vec<uint8_t> output; |
| 434 | output.setToExternal( |
| 435 | reinterpret_cast<uint8_t*>(const_cast<char*>(response.output().data())), |
| 436 | response.output().size(), false); |
| 437 | |
| 438 | _hidl_cb(ErrorCode::OK, params, output); |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 439 | return Void(); |
| 440 | } |
| 441 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 442 | Return<ErrorCode> KeymasterDevice::abort(uint64_t operationHandle) |
| 443 | { |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 444 | LOG(VERBOSE) << "Running KeymasterDevice::abort"; |
| 445 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 446 | AbortOperationRequest request; |
| 447 | AbortOperationResponse response; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 448 | |
nagendra modadugu | 284b939 | 2017-09-27 13:51:23 -0700 | [diff] [blame^] | 449 | request.mutable_handle()->set_handle(operationHandle); |
| 450 | |
| 451 | KM_CALL(AbortOperation); |
| 452 | |
| 453 | return ErrorCode::OK; |
Andrew Scull | e4e2ffc | 2017-08-10 10:03:20 +0100 | [diff] [blame] | 454 | } |
| 455 | |
| 456 | } // namespace keymaster |
| 457 | } // namespace hardware |
| 458 | } // namespace android |