Skip to content

Commit e9b9fd6

Browse files
committed
Improve fallback handling for GSS session encryption when native library is missing (#6422)
Improves #6416 (cherry picked from commit e222c91)
1 parent f87005b commit e9b9fd6

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

src/Npgsql/Internal/NpgsqlConnector.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,22 @@ internal async ValueTask<GssEncryptionResult> GSSEncrypt(bool async, bool isRequ
676676

677677
try
678678
{
679-
var data = authentication.GetOutgoingBlob(ReadOnlySpan<byte>.Empty, out var statusCode)!;
679+
byte[]? data;
680+
NegotiateAuthenticationStatusCode statusCode;
681+
682+
try
683+
{
684+
data = authentication.GetOutgoingBlob(ReadOnlySpan<byte>.Empty, out statusCode)!;
685+
}
686+
catch (TypeInitializationException)
687+
{
688+
// On UNIX .NET throws TypeInitializationException if it's unable to load the native library
689+
if (isRequired)
690+
throw new NpgsqlException("Unable to load native library to negotiate GSS encryption");
691+
692+
return GssEncryptionResult.GetCredentialFailure;
693+
}
694+
680695
if (statusCode != NegotiateAuthenticationStatusCode.ContinueNeeded)
681696
{
682697
// Unable to retrieve credentials

0 commit comments

Comments
 (0)