Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020, 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 | #define LOG_TAG "android.hardware.security.keymint-impl" |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 18 | #include <android-base/logging.h> |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 19 | |
| 20 | #include "AndroidKeyMintDevice.h" |
| 21 | |
| 22 | #include <aidl/android/hardware/security/keymint/ErrorCode.h> |
| 23 | |
| 24 | #include <keymaster/android_keymaster.h> |
| 25 | #include <keymaster/contexts/pure_soft_keymaster_context.h> |
| 26 | #include <keymaster/keymaster_configuration.h> |
| 27 | |
| 28 | #include "AndroidKeyMintOperation.h" |
| 29 | #include "KeyMintUtils.h" |
| 30 | |
| 31 | namespace aidl::android::hardware::security::keymint { |
| 32 | |
| 33 | using namespace ::keymaster; |
Shawn Willden | 96d4e8c | 2020-12-07 17:03:54 -0700 | [diff] [blame] | 34 | using namespace km_utils; |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 35 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 36 | namespace { |
| 37 | |
| 38 | vector<KeyCharacteristics> convertKeyCharacteristics(SecurityLevel keyMintSecurityLevel, |
| 39 | const AuthorizationSet& sw_enforced, |
| 40 | const AuthorizationSet& hw_enforced) { |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 41 | KeyCharacteristics keyMintEnforced{keyMintSecurityLevel, {}}; |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 42 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 43 | if (keyMintSecurityLevel != SecurityLevel::SOFTWARE) { |
| 44 | // We're pretending to be TRUSTED_ENVIRONMENT or STRONGBOX. Only the entries in hw_enforced |
| 45 | // should be returned. |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 46 | keyMintEnforced.authorizations = kmParamSet2Aidl(hw_enforced); |
| 47 | return {std::move(keyMintEnforced)}; |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 50 | KeyCharacteristics keystoreEnforced{SecurityLevel::KEYSTORE, {}}; |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 51 | CHECK(hw_enforced.empty()) << "Hardware-enforced list is non-empty for pure SW KeyMint"; |
| 52 | |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 53 | // This is a pure software implementation, so all tags are in sw_enforced. |
| 54 | // We need to walk through the SW-enforced list and figure out which tags to |
| 55 | // return in the software list and which in the keystore list. |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 56 | |
| 57 | for (auto& entry : sw_enforced) { |
| 58 | switch (entry.tag) { |
| 59 | /* Invalid and unused */ |
| 60 | case KM_TAG_ECIES_SINGLE_HASH_MODE: |
| 61 | case KM_TAG_INVALID: |
| 62 | case KM_TAG_KDF: |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 63 | case KM_TAG_ROLLBACK_RESISTANCE: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 64 | CHECK(false) << "We shouldn't see tag " << entry.tag; |
| 65 | break; |
| 66 | |
| 67 | /* Unimplemented */ |
| 68 | case KM_TAG_ALLOW_WHILE_ON_BODY: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 69 | case KM_TAG_BOOTLOADER_ONLY: |
| 70 | case KM_TAG_EARLY_BOOT_ONLY: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 71 | case KM_TAG_ROLLBACK_RESISTANT: |
| 72 | case KM_TAG_STORAGE_KEY: |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 73 | case KM_TAG_TRUSTED_CONFIRMATION_REQUIRED: |
| 74 | case KM_TAG_TRUSTED_USER_PRESENCE_REQUIRED: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 75 | break; |
| 76 | |
| 77 | /* Unenforceable */ |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 78 | case KM_TAG_CREATION_DATETIME: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 79 | break; |
| 80 | |
| 81 | /* Disallowed in KeyCharacteristics */ |
| 82 | case KM_TAG_APPLICATION_DATA: |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 83 | case KM_TAG_ATTESTATION_APPLICATION_ID: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 84 | break; |
| 85 | |
| 86 | /* Not key characteristics */ |
| 87 | case KM_TAG_ASSOCIATED_DATA: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 88 | case KM_TAG_ATTESTATION_CHALLENGE: |
| 89 | case KM_TAG_ATTESTATION_ID_BRAND: |
| 90 | case KM_TAG_ATTESTATION_ID_DEVICE: |
| 91 | case KM_TAG_ATTESTATION_ID_IMEI: |
| 92 | case KM_TAG_ATTESTATION_ID_MANUFACTURER: |
| 93 | case KM_TAG_ATTESTATION_ID_MEID: |
| 94 | case KM_TAG_ATTESTATION_ID_MODEL: |
| 95 | case KM_TAG_ATTESTATION_ID_PRODUCT: |
| 96 | case KM_TAG_ATTESTATION_ID_SERIAL: |
| 97 | case KM_TAG_AUTH_TOKEN: |
| 98 | case KM_TAG_CERTIFICATE_SERIAL: |
| 99 | case KM_TAG_CERTIFICATE_SUBJECT: |
| 100 | case KM_TAG_CONFIRMATION_TOKEN: |
| 101 | case KM_TAG_DEVICE_UNIQUE_ATTESTATION: |
| 102 | case KM_TAG_IDENTITY_CREDENTIAL_KEY: |
| 103 | case KM_TAG_MAC_LENGTH: |
| 104 | case KM_TAG_NONCE: |
| 105 | case KM_TAG_RESET_SINCE_ID_ROTATION: |
| 106 | case KM_TAG_ROOT_OF_TRUST: |
| 107 | case KM_TAG_UNIQUE_ID: |
| 108 | break; |
| 109 | |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 110 | /* KeyMint-enforced */ |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 111 | case KM_TAG_ALGORITHM: |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 112 | case KM_TAG_APPLICATION_ID: |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 113 | case KM_TAG_AUTH_TIMEOUT: |
| 114 | case KM_TAG_BLOB_USAGE_REQUIREMENTS: |
| 115 | case KM_TAG_BLOCK_MODE: |
| 116 | case KM_TAG_BOOT_PATCHLEVEL: |
| 117 | case KM_TAG_CALLER_NONCE: |
| 118 | case KM_TAG_DIGEST: |
| 119 | case KM_TAG_EC_CURVE: |
| 120 | case KM_TAG_EXPORTABLE: |
| 121 | case KM_TAG_INCLUDE_UNIQUE_ID: |
| 122 | case KM_TAG_KEY_SIZE: |
| 123 | case KM_TAG_MAX_USES_PER_BOOT: |
| 124 | case KM_TAG_MIN_MAC_LENGTH: |
| 125 | case KM_TAG_MIN_SECONDS_BETWEEN_OPS: |
| 126 | case KM_TAG_NO_AUTH_REQUIRED: |
| 127 | case KM_TAG_ORIGIN: |
| 128 | case KM_TAG_OS_PATCHLEVEL: |
| 129 | case KM_TAG_OS_VERSION: |
| 130 | case KM_TAG_PADDING: |
| 131 | case KM_TAG_PURPOSE: |
| 132 | case KM_TAG_RSA_OAEP_MGF_DIGEST: |
| 133 | case KM_TAG_RSA_PUBLIC_EXPONENT: |
| 134 | case KM_TAG_UNLOCKED_DEVICE_REQUIRED: |
| 135 | case KM_TAG_USER_AUTH_TYPE: |
| 136 | case KM_TAG_USER_SECURE_ID: |
| 137 | case KM_TAG_VENDOR_PATCHLEVEL: |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 138 | keyMintEnforced.authorizations.push_back(kmParam2Aidl(entry)); |
| 139 | break; |
| 140 | |
| 141 | /* Keystore-enforced */ |
| 142 | case KM_TAG_ACTIVE_DATETIME: |
| 143 | case KM_TAG_ALL_APPLICATIONS: |
| 144 | case KM_TAG_ALL_USERS: |
| 145 | case KM_TAG_ORIGINATION_EXPIRE_DATETIME: |
| 146 | case KM_TAG_USAGE_EXPIRE_DATETIME: |
| 147 | case KM_TAG_USER_ID: |
| 148 | case KM_TAG_USAGE_COUNT_LIMIT: |
| 149 | keystoreEnforced.authorizations.push_back(kmParam2Aidl(entry)); |
| 150 | break; |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
Shawn Willden | 09f4710 | 2021-01-15 15:21:56 -0700 | [diff] [blame^] | 154 | vector<KeyCharacteristics> retval; |
| 155 | retval.reserve(2); |
| 156 | if (!keyMintEnforced.authorizations.empty()) retval.push_back(std::move(keyMintEnforced)); |
| 157 | if (!keystoreEnforced.authorizations.empty()) retval.push_back(std::move(keystoreEnforced)); |
| 158 | |
| 159 | return retval; |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Shawn Willden | d7d4f31 | 2020-12-21 08:31:01 -0700 | [diff] [blame] | 162 | Certificate convertCertificate(const keymaster_blob_t& cert) { |
| 163 | return {std::vector<uint8_t>(cert.data, cert.data + cert.data_length)}; |
| 164 | } |
| 165 | |
| 166 | vector<Certificate> convertCertificateChain(const CertificateChain& chain) { |
| 167 | vector<Certificate> retval; |
| 168 | retval.reserve(chain.entry_count); |
| 169 | std::transform(chain.begin(), chain.end(), std::back_inserter(retval), convertCertificate); |
| 170 | return retval; |
| 171 | } |
| 172 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 173 | } // namespace |
| 174 | |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 175 | constexpr size_t kOperationTableSize = 16; |
| 176 | |
| 177 | AndroidKeyMintDevice::AndroidKeyMintDevice(SecurityLevel securityLevel) |
| 178 | : impl_(new ::keymaster::AndroidKeymaster( |
| 179 | [&]() -> auto { |
| 180 | auto context = new PureSoftKeymasterContext( |
| 181 | KmVersion::KEYMINT_1, static_cast<keymaster_security_level_t>(securityLevel)); |
| 182 | context->SetSystemVersion(::keymaster::GetOsVersion(), |
| 183 | ::keymaster::GetOsPatchlevel()); |
| 184 | return context; |
| 185 | }(), |
| 186 | kOperationTableSize)), |
| 187 | securityLevel_(securityLevel) {} |
| 188 | |
| 189 | AndroidKeyMintDevice::~AndroidKeyMintDevice() {} |
| 190 | |
| 191 | ScopedAStatus AndroidKeyMintDevice::getHardwareInfo(KeyMintHardwareInfo* info) { |
| 192 | info->versionNumber = 1; |
| 193 | info->securityLevel = securityLevel_; |
| 194 | info->keyMintName = "FakeKeyMintDevice"; |
| 195 | info->keyMintAuthorName = "Google"; |
| 196 | |
| 197 | return ScopedAStatus::ok(); |
| 198 | } |
| 199 | |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 200 | ScopedAStatus AndroidKeyMintDevice::addRngEntropy(const vector<uint8_t>& data) { |
| 201 | if (data.size() == 0) { |
| 202 | return ScopedAStatus::ok(); |
| 203 | } |
| 204 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 205 | AddEntropyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 206 | request.random_data.Reinitialize(data.data(), data.size()); |
| 207 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 208 | AddEntropyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 209 | impl_->AddRngEntropy(request, &response); |
| 210 | |
| 211 | return kmError2ScopedAStatus(response.error); |
| 212 | } |
| 213 | |
| 214 | ScopedAStatus AndroidKeyMintDevice::generateKey(const vector<KeyParameter>& keyParams, |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 215 | KeyCreationResult* creationResult) { |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 216 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 217 | GenerateKeyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 218 | request.key_description.Reinitialize(KmParamSet(keyParams)); |
| 219 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 220 | GenerateKeyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 221 | impl_->GenerateKey(request, &response); |
| 222 | |
| 223 | if (response.error != KM_ERROR_OK) { |
| 224 | // Note a key difference between this current aidl and previous hal, is |
| 225 | // that hal returns void where as aidl returns the error status. If |
| 226 | // aidl returns error, then aidl will not return any change you may make |
| 227 | // to the out parameters. This is quite different from hal where all |
| 228 | // output variable can be modified due to hal returning void. |
| 229 | // |
| 230 | // So the caller need to be aware not to expect aidl functions to clear |
| 231 | // the output variables for you in case of error. If you left some |
| 232 | // wrong data set in the out parameters, they will stay there. |
| 233 | return kmError2ScopedAStatus(response.error); |
| 234 | } |
| 235 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 236 | creationResult->keyBlob = kmBlob2vector(response.key_blob); |
| 237 | creationResult->keyCharacteristics = |
| 238 | convertKeyCharacteristics(securityLevel_, response.unenforced, response.enforced); |
Shawn Willden | d7d4f31 | 2020-12-21 08:31:01 -0700 | [diff] [blame] | 239 | creationResult->certificateChain = convertCertificateChain(response.certificate_chain); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 240 | return ScopedAStatus::ok(); |
| 241 | } |
| 242 | |
| 243 | ScopedAStatus AndroidKeyMintDevice::importKey(const vector<KeyParameter>& keyParams, |
| 244 | KeyFormat keyFormat, const vector<uint8_t>& keyData, |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 245 | KeyCreationResult* creationResult) { |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 246 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 247 | ImportKeyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 248 | request.key_description.Reinitialize(KmParamSet(keyParams)); |
| 249 | request.key_format = legacy_enum_conversion(keyFormat); |
Shawn Willden | 6e20ea4 | 2020-12-21 18:52:34 -0700 | [diff] [blame] | 250 | request.key_data = KeymasterKeyBlob(keyData.data(), keyData.size()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 251 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 252 | ImportKeyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 253 | impl_->ImportKey(request, &response); |
| 254 | |
| 255 | if (response.error != KM_ERROR_OK) { |
| 256 | return kmError2ScopedAStatus(response.error); |
| 257 | } |
| 258 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 259 | creationResult->keyBlob = kmBlob2vector(response.key_blob); |
| 260 | creationResult->keyCharacteristics = |
| 261 | convertKeyCharacteristics(securityLevel_, response.unenforced, response.enforced); |
Shawn Willden | d7d4f31 | 2020-12-21 08:31:01 -0700 | [diff] [blame] | 262 | creationResult->certificateChain = convertCertificateChain(response.certificate_chain); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 263 | |
| 264 | return ScopedAStatus::ok(); |
| 265 | } |
| 266 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 267 | ScopedAStatus AndroidKeyMintDevice::importWrappedKey(const vector<uint8_t>& wrappedKeyData, |
| 268 | const vector<uint8_t>& wrappingKeyBlob, |
| 269 | const vector<uint8_t>& maskingKey, |
| 270 | const vector<KeyParameter>& unwrappingParams, |
| 271 | int64_t passwordSid, int64_t biometricSid, |
| 272 | KeyCreationResult* creationResult) { |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 273 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 274 | ImportWrappedKeyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 275 | request.SetWrappedMaterial(wrappedKeyData.data(), wrappedKeyData.size()); |
| 276 | request.SetWrappingMaterial(wrappingKeyBlob.data(), wrappingKeyBlob.size()); |
| 277 | request.SetMaskingKeyMaterial(maskingKey.data(), maskingKey.size()); |
| 278 | request.additional_params.Reinitialize(KmParamSet(unwrappingParams)); |
| 279 | request.password_sid = static_cast<uint64_t>(passwordSid); |
| 280 | request.biometric_sid = static_cast<uint64_t>(biometricSid); |
| 281 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 282 | ImportWrappedKeyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 283 | impl_->ImportWrappedKey(request, &response); |
| 284 | |
| 285 | if (response.error != KM_ERROR_OK) { |
| 286 | return kmError2ScopedAStatus(response.error); |
| 287 | } |
| 288 | |
Shawn Willden | 763166c | 2021-01-10 19:45:01 -0700 | [diff] [blame] | 289 | creationResult->keyBlob = kmBlob2vector(response.key_blob); |
| 290 | creationResult->keyCharacteristics = |
| 291 | convertKeyCharacteristics(securityLevel_, response.unenforced, response.enforced); |
Shawn Willden | d7d4f31 | 2020-12-21 08:31:01 -0700 | [diff] [blame] | 292 | creationResult->certificateChain = convertCertificateChain(response.certificate_chain); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 293 | |
| 294 | return ScopedAStatus::ok(); |
| 295 | } |
| 296 | |
| 297 | ScopedAStatus AndroidKeyMintDevice::upgradeKey(const vector<uint8_t>& keyBlobToUpgrade, |
| 298 | const vector<KeyParameter>& upgradeParams, |
| 299 | vector<uint8_t>* keyBlob) { |
| 300 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 301 | UpgradeKeyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 302 | request.SetKeyMaterial(keyBlobToUpgrade.data(), keyBlobToUpgrade.size()); |
| 303 | request.upgrade_params.Reinitialize(KmParamSet(upgradeParams)); |
| 304 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 305 | UpgradeKeyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 306 | impl_->UpgradeKey(request, &response); |
| 307 | |
| 308 | if (response.error != KM_ERROR_OK) { |
| 309 | return kmError2ScopedAStatus(response.error); |
| 310 | } |
| 311 | |
| 312 | *keyBlob = kmBlob2vector(response.upgraded_key); |
| 313 | return ScopedAStatus::ok(); |
| 314 | } |
| 315 | |
| 316 | ScopedAStatus AndroidKeyMintDevice::deleteKey(const vector<uint8_t>& keyBlob) { |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 317 | DeleteKeyRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 318 | request.SetKeyMaterial(keyBlob.data(), keyBlob.size()); |
| 319 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 320 | DeleteKeyResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 321 | impl_->DeleteKey(request, &response); |
| 322 | |
| 323 | return kmError2ScopedAStatus(response.error); |
| 324 | } |
| 325 | |
| 326 | ScopedAStatus AndroidKeyMintDevice::deleteAllKeys() { |
| 327 | // There's nothing to be done to delete software key blobs. |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 328 | DeleteAllKeysRequest request(impl_->message_version()); |
| 329 | DeleteAllKeysResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 330 | impl_->DeleteAllKeys(request, &response); |
| 331 | |
| 332 | return kmError2ScopedAStatus(response.error); |
| 333 | } |
| 334 | |
| 335 | ScopedAStatus AndroidKeyMintDevice::destroyAttestationIds() { |
| 336 | return kmError2ScopedAStatus(KM_ERROR_UNIMPLEMENTED); |
| 337 | } |
| 338 | |
| 339 | ScopedAStatus AndroidKeyMintDevice::begin(KeyPurpose purpose, const vector<uint8_t>& keyBlob, |
| 340 | const vector<KeyParameter>& params, |
| 341 | const HardwareAuthToken& authToken, BeginResult* result) { |
| 342 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 343 | BeginOperationRequest request(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 344 | request.purpose = legacy_enum_conversion(purpose); |
| 345 | request.SetKeyMaterial(keyBlob.data(), keyBlob.size()); |
| 346 | request.additional_params.Reinitialize(KmParamSet(params)); |
| 347 | |
| 348 | vector<uint8_t> vector_token = authToken2AidlVec(authToken); |
| 349 | request.additional_params.push_back( |
| 350 | TAG_AUTH_TOKEN, reinterpret_cast<uint8_t*>(vector_token.data()), vector_token.size()); |
| 351 | |
Shawn Willden | 950eb0b | 2021-01-06 19:15:29 +0000 | [diff] [blame] | 352 | BeginOperationResponse response(impl_->message_version()); |
Shawn Willden | 815e896 | 2020-12-11 13:05:27 +0000 | [diff] [blame] | 353 | impl_->BeginOperation(request, &response); |
| 354 | |
| 355 | if (response.error != KM_ERROR_OK) { |
| 356 | return kmError2ScopedAStatus(response.error); |
| 357 | } |
| 358 | |
| 359 | result->params = kmParamSet2Aidl(response.output_params); |
| 360 | result->challenge = response.op_handle; |
| 361 | result->operation = |
| 362 | ndk::SharedRefBase::make<AndroidKeyMintOperation>(impl_, response.op_handle); |
| 363 | return ScopedAStatus::ok(); |
| 364 | } |
| 365 | |
| 366 | IKeyMintDevice* CreateKeyMintDevice(SecurityLevel securityLevel) { |
| 367 | |
| 368 | return ::new AndroidKeyMintDevice(securityLevel); |
| 369 | } |
| 370 | |
| 371 | } // namespace aidl::android::hardware::security::keymint |