Fix Identity compilation (WinAPI crypto API) on UWP (#4931)

* Fix Identity compilation (WinAPI crypto API) on UWP

* Clang-format

---------

Co-authored-by: Anton Kolesnyk <antkmsft@users.noreply.github.com>
This commit is contained in:
Anton Kolesnyk 2023-09-07 10:28:37 -07:00 committed by GitHub
parent f7452cc233
commit a8dd2b021b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 7 deletions

View File

@ -101,7 +101,7 @@ target_include_directories(
target_link_libraries(azure-identity PUBLIC Azure::azure-core)
if(WIN32)
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
find_package(wil CONFIG REQUIRED)
target_link_libraries(azure-identity PRIVATE WIL::WIL bcrypt crypt32)
else()

View File

@ -21,6 +21,7 @@
#if defined(AZ_PLATFORM_WINDOWS)
#include <Windows.h>
#if !defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP // not UWP
#pragma warning(push)
#pragma warning(disable : 6553)
#pragma warning(disable : 6001) // Using uninitialized memory 'pNode'.
@ -29,7 +30,11 @@
#include <wil/resource.h>
#include <wil/result.h>
#pragma warning(pop)
#else
#endif // UWP
#endif
#if !defined(AZ_PLATFORM_WINDOWS) \
|| (defined(WINAPI_PARTITION_DESKTOP) && !WINAPI_PARTITION_DESKTOP)
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/ossl_typ.h>
@ -71,7 +76,7 @@ using CertificateThumbprint = std::vector<unsigned char>;
using UniquePrivateKey = Azure::Identity::_detail::UniquePrivateKey;
using PrivateKey = decltype(std::declval<UniquePrivateKey>().get());
#if defined(AZ_PLATFORM_WINDOWS)
#if defined(AZ_PLATFORM_WINDOWS) && (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP)
enum PrivateKeyType
{
Rsa,
@ -360,7 +365,7 @@ std::vector<unsigned char> SignPkcs1Sha256(PrivateKey key, const uint8_t* data,
void Azure::Identity::_detail::FreePrivateKeyImpl(void* pkey)
{
#if defined(AZ_PLATFORM_WINDOWS)
#if defined(AZ_PLATFORM_WINDOWS) && (!defined(WINAPI_PARTITION_DESKTOP) || WINAPI_PARTITION_DESKTOP)
BCryptDestroyKey(static_cast<BCRYPT_KEY_HANDLE>(pkey));
#else
EVP_PKEY_free(static_cast<EVP_PKEY*>(pkey));

View File

@ -9,7 +9,7 @@
},
{
"name": "wil",
"platform": "windows"
"platform": "windows & !uwp"
}
]
}

View File

@ -6,7 +6,7 @@
include(CMakeFindDependencyMacro)
find_dependency(azure-core-cpp)
if (WIN32)
if(WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
find_dependency(wil)
else()
find_dependency(OpenSSL)

View File

@ -22,7 +22,7 @@
},
{
"name": "wil",
"platform": "windows"
"platform": "windows & !uwp"
},
{
"name": "vcpkg-cmake",