1
1
using System ;
2
2
using System . Buffers ;
3
- using System . Collections . Generic ;
4
3
using System . Diagnostics ;
5
- using System . Linq ;
6
4
7
5
#nullable enable
8
6
@@ -13,7 +11,6 @@ internal abstract class SspiContextProvider
13
11
private TdsParser _parser = null ! ;
14
12
private ServerInfo _serverInfo = null ! ;
15
13
16
- private List < SspiAuthenticationParameters > ? _authParams ;
17
14
private SspiAuthenticationParameters ? _authParam ;
18
15
19
16
private protected TdsParserStateObject _physicalStateObj = null ! ;
@@ -22,22 +19,15 @@ internal void Initialize(
22
19
ServerInfo serverInfo ,
23
20
TdsParserStateObject physicalStateObj ,
24
21
TdsParser parser ,
25
- #if NETFRAMEWORK
26
22
string serverSpn
27
- #else
28
- string [ ] serverSpns
29
- #endif
30
23
)
31
24
{
32
25
_parser = parser ;
33
26
_physicalStateObj = physicalStateObj ;
34
27
_serverInfo = serverInfo ;
35
28
36
- #if NETFRAMEWORK
37
29
_authParam = CreateAuthParams ( serverSpn ) ;
38
- #else
39
- _authParams = [ .. serverSpns . Select ( CreateAuthParams ) ] ;
40
- #endif
30
+
41
31
Initialize ( ) ;
42
32
}
43
33
@@ -51,43 +41,13 @@ internal void WriteSSPIContext(ReadOnlySpan<byte> receivedBuff, IBufferWriter<by
51
41
{
52
42
using var _ = TrySNIEventScope . Create ( nameof ( SspiContextProvider ) ) ;
53
43
54
- if ( ! TryRunSingle ( receivedBuff , outgoingBlobWriter ) && ! TryRunMultiple ( receivedBuff , outgoingBlobWriter ) )
44
+ if ( ! ( _authParam is { } && RunGenerateSspiClientContext ( receivedBuff , outgoingBlobWriter , _authParam ) ) )
55
45
{
56
46
// If we've hit here, the SSPI context provider implementation failed to generate the SSPI context.
57
47
SSPIError ( SQLMessage . SSPIGenerateError ( ) , TdsEnums . GEN_CLIENT_CONTEXT ) ;
58
48
}
59
49
}
60
50
61
- /// <summary>
62
- /// If we only have a single auth param, we know it's the correct one to use.
63
- /// </summary>
64
- private bool TryRunSingle ( ReadOnlySpan < byte > receivedBuff , IBufferWriter < byte > outgoingBlobWriter )
65
- {
66
- return _authParam is { } && RunGenerateSspiClientContext ( receivedBuff , outgoingBlobWriter , _authParam ) ;
67
- }
68
-
69
- /// <summary>
70
- /// If we have multiple, we need to loop through them, and then identify the correct one for future use.
71
- /// </summary>
72
- private bool TryRunMultiple ( ReadOnlySpan < byte > receivedBuff , IBufferWriter < byte > outgoingBlobWriter )
73
- {
74
- if ( _authParams is { } )
75
- {
76
- foreach ( var authParam in _authParams )
77
- {
78
- if ( RunGenerateSspiClientContext ( receivedBuff , outgoingBlobWriter , authParam ) )
79
- {
80
- // Reset the _authParams to only have a single one going forward to always call the context with that one
81
- _authParam = authParam ;
82
- _authParams = null ;
83
- return true ;
84
- }
85
- }
86
- }
87
-
88
- return false ;
89
- }
90
-
91
51
private SspiAuthenticationParameters CreateAuthParams ( string serverSpn )
92
52
{
93
53
var options = _parser . Connection . ConnectionOptions ;
0 commit comments