Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

On Browser DOM scenarios use the SubtleCrypto API #49511

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1863d35
[WIP] - Start crypto worker and initialize channel.
AaronRobinsonMSFT Mar 10, 2021
d5c4199
Make Emscripten minimizer happy by using getters instead of fields.
AaronRobinsonMSFT Mar 10, 2021
4e2d738
Add new System.Security.Cryptography.Native.Browser library.
AaronRobinsonMSFT Mar 11, 2021
5ec3db7
Initialize WebWorker earlier.
AaronRobinsonMSFT Mar 11, 2021
c7e3888
Update logging and be less strict for output buffer size.
AaronRobinsonMSFT Mar 11, 2021
47b5e6c
Focus SHA tests for non-browser and browser DOM scenarios.
AaronRobinsonMSFT Mar 11, 2021
891b23c
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 11, 2021
d4ea7d6
Add missing namespaces to test builds.
AaronRobinsonMSFT Mar 12, 2021
8062a2f
Additional locations for that need the crypto_worker.js file.
AaronRobinsonMSFT Mar 12, 2021
2b38fdd
Add new JS and native binaries... everywhere.
AaronRobinsonMSFT Mar 12, 2021
84dd60b
Reference the correct location for the webworker file.
AaronRobinsonMSFT Mar 13, 2021
36b2f56
Specify the correct native directory path for the JS WebWorker file.
AaronRobinsonMSFT Mar 13, 2021
80087a5
Only enable Crypto WebWorker when running in the browser scenario.
AaronRobinsonMSFT Mar 15, 2021
6a3b8a6
Condition more tests based on platform Crypto support needed.
AaronRobinsonMSFT Mar 15, 2021
d78f0e2
Rename crypto_worker.js to dotnet_crypto_worker.js
AaronRobinsonMSFT Mar 15, 2021
2e74b1f
Missing installer directory.
AaronRobinsonMSFT Mar 15, 2021
7eb087d
Style
AaronRobinsonMSFT Mar 16, 2021
b04d0cc
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 16, 2021
925dcc0
Change internal API name to use generic "digest" name instead
AaronRobinsonMSFT Mar 16, 2021
753c57b
Add test for not supported platform crypto WRT SHA
AaronRobinsonMSFT Mar 17, 2021
74a4e7e
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 17, 2021
b217fc4
Browser uses Unix binary builds so removing Windows placeholder.
AaronRobinsonMSFT Mar 17, 2021
a95e9d6
Add libSystem.Security.Cryptography.Native.Browser.a for Windows build.
AaronRobinsonMSFT Mar 18, 2021
ce6d2b1
More Windows build changes.
AaronRobinsonMSFT Mar 18, 2021
42eac88
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 23, 2021
55dfe74
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 24, 2021
f777cb3
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 25, 2021
c13a76e
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 25, 2021
f2e28fc
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 25, 2021
c749ab5
Merge remote-tracking branch 'upstream/main' into wasm_crypto
AaronRobinsonMSFT Mar 29, 2021
4c5a3e0
Merge remote-tracking branch 'upstream/main' into wasm_crypto
lewing Apr 22, 2021
44ea919
Merge branch 'main' into wasm_crypto
lewing Apr 22, 2021
742cbc3
Fix the js inclusion logic
lewing Apr 22, 2021
76dd72b
Add libSystem.Globalization.Native explicitly
lewing Apr 23, 2021
bc7ec42
Merge branch 'main' into wasm_crypto
jeffhandley May 11, 2021
3eb7b2f
Merge branch 'main' into wasm_crypto
jeffhandley May 11, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions eng/SignCheckExclusionsFile.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
*comhosttemplatecomhostdll.dll;;Template, DO-NOT-SIGN, https://github.com/dotnet/core-setup/pull/7549
*staticapphosttemplateapphostexe.exe;;Template, DO-NOT-SIGN, https://github.com/dotnet/core-setup/pull/7549
*dotnet.js;;Workaround, https://github.com/dotnet/core-eng/issues/9933
*dotnet_crypto_worker.js;;Workaround, https://github.com/dotnet/core-eng/issues/9933
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ViktorHofer just curious, what is the purpose of this file? From the linked issue, it seems that signing validation happens in an outer ring - in which case what is the purpose of these exclusions. Just curious

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That file predates the outer ring signing validation. @mmitche do you know if the Validate-DotNet outer ring validation honors the SignCheckExclusionFile in our repo?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also just saw that the outer ring signing validation is failing and opened https://github.com/dotnet/core-eng/issues/12601 to better understand who tracks that pipeline.

1 change: 1 addition & 0 deletions eng/liveBuilds.targets
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@
$(LibrariesNativeArtifactsPath)dotnet.js;
$(LibrariesNativeArtifactsPath)dotnet.wasm;
$(LibrariesNativeArtifactsPath)dotnet.timezones.blat;
$(LibrariesNativeArtifactsPath)dotnet_crypto_worker.js;
$(LibrariesNativeArtifactsPath)*.dat;"
IsNative="true" />
<LibrariesRuntimeFiles Condition="'$(TargetOS)' == 'Browser'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
<PlatformManifestFileEntry Include="libSystem.Net.Security.Native.so" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Apple.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Apple.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.Browser.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.a" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.dylib" IsNative="true" />
<PlatformManifestFileEntry Include="libSystem.Security.Cryptography.Native.OpenSsl.so" IsNative="true" />
Expand Down Expand Up @@ -201,6 +202,7 @@
<PlatformManifestFileEntry Include="dotnet.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.wasm" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet.timezones.blat" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet_crypto_worker.js" IsNative="true" />
<PlatformManifestFileEntry Include="icudt.dat" IsNative="true" />
<PlatformManifestFileEntry Include="icudt_no_CJK.dat" IsNative="true" />
<PlatformManifestFileEntry Include="icudt_CJK.dat" IsNative="true" />
Expand All @@ -210,7 +212,9 @@
<PlatformManifestFileEntry Include="binding_support.js" IsNative="true" />
<PlatformManifestFileEntry Include="dotnet_support.js" IsNative="true" />
<PlatformManifestFileEntry Include="library_mono.js" IsNative="true" />
<PlatformManifestFileEntry Include="library_channel.js" IsNative="true" />
<PlatformManifestFileEntry Include="pal_random.js" IsNative="true" />
<PlatformManifestFileEntry Include="pal_crypto_webworker.js" IsNative="true" />
<PlatformManifestFileEntry Include="corebindings.c" IsNative="true" />
<PlatformManifestFileEntry Include="driver.c" IsNative="true" />
<PlatformManifestFileEntry Include="pinvoke.c" IsNative="true" />
Expand Down
12 changes: 12 additions & 0 deletions src/libraries/Common/src/Interop/Browser/Interop.Libraries.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

internal static partial class Interop
{
internal static partial class Libraries
{
// Shims
internal const string SystemNative = "libSystem.Native";
internal const string CryptoNative = "libSystem.Security.Cryptography.Native.Browser";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

internal static partial class Interop
{
internal static partial class BrowserCrypto
{
internal enum SimpleDigest
{
Sha1,
Sha256,
Sha384,
Sha512,
};

[DllImport(Libraries.CryptoNative, EntryPoint = "SystemCryptoNativeBrowser_SimpleDigestHash")]
internal static extern unsafe int SimpleDigestHash(
SimpleDigest hash,
byte* input_buffer,
int input_len,
byte* output_buffer,
int output_len);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public static partial class PlatformDetection
public static bool IsUsingLimitedCultures => !IsNotMobile;
public static bool IsNotUsingLimitedCultures => IsNotMobile;

public static bool IsPlatformCryptoSupported => !IsBrowser || IsBrowserDomSupported;
public static bool IsNotPlatformCryptoSupported => !IsPlatformCryptoSupported;
AaronRobinsonMSFT marked this conversation as resolved.
Show resolved Hide resolved

// Please make sure that you have the libgdiplus dependency installed.
// For details, see https://docs.microsoft.com/dotnet/core/install/dependencies?pivots=os-macos&tabs=netcore31#libgdiplus
public static bool IsDrawingSupported
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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);

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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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>

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);
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

var CryptoWebWorkerLib = {
$CRYPTOWEBWORKER: {
call_digest: function (hash, input_buffer, input_len, output_buffer, output_len) {
if (MONO.mono_wasm_crypto.channel === null) {
return 0; // Not supported
}

var msg = {
func: "digest",
type: hash,
data: Array.from(Module.HEAPU8.subarray (input_buffer, input_buffer + input_len))
};
var response = MONO.mono_wasm_crypto.channel.send_msg (JSON.stringify (msg));
var digest = JSON.parse (response);
if (digest.length > output_len) {
throw "DIGEST HASH: Digest length exceeds output length: " + digest.length + " > " + output_len;
}

Module.HEAPU8.set (digest, output_buffer);
return 1;
}
},
dotnet_browser_simple_digest_hash: function (hash, input_buffer, input_len, output_buffer, output_len) {
return CRYPTOWEBWORKER.call_digest (hash, input_buffer, input_len, output_buffer, output_len);
},
};

autoAddDeps(CryptoWebWorkerLib, '$CRYPTOWEBWORKER')
mergeInto(LibraryManager.library, CryptoWebWorkerLib)
2 changes: 1 addition & 1 deletion src/libraries/Native/Unix/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ endif()
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
project(System.Security.Cryptography.Native.Browser C)

set(ANYOS_SOURCES_DIR ../../AnyOS/System.Security.Cryptography.Native.Browser)
include_directories("${ANYOS_SOURCES_DIR}")

set (NATIVE_SOURCES
${ANYOS_SOURCES_DIR}/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})
Loading