-
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
Changes from 11 commits
8adfef4
bf59162
72f1c99
7f1f800
e9c04ad
a0f5c7a
7c9b0f3
454da94
4e07c89
9536950
a813d22
ca8fbea
f7c90b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm probably missing something, but from my understanding There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Here's the PR to add that back: #3347 |
||
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 |
This file was deleted.
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; } | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.