Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLayomi Akinrinade <layomia@gmail.com>2022-05-25 01:19:32 +0300
committerGitHub <noreply@github.com>2022-05-25 01:19:32 +0300
commitbfbb78354e536ac616f2f9dabf3db2b8fa8b9f64 (patch)
tree2cb29e98010fa2d9f3612aa980eba18283db1175 /src/native/libs
parentc5f949efa20bcb555c453037fa954fcc403f9490 (diff)
Use SubtleCrypto API on browser DOM scenarios (#65966)
* Use SubtleCrypto API on browser DOM scenarios * Add sync over async implementation * Address misc feedback and make fixes * Address pinvoke errors * [Attempt] Correct execution of native digest API call at wasm layer * [Fix up] Correct execution of native digest API call at wasm layer * Update src/tests/BuildWasmApps/Wasm.Build.Tests/BuildTestBase.cs * Address feedback and clean up * Re-implement the crypto worker in ts * Address feedback * Revert "Re-implement the crypto worker in ts" This reverts commit 6a743909605fb5b1194cae6bf571c2e6ff059409. * * moved stuff around and renamed it * initialization bit later * Add code to handle errors in worker (particularly on init) * Clean up * Add crypto dll to wasm native project * Add e2e test * Adjust test to reflect lack of SharedArrayBuffer for Chrome in test harness * Enable Chrome test and validate hashed value in tests * fix merge to track assert being renamed to mono_assert Co-authored-by: Eric StJohn <ericstj@microsoft.com> Co-authored-by: pavelsavara <pavel.savara@gmail.com> Co-authored-by: Ankit Jain <radical@gmail.com>
Diffstat (limited to 'src/native/libs')
-rw-r--r--src/native/libs/CMakeLists.txt2
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt14
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h18
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c30
-rw-r--r--src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h25
5 files changed, 88 insertions, 1 deletions
diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt
index c15ca54cb10..577a6dee6b7 100644
--- a/src/native/libs/CMakeLists.txt
+++ b/src/native/libs/CMakeLists.txt
@@ -149,7 +149,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER)
add_subdirectory(System.Native)
if (CLR_CMAKE_TARGET_BROWSER)
- # skip for now
+ add_subdirectory(System.Security.Cryptography.Native.Browser)
elseif (CLR_CMAKE_TARGET_MACCATALYST)
add_subdirectory(System.Net.Security.Native)
# System.Security.Cryptography.Native is intentionally disabled on iOS
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt b/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt
new file mode 100644
index 00000000000..c411aa9ee9c
--- /dev/null
+++ b/src/native/libs/System.Security.Cryptography.Native.Browser/CMakeLists.txt
@@ -0,0 +1,14 @@
+project(System.Security.Cryptography.Native.Browser C)
+
+set (NATIVE_SOURCES
+ pal_crypto_webworker.c
+)
+
+add_library (System.Security.Cryptography.Native.Browser-Static
+ STATIC
+ ${NATIVE_SOURCES}
+)
+
+set_target_properties(System.Security.Cryptography.Native.Browser-Static PROPERTIES OUTPUT_NAME System.Security.Cryptography.Native.Browser CLEAN_DIRECT_OUTPUT 1)
+
+install (TARGETS System.Security.Cryptography.Native.Browser-Static DESTINATION ${STATIC_LIB_DESTINATION})
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h
new file mode 100644
index 00000000000..775fe634536
--- /dev/null
+++ b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h
@@ -0,0 +1,18 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#pragma once
+
+#include <emscripten.h>
+
+#ifndef __EMSCRIPTEN__
+#error Cryptography Native Browser is designed to be compiled with Emscripten.
+#endif // __EMSCRIPTEN__
+
+#ifndef PALEXPORT
+#ifdef TARGET_UNIX
+#define PALEXPORT __attribute__ ((__visibility__ ("default")))
+#else
+#define PALEXPORT __declspec(dllexport)
+#endif
+#endif // PALEXPORT
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c
new file mode 100644
index 00000000000..5f4da5a9862
--- /dev/null
+++ b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.c
@@ -0,0 +1,30 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#include "pal_browser.h"
+#include "pal_crypto_webworker.h"
+
+// Forward declarations
+extern int32_t dotnet_browser_simple_digest_hash(
+ enum simple_digest ver,
+ uint8_t* input_buffer,
+ int32_t input_len,
+ uint8_t* output_buffer,
+ int32_t output_len);
+
+extern int32_t dotnet_browser_can_use_simple_digest_hash(void);
+
+int32_t SystemCryptoNativeBrowser_SimpleDigestHash(
+ enum simple_digest ver,
+ uint8_t* input_buffer,
+ int32_t input_len,
+ uint8_t* output_buffer,
+ int32_t output_len)
+{
+ return dotnet_browser_simple_digest_hash(ver, input_buffer, input_len, output_buffer, output_len);
+}
+
+int32_t SystemCryptoNativeBrowser_CanUseSimpleDigestHash(void)
+{
+ return dotnet_browser_can_use_simple_digest_hash();
+}
diff --git a/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h
new file mode 100644
index 00000000000..fe8b4d2762b
--- /dev/null
+++ b/src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.h
@@ -0,0 +1,25 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+#pragma once
+
+#include <stdint.h>
+
+// These values are also defined in the System.Security.Cryptography library's
+// browser-crypto implementation, and utilized in the dotnet-crypto-worker in the wasm runtime.
+enum simple_digest
+{
+ sd_sha_1,
+ sd_sha_256,
+ sd_sha_384,
+ sd_sha_512,
+};
+
+PALEXPORT int32_t SystemCryptoNativeBrowser_SimpleDigestHash(
+ enum simple_digest ver,
+ uint8_t* input_buffer,
+ int32_t input_len,
+ uint8_t* output_buffer,
+ int32_t output_len);
+
+PALEXPORT int32_t SystemCryptoNativeBrowser_CanUseSimpleDigestHash(void);