X Tutup
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
16 changes: 16 additions & 0 deletions src/Npgsql/Internal/NpgsqlConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -881,11 +881,20 @@ internal async Task NegotiateEncryption(SslMode sslMode, NpgsqlTimeout timeout,
// Windows crypto API has a bug with pem certs
// See #3650
using var previousCert = cert;
#if NET9_0_OR_GREATER
cert = X509CertificateLoader.LoadPkcs12(cert.Export(X509ContentType.Pkcs12), null);
#else
cert = new X509Certificate2(cert.Export(X509ContentType.Pkcs12));
#endif
}
}

#if NET9_0_OR_GREATER
// If it's null, it's probably PFX
cert ??= X509CertificateLoader.LoadPkcs12FromFile(certPath, password);
#else
cert ??= new X509Certificate2(certPath, password);
#endif
clientCertificates.Add(cert);

_certificate = cert;
Expand Down Expand Up @@ -1727,7 +1736,14 @@ static RemoteCertificateValidationCallback SslRootValidation(bool verifyFull, st
certs.ImportFromPemFile(certRootPath);

if (certs.Count == 0)
{
#if NET9_0_OR_GREATER
// This is not a PEM certificate, probably PFX
certs.Add(X509CertificateLoader.LoadPkcs12FromFile(certRootPath, null));
#else
certs.Add(new X509Certificate2(certRootPath));
#endif
}
}

chain.ChainPolicy.CustomTrustStore.AddRange(certs);
Expand Down
2 changes: 1 addition & 1 deletion src/Npgsql/Npgsql.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Description>Npgsql is the open source .NET data provider for PostgreSQL.</Description>
<PackageTags>npgsql;postgresql;postgres;ado;ado.net;database;sql</PackageTags>
<PackageReadmeFile>README.md</PackageReadmeFile>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<NoWarn>$(NoWarn);CA2017</NoWarn>
<NoWarn>$(NoWarn);NPG9001</NoWarn> <!-- Converter-related APIs are experimental -->
<NoWarn>$(NoWarn);NPG9002</NoWarn> <!-- DatabaseInfo-related APIs are experimental -->
Expand Down
X Tutup