Skip to content

Commit

Permalink
Use Npgsql 9.0.0-preview.1-ci.20241025T100626 (#3330)
Browse files Browse the repository at this point in the history
  • Loading branch information
roji authored Oct 27, 2024
1 parent 90e2c70 commit 222c13a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<EFCoreVersion>[9.0.0-rc.2.24474.1]</EFCoreVersion>
<MicrosoftExtensionsVersion>9.0.0-rc.2.24473.5</MicrosoftExtensionsVersion>
<NpgsqlVersion>8.0.5</NpgsqlVersion>
<NpgsqlVersion>9.0.0-preview.1-ci.20241025T100626</NpgsqlVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
19 changes: 12 additions & 7 deletions src/EFCore.PG/Storage/Internal/NpgsqlDataSourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,19 @@ enumDefinition.StoreTypeSchema is null
}

// Legacy authentication-related callbacks at the EF level; apply these when building a data source as well.
if (npgsqlOptionsExtension.ProvideClientCertificatesCallback is not null)
if (npgsqlOptionsExtension.ProvideClientCertificatesCallback is not null
|| npgsqlOptionsExtension.RemoteCertificateValidationCallback is not null)
{
dataSourceBuilder.UseClientCertificatesCallback(x => npgsqlOptionsExtension.ProvideClientCertificatesCallback(x));
}

if (npgsqlOptionsExtension.RemoteCertificateValidationCallback is not null)
{
dataSourceBuilder.UseUserCertificateValidationCallback(npgsqlOptionsExtension.RemoteCertificateValidationCallback);
dataSourceBuilder.UseSslClientAuthenticationOptionsCallback(o =>
{
if (npgsqlOptionsExtension.ProvideClientCertificatesCallback is not null)
{
o.ClientCertificates ??= new();
npgsqlOptionsExtension.ProvideClientCertificatesCallback(o.ClientCertificates);
}
o.RemoteCertificateValidationCallback = npgsqlOptionsExtension.RemoteCertificateValidationCallback;
});
}

// Finally, if the user has provided a data source builder configuration action, invoke it.
Expand Down
18 changes: 11 additions & 7 deletions src/EFCore.PG/Storage/Internal/NpgsqlRelationalConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,18 @@ protected override DbConnection CreateDbConnection()

var conn = new NpgsqlConnection(ConnectionString);

if (_provideClientCertificatesCallback is not null)
if (_provideClientCertificatesCallback is not null || _remoteCertificateValidationCallback is not null)
{
conn.ProvideClientCertificatesCallback = _provideClientCertificatesCallback;
}

if (_remoteCertificateValidationCallback is not null)
{
conn.UserCertificateValidationCallback = _remoteCertificateValidationCallback;
conn.SslClientAuthenticationOptionsCallback = o =>
{
if (_provideClientCertificatesCallback is not null)
{
o.ClientCertificates ??= new();
_provideClientCertificatesCallback(o.ClientCertificates);
}
o.RemoteCertificateValidationCallback = _remoteCertificateValidationCallback;
};
}

if (_providePasswordCallback is not null)
Expand Down

0 comments on commit 222c13a

Please sign in to comment.