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

Fix implementation of NegotiateAuthentication.Wrap for Kerberos on Windows #91152

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

filipnavara
Copy link
Member

Fixes PowerShell/PowerShell#20168

The bug existed in .NET 7 but it was not uncovered until #86948 exposed it through NegotiateStream APIs.

Unfortunately, we lack testing infrastructure for testing Kerberos on Windows. NegotiateStreamKerberosTest outer loop test is supposed to cover it but I am not sure if it's even executed in any reasonable fashion. Thanks to @jborean93 for manually testing it on the affected use case in PowerShell.

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 26, 2023
@ghost
Copy link

ghost commented Aug 26, 2023

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

Issue Details

Fixes PowerShell/PowerShell#20168

The bug existed in .NET 7 but it was not uncovered until #86948 exposed it through NegotiateStream APIs.

Unfortunately, we lack testing infrastructure for testing Kerberos on Windows. NegotiateStreamKerberosTest outer loop test is supposed to cover it but I am not sure if it's even executed in any reasonable fashion. Thanks to @jborean93 for manually testing it on the affected use case in PowerShell.

Author: filipnavara
Assignees: -
Labels:

area-System.Net.Security, community-contribution

Milestone: -

@karelz karelz requested review from wfurt and rzikm August 26, 2023 11:02
Copy link
Member

@rzikm rzikm left a comment

Choose a reason for hiding this comment

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

LGTM, Thanks!

@rzikm
Copy link
Member

rzikm commented Aug 28, 2023

/azp run runtime libraries-coreclr-outerloop

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

@rzikm
Copy link
Member

rzikm commented Aug 28, 2023

/azp list

@azure-pipelines
Copy link

CI/CD Pipelines for this repository:

@rzikm
Copy link
Member

rzikm commented Aug 28, 2023

/azp run runtime-libraries-coreclr outerloop

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@rzikm
Copy link
Member

rzikm commented Aug 28, 2023

CI failures are unrelated, we are good to merge. I will give @wfurt a chance to have a look at this before merging. Thanks, Filip!

@filipnavara
Copy link
Member Author

Thanks for review and running the tests!

Copy link
Member

@wfurt wfurt left a comment

Choose a reason for hiding this comment

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

LGTM

@wfurt wfurt merged commit 33a4319 into dotnet:main Aug 29, 2023
@wfurt
Copy link
Member

wfurt commented Aug 29, 2023

should we try to take it to 8.0 @filipnavara? The fact that it impacts Powershell is concerning IMHO @karelz

@filipnavara
Copy link
Member Author

should we try to take it to 8.0 @filipnavara? The fact that it impacts Powershell is concerning IMHO @karelz

Almost certainly yes.

@karelz karelz added this to the 9.0.0 milestone Aug 29, 2023
@karelz
Copy link
Member

karelz commented Aug 29, 2023

@filipnavara is there a summary explanation, why we the bug is now exposed more in 8.0? (that will help to decide if we should take it for 8.0)

@filipnavara
Copy link
Member Author

filipnavara commented Aug 29, 2023

Sure. Here's the simple explanation, I can stretch it out if necessary... ;-)

In .NET 7 the NegotiateStream implementation used internal NegotiateStreamPal.Encrypt method to encrypt messages on Windows. PR #86948 switched the encryption to use the NegotiateAuthentication.Wrap public method instead. The only difference between these two methods should have been that Encrypt produces extra 4-byte length prefix. Unfortunately, the implementation of Wrap turned out to have more unintended differences which got exposed by this switch.

Wrap as implemented in .NET 7 and .NET 8 before this fix worked for NTLM because the size of signature/encryption prefix is fixed and there's no encryption padding. In Kerberos the prefix length can be different, and some encryption schemes need additional padding. This PR matches what Encrypt method did in .NET 7 in terms of the buffer management.

@rzikm
Copy link
Member

rzikm commented Aug 30, 2023

/backport to release/8.0

@github-actions
Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/runtime/actions/runs/6021734007

@ghost ghost locked as resolved and limited conversation to collaborators Sep 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Security community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Get-ADUser throws "the encryption operation failed" on latest PowerShell 7.4-preview.5 daily build
4 participants