@@ -42,13 +42,15 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationClientOpt
4242 {
4343 return new UnixNegotiateAuthenticationPal ( clientOptions ) ;
4444 }
45- catch ( Win32Exception )
45+ catch ( Interop . NetSecurityNative . GssApiException gex )
4646 {
47- return new UnsupportedNegotiateAuthenticationPal ( clientOptions ) ;
48- }
49- catch ( PlatformNotSupportedException )
50- {
51- return new UnsupportedNegotiateAuthenticationPal ( clientOptions ) ;
47+ if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Error ( null , gex ) ;
48+ NegotiateAuthenticationStatusCode statusCode = UnixNegotiateAuthenticationPal . GetErrorCode ( gex ) ;
49+ if ( statusCode <= NegotiateAuthenticationStatusCode . GenericFailure )
50+ {
51+ statusCode = NegotiateAuthenticationStatusCode . Unsupported ;
52+ }
53+ return new UnsupportedNegotiateAuthenticationPal ( clientOptions , statusCode ) ;
5254 }
5355 catch ( EntryPointNotFoundException )
5456 {
@@ -63,13 +65,15 @@ public static NegotiateAuthenticationPal Create(NegotiateAuthenticationServerOpt
6365 {
6466 return new UnixNegotiateAuthenticationPal ( serverOptions ) ;
6567 }
66- catch ( Win32Exception )
68+ catch ( Interop . NetSecurityNative . GssApiException gex )
6769 {
68- return new UnsupportedNegotiateAuthenticationPal ( serverOptions ) ;
69- }
70- catch ( PlatformNotSupportedException )
71- {
72- return new UnsupportedNegotiateAuthenticationPal ( serverOptions ) ;
70+ if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Error ( null , gex ) ;
71+ NegotiateAuthenticationStatusCode statusCode = UnixNegotiateAuthenticationPal . GetErrorCode ( gex ) ;
72+ if ( statusCode <= NegotiateAuthenticationStatusCode . GenericFailure )
73+ {
74+ statusCode = NegotiateAuthenticationStatusCode . Unsupported ;
75+ }
76+ return new UnsupportedNegotiateAuthenticationPal ( serverOptions , statusCode ) ;
7377 }
7478 catch ( EntryPointNotFoundException )
7579 {
@@ -184,22 +188,25 @@ public UnixNegotiateAuthenticationPal(NegotiateAuthenticationClientOptions clien
184188
185189 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , $ "Peer SPN-> '{ _spn } '") ;
186190
187- if ( clientOptions . Credential == CredentialCache . DefaultCredentials ||
191+ if ( clientOptions . Credential == CredentialCache . DefaultNetworkCredentials ||
188192 string . IsNullOrWhiteSpace ( clientOptions . Credential . UserName ) ||
189193 string . IsNullOrWhiteSpace ( clientOptions . Credential . Password ) )
190194 {
191195 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , "using DefaultCredentials" ) ;
192- _credentialsHandle = AcquireDefaultCredential ( ) ;
193196
194197 if ( _packageType == Interop . NetSecurityNative . PackageType . NTLM )
195198 {
196199 // NTLM authentication is not possible with default credentials which are no-op
200+ if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , SR . net_ntlm_not_possible_default_cred ) ;
197201 throw new PlatformNotSupportedException ( SR . net_ntlm_not_possible_default_cred ) ;
198202 }
199203 if ( string . IsNullOrEmpty ( _spn ) )
200204 {
205+ if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , SR . net_nego_not_supported_empty_target_with_defaultcreds ) ;
201206 throw new PlatformNotSupportedException ( SR . net_nego_not_supported_empty_target_with_defaultcreds ) ;
202207 }
208+
209+ _credentialsHandle = SafeGssCredHandle . Create ( string . Empty , string . Empty , _packageType ) ;
203210 }
204211 else
205212 {
@@ -229,7 +236,7 @@ public UnixNegotiateAuthenticationPal(NegotiateAuthenticationServerOptions serve
229236
230237 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Info ( this , $ "Peer SPN-> '{ _spn } '") ;
231238
232- if ( serverOptions . Credential == CredentialCache . DefaultCredentials ||
239+ if ( serverOptions . Credential == CredentialCache . DefaultNetworkCredentials ||
233240 string . IsNullOrWhiteSpace ( serverOptions . Credential . UserName ) ||
234241 string . IsNullOrWhiteSpace ( serverOptions . Credential . Password ) )
235242 {
@@ -462,24 +469,7 @@ private static Interop.NetSecurityNative.PackageType GetPackageType(string packa
462469 else
463470 {
464471 // Native shim currently supports only NTLM, Negotiate and Kerberos
465- throw new PlatformNotSupportedException ( SR . net_securitypackagesupport ) ;
466- }
467- }
468-
469- private SafeGssCredHandle AcquireDefaultCredential ( )
470- {
471- try
472- {
473- return SafeGssCredHandle . Create ( string . Empty , string . Empty , _packageType ) ;
474- }
475- catch ( Exception ex )
476- {
477- if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Error ( this , ex ) ;
478-
479- // NOTE: We throw PlatformNotSupportedException which is caught in
480- // NegotiateAuthenticationPal.Create and transformed into instantiation of
481- // UnsupportedNegotiateAuthenticationPal.
482- throw new PlatformNotSupportedException ( ex . Message , ex ) ;
472+ throw new Interop . NetSecurityNative . GssApiException ( Interop . NetSecurityNative . Status . GSS_S_UNAVAILABLE , 0 ) ;
483473 }
484474 }
485475
@@ -511,14 +501,10 @@ private SafeGssCredHandle AcquireCredentialsHandle(NetworkCredential credential)
511501
512502 return SafeGssCredHandle . Create ( username , password , _packageType ) ;
513503 }
514- catch ( Exception ex )
504+ catch ( Exception ex ) when ( ex is not Interop . NetSecurityNative . GssApiException )
515505 {
516506 if ( NetEventSource . Log . IsEnabled ( ) ) NetEventSource . Error ( this , ex ) ;
517-
518- // NOTE: We throw PlatformNotSupportedException which is caught in
519- // NegotiateAuthenticationPal.Create and transformed into instantiation of
520- // UnsupportedNegotiateAuthenticationPal.
521- throw new PlatformNotSupportedException ( ex . Message , ex ) ;
507+ throw new Interop . NetSecurityNative . GssApiException ( Interop . NetSecurityNative . Status . GSS_S_BAD_NAME , 0 ) ;
522508 }
523509 }
524510
@@ -753,7 +739,7 @@ private NegotiateAuthenticationStatusCode AcceptSecurityContext(
753739 }
754740
755741 // https://www.gnu.org/software/gss/reference/gss.pdf (page 25)
756- private static NegotiateAuthenticationStatusCode GetErrorCode ( Interop . NetSecurityNative . GssApiException exception )
742+ internal static NegotiateAuthenticationStatusCode GetErrorCode ( Interop . NetSecurityNative . GssApiException exception )
757743 {
758744 switch ( exception . MajorStatus )
759745 {
0 commit comments