From 1e806a17b82a062dc536899984277973b8a36f8e Mon Sep 17 00:00:00 2001 From: George Arama <50641385+gearama@users.noreply.github.com> Date: Wed, 22 May 2024 15:29:31 -0700 Subject: [PATCH] Keyvault macros deprecate and new names (#5647) * deprecate macros * dasda * need to remove from cpp due to deprecated error * test * hgjg * comments * definitions * clangs * Update sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md Co-authored-by: Ahson Khan * move test app to build_testing --------- Co-authored-by: Ahson Khan --- .../azure-security-keyvault-keys/CHANGELOG.md | 4 + .../CMakeLists.txt | 1 + .../azure/keyvault/keys/key_client_models.hpp | 43 +++++- .../src/key_encryption_algorithm.cpp | 37 +++++- .../test/macros-build/CMakeLists.txt | 17 +++ .../test/macros-build/macros_build.cpp | 34 +++++ .../test/macros-build/macros_build.hpp | 6 + .../test/ut/key_client_test.cpp | 123 ++++++++++++++++-- 8 files changed, 246 insertions(+), 19 deletions(-) create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/macros-build/CMakeLists.txt create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.cpp create mode 100644 sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.hpp diff --git a/sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md b/sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md index 330ae2f5b..2dc3d7dca 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md +++ b/sdk/keyvault/azure-security-keyvault-keys/CHANGELOG.md @@ -6,6 +6,10 @@ ### Breaking Changes +- Deprecated `KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP` in favor of `KeyEncryptionAlgorithm::CkmRsaAesKeyWrap`. +- Deprecated `KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256` in favor of `KeyEncryptionAlgorithm::RsaAesKeyWrap256`. +- Deprecated `KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384` in favor of `KeyEncryptionAlgorithm::RsaAesKeyWrap384`. + ### Bugs Fixed ### Other Changes diff --git a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt index 431fcfe71..9a18bee07 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt +++ b/sdk/keyvault/azure-security-keyvault-keys/CMakeLists.txt @@ -147,6 +147,7 @@ if(BUILD_TESTING) add_subdirectory(test/ut) add_subdirectory(test/ut-hsm) + add_subdirectory(test/macros-build) endif() if (BUILD_PERFORMANCE_TESTS) diff --git a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp index 12ea22f6b..ce8f599e5 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp +++ b/sdk/keyvault/azure-security-keyvault-keys/inc/azure/keyvault/keys/key_client_models.hpp @@ -312,24 +312,59 @@ namespace Azure { namespace Security { namespace KeyVault { namespace Keys { * @param value The string value of the instance. */ explicit KeyEncryptionAlgorithm(std::string value) : ExtendableEnumeration(std::move(value)) {} - +#ifndef CKM_RSA_AES_KEY_WRAP + /** + * @brief Gets the CKM_RSA_AES_KEY_WRAP algorithm. + * + * @deprecated Use KeyEncryptionAlgorithm::CkmRsaAesKeyWrap. + */ + [[deprecated("Use " + "KeyEncryptionAlgorithm::" + "CkmRsaAesKeyWrap" + ".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm + CKM_RSA_AES_KEY_WRAP; +#endif // !CKM_RSA_AES_KEY_WRAP /** * @brief Gets the CKM_RSA_AES_KEY_WRAP algorithm. * */ - AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm CKM_RSA_AES_KEY_WRAP; + AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm CkmRsaAesKeyWrap; +#ifndef RSA_AES_KEY_WRAP_256 + /** + * @brief Gets the RSA_AES_KEY_WRAP_256 algorithm. + * + * @deprecated Use KeyEncryptionAlgorithm::RsaAesKeyWrap256. + */ + [[deprecated("Use " + "KeyEncryptionAlgorithm::" + "RsaAesKeyWrap256" + ".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm + RSA_AES_KEY_WRAP_256; +#endif // !RSA_AES_KEY_WRAP_256 /** * @brief Gets the RSA_AES_KEY_WRAP_256 algorithm. * */ - AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RSA_AES_KEY_WRAP_256; + AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RsaAesKeyWrap256; +#ifndef RSA_AES_KEY_WRAP_384 + /** + * @brief Gets the RSA_AES_KEY_WRAP_384 algorithm. + * + * @deprecated Use KeyEncryptionAlgorithm::RsaAesKeyWrap384. + */ + [[deprecated("Use " + "KeyEncryptionAlgorithm::" + "RsaAesKeyWrap384" + ".")]] AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm + RSA_AES_KEY_WRAP_384; +#endif // !RSA_AES_KEY_WRAP_384 /** * @brief Gets the RSA_AES_KEY_WRAP_384 algorithm. * */ - AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RSA_AES_KEY_WRAP_384; + AZ_SECURITY_KEYVAULT_KEYS_DLLEXPORT static const KeyEncryptionAlgorithm RsaAesKeyWrap384; }; /** diff --git a/sdk/keyvault/azure-security-keyvault-keys/src/key_encryption_algorithm.cpp b/sdk/keyvault/azure-security-keyvault-keys/src/key_encryption_algorithm.cpp index fc8f47d7e..eee87b2cc 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/src/key_encryption_algorithm.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/src/key_encryption_algorithm.cpp @@ -5,13 +5,38 @@ #include "private/key_constants.hpp" namespace Azure { namespace Security { namespace KeyVault { namespace Keys { +// Disable deprecation warning +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP( + _detail::CKM_RSA_AES_KEY_WRAP_Value); - const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP( - _detail::CKM_RSA_AES_KEY_WRAP_Value); + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256( + _detail::RSA_AES_KEY_WRAP_256_Value); - const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256( - _detail::RSA_AES_KEY_WRAP_256_Value); + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384( + _detail::RSA_AES_KEY_WRAP_384_Value); +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif // _MSC_VER + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::CkmRsaAesKeyWrap( + _detail::CKM_RSA_AES_KEY_WRAP_Value); - const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384( - _detail::RSA_AES_KEY_WRAP_384_Value); + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RsaAesKeyWrap256( + _detail::RSA_AES_KEY_WRAP_256_Value); + + const KeyEncryptionAlgorithm KeyEncryptionAlgorithm::RsaAesKeyWrap384( + _detail::RSA_AES_KEY_WRAP_384_Value); }}}} // namespace Azure::Security::KeyVault::Keys diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/CMakeLists.txt b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/CMakeLists.txt new file mode 100644 index 000000000..cb966c51c --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/CMakeLists.txt @@ -0,0 +1,17 @@ +# Copyright (c) Microsoft Corporation. +# Licensed under the MIT License. + +cmake_minimum_required (VERSION 3.13) + +project (macros-test LANGUAGES CXX) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +add_executable ( + macros-build + macros_build.cpp + macros_build.hpp) + +create_per_service_target_build_for_sample(keyvault macros-build) + +target_link_libraries(macros-build PRIVATE azure-security-keyvault-keys) diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.cpp new file mode 100644 index 000000000..58d86777a --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.cpp @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +/** + * @brief Tests the ability to build when certain macros are defined outside the keyvault + * code simulating the customer scenario. If there is an issue there is a build break + * + */ + +#include "macros_build.hpp" + +#include + +#include +#include +#include +#include +#include + +using namespace Azure::Security::KeyVault::Keys; + +int main() +{ + std::cout << "CKM_RSA_AES_KEY_WRAP : " << CKM_RSA_AES_KEY_WRAP << std::endl; + std::cout << "RSA_AES_KEY_WRAP_256 : " << RSA_AES_KEY_WRAP_256 << std::endl; + std::cout << "RSA_AES_KEY_WRAP_384 : " << RSA_AES_KEY_WRAP_384 << std::endl; + + std::cout << "KeyEncryptionAlgorithm::CkmRsaAesKeyWrap : " + << KeyEncryptionAlgorithm::CkmRsaAesKeyWrap.ToString() << std::endl; + std::cout << "KeyEncryptionAlgorithm::RsaAesKeyWrap256 : " + << KeyEncryptionAlgorithm::RsaAesKeyWrap256.ToString() << std::endl; + std::cout << "KeyEncryptionAlgorithm::RsaAesKeyWrap384 : " + << KeyEncryptionAlgorithm::RsaAesKeyWrap384.ToString() << std::endl; +} diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.hpp b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.hpp new file mode 100644 index 000000000..68f45bad5 --- /dev/null +++ b/sdk/keyvault/azure-security-keyvault-keys/test/macros-build/macros_build.hpp @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#define CKM_RSA_AES_KEY_WRAP 1 +#define RSA_AES_KEY_WRAP_256 2 +#define RSA_AES_KEY_WRAP_384 3 diff --git a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_test.cpp b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_test.cpp index 7a3a0ff9e..990783bfd 100644 --- a/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_test.cpp +++ b/sdk/keyvault/azure-security-keyvault-keys/test/ut/key_client_test.cpp @@ -86,24 +86,129 @@ TEST(KeyReleaseOptionsUnitTest, Most) TEST(KeyReleaseOptionsUnitTest, All) { - KeyReleaseOptions options; - options.Target = "xyz"; - options.Nonce = "abc"; - options.Encryption = KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP; - auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); - auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::CkmRsaAesKeyWrap; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); - EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); - EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); - EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap256; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::RsaAesKeyWrap384; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } +// Disable deprecation warning +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } + { + KeyReleaseOptions options; + options.Target = "xyz"; + options.Nonce = "abc"; + options.Encryption = KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384; + auto serialized = _detail::KeyReleaseOptionsSerializer::KeyReleaseOptionsSerialize(options); + auto deserialized = Azure::Core::Json::_internal::json::parse(serialized); + + EXPECT_EQ(options.Target, deserialized[_detail::TargetValue]); + EXPECT_EQ(options.Nonce.Value(), deserialized[_detail::NonceValue]); + EXPECT_EQ(options.Encryption.Value().ToString(), deserialized[_detail::EncryptionValue]); + } +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif // _MSC_VER } TEST(KeyEncryptionAlgorithmUnitTest, CheckValues) { +// Disable deprecation warning +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable : 4996) +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" +#elif defined(__GNUC__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif EXPECT_EQ( KeyEncryptionAlgorithm::CKM_RSA_AES_KEY_WRAP.ToString(), _detail::CKM_RSA_AES_KEY_WRAP_Value); EXPECT_EQ( KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_256.ToString(), _detail::RSA_AES_KEY_WRAP_256_Value); EXPECT_EQ( KeyEncryptionAlgorithm::RSA_AES_KEY_WRAP_384.ToString(), _detail::RSA_AES_KEY_WRAP_384_Value); +#if defined(_MSC_VER) +#pragma warning(pop) +#elif defined(__clang__) +#pragma clang diagnostic pop +#elif defined(__GNUC__) +#pragma GCC diagnostic pop +#endif // _MSC_VER + + EXPECT_EQ( + KeyEncryptionAlgorithm::CkmRsaAesKeyWrap.ToString(), _detail::CKM_RSA_AES_KEY_WRAP_Value); + EXPECT_EQ( + KeyEncryptionAlgorithm::RsaAesKeyWrap256.ToString(), _detail::RSA_AES_KEY_WRAP_256_Value); + EXPECT_EQ( + KeyEncryptionAlgorithm::RsaAesKeyWrap384.ToString(), _detail::RSA_AES_KEY_WRAP_384_Value); }