Skip to content

Commit 92e3db4

Browse files
committed
Fix gss encryption on windows (#6556)
Fixes #6555 (cherry picked from commit 2024d5a)
1 parent 62a2f37 commit 92e3db4

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/Npgsql/Internal/NpgsqlConnector.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,9 @@ internal async ValueTask<GssEncryptionResult> GSSEncrypt(bool async, bool isRequ
679679
{
680680
TargetName = targetName,
681681
RequireMutualAuthentication = true,
682-
RequiredProtectionLevel = ProtectionLevel.EncryptAndSign
682+
RequiredProtectionLevel = ProtectionLevel.EncryptAndSign,
683+
// GSS encryption only works with kerberos
684+
Package = "Kerberos"
683685
};
684686

685687
NegotiateOptionsCallback?.Invoke(clientOptions);

test/Npgsql.Tests/ConnectionTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ public async Task Sync_open_blocked_same_thread()
15961596
}
15971597

15981598
[Test, IssueLink("https://github.com/npgsql/npgsql/issues/6427")]
1599-
[Platform(Include = "Win")] // Hangs on linux and mac when server closes the socket
1599+
[Platform(Include = "Win")] // Hangs on linux and mac (probably because of missing kerberos token)
16001600
public async Task Gss_encryption_retry_does_not_clear_pool()
16011601
{
16021602
if (IsMultiplexing)
@@ -1610,7 +1610,13 @@ public async Task Gss_encryption_retry_does_not_clear_pool()
16101610
// Break connection on gss encryption request to force the client to create a new connection and retry again
16111611
// This emulates the behavior of older versions of PostgreSQL or its forks, like Supabase
16121612
await using var postmaster = PgPostmasterMock.Start(csb.ConnectionString, breakOnGssEncryptionRequest: true);
1613-
await using var dataSource = CreateDataSource(postmaster.ConnectionString);
1613+
await using var dataSource = CreateDataSource(builder =>
1614+
{
1615+
builder.ConnectionStringBuilder.ConnectionString = postmaster.ConnectionString;
1616+
// We use kerberos by default, which requires specific credentials to work
1617+
// Change it negotiate so SSPI on windows can use NTLM credentials
1618+
builder.UseNegotiateOptionsCallback(options => options.Package = "Negotiate");
1619+
});
16141620

16151621
PgServerMock server;
16161622

0 commit comments

Comments
 (0)