diff options
author | Haamed Gheibi <haamed@google.com> | 2022-02-09 14:35:06 -0800 |
---|---|---|
committer | Haamed Gheibi <haamed@google.com> | 2022-02-09 14:41:16 -0800 |
commit | ab52181d73b04e131fd72e32d69b5123a5d6892b (patch) | |
tree | 0ac86b537180b6fb97716b3058dfae44af9eaac7 /security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp | |
parent | f99b35c293439db0b7436b47b939eb8c7bf21b51 (diff) | |
parent | 4d2548cfa7b86b79a516be9b60f6b666cc9af682 (diff) |
Merge TP1A.220126.001
Change-Id: Ibf6bd2c20d9927fde8b2a05dde2b58bd8faea20f
Diffstat (limited to 'security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp')
-rw-r--r-- | security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp | 57 |
1 files changed, 53 insertions, 4 deletions
diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index 374f2da7a8..146a527561 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -25,6 +25,7 @@ #include <cppbor_parse.h> #include <cutils/properties.h> #include <gmock/gmock.h> +#include <openssl/evp.h> #include <openssl/mem.h> #include <remote_prov/remote_prov_utils.h> @@ -206,6 +207,21 @@ uint32_t KeyMintAidlTestBase::boot_patch_level() { return boot_patch_level(key_characteristics_); } +bool KeyMintAidlTestBase::Curve25519Supported() { + // Strongbox never supports curve 25519. + if (SecLevel() == SecurityLevel::STRONGBOX) { + return false; + } + + // Curve 25519 was included in version 2 of the KeyMint interface. + int32_t version = 0; + auto status = keymint_->getInterfaceVersion(&version); + if (!status.isOk()) { + ADD_FAILURE() << "Failed to determine interface version"; + } + return version >= 2; +} + ErrorCode KeyMintAidlTestBase::GetReturnErrorCode(const Status& result) { if (result.isOk()) return ErrorCode::OK; @@ -543,7 +559,12 @@ ErrorCode KeyMintAidlTestBase::Update(const string& input, string* output) { std::vector<uint8_t> o_put; result = op_->update(vector<uint8_t>(input.begin(), input.end()), {}, {}, &o_put); - if (result.isOk()) output->append(o_put.begin(), o_put.end()); + if (result.isOk()) { + output->append(o_put.begin(), o_put.end()); + } else { + // Failure always terminates the operation. + op_ = {}; + } return GetReturnErrorCode(result); } @@ -740,6 +761,19 @@ void KeyMintAidlTestBase::LocalVerifyMessage(const string& message, const string if (digest == Digest::NONE) { switch (EVP_PKEY_id(pub_key.get())) { + case EVP_PKEY_ED25519: { + ASSERT_EQ(64, signature.size()); + uint8_t pub_keydata[32]; + size_t pub_len = sizeof(pub_keydata); + ASSERT_EQ(1, EVP_PKEY_get_raw_public_key(pub_key.get(), pub_keydata, &pub_len)); + ASSERT_EQ(sizeof(pub_keydata), pub_len); + ASSERT_EQ(1, ED25519_verify(reinterpret_cast<const uint8_t*>(message.data()), + message.size(), + reinterpret_cast<const uint8_t*>(signature.data()), + pub_keydata)); + break; + } + case EVP_PKEY_EC: { vector<uint8_t> data((EVP_PKEY_bits(pub_key.get()) + 7) / 8); size_t data_size = std::min(data.size(), message.size()); @@ -1166,16 +1200,31 @@ vector<PaddingMode> KeyMintAidlTestBase::InvalidPaddingModes(Algorithm algorithm vector<EcCurve> KeyMintAidlTestBase::ValidCurves() { if (securityLevel_ == SecurityLevel::STRONGBOX) { return {EcCurve::P_256}; + } else if (Curve25519Supported()) { + return {EcCurve::P_224, EcCurve::P_256, EcCurve::P_384, EcCurve::P_521, + EcCurve::CURVE_25519}; } else { - return {EcCurve::P_224, EcCurve::P_256, EcCurve::P_384, EcCurve::P_521}; + return { + EcCurve::P_224, + EcCurve::P_256, + EcCurve::P_384, + EcCurve::P_521, + }; } } vector<EcCurve> KeyMintAidlTestBase::InvalidCurves() { if (SecLevel() == SecurityLevel::STRONGBOX) { - return {EcCurve::P_224, EcCurve::P_384, EcCurve::P_521}; + // Curve 25519 is not supported, either because: + // - KeyMint v1: it's an unknown enum value + // - KeyMint v2+: it's not supported by StrongBox. + return {EcCurve::P_224, EcCurve::P_384, EcCurve::P_521, EcCurve::CURVE_25519}; } else { - return {}; + if (Curve25519Supported()) { + return {}; + } else { + return {EcCurve::CURVE_25519}; + } } } |