-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Use SubtleCrypto API on browser DOM scenarios #65966
Conversation
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones Issue Detailsnull
|
src/native/libs/System.Security.Cryptography.Native.Browser/pal_browser.h
Outdated
Show resolved
Hide resolved
src/native/libs/System.Security.Cryptography.Native.Browser/pal_crypto_webworker.js
Outdated
Show resolved
Hide resolved
.../src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SimpleDigestHash.cs
Outdated
Show resolved
Hide resolved
I wonder if we should rather add it to main typescript codebase in |
235212a
to
4f88dee
Compare
c292c73
to
16b0267
Compare
.../src/Interop/Browser/System.Security.Cryptography.Native.Browser/Interop.SimpleDigestHash.cs
Outdated
Show resolved
Hide resolved
651d0a4
to
ac117cb
Compare
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
Done, this works thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
msg_char_len: chan.get_msg_len() | ||
}); | ||
worker.onerror = event => { | ||
console.warn(`MONO_WASM: Error in Crypto WebWorker. Cryptography digest calls will fallback to managed implementation. Error: ${event.message}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this fallback. I thought it was all or nothing. @bartonjs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All or nothing was the original plan. But since Safari can't (at least, couldn't) do it we got authorization to do native-preferred with managed fallback. (That's why we already have managed SHA1/SHA256/SHA384/SHA512 checked in for wasm)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safari is always a no, right? The never okay I get and that check is at the top of this method. However, this error callback path seems to imply that if a catastrophic error occurs during a call where the SubtleCrypto libraries are supported, on the next call we will fallback to the managed implementation. The message might be confusing me, but setting mono_wasm_crypto
to null
after it was set appears we are falling back on a supported platform. Is that fallback also supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh. Um, no, that probably shouldn't fall back. I think that we're expecting to be able to say "these are the characteristics, and if your browser has them then you get native crypto (which may or may not be FIPS/etc-acceptable) over managed crypto (which never is)". Changing after the first call seems... bad.
@blowdart or @GrabYourPitchforks may wish to disagree and say that if stuff breaks it's OK to fall back to managed... but I think that makes Barry's job harder, so I don't expect they'll feel differently.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I seem to remember discussing this and talking about addressing it with documentation and no promises ever of fips compliance (I still hate it though). @GrabYourPitchforks does that ring a bell?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of https://github.com/dotnet/runtime/pull/65966/files#diff-46676f417228802cba4f54049a643b76f11d4b8feb4953f39cb439ecaeba4097R10, I don't think this is a dynamic fallback... just the startup code. But it'd be good to get full closure on this in the fullness of time.
// Read in request | ||
var req = this._read_request(); | ||
if (req === this.STATE_SHUTDOWN) | ||
break; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be in try/catch block too, so we can send an error response?
} | ||
catch (err) { | ||
console.log("Request error: " + err); | ||
resp = JSON.stringify(err); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a way to indicate that this is returning an error, or that the operation failed? Do IUC, that the caller will get the response, and if the length happens to match the expected one, then it will think that the error response is actually valid?
return ii - start; | ||
} | ||
|
||
private read_response(): string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should detect that the response was an error, and throw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C# LGTM. The JS looks as reasonable as I can assess it to be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can land it in this state and address any remaining issues in follow up work
Browser builds failing with:
|
It was renamed to |
/azp run runtime-wasm |
Azure Pipelines successfully started running 1 pipeline(s). |
The wasm/aot test failure is #69681 , and unrelated to this PR. |
Contributes to #40074. For WASM, uses the SubtleCrypto browser-native implementation for the SHA1, SHA256, SHA384, SHA512 algorithms, and adds infrastructure to support using the native implementation. Support for the rest of the algorithms will come in a single follow-up PR.