4
4
5
5
using System ;
6
6
using System . Buffers ;
7
+ using System . Collections . Generic ;
7
8
using System . Diagnostics ;
8
9
using System . IO ;
9
10
using System . Net ;
@@ -33,11 +34,11 @@ internal class SNIProxy
33
34
/// <param name="sspiClientContextStatus">SSPI client context status</param>
34
35
/// <param name="receivedBuff">Receive buffer</param>
35
36
/// <param name="sendWriter">Writer for send buffer</param>
36
- /// <param name="serverName ">Service Principal Name buffer </param>
37
+ /// <param name="serverNames ">Service Principal Name</param>
37
38
/// <returns>SNI error code</returns>
38
- internal static void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , ReadOnlySpan < byte > receivedBuff , IBufferWriter < byte > sendWriter , byte [ ] [ ] serverName )
39
+ internal static void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , ReadOnlySpan < byte > receivedBuff , IBufferWriter < byte > sendWriter , string [ ] serverNames )
39
40
{
40
- // TODO: this should use ReadOnlyMemory all the way through
41
+ // TODO: this should use ReadOnlySpan all the way through
41
42
byte [ ] array = null ;
42
43
43
44
if ( ! receivedBuff . IsEmpty )
@@ -46,10 +47,10 @@ internal static void GenSspiClientContext(SspiClientContextStatus sspiClientCont
46
47
receivedBuff . CopyTo ( array ) ;
47
48
}
48
49
49
- GenSspiClientContext ( sspiClientContextStatus , array , sendWriter , serverName ) ;
50
+ GenSspiClientContext ( sspiClientContextStatus , array , sendWriter , serverNames ) ;
50
51
}
51
52
52
- private static void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , byte [ ] receivedBuff , IBufferWriter < byte > sendWriter , byte [ ] [ ] serverName )
53
+ private static void GenSspiClientContext ( SspiClientContextStatus sspiClientContextStatus , byte [ ] receivedBuff , IBufferWriter < byte > sendWriter , string [ ] serverNames )
53
54
{
54
55
SafeDeleteContext securityContext = sspiClientContextStatus . SecurityContext ;
55
56
ContextFlagsPal contextFlags = sspiClientContextStatus . ContextFlags ;
@@ -81,15 +82,10 @@ private static void GenSspiClientContext(SspiClientContextStatus sspiClientConte
81
82
| ContextFlagsPal . Delegate
82
83
| ContextFlagsPal . MutualAuth ;
83
84
84
- string [ ] serverSPNs = new string [ serverName . Length ] ;
85
- for ( int i = 0 ; i < serverName . Length ; i ++ )
86
- {
87
- serverSPNs [ i ] = Encoding . Unicode . GetString ( serverName [ i ] ) ;
88
- }
89
85
SecurityStatusPal statusCode = NegotiateStreamPal . InitializeSecurityContext (
90
86
credentialsHandle ,
91
87
ref securityContext ,
92
- serverSPNs ,
88
+ serverNames ,
93
89
requestedContextFlags ,
94
90
inSecurityBufferArray ,
95
91
outSecurityBuffer ,
@@ -164,7 +160,7 @@ internal static SNIHandle CreateConnectionHandle(
164
160
string fullServerName ,
165
161
TimeoutTimer timeout ,
166
162
out byte [ ] instanceName ,
167
- ref byte [ ] [ ] spnBuffer ,
163
+ ref string [ ] spnBuffer ,
168
164
string serverSPN ,
169
165
bool flushCache ,
170
166
bool async ,
@@ -228,12 +224,12 @@ internal static SNIHandle CreateConnectionHandle(
228
224
return sniHandle ;
229
225
}
230
226
231
- private static byte [ ] [ ] GetSqlServerSPNs ( DataSource dataSource , string serverSPN )
227
+ private static string [ ] GetSqlServerSPNs ( DataSource dataSource , string serverSPN )
232
228
{
233
229
Debug . Assert ( ! string . IsNullOrWhiteSpace ( dataSource . ServerName ) ) ;
234
230
if ( ! string . IsNullOrWhiteSpace ( serverSPN ) )
235
231
{
236
- return new byte [ 1 ] [ ] { Encoding . Unicode . GetBytes ( serverSPN ) } ;
232
+ return new [ ] { serverSPN } ;
237
233
}
238
234
239
235
string hostName = dataSource . ServerName ;
@@ -251,7 +247,7 @@ private static byte[][] GetSqlServerSPNs(DataSource dataSource, string serverSPN
251
247
return GetSqlServerSPNs ( hostName , postfix , dataSource . ResolvedProtocol ) ;
252
248
}
253
249
254
- private static byte [ ] [ ] GetSqlServerSPNs ( string hostNameOrAddress , string portOrInstanceName , DataSource . Protocol protocol )
250
+ private static string [ ] GetSqlServerSPNs ( string hostNameOrAddress , string portOrInstanceName , DataSource . Protocol protocol )
255
251
{
256
252
Debug . Assert ( ! string . IsNullOrWhiteSpace ( hostNameOrAddress ) ) ;
257
253
IPHostEntry hostEntry = null ;
@@ -282,12 +278,12 @@ private static byte[][] GetSqlServerSPNs(string hostNameOrAddress, string portOr
282
278
string serverSpnWithDefaultPort = serverSpn + $ ":{ DefaultSqlServerPort } ";
283
279
// Set both SPNs with and without Port as Port is optional for default instance
284
280
SqlClientEventSource . Log . TryAdvancedTraceEvent ( "SNIProxy.GetSqlServerSPN | Info | ServerSPNs {0} and {1}" , serverSpn , serverSpnWithDefaultPort ) ;
285
- return new byte [ ] [ ] { Encoding . Unicode . GetBytes ( serverSpn ) , Encoding . Unicode . GetBytes ( serverSpnWithDefaultPort ) } ;
281
+ return new [ ] { serverSpn , serverSpnWithDefaultPort } ;
286
282
}
287
283
// else Named Pipes do not need to valid port
288
284
289
285
SqlClientEventSource . Log . TryAdvancedTraceEvent ( "SNIProxy.GetSqlServerSPN | Info | ServerSPN {0}" , serverSpn ) ;
290
- return new byte [ ] [ ] { Encoding . Unicode . GetBytes ( serverSpn ) } ;
286
+ return new [ ] { serverSpn } ;
291
287
}
292
288
293
289
/// <summary>
0 commit comments