dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
14.97k stars 4.66k forks source link

System.Net.Security is not supported on os-wasi #94980

Open richlander opened 10 months ago

richlander commented 10 months ago

I was trying to use HttpClient with an https endpoint with wasi, with a program similar to one at SteveSandersonMS/spiderlightning-dotnet (with the addition of HttpClient usage).

We should resolve this or provide guidance in the message on the alternative. HTTPS is pretty common.

Ideally, HttpClient uses a Wasi HttpHandler implementation by default that supports SSL/TLS and if scenarios require it, we have an option to bundle OpenSSL and ca-certificates. We've had a longstanding policy not to ship OpenSSL, however, we ship it with our containers and wasm seems very similar to that.

Unhandled Exception:
System.PlatformNotSupportedException: System.Net.Security is not supported on this platform.
   at System.Net.Security.SslClientAuthenticationOptions..ctor()
   at System.Net.Http.SocketsHttpHandler.get_SslOptions()
   at System.Net.Http.HttpClientHandler.ThrowForModifiedManagedSslOptionsIfStarted()
   at System.Net.Http.HttpClientHandler.set_ClientCertificateOptions(ClientCertificateOption value)
   at System.Net.Http.HttpClientHandler..ctor()
   at System.Net.Http.HttpClient..ctor()
ghost commented 10 months ago

Tagging subscribers to 'arch-wasm': @lewing See info in area-owners.md if you want to be subscribed.

Issue Details
I was trying to use `HttpClient` with an `https` endpoint. We should resolve this or provide guidance in the message on the alternative. HTTPS is pretty common. ```bash Unhandled Exception: System.PlatformNotSupportedException: System.Net.Security is not supported on this platform. at System.Net.Security.SslClientAuthenticationOptions..ctor() at System.Net.Http.SocketsHttpHandler.get_SslOptions() at System.Net.Http.HttpClientHandler.ThrowForModifiedManagedSslOptionsIfStarted() at System.Net.Http.HttpClientHandler.set_ClientCertificateOptions(ClientCertificateOption value) at System.Net.Http.HttpClientHandler..ctor() at System.Net.Http.HttpClient..ctor() ```
Author: richlander
Assignees: -
Labels: `arch-wasm`, `os-wasi`
Milestone: -
lewing commented 10 months ago

The long term plan here would be to implement a platform abstraction for System.Net.Security that wrapped https://github.com/WebAssembly/wasi-crypto in its final form. There are also other options available for technology demonstrations/non-shipping code.