Skip to content

Commit

Permalink
[Android] Use Android SDK instead of OpenSSL where possible (#43740)
Browse files Browse the repository at this point in the history
This PR redirects all RandomNumberGenerator, MD5, Sha1-512, HMAC and AES APIs to use Android SDK instead of OpenSSL.
  • Loading branch information
EgorBo authored Nov 12, 2020
1 parent a41e100 commit 5af16f2
Show file tree
Hide file tree
Showing 5 changed files with 695 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ elseif(CLR_CMAKE_TARGET_TVOS)
elseif(CLR_CMAKE_TARGET_ANDROID AND NOT CROSS_ROOTFS)
#add_subdirectory(System.Net.Security.Native) # TODO: reenable
if (NOT "$ENV{ANDROID_OPENSSL_AAR}" STREQUAL "")
set(PREFER_OPENSSL_ANDROID 1)
add_subdirectory(System.Security.Cryptography.Native)
endif()
else()
Expand All @@ -237,3 +238,8 @@ endif()
if(CLR_CMAKE_TARGET_OSX OR CLR_CMAKE_TARGET_IOS OR CLR_CMAKE_TARGET_TVOS)
add_subdirectory(System.Security.Cryptography.Native.Apple)
endif()

# if ANDROID_OPENSSL_AAR is not set - use Android Native Crypto (it's going to replace openssl eventually)
if(CLR_CMAKE_TARGET_ANDROID AND NOT PREFER_OPENSSL_ANDROID)
add_subdirectory(System.Security.Cryptography.Native.Android)
endif()
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
project(System.Security.Cryptography.Native.Android C)

add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
add_compile_options(-Wno-unused-parameter)
add_compile_options(-Wno-unused-variable)

set(NATIVECRYPTO_SOURCES
android_security.c
)

add_library(System.Security.Cryptography.Native.Android
SHARED
${NATIVECRYPTO_SOURCES}
${VERSION_FILE_PATH}
)

add_library(System.Security.Cryptography.Native.Android-Static
STATIC
${NATIVECRYPTO_SOURCES}
)

set_target_properties(System.Security.Cryptography.Native.Android-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.Android CLEAN_DIRECT_OUTPUT 1)

target_link_libraries(System.Security.Cryptography.Native.Android
-llog
)

# TODO: Use "System.Security.Cryptography.Native.Android" name (will require a lot of csproj changes here and there)
set_target_properties(System.Security.Cryptography.Native.Android PROPERTIES OUTPUT_NAME "System.Security.Cryptography.Native.OpenSsl")

install_with_stripped_symbols (System.Security.Cryptography.Native.Android PROGRAMS .)
install (TARGETS System.Security.Cryptography.Native.Android-Static DESTINATION .)
Loading

0 comments on commit 5af16f2

Please sign in to comment.