Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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