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

Crypto support in wasi-wasm runtime #99126

Open
knutwannheden opened this issue Feb 29, 2024 · 5 comments
Open

Crypto support in wasi-wasm runtime #99126

knutwannheden opened this issue Feb 29, 2024 · 5 comments
Labels
area-System.Security os-wasi Related to WASI variant of arch-wasm
Milestone

Comments

@knutwannheden
Copy link

Description

Currently, the System.Security.Cryptography.HashAlgorithmName methods throw a PlatformNotSupportedException when executed in a C# program that got compiled against the wasi-wasm runtime. While the WASI Crypto API hasn't been finalized (AFAICT) and wasmtime doesn't provide any implementation, it would be really useful if at least the managed implementation of these crypto functions were available for programs running under wasi-wasm.

Reproduction Steps

Compile any program accessing any of the crypto functions (e.g. SHA1). When run an exception will be thrown:

System.PlatformNotSupportedException: SystemSecurityCryptography_PlatformNotSupported
   at System.Security.Cryptography.SHA1.Create()
   ...

Expected behavior

While no WASI Crypto API has been finalized and made available via wasmtime, it would be really useful if the managed implementations could be used. I am trying to use Roslyn APIs, which internally use both SHA1 and SHA256 and thus cannot be executed under wasi-wasm.

Actual behavior

A PlatformNotSupportedException gets thrown.

Regression?

No response

Known Workarounds

No response

Configuration

  • .NET 9 (preview 1)
  • wasi-wasm runtime platform

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 29, 2024
@ghost
Copy link

ghost commented Feb 29, 2024

Tagging subscribers to this area: @dotnet/area-system-security, @bartonjs, @vcsjones
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Currently, the System.Security.Cryptography.HashAlgorithmName methods throw a PlatformNotSupportedException when executed in a C# program that got compiled against the wasi-wasm runtime. While the WASI Crypto API hasn't been finalized (AFAICT) and wasmtime doesn't provide any implementation, it would be really useful if at least the managed implementation of these crypto functions were available for programs running under wasi-wasm.

Reproduction Steps

Compile any program accessing any of the crypto functions (e.g. SHA1). When run an exception will be thrown:

System.PlatformNotSupportedException: SystemSecurityCryptography_PlatformNotSupported
   at System.Security.Cryptography.SHA1.Create()
   ...

Expected behavior

While no WASI Crypto API has been finalized and made available via wasmtime, it would be really useful if the managed implementations could be used. I am trying to use Roslyn APIs, which internally use both SHA1 and SHA256 and thus cannot be executed under wasi-wasm.

Actual behavior

A PlatformNotSupportedException gets thrown.

Regression?

No response

Known Workarounds

No response

Configuration

  • .NET 9 (preview 1)
  • wasi-wasm runtime platform

Other information

No response

Author: knutwannheden
Assignees: -
Labels:

area-System.Security

Milestone: -

@vcsjones vcsjones added the os-wasi Related to WASI variant of arch-wasm label Feb 29, 2024
@bartonjs
Copy link
Member

bartonjs commented Mar 5, 2024

There's not a special wasi build of System.Security.Cryptography. Is it not the same as browser?

<TargetFrameworks>$(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent)-android;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent)-browser;$(NetCoreAppCurrent)</TargetFrameworks>

Based on the message, I think it's just pulling in the RID-less build; since that looks like the output from <GeneratePlatformNotSupportedAssemblyMessage Condition="'$(TargetPlatformIdentifier)' == ''">SR.SystemSecurityCryptography_PlatformNotSupported</GeneratePlatformNotSupportedAssemblyMessage>

@vcsjones
Copy link
Member

vcsjones commented Mar 5, 2024

Is it not the same as browser?

It's not. We would need to treat $(NetCoreAppCurrent)-wasi the same as browser.

@vcsjones
Copy link
Member

vcsjones commented Mar 5, 2024

We would also need to go and annotate all of our UnsupportedOSPlatforms that have browser with "wasi", I think.

@lewing
Copy link
Member

lewing commented Apr 1, 2024

Correct, since wasi is still an experiemental platform we haven't annotated the apis for the analyzer yet. https://github.com/WebAssembly/WASI-crypto is the proposal we would wrap if we decide to add platform support.

@lewing lewing added this to the Future milestone Apr 1, 2024
@lewing lewing removed the untriaged New issue has not been triaged by the area owner label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Security os-wasi Related to WASI variant of arch-wasm
Projects
None yet
Development

No branches or pull requests

4 participants