Loading keymaster/4.0/support/Android.bp +4 −6 Original line number Diff line number Diff line Loading @@ -27,11 +27,10 @@ cc_library { "authorization_set.cpp", "key_param_output.cpp", "keymaster_utils.cpp", "Keymaster.cpp", "Keymaster3.cpp", "Keymaster4.cpp", ], export_include_dirs: ["include"], export_include_dirs: [ "include", ], shared_libs: [ "android.hardware.keymaster@3.0", "android.hardware.keymaster@4.0", Loading @@ -39,6 +38,5 @@ cc_library { "libcrypto", "libhardware", "libhidlbase", "libutils", ] ], } keymaster/4.1/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ cc_binary { "libhidlbase", "libkeymaster4", "libkeymaster41", "libkeymaster4_1support", "liblog", "libutils", ], Loading keymaster/4.1/support/Android.bp +8 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ cc_library { ], srcs: [ "attestation_record.cpp", "Keymaster.cpp", "Keymaster3.cpp", "Keymaster4.cpp", ], export_include_dirs: ["include"], shared_libs: [ Loading @@ -34,5 +37,10 @@ cc_library { "libcrypto", "libhidlbase", "libkeymaster4support", "libutils", ], export_shared_lib_headers: [ "android.hardware.keymaster@4.1", "libkeymaster4support", ], } keymaster/4.0/support/Keymaster.cpp→keymaster/4.1/support/Keymaster.cpp +26 −26 Original line number Diff line number Diff line Loading @@ -14,19 +14,18 @@ ** limitations under the License. */ #include <keymasterV4_0/Keymaster.h> #include <keymasterV4_1/Keymaster.h> #include <iomanip> #include <android-base/logging.h> #include <android/hidl/manager/1.2/IServiceManager.h> #include <keymasterV4_0/Keymaster3.h> #include <keymasterV4_0/Keymaster4.h> #include <keymasterV4_0/key_param_output.h> #include <keymasterV4_0/keymaster_utils.h> #include <keymasterV4_1/Keymaster3.h> #include <keymasterV4_1/Keymaster4.h> namespace android { namespace hardware { namespace android::hardware { template <class T> std::ostream& operator<<(std::ostream& os, const hidl_vec<T>& vec) { Loading Loading @@ -57,6 +56,7 @@ std::ostream& operator<<(std::ostream& os, const hidl_array<uint8_t, N>& vec) { } namespace keymaster { namespace V4_0 { std::ostream& operator<<(std::ostream& os, const HmacSharingParameters& params) { Loading @@ -66,7 +66,9 @@ std::ostream& operator<<(std::ostream& os, const HmacSharingParameters& params) return os; } namespace support { } // namespace V4_0 namespace V4_1::support { using ::android::sp; using ::android::hidl::manager::V1_2::IServiceManager; Loading Loading @@ -147,7 +149,7 @@ static hidl_vec<HmacSharingParameters> getHmacParameters( for (auto& keymaster : keymasters) { if (keymaster->halVersion().majorVersion < 4) continue; auto rc = keymaster->getHmacSharingParameters([&](auto error, auto& params) { CHECK(error == ErrorCode::OK) CHECK(error == V4_0::ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; params_vec.push_back(params); }); Loading @@ -170,9 +172,9 @@ static void computeHmac(const Keymaster::KeymasterSet& keymasters, if (keymaster->halVersion().majorVersion < 4) continue; LOG(DEBUG) << "Computing HMAC for " << *keymaster; auto rc = keymaster->computeSharedHmac( params, [&](ErrorCode error, const hidl_vec<uint8_t>& curSharingCheck) { CHECK(error == ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; params, [&](V4_0::ErrorCode error, const hidl_vec<uint8_t>& curSharingCheck) { CHECK(error == V4_0::ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; if (firstKeymaster) { sharingCheck = curSharingCheck; firstKeymaster = false; Loading @@ -191,8 +193,6 @@ void Keymaster::performHmacKeyAgreement(const KeymasterSet& keymasters) { computeHmac(keymasters, getHmacParameters(keymasters)); } } // namespace support } // namespace V4_0 } // namespace V4_1::support } // namespace keymaster } // namespace hardware } // namespace android } // namespace android::hardware keymaster/4.0/support/Keymaster3.cpp→keymaster/4.1/support/Keymaster3.cpp +33 −38 Original line number Diff line number Diff line Loading @@ -15,23 +15,19 @@ ** limitations under the License. */ #include <keymasterV4_0/Keymaster3.h> #include <keymasterV4_1/Keymaster3.h> #include <android-base/logging.h> #include <keymasterV4_0/keymaster_utils.h> namespace android { namespace hardware { namespace keymaster { namespace V4_0 { namespace support { namespace android::hardware::keymaster::V4_1::support { using android::hardware::details::StatusOf; namespace { ErrorCode convert(V3_0::ErrorCode error) { return static_cast<ErrorCode>(error); V4_0::ErrorCode convert(V3_0::ErrorCode error) { return static_cast<V4_0::ErrorCode>(error); } V3_0::KeyPurpose convert(KeyPurpose purpose) { Loading @@ -53,7 +49,7 @@ V3_0::KeyParameter convert(const KeyParameter& param) { KeyParameter convert(const V3_0::KeyParameter& param) { KeyParameter converted; converted.tag = static_cast<Tag>(param.tag); converted.tag = static_cast<V4_0::Tag>(param.tag); static_assert(sizeof(converted.f) == sizeof(param.f), "This function assumes sizes match"); memcpy(&converted.f, ¶m.f, sizeof(param.f)); converted.blob = param.blob; Loading Loading @@ -89,7 +85,7 @@ hidl_vec<V3_0::KeyParameter> convertAndAddAuthToken(const hidl_vec<KeyParameter> converted[i] = convert(params[i]); } converted[params.size()].tag = V3_0::Tag::AUTH_TOKEN; converted[params.size()].blob = authToken2HidlVec(authToken); converted[params.size()].blob = V4_0::support::authToken2HidlVec(authToken); return converted; } Loading @@ -110,7 +106,10 @@ void Keymaster3::getVersionIfNeeded() { [&](bool isSecure, bool supportsEllipticCurve, bool supportsSymmetricCryptography, bool supportsAttestation, bool supportsAllDigests, const hidl_string& keymasterName, const hidl_string& keymasterAuthorName) { version_ = {keymasterName, keymasterAuthorName, 0 /* major version, filled below */, version_ = {keymasterName, keymasterAuthorName, 0 /* major version, filled below */, 0 /* minor version */, isSecure ? SecurityLevel::TRUSTED_ENVIRONMENT : SecurityLevel::SOFTWARE, supportsEllipticCurve}; supportsSymmetricCryptography_ = supportsSymmetricCryptography; Loading Loading @@ -139,10 +138,10 @@ Return<void> Keymaster3::getHardwareInfo(Keymaster3::getHardwareInfo_cb _hidl_cb return Void(); } Return<ErrorCode> Keymaster3::addRngEntropy(const hidl_vec<uint8_t>& data) { Return<V4_0::ErrorCode> Keymaster3::addRngEntropy(const hidl_vec<uint8_t>& data) { auto rc = km3_dev_->addRngEntropy(data); if (!rc.isOk()) { return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); } return convert(rc); } Loading Loading @@ -215,21 +214,21 @@ Return<void> Keymaster3::upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, return rc; } Return<ErrorCode> Keymaster3::deleteKey(const hidl_vec<uint8_t>& keyBlob) { Return<V4_0::ErrorCode> Keymaster3::deleteKey(const hidl_vec<uint8_t>& keyBlob) { auto rc = km3_dev_->deleteKey(keyBlob); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Return<ErrorCode> Keymaster3::deleteAllKeys() { Return<V4_0::ErrorCode> Keymaster3::deleteAllKeys() { auto rc = km3_dev_->deleteAllKeys(); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Return<ErrorCode> Keymaster3::destroyAttestationIds() { Return<V4_0::ErrorCode> Keymaster3::destroyAttestationIds() { auto rc = km3_dev_->destroyAttestationIds(); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Loading @@ -256,8 +255,8 @@ Return<void> Keymaster3::update(uint64_t operationHandle, const hidl_vec<KeyPara _hidl_cb(convert(error), inputConsumed, convert(outParams), output); }; auto rc = km3_dev_->update(operationHandle, convertAndAddAuthToken(inParams, authToken), input, cb); auto rc = km3_dev_->update(operationHandle, convertAndAddAuthToken(inParams, authToken), input, cb); rc.isOk(); // move ctor prereq return rc; } Loading @@ -278,14 +277,10 @@ Return<void> Keymaster3::finish(uint64_t operationHandle, const hidl_vec<KeyPara return rc; } Return<ErrorCode> Keymaster3::abort(uint64_t operationHandle) { Return<V4_0::ErrorCode> Keymaster3::abort(uint64_t operationHandle) { auto rc = km3_dev_->abort(operationHandle); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } } // namespace support } // namespace V4_0 } // namespace keymaster } // namespace hardware } // namespace android } // namespace android::hardware::keymaster::V4_1::support Loading
keymaster/4.0/support/Android.bp +4 −6 Original line number Diff line number Diff line Loading @@ -27,11 +27,10 @@ cc_library { "authorization_set.cpp", "key_param_output.cpp", "keymaster_utils.cpp", "Keymaster.cpp", "Keymaster3.cpp", "Keymaster4.cpp", ], export_include_dirs: ["include"], export_include_dirs: [ "include", ], shared_libs: [ "android.hardware.keymaster@3.0", "android.hardware.keymaster@4.0", Loading @@ -39,6 +38,5 @@ cc_library { "libcrypto", "libhardware", "libhidlbase", "libutils", ] ], }
keymaster/4.1/default/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -31,6 +31,7 @@ cc_binary { "libhidlbase", "libkeymaster4", "libkeymaster41", "libkeymaster4_1support", "liblog", "libutils", ], Loading
keymaster/4.1/support/Android.bp +8 −0 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ cc_library { ], srcs: [ "attestation_record.cpp", "Keymaster.cpp", "Keymaster3.cpp", "Keymaster4.cpp", ], export_include_dirs: ["include"], shared_libs: [ Loading @@ -34,5 +37,10 @@ cc_library { "libcrypto", "libhidlbase", "libkeymaster4support", "libutils", ], export_shared_lib_headers: [ "android.hardware.keymaster@4.1", "libkeymaster4support", ], }
keymaster/4.0/support/Keymaster.cpp→keymaster/4.1/support/Keymaster.cpp +26 −26 Original line number Diff line number Diff line Loading @@ -14,19 +14,18 @@ ** limitations under the License. */ #include <keymasterV4_0/Keymaster.h> #include <keymasterV4_1/Keymaster.h> #include <iomanip> #include <android-base/logging.h> #include <android/hidl/manager/1.2/IServiceManager.h> #include <keymasterV4_0/Keymaster3.h> #include <keymasterV4_0/Keymaster4.h> #include <keymasterV4_0/key_param_output.h> #include <keymasterV4_0/keymaster_utils.h> #include <keymasterV4_1/Keymaster3.h> #include <keymasterV4_1/Keymaster4.h> namespace android { namespace hardware { namespace android::hardware { template <class T> std::ostream& operator<<(std::ostream& os, const hidl_vec<T>& vec) { Loading Loading @@ -57,6 +56,7 @@ std::ostream& operator<<(std::ostream& os, const hidl_array<uint8_t, N>& vec) { } namespace keymaster { namespace V4_0 { std::ostream& operator<<(std::ostream& os, const HmacSharingParameters& params) { Loading @@ -66,7 +66,9 @@ std::ostream& operator<<(std::ostream& os, const HmacSharingParameters& params) return os; } namespace support { } // namespace V4_0 namespace V4_1::support { using ::android::sp; using ::android::hidl::manager::V1_2::IServiceManager; Loading Loading @@ -147,7 +149,7 @@ static hidl_vec<HmacSharingParameters> getHmacParameters( for (auto& keymaster : keymasters) { if (keymaster->halVersion().majorVersion < 4) continue; auto rc = keymaster->getHmacSharingParameters([&](auto error, auto& params) { CHECK(error == ErrorCode::OK) CHECK(error == V4_0::ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; params_vec.push_back(params); }); Loading @@ -170,9 +172,9 @@ static void computeHmac(const Keymaster::KeymasterSet& keymasters, if (keymaster->halVersion().majorVersion < 4) continue; LOG(DEBUG) << "Computing HMAC for " << *keymaster; auto rc = keymaster->computeSharedHmac( params, [&](ErrorCode error, const hidl_vec<uint8_t>& curSharingCheck) { CHECK(error == ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; params, [&](V4_0::ErrorCode error, const hidl_vec<uint8_t>& curSharingCheck) { CHECK(error == V4_0::ErrorCode::OK) << "Failed to get HMAC parameters from " << *keymaster << " error " << error; if (firstKeymaster) { sharingCheck = curSharingCheck; firstKeymaster = false; Loading @@ -191,8 +193,6 @@ void Keymaster::performHmacKeyAgreement(const KeymasterSet& keymasters) { computeHmac(keymasters, getHmacParameters(keymasters)); } } // namespace support } // namespace V4_0 } // namespace V4_1::support } // namespace keymaster } // namespace hardware } // namespace android } // namespace android::hardware
keymaster/4.0/support/Keymaster3.cpp→keymaster/4.1/support/Keymaster3.cpp +33 −38 Original line number Diff line number Diff line Loading @@ -15,23 +15,19 @@ ** limitations under the License. */ #include <keymasterV4_0/Keymaster3.h> #include <keymasterV4_1/Keymaster3.h> #include <android-base/logging.h> #include <keymasterV4_0/keymaster_utils.h> namespace android { namespace hardware { namespace keymaster { namespace V4_0 { namespace support { namespace android::hardware::keymaster::V4_1::support { using android::hardware::details::StatusOf; namespace { ErrorCode convert(V3_0::ErrorCode error) { return static_cast<ErrorCode>(error); V4_0::ErrorCode convert(V3_0::ErrorCode error) { return static_cast<V4_0::ErrorCode>(error); } V3_0::KeyPurpose convert(KeyPurpose purpose) { Loading @@ -53,7 +49,7 @@ V3_0::KeyParameter convert(const KeyParameter& param) { KeyParameter convert(const V3_0::KeyParameter& param) { KeyParameter converted; converted.tag = static_cast<Tag>(param.tag); converted.tag = static_cast<V4_0::Tag>(param.tag); static_assert(sizeof(converted.f) == sizeof(param.f), "This function assumes sizes match"); memcpy(&converted.f, ¶m.f, sizeof(param.f)); converted.blob = param.blob; Loading Loading @@ -89,7 +85,7 @@ hidl_vec<V3_0::KeyParameter> convertAndAddAuthToken(const hidl_vec<KeyParameter> converted[i] = convert(params[i]); } converted[params.size()].tag = V3_0::Tag::AUTH_TOKEN; converted[params.size()].blob = authToken2HidlVec(authToken); converted[params.size()].blob = V4_0::support::authToken2HidlVec(authToken); return converted; } Loading @@ -110,7 +106,10 @@ void Keymaster3::getVersionIfNeeded() { [&](bool isSecure, bool supportsEllipticCurve, bool supportsSymmetricCryptography, bool supportsAttestation, bool supportsAllDigests, const hidl_string& keymasterName, const hidl_string& keymasterAuthorName) { version_ = {keymasterName, keymasterAuthorName, 0 /* major version, filled below */, version_ = {keymasterName, keymasterAuthorName, 0 /* major version, filled below */, 0 /* minor version */, isSecure ? SecurityLevel::TRUSTED_ENVIRONMENT : SecurityLevel::SOFTWARE, supportsEllipticCurve}; supportsSymmetricCryptography_ = supportsSymmetricCryptography; Loading Loading @@ -139,10 +138,10 @@ Return<void> Keymaster3::getHardwareInfo(Keymaster3::getHardwareInfo_cb _hidl_cb return Void(); } Return<ErrorCode> Keymaster3::addRngEntropy(const hidl_vec<uint8_t>& data) { Return<V4_0::ErrorCode> Keymaster3::addRngEntropy(const hidl_vec<uint8_t>& data) { auto rc = km3_dev_->addRngEntropy(data); if (!rc.isOk()) { return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); } return convert(rc); } Loading Loading @@ -215,21 +214,21 @@ Return<void> Keymaster3::upgradeKey(const hidl_vec<uint8_t>& keyBlobToUpgrade, return rc; } Return<ErrorCode> Keymaster3::deleteKey(const hidl_vec<uint8_t>& keyBlob) { Return<V4_0::ErrorCode> Keymaster3::deleteKey(const hidl_vec<uint8_t>& keyBlob) { auto rc = km3_dev_->deleteKey(keyBlob); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Return<ErrorCode> Keymaster3::deleteAllKeys() { Return<V4_0::ErrorCode> Keymaster3::deleteAllKeys() { auto rc = km3_dev_->deleteAllKeys(); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Return<ErrorCode> Keymaster3::destroyAttestationIds() { Return<V4_0::ErrorCode> Keymaster3::destroyAttestationIds() { auto rc = km3_dev_->destroyAttestationIds(); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } Loading @@ -256,8 +255,8 @@ Return<void> Keymaster3::update(uint64_t operationHandle, const hidl_vec<KeyPara _hidl_cb(convert(error), inputConsumed, convert(outParams), output); }; auto rc = km3_dev_->update(operationHandle, convertAndAddAuthToken(inParams, authToken), input, cb); auto rc = km3_dev_->update(operationHandle, convertAndAddAuthToken(inParams, authToken), input, cb); rc.isOk(); // move ctor prereq return rc; } Loading @@ -278,14 +277,10 @@ Return<void> Keymaster3::finish(uint64_t operationHandle, const hidl_vec<KeyPara return rc; } Return<ErrorCode> Keymaster3::abort(uint64_t operationHandle) { Return<V4_0::ErrorCode> Keymaster3::abort(uint64_t operationHandle) { auto rc = km3_dev_->abort(operationHandle); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, ErrorCode>(rc); if (!rc.isOk()) return StatusOf<V3_0::ErrorCode, V4_0::ErrorCode>(rc); return convert(rc); } } // namespace support } // namespace V4_0 } // namespace keymaster } // namespace hardware } // namespace android } // namespace android::hardware::keymaster::V4_1::support