-
Notifications
You must be signed in to change notification settings - Fork 311
Expose SspiAuthenticationParameters on SspiContextProvider #2454
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8adfef4
Pass SqlAuthenticationParameters in GenerateSspiClientContext
twsouthwick bf59162
Merge branch 'main' into auth-params
twsouthwick 72f1c99
Remove comment and whitespace changes
twsouthwick 7f1f800
use net framework logging
twsouthwick e9c04ad
consolidate builder for sqlauthparameters and use serverSpn as resource
twsouthwick a0f5c7a
Merge remote-tracking branch 'origin/main' into auth-params
twsouthwick 7c9b0f3
create separate SspiAuthenticationParameters
twsouthwick 454da94
rename to resource
twsouthwick 4e07c89
revert
twsouthwick 9536950
add resource
twsouthwick a813d22
rename to SspiContextProvider
twsouthwick ca8fbea
Merge remote-tracking branch 'origin/main' into auth-params
twsouthwick f7c90b4
deal with merge conflicts
twsouthwick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 0 additions & 45 deletions
45
...icrosoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...icrosoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSspiContextProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#if NET | ||
|
||
using System; | ||
using System.Buffers; | ||
using System.Net.Security; | ||
|
||
#nullable enable | ||
|
||
namespace Microsoft.Data.SqlClient | ||
{ | ||
internal sealed class NegotiateSspiContextProvider : SspiContextProvider | ||
{ | ||
private NegotiateAuthentication? _negotiateAuth = null; | ||
|
||
protected override bool GenerateSspiClientContext(ReadOnlySpan<byte> incomingBlob, IBufferWriter<byte> outgoingBlobWriter, SspiAuthenticationParameters authParams) | ||
{ | ||
NegotiateAuthenticationStatusCode statusCode = NegotiateAuthenticationStatusCode.UnknownCredentials; | ||
|
||
_negotiateAuth ??= new(new NegotiateAuthenticationClientOptions { Package = "Negotiate", TargetName = authParams.Resource }); | ||
var sendBuff = _negotiateAuth.GetOutgoingBlob(incomingBlob, out statusCode)!; | ||
|
||
// Log session id, status code and the actual SPN used in the negotiation | ||
SqlClientEventSource.Log.TryTraceEvent("{0}.{1} | Info | Session Id {2}, StatusCode={3}, SPN={4}", nameof(NegotiateSspiContextProvider), | ||
nameof(GenerateSspiClientContext), _physicalStateObj.SessionId, statusCode, _negotiateAuth.TargetName); | ||
|
||
if (statusCode == NegotiateAuthenticationStatusCode.Completed || statusCode == NegotiateAuthenticationStatusCode.ContinueNeeded) | ||
{ | ||
outgoingBlobWriter.Write(sendBuff); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
} | ||
} | ||
#endif |
58 changes: 0 additions & 58 deletions
58
src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/SSPIContextProvider.cs
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
...icrosoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/SspiAuthenticationParameters.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#nullable enable | ||
|
||
namespace Microsoft.Data.SqlClient | ||
{ | ||
internal sealed class SspiAuthenticationParameters | ||
{ | ||
public SspiAuthenticationParameters(string serverName, string resource) | ||
{ | ||
ServerName = serverName; | ||
Resource = resource; | ||
} | ||
|
||
public string Resource { get; } | ||
|
||
public string ServerName { get; } | ||
|
||
public string? UserId { get; set; } | ||
|
||
public string? DatabaseName { get; set; } | ||
|
||
public string? Password { get; set; } | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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'm probably missing something, but from my understanding
SspiContextProvider
attempts to generate sspi context by iterating over eachserverSpns
(which is passed viaauthParams.Resource
). But because_negotiateAuth
is cached here, if it fails for the first spn, it's also going to fail for the others since it's going to be the exact same spn.Uh oh!
There was an error while loading. Please reload this page.
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.
You're right, nice catch! The implementation used to reset _negotiateAuth to null if authentication failed, but that's missing now. @twsouthwick can we correct it in a follow up PR?
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.
Will do - good catch. I'll open a separate PR for that.
The looping was added independently of the work I've been doing, so I'm not fully aware of how it's expected to work.
It opens a question as to the design I've moved this to - if we have a list of SPNs, what's the expected outcome? I think things will be just fine if it's the first SPN that completes the SSPI handshake. However if it's the second, on subsequent attempts it will be trying the first again. I can update the SspiContextProvider base to keep track of what was the successfull SPN to only submit that on subsequent calls.
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.
Here's the PR to add that back: #3347