-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Managed implementation of NTLM for Android and tvOS #66879
Conversation
I couldn't figure out the best area label to add to this PR. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/ncl, @vcsjones Issue DetailsContributes to #62264 This is based on @wfurt's managed NTLM code and extended to cover couple more scenarios (SPNs, channel bindings, message integrity code). It integrates it into HTTP authentication for SocketsHttpHandler for Android and tvOS platforms. Notably, it does not integrate into SMTP client and NegotiateStream implementations but it would be rather trivial to add after the basic code is merged. TODO:
|
} | ||
} | ||
|
||
public void Transform(ReadOnlySpan<byte> input, Span<byte> output) |
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.
It looks to me like Transform is only ever called once on any given instance. Rather than an instantiable class, this should just be
internal static class RC4
{
internal static void Transform(ReadOnlySpan<byte> key, ReadOnlySpan<byte> input, Span<byte> output)
{
Span<byte> state = stackalloc byte[256];
...
}
}
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.
That's the case for the MIC calculation but it would be reused for Encrypt/Decrypt if we implement it later (for SMTP authentication and NegotiateStream).
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
Outdated
Show resolved
Hide resolved
// as NTLM has only one challenege message. | ||
if (!NtlmOid.Equals(mech)) | ||
{ | ||
throw new Win32Exception(NTE_FAIL, $"'{mech}' mechanism is not 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.
Exception messages should be in resx (and thus use format placeholders instead of interpolation)
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.
Yep, I have this one in the TODO in the initial comment.
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
Outdated
Show resolved
Hide resolved
54dc4d1
to
efedd2a
Compare
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
Outdated
Show resolved
Hide resolved
src/libraries/Common/src/System/Net/NTAuthentication.Managed.cs
Outdated
Show resolved
Hide resolved
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.
generally LGTM.
Thanks @filipnavara.
This looks like great start.
enterprise tests failures are tracked by #66970 |
Some of the failures are/were from the temporary test I added. I'll remove it on next pass. |
/azp run runtime-extra-platforms |
Azure Pipelines successfully started running 1 pipeline(s). |
On tvOS devices, it's crashing pretty early. Quite likely not related to this change directly, but we do want to enable System.Net.Security as a result.
|
Should we disable tvOS for now and focus on Android? It seems like it is failing as well but from the logs I cannot see what is wrong. |
…ommit. Read NegTokenResp explicitly. Add mechListMIC reading and verification.
8188f65
to
50a8fc6
Compare
The System.Net.Security.Tests crashes are completely unrelated to these changes. In fact, the only relevant test in that batch is the MD4 one for the managed implementation. I did NOT enable the implementation of |
Tests may be #68206 |
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
* Move MD4 implementation into Common/src/System/Net/Security * Add minimal RC4 implementation * WIP: Integrate managed Ntlm implementation into SocketsHttpHandler Co-authored-by: Tomas Weinfurt <[email protected]> * WIP: Makeshift tests for NTLM/Negotiate authentication * Fix compilation, clean up some of the hashing * Avoid using a temporary buffer * Add computation of signing keys, sealing keys and mechListMIC * Various cleanups * Send SPN in target information * Add some validation, mark spots with missing validation * Clean up some of the memory offset manipulation * Move NTLM version into static variable * Add support for channel bindings, clean up * Fix hash calculation in makeNtlm2Hash accidentally broken with last commit. Read NegTokenResp explicitly. Add mechListMIC reading and verification. * Verify last authentication token in HTTP Negotiate authentication * Address feedback * Fix tvOS builds by making few methods static * Enable System.Net.Security tests on Android and iOS Co-authored-by: Tomas Weinfurt <[email protected]> Co-authored-by: Steve Pfister <[email protected]>
@filipnavara Thank you for adding a native RC4 implementation to .NET. Would you consider making the class public so it can be used? I have some old code that uses RC4 (not related to NTLM for Android and tvOS) and it would be nice to be able to call into .NET directly. |
@EatonZ Every new API would have to go through API review process. RC4 is unlikely to pass through that process because the algorithm is insecure and deprecated. Feel free to copy the implementation under the current MIT license though, it is really small. |
@filipnavara Thanks for the fast response. That is what I was going to do anyway, but thought I'd ask. |
Contributes to #62264
This is based on @wfurt's managed NTLM code and extended to cover couple more scenarios (SPNs, channel bindings, message integrity code). It integrates it into HTTP authentication for SocketsHttpHandler for Android and tvOS platforms. Notably, it does not integrate into SMTP client and NegotiateStream implementations but it would be rather trivial to add after the basic code is merged.
TODO: