diff --git a/security/keymint/aidl/default/Android.bp b/security/keymint/aidl/default/Android.bp index 491a2c1c95..79697c4e9e 100644 --- a/security/keymint/aidl/default/Android.bp +++ b/security/keymint/aidl/default/Android.bp @@ -9,7 +9,7 @@ cc_binary { "-Wextra", ], shared_libs: [ - "android.hardware.security.keymint-ndk_platform", + "android.hardware.security.keymint-unstable-ndk_platform", "libbase", "libbinder_ndk", "libcppbor", diff --git a/security/keymint/aidl/vts/functional/Android.bp b/security/keymint/aidl/vts/functional/Android.bp index ef7adb10a6..c7cc3807b9 100644 --- a/security/keymint/aidl/vts/functional/Android.bp +++ b/security/keymint/aidl/vts/functional/Android.bp @@ -25,13 +25,13 @@ cc_test { "VerificationTokenTest.cpp", ], shared_libs: [ - "libbinder", + "libbinder_ndk", "libcrypto", "libkeymint", "libkeymint_support", ], static_libs: [ - "android.hardware.security.keymint-cpp", + "android.hardware.security.keymint-unstable-ndk_platform", "libcppbor_external", "libkeymint_vts_test_utils", ], @@ -54,13 +54,13 @@ cc_test_library { ".", ], shared_libs: [ - "libbinder", + "libbinder_ndk", "libcrypto", "libkeymint", "libkeymint_support", ], static_libs: [ - "android.hardware.security.keymint-cpp", + "android.hardware.security.keymint-unstable-ndk_platform", "libcppbor", ], } diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp index ea3a329573..9ba4099819 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.cpp @@ -20,11 +20,12 @@ #include #include +#include #include #include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { using namespace std::literals::chrono_literals; using std::endl; @@ -42,19 +43,19 @@ using std::optional; namespace test { -ErrorCode KeyMintAidlTestBase::GetReturnErrorCode(Status result) { +ErrorCode KeyMintAidlTestBase::GetReturnErrorCode(const Status& result) { if (result.isOk()) return ErrorCode::OK; - if (result.exceptionCode() == binder::Status::EX_SERVICE_SPECIFIC) { - return static_cast(result.serviceSpecificErrorCode()); + if (result.getExceptionCode() == EX_SERVICE_SPECIFIC) { + return static_cast(result.getServiceSpecificError()); } return ErrorCode::UNKNOWN_ERROR; } -void KeyMintAidlTestBase::InitializeKeyMint(sp keyMint) { +void KeyMintAidlTestBase::InitializeKeyMint(std::shared_ptr keyMint) { ASSERT_NE(keyMint, nullptr); - keymint_ = keyMint; + keymint_ = std::move(keyMint); KeyMintHardwareInfo info; ASSERT_TRUE(keymint_->getHardwareInfo(&info).isOk()); @@ -68,8 +69,12 @@ void KeyMintAidlTestBase::InitializeKeyMint(sp keyMint) { } void KeyMintAidlTestBase::SetUp() { - InitializeKeyMint( - android::waitForDeclaredService(String16(GetParam().c_str()))); + if (AServiceManager_isDeclared(GetParam().c_str())) { + ::ndk::SpAIBinder binder(AServiceManager_waitForService(GetParam().c_str())); + InitializeKeyMint(IKeyMintDevice::fromBinder(binder)); + } else { + InitializeKeyMint(nullptr); + } } ErrorCode KeyMintAidlTestBase::GenerateKey(const AuthorizationSet& key_desc, @@ -176,7 +181,7 @@ ErrorCode KeyMintAidlTestBase::DeleteKey(vector* key_blob, bool keep_ke *key_blob = vector(); } - EXPECT_TRUE(result.isOk()) << result.serviceSpecificErrorCode() << endl; + EXPECT_TRUE(result.isOk()) << result.getServiceSpecificError() << endl; return GetReturnErrorCode(result); } @@ -186,7 +191,7 @@ ErrorCode KeyMintAidlTestBase::DeleteKey(bool keep_key_blob) { ErrorCode KeyMintAidlTestBase::DeleteAllKeys() { Status result = keymint_->deleteAllKeys(); - EXPECT_TRUE(result.isOk()) << result.serviceSpecificErrorCode() << endl; + EXPECT_TRUE(result.isOk()) << result.getServiceSpecificError() << endl; return GetReturnErrorCode(result); } @@ -201,7 +206,8 @@ void KeyMintAidlTestBase::CheckedDeleteKey() { ErrorCode KeyMintAidlTestBase::Begin(KeyPurpose purpose, const vector& key_blob, const AuthorizationSet& in_params, - AuthorizationSet* out_params, sp& op) { + AuthorizationSet* out_params, + std::shared_ptr& op) { SCOPED_TRACE("Begin"); Status result; BeginResult out; @@ -326,7 +332,7 @@ ErrorCode KeyMintAidlTestBase::Finish(const AuthorizationSet& in_params, const s output->append(oPut.begin(), oPut.end()); } - op_.clear(); // So dtor doesn't Abort(). + op_.reset(); return GetReturnErrorCode(result); } @@ -358,7 +364,7 @@ ErrorCode KeyMintAidlTestBase::Finish(const string& message, const string& signa return result; } -ErrorCode KeyMintAidlTestBase::Abort(const sp& op) { +ErrorCode KeyMintAidlTestBase::Abort(const std::shared_ptr& op) { SCOPED_TRACE("Abort"); EXPECT_NE(op, nullptr); @@ -368,7 +374,7 @@ ErrorCode KeyMintAidlTestBase::Abort(const sp& op) { Status retval = op->abort(); EXPECT_TRUE(retval.isOk()); - return static_cast(retval.serviceSpecificErrorCode()); + return static_cast(retval.getServiceSpecificError()); } ErrorCode KeyMintAidlTestBase::Abort() { @@ -380,14 +386,14 @@ ErrorCode KeyMintAidlTestBase::Abort() { } Status retval = op_->abort(); - return static_cast(retval.serviceSpecificErrorCode()); + return static_cast(retval.getServiceSpecificError()); } void KeyMintAidlTestBase::AbortIfNeeded() { SCOPED_TRACE("AbortIfNeeded"); if (op_) { EXPECT_EQ(ErrorCode::OK, Abort()); - op_.clear(); + op_.reset(); } } @@ -522,7 +528,7 @@ void KeyMintAidlTestBase::VerifyMessage(const vector& key_blob, const s AuthorizationSet finish_out_params; EXPECT_EQ(ErrorCode::OK, Finish(finish_params, message.substr(consumed), signature, &finish_out_params, &output)); - op_.clear(); + op_.reset(); EXPECT_TRUE(output.empty()); } @@ -750,4 +756,4 @@ vector KeyMintAidlTestBase::ValidDigests(bool withNone, bool withMD5) { } // namespace test -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h index 052736b672..f73c26d9e1 100644 --- a/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h +++ b/security/keymint/aidl/vts/functional/KeyMintAidlTestBase.h @@ -22,15 +22,15 @@ #include #include -#include -#include +#include +#include #include -namespace android::hardware::security::keymint::test { +namespace aidl::android::hardware::security::keymint::test { using ::android::sp; -using binder::Status; +using Status = ::ndk::ScopedAStatus; using ::std::shared_ptr; using ::std::string; using ::std::vector; @@ -49,12 +49,12 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam { AbortIfNeeded(); } - void InitializeKeyMint(sp keyMint); + void InitializeKeyMint(std::shared_ptr keyMint); IKeyMintDevice& keyMint() { return *keymint_; } uint32_t os_version() { return os_version_; } uint32_t os_patch_level() { return os_patch_level_; } - ErrorCode GetReturnErrorCode(Status result); + ErrorCode GetReturnErrorCode(const Status& result); ErrorCode GenerateKey(const AuthorizationSet& key_desc, vector* key_blob, KeyCharacteristics* key_characteristics); @@ -80,7 +80,7 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam { ErrorCode Begin(KeyPurpose purpose, const vector& key_blob, const AuthorizationSet& in_params, AuthorizationSet* out_params, - sp& op); + std::shared_ptr& op); ErrorCode Begin(KeyPurpose purpose, const vector& key_blob, const AuthorizationSet& in_params, AuthorizationSet* out_params); ErrorCode Begin(KeyPurpose purpose, const AuthorizationSet& in_params, @@ -98,7 +98,7 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam { ErrorCode Finish(string* output) { return Finish(string(), output); } ErrorCode Abort(); - ErrorCode Abort(const sp& op); + ErrorCode Abort(const shared_ptr& op); void AbortIfNeeded(); string ProcessMessage(const vector& key_blob, KeyPurpose operation, @@ -159,17 +159,17 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam { vector ValidDigests(bool withNone, bool withMD5); static vector build_params() { - auto params = android::getAidlHalInstanceNames(IKeyMintDevice::descriptor); + auto params = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor); return params; } - sp op_; + std::shared_ptr op_; vector certChain_; vector key_blob_; KeyCharacteristics key_characteristics_; private: - sp keymint_; + std::shared_ptr keymint_; uint32_t os_version_; uint32_t os_patch_level_; @@ -182,6 +182,6 @@ class KeyMintAidlTestBase : public ::testing::TestWithParam { #define INSTANTIATE_KEYMINT_AIDL_TEST(name) \ INSTANTIATE_TEST_SUITE_P(PerInstance, name, \ testing::ValuesIn(KeyMintAidlTestBase::build_params()), \ - android::PrintInstanceNameToString) + ::android::PrintInstanceNameToString) -} // namespace android::hardware::security::keymint::test +} // namespace aidl::android::hardware::security::keymint::test diff --git a/security/keymint/aidl/vts/functional/KeyMintTest.cpp b/security/keymint/aidl/vts/functional/KeyMintTest.cpp index f9423a24a3..6e38539a36 100644 --- a/security/keymint/aidl/vts/functional/KeyMintTest.cpp +++ b/security/keymint/aidl/vts/functional/KeyMintTest.cpp @@ -26,7 +26,7 @@ #include -#include +#include #include #include @@ -37,21 +37,21 @@ static bool arm_deleteAllKeys = false; static bool dump_Attestations = false; -using android::hardware::security::keymint::AuthorizationSet; -using android::hardware::security::keymint::KeyCharacteristics; -using android::hardware::security::keymint::KeyFormat; +using aidl::android::hardware::security::keymint::AuthorizationSet; +using aidl::android::hardware::security::keymint::KeyCharacteristics; +using aidl::android::hardware::security::keymint::KeyFormat; -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { bool operator==(const keymint::AuthorizationSet& a, const keymint::AuthorizationSet& b) { return a.size() == b.size() && std::equal(a.begin(), a.end(), b.begin()); } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint namespace std { -using namespace android::hardware::security::keymint; +using namespace aidl::android::hardware::security::keymint; template <> struct std::equal_to { @@ -73,7 +73,7 @@ struct std::equal_to { } // namespace std -namespace android::hardware::security::keymint::test { +namespace aidl::android::hardware::security::keymint::test { namespace { @@ -834,7 +834,7 @@ TEST_P(SigningOperationsTest, RsaAbort) { EXPECT_EQ(ErrorCode::INVALID_OPERATION_HANDLE, Abort()); // Set to sentinel, so TearDown() doesn't try to abort again. - op_.clear(); + op_.reset(); } /* @@ -3115,7 +3115,7 @@ TEST_P(EncryptionOperationsTest, AesGcmAadOutOfOrder) { EXPECT_EQ(ErrorCode::INVALID_TAG, Update(update_params, "", &update_out_params, &ciphertext, &input_consumed)); - op_.clear(); + op_.reset(); } /* @@ -3973,7 +3973,7 @@ TEST_P(ClearOperationsTest, TooManyOperations) { auto params = AuthorizationSetBuilder().Padding(PaddingMode::NONE); constexpr size_t max_operations = 100; // set to arbituary large number - sp op_handles[max_operations]; + std::shared_ptr op_handles[max_operations]; AuthorizationSet out_params; ErrorCode result; size_t i; @@ -4040,7 +4040,7 @@ TEST_P(TransportLimitTest, LargeFinishInput) { INSTANTIATE_KEYMINT_AIDL_TEST(TransportLimitTest); -} // namespace android::hardware::security::keymint::test +} // namespace aidl::android::hardware::security::keymint::test int main(int argc, char** argv) { ::testing::InitGoogleTest(&argc, argv); diff --git a/security/keymint/aidl/vts/functional/VerificationTokenTest.cpp b/security/keymint/aidl/vts/functional/VerificationTokenTest.cpp index 6d3a34e7a6..0b1eccddfd 100644 --- a/security/keymint/aidl/vts/functional/VerificationTokenTest.cpp +++ b/security/keymint/aidl/vts/functional/VerificationTokenTest.cpp @@ -16,7 +16,7 @@ #include "KeyMintAidlTestBase.h" -namespace android::hardware::security::keymint::test { +namespace aidl::android::hardware::security::keymint::test { class VerificationTokenTest : public KeyMintAidlTestBase { protected: @@ -165,4 +165,4 @@ TEST_P(VerificationTokenTest, MacChangesOnChangingTimestamp) { INSTANTIATE_KEYMINT_AIDL_TEST(VerificationTokenTest); -} // namespace android::hardware::security::keymint::test +} // namespace aidl::android::hardware::security::keymint::test diff --git a/security/keymint/support/Android.bp b/security/keymint/support/Android.bp index ddac92fc6b..0cfa798344 100644 --- a/security/keymint/support/Android.bp +++ b/security/keymint/support/Android.bp @@ -31,7 +31,7 @@ cc_library { "include", ], shared_libs: [ - "android.hardware.security.keymint-cpp", + "android.hardware.security.keymint-unstable-ndk_platform", "libbase", "libcrypto", "libutils", diff --git a/security/keymint/support/attestation_record.cpp b/security/keymint/support/attestation_record.cpp index 1b074958c0..596b097bed 100644 --- a/security/keymint/support/attestation_record.cpp +++ b/security/keymint/support/attestation_record.cpp @@ -18,8 +18,8 @@ #include -#include -#include +#include +#include #include @@ -33,7 +33,7 @@ #define AT __FILE__ ":" << __LINE__ -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { struct stack_st_ASN1_TYPE_Delete { void operator()(stack_st_ASN1_TYPE* p) { sk_ASN1_TYPE_free(p); } @@ -380,4 +380,4 @@ ErrorCode parse_root_of_trust(const uint8_t* asn1_key_desc, size_t asn1_key_desc return ErrorCode::OK; // KM_ERROR_OK; } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/authorization_set.cpp b/security/keymint/support/authorization_set.cpp index e2aac9a3c5..37b6cd1ff3 100644 --- a/security/keymint/support/authorization_set.cpp +++ b/security/keymint/support/authorization_set.cpp @@ -16,19 +16,13 @@ #include -#include -#include +#include +#include +#include +#include +#include -#include - -#include -#include -#include -#include -#include -#include - -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { void AuthorizationSet::Sort() { std::sort(data_.begin(), data_.end()); @@ -218,7 +212,7 @@ AuthorizationSetBuilder& AuthorizationSetBuilder::GcmModeMacLen(uint32_t macLeng } AuthorizationSetBuilder& AuthorizationSetBuilder::BlockMode( - std::initializer_list blockModes) { + std::initializer_list blockModes) { for (auto mode : blockModes) { push_back(TAG_BLOCK_MODE, mode); } @@ -240,4 +234,4 @@ AuthorizationSetBuilder& AuthorizationSetBuilder::Padding( return *this; } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/attestation_record.h b/security/keymint/support/include/keymint_support/attestation_record.h index 0739569473..bc76c9398e 100644 --- a/security/keymint/support/include/keymint_support/attestation_record.h +++ b/security/keymint/support/include/keymint_support/attestation_record.h @@ -16,14 +16,14 @@ #pragma once -#include -#include +#include +#include #include #include #include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { class AuthorizationSet; @@ -84,4 +84,4 @@ ErrorCode parse_root_of_trust(const uint8_t* asn1_key_desc, size_t asn1_key_desc VerifiedBoot* verified_boot_state, bool* device_locked, std::vector* verified_boot_hash); -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/authorization_set.h b/security/keymint/support/include/keymint_support/authorization_set.h index 027720040e..c85f3050d9 100644 --- a/security/keymint/support/include/keymint_support/authorization_set.h +++ b/security/keymint/support/include/keymint_support/authorization_set.h @@ -18,14 +18,14 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { using std::vector; @@ -307,4 +307,4 @@ class AuthorizationSetBuilder : public AuthorizationSet { } }; -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/key_param_output.h b/security/keymint/support/include/keymint_support/key_param_output.h index b109105bd7..6e0e35d9c0 100644 --- a/security/keymint/support/include/keymint_support/key_param_output.h +++ b/security/keymint/support/include/keymint_support/key_param_output.h @@ -19,24 +19,24 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include "keymint_tags.h" -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { inline ::std::ostream& operator<<(::std::ostream& os, Algorithm value) { return os << toString(value); @@ -96,4 +96,4 @@ inline ::std::ostream& operator<<(::std::ostream& os, Tag tag) { return os << toString(tag); } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/keymint_tags.h b/security/keymint/support/include/keymint_support/keymint_tags.h index d418fec0ab..4e3d7ff3a0 100644 --- a/security/keymint/support/include/keymint_support/keymint_tags.h +++ b/security/keymint/support/include/keymint_support/keymint_tags.h @@ -16,20 +16,20 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { constexpr TagType typeFromTag(Tag tag) { return static_cast(static_cast(tag) & static_cast(0xf0000000)); @@ -325,4 +325,4 @@ inline NullOr>::type&> return accessTagValue(ttag, param); } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/keymint_utils.h b/security/keymint/support/include/keymint_support/keymint_utils.h index 878b7df3f7..53d5b96959 100644 --- a/security/keymint/support/include/keymint_support/keymint_utils.h +++ b/security/keymint/support/include/keymint_support/keymint_utils.h @@ -16,9 +16,9 @@ #pragma once -#include +#include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { using std::vector; @@ -39,4 +39,4 @@ vector authToken2vector(const HardwareAuthToken& token); uint32_t getOsVersion(); uint32_t getOsPatchlevel(); -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/include/keymint_support/openssl_utils.h b/security/keymint/support/include/keymint_support/openssl_utils.h index 08788106db..9ae7e52383 100644 --- a/security/keymint/support/include/keymint_support/openssl_utils.h +++ b/security/keymint/support/include/keymint_support/openssl_utils.h @@ -16,12 +16,12 @@ #pragma once -#include +#include #include #include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { template struct UniquePtrDeleter { @@ -61,4 +61,4 @@ inline const EVP_MD* openssl_digest(Digest digest) { return nullptr; } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/key_param_output.cpp b/security/keymint/support/key_param_output.cpp index d8e2fff13d..c56e0354e6 100644 --- a/security/keymint/support/key_param_output.cpp +++ b/security/keymint/support/key_param_output.cpp @@ -20,7 +20,7 @@ #include -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { using ::std::endl; using ::std::ostream; @@ -69,4 +69,4 @@ ostream& operator<<(ostream& os, const KeyParameter& param) { return os << "UNKNOWN TAG TYPE!"; } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint diff --git a/security/keymint/support/keymint_utils.cpp b/security/keymint/support/keymint_utils.cpp index 63606f4096..e73d602b1d 100644 --- a/security/keymint/support/keymint_utils.cpp +++ b/security/keymint/support/keymint_utils.cpp @@ -16,14 +16,10 @@ #include -#include - #include #include -#include - -namespace android::hardware::security::keymint { +namespace aidl::android::hardware::security::keymint { namespace { @@ -112,4 +108,4 @@ uint32_t getOsPatchlevel() { return getOsPatchlevel(patchlevel.c_str()); } -} // namespace android::hardware::security::keymint +} // namespace aidl::android::hardware::security::keymint