@@ -21,48 +21,9 @@ internal class SNIProxy
21
21
private const int DefaultSqlServerDacPort = 1434 ;
22
22
private const string SqlServerSpnHeader = "MSSQLSvc" ;
23
23
24
- internal class SspiClientContextResult
25
- {
26
- internal const uint OK = 0 ;
27
- internal const uint Failed = 1 ;
28
- internal const uint KerberosTicketMissing = 2 ;
29
- }
30
-
31
- internal static readonly SNIProxy s_singleton = new SNIProxy ( ) ;
24
+ private static readonly SNIProxy s_singleton = new SNIProxy ( ) ;
32
25
33
- internal static SNIProxy GetInstance ( ) => s_singleton ;
34
-
35
- /// <summary>
36
- /// Enable SSL on a connection
37
- /// </summary>
38
- /// <param name="handle">Connection handle</param>
39
- /// <param name="options"></param>
40
- /// <returns>SNI error code</returns>
41
- internal uint EnableSsl ( SNIHandle handle , uint options )
42
- {
43
- try
44
- {
45
- SqlClientEventSource . Log . TryTraceEvent ( "SNIProxy.EnableSsl | Info | Session Id {0}" , handle ? . ConnectionId ) ;
46
- return handle . EnableSsl ( options ) ;
47
- }
48
- catch ( Exception e )
49
- {
50
- SqlClientEventSource . Log . TryTraceEvent ( "SNIProxy.EnableSsl | Err | Session Id {0}, SNI Handshake failed with exception: {1}" , handle ? . ConnectionId , e ? . Message ) ;
51
- return SNICommon . ReportSNIError ( SNIProviders . SSL_PROV , SNICommon . HandshakeFailureError , e ) ;
52
- }
53
- }
54
-
55
- /// <summary>
56
- /// Disable SSL on a connection
57
- /// </summary>
58
- /// <param name="handle">Connection handle</param>
59
- /// <returns>SNI error code</returns>
60
- internal uint DisableSsl ( SNIHandle handle )
61
- {
62
- SqlClientEventSource . Log . TryTraceEvent ( "SNIProxy.DisableSsl | Info | Session Id {0}" , handle ? . ConnectionId ) ;
63
- handle . DisableSsl ( ) ;
64
- return TdsEnums . SNI_SUCCESS ;
65
- }
26
+ internal static SNIProxy Instance => s_singleton ;
66
27
67
28
/// <summary>
68
29
/// Generate SSPI context
@@ -72,7 +33,7 @@ internal uint DisableSsl(SNIHandle handle)
72
33
/// <param name="sendBuff">Send buffer</param>
73
34
/// <param name="serverName">Service Principal Name buffer</param>
74
35
/// <returns>SNI error code</returns>
75
- internal void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , byte [ ] receivedBuff , ref byte [ ] sendBuff , byte [ ] [ ] serverName )
36
+ internal static void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , byte [ ] receivedBuff , ref byte [ ] sendBuff , byte [ ] [ ] serverName )
76
37
{
77
38
SafeDeleteContext securityContext = sspiClientContextStatus . SecurityContext ;
78
39
ContextFlagsPal contextFlags = sspiClientContextStatus . ContextFlags ;
@@ -165,83 +126,6 @@ private static bool IsErrorStatus(SecurityStatusPalErrorCode errorCode)
165
126
errorCode != SecurityStatusPalErrorCode . Renegotiate ;
166
127
}
167
128
168
- /// <summary>
169
- /// Set connection buffer size
170
- /// </summary>
171
- /// <param name="handle">SNI handle</param>
172
- /// <param name="bufferSize">Buffer size</param>
173
- /// <returns>SNI error code</returns>
174
- internal uint SetConnectionBufferSize ( SNIHandle handle , uint bufferSize )
175
- {
176
- handle . SetBufferSize ( ( int ) bufferSize ) ;
177
- return TdsEnums . SNI_SUCCESS ;
178
- }
179
-
180
- /// <summary>
181
- /// Copies data in SNIPacket to given byte array parameter
182
- /// </summary>
183
- /// <param name="packet">SNIPacket object containing data packets</param>
184
- /// <param name="inBuff">Destination byte array where data packets are copied to</param>
185
- /// <param name="dataSize">Length of data packets</param>
186
- /// <returns>SNI error status</returns>
187
- internal uint PacketGetData ( SNIPacket packet , byte [ ] inBuff , ref uint dataSize )
188
- {
189
- int dataSizeInt = 0 ;
190
- packet . GetData ( inBuff , ref dataSizeInt ) ;
191
- dataSize = ( uint ) dataSizeInt ;
192
-
193
- return TdsEnums . SNI_SUCCESS ;
194
- }
195
-
196
- /// <summary>
197
- /// Read synchronously
198
- /// </summary>
199
- /// <param name="handle">SNI handle</param>
200
- /// <param name="packet">SNI packet</param>
201
- /// <param name="timeout">Timeout</param>
202
- /// <returns>SNI error status</returns>
203
- internal uint ReadSyncOverAsync ( SNIHandle handle , out SNIPacket packet , int timeout )
204
- {
205
- return handle . Receive ( out packet , timeout ) ;
206
- }
207
-
208
- /// <summary>
209
- /// Get SNI connection ID
210
- /// </summary>
211
- /// <param name="handle">SNI handle</param>
212
- /// <param name="clientConnectionId">Client connection ID</param>
213
- /// <returns>SNI error status</returns>
214
- internal uint GetConnectionId ( SNIHandle handle , ref Guid clientConnectionId )
215
- {
216
- clientConnectionId = handle . ConnectionId ;
217
- SqlClientEventSource . Log . TryTraceEvent ( "SNIProxy.GetConnectionId | Info | Session Id {0}" , clientConnectionId ) ;
218
- return TdsEnums . SNI_SUCCESS ;
219
- }
220
-
221
- /// <summary>
222
- /// Send a packet
223
- /// </summary>
224
- /// <param name="handle">SNI handle</param>
225
- /// <param name="packet">SNI packet</param>
226
- /// <param name="sync">true if synchronous, false if asynchronous</param>
227
- /// <returns>SNI error status</returns>
228
- internal uint WritePacket ( SNIHandle handle , SNIPacket packet , bool sync )
229
- {
230
- uint result ;
231
- if ( sync )
232
- {
233
- result = handle . Send ( packet ) ;
234
- handle . ReturnPacket ( packet ) ;
235
- }
236
- else
237
- {
238
- result = handle . SendAsync ( packet ) ;
239
- }
240
-
241
- SqlClientEventSource . Log . TryTraceEvent ( "SNIProxy.WritePacket | Info | Session Id {0}, SendAsync Result {1}" , handle ? . ConnectionId , result ) ;
242
- return result ;
243
- }
244
-
245
129
/// <summary>
246
130
/// Create a SNI connection handle
247
131
/// </summary>
@@ -258,7 +142,7 @@ internal uint WritePacket(SNIHandle handle, SNIPacket packet, bool sync)
258
142
/// <param name="cachedFQDN">Used for DNS Cache</param>
259
143
/// <param name="pendingDNSInfo">Used for DNS Cache</param>
260
144
/// <returns>SNI handle</returns>
261
- internal SNIHandle CreateConnectionHandle ( string fullServerName , bool ignoreSniOpenTimeout , long timerExpire , out byte [ ] instanceName , ref byte [ ] [ ] spnBuffer ,
145
+ internal static SNIHandle CreateConnectionHandle ( string fullServerName , bool ignoreSniOpenTimeout , long timerExpire , out byte [ ] instanceName , ref byte [ ] [ ] spnBuffer ,
262
146
bool flushCache , bool async , bool parallel , bool isIntegratedSecurity , SqlConnectionIPAddressPreference ipPreference , string cachedFQDN , ref SQLDNSInfo pendingDNSInfo )
263
147
{
264
148
instanceName = new byte [ 1 ] ;
@@ -380,7 +264,7 @@ private static byte[][] GetSqlServerSPNs(string hostNameOrAddress, string portOr
380
264
/// <param name="cachedFQDN">Key for DNS Cache</param>
381
265
/// <param name="pendingDNSInfo">Used for DNS Cache</param>
382
266
/// <returns>SNITCPHandle</returns>
383
- private SNITCPHandle CreateTcpHandle ( DataSource details , long timerExpire , bool parallel , SqlConnectionIPAddressPreference ipPreference , string cachedFQDN , ref SQLDNSInfo pendingDNSInfo )
267
+ private static SNITCPHandle CreateTcpHandle ( DataSource details , long timerExpire , bool parallel , SqlConnectionIPAddressPreference ipPreference , string cachedFQDN , ref SQLDNSInfo pendingDNSInfo )
384
268
{
385
269
// TCP Format:
386
270
// tcp:<host name>\<instance name>
@@ -421,16 +305,14 @@ private SNITCPHandle CreateTcpHandle(DataSource details, long timerExpire, bool
421
305
return new SNITCPHandle ( hostName , port , timerExpire , parallel , ipPreference , cachedFQDN , ref pendingDNSInfo ) ;
422
306
}
423
307
424
-
425
-
426
308
/// <summary>
427
309
/// Creates an SNINpHandle object
428
310
/// </summary>
429
311
/// <param name="details">Data source</param>
430
312
/// <param name="timerExpire">Timer expiration</param>
431
313
/// <param name="parallel">Should MultiSubnetFailover be used. Only returns an error for named pipes.</param>
432
314
/// <returns>SNINpHandle</returns>
433
- private SNINpHandle CreateNpHandle ( DataSource details , long timerExpire , bool parallel )
315
+ private static SNINpHandle CreateNpHandle ( DataSource details , long timerExpire , bool parallel )
434
316
{
435
317
if ( parallel )
436
318
{
@@ -441,39 +323,6 @@ private SNINpHandle CreateNpHandle(DataSource details, long timerExpire, bool pa
441
323
return new SNINpHandle ( details . PipeHostName , details . PipeName , timerExpire ) ;
442
324
}
443
325
444
- /// <summary>
445
- /// Read packet asynchronously
446
- /// </summary>
447
- /// <param name="handle">SNI handle</param>
448
- /// <param name="packet">Packet</param>
449
- /// <returns>SNI error status</returns>
450
- internal uint ReadAsync ( SNIHandle handle , out SNIPacket packet )
451
- {
452
- packet = null ;
453
- return handle . ReceiveAsync ( ref packet ) ;
454
- }
455
-
456
- /// <summary>
457
- /// Set packet data
458
- /// </summary>
459
- /// <param name="packet">SNI packet</param>
460
- /// <param name="data">Data</param>
461
- /// <param name="length">Length</param>
462
- internal void PacketSetData ( SNIPacket packet , byte [ ] data , int length )
463
- {
464
- packet . AppendData ( data , length ) ;
465
- }
466
-
467
- /// <summary>
468
- /// Check SNI handle connection
469
- /// </summary>
470
- /// <param name="handle"></param>
471
- /// <returns>SNI error status</returns>
472
- internal uint CheckConnection ( SNIHandle handle )
473
- {
474
- return handle . CheckConnection ( ) ;
475
- }
476
-
477
326
/// <summary>
478
327
/// Get last SNI error on this thread
479
328
/// </summary>
@@ -489,7 +338,7 @@ internal SNIError GetLastError()
489
338
/// <param name="fullServerName">The data source</param>
490
339
/// <param name="error">Set true when an error occurred while getting LocalDB up</param>
491
340
/// <returns></returns>
492
- private string GetLocalDBDataSource ( string fullServerName , out bool error )
341
+ private static string GetLocalDBDataSource ( string fullServerName , out bool error )
493
342
{
494
343
string localDBConnectionString = null ;
495
344
bool isBadLocalDBDataSource ;
0 commit comments