Skip to main content

Fixed: "The remote certificate was rejected by the provided RemoteCertificateValidationCallback" with MySql.Data

· 4 min read
Jagdish Kumawat
Founder @ Dewiride

I gave SslCa the right CA as a .pfx file, and the driver refused a server it should have accepted. With SslMode=VerifyCA or VerifyFull, the PFX route refused every time I tried it, on macOS and on Linux. The same CA as a .pem file worked at once.

What I Was Doing​

Oracle's documentation says SslCa takes a PEM or a PFX file, so I converted my CA to PFX and tried it on MySql.Data 26.10.0 and .NET 10:

Connection string
…;SslMode=VerifyCA;SslCa=/Users/you/projects/mysql-connection-test/certs/ca.pfx
Terminal
dotnet run test-connection.cs

What I Expected​

A connection: the same CA, in another format.

What I Got​

Output
Unhandled exception. System.Security.Authentication.AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.

The test program stopping with AuthenticationException: The remote certificate was rejected by the provided RemoteCertificateValidationCallback.

What I Checked​

I tried every combination I could, against a server whose certificate had the right name and was signed by that CA:

Connection stringmacOSLinux container
SslMode=VerifyCA;SslCa=ca.pfxRefusedRefused
SslMode=VerifyFull;SslCa=ca.pfxRefusedRefused
The same two, with SSL_CERT_FILE pointing at the CANot triedRefused
SslMode=VerifyFull;CertificateFile=client.pfx;CertificatePassword=…RefusedRefused
SslMode=Required;SslCa=ca.pfxConnectsConnects
SslMode=VerifyCA;SslCa=ca.pemConnectsConnects

I didn't add the CA to the macOS system keychain, because that changes what the whole computer trusts. I didn't test on Windows, where Oracle's documentation describes a certificate store for PFX files.

Oracle's documentation describes the PFX route but doesn't say what it takes to pass these checks, so I can't tell you what would make it work. The message itself only says that the driver's own check said no.

Why It Happens​

The message comes from .NET's SslStream: the driver passes it a callback that decides whether to accept the server's certificate, and that callback returned false. The driver picks its check from the file's extension. A .pfx goes down one route and anything else down the PEM route, and in my tests, only the PEM route could say yes.

The Fix​

Use the CA as a PEM file. If you only have a PFX, convert it:

Terminal
openssl pkcs12 -in ca.pfx -nokeys -out ca.pem -passin pass:

Replace what follows pass: with the file's password, if it has one. The result starts with a few lines about the file before BEGIN CERTIFICATE, and the driver reads it fine. Then:

Connection string
…;SslMode=VerifyCA;SslCa=/Users/you/projects/mysql-connection-test/certs/ca.pem

After the Fix​

Terminal
dotnet run test-connection.cs
Output
Connected as inventory_app@% to MySQL 9.7.4
TLS: TLSv1.2

The test program printing Connected as inventory_app@% with TLS: TLSv1.2, with the same CA as a PEM file.

Common Mistakes​

MistakeWhat happensDo this instead
Using SslMode=Required so the PFX "works"Nothing checks the serverUse a PEM CA with VerifyCA
Turning off validation in codeThe same as having no checkFix the file
Combining a client PFX with a verified serverRefused in my testsChoose one: see below

Troubleshooting​

SymptomLikely causeFix
You need a client certificate and a verified serverWith this driver, those need different routesA PEM client pair isn't sent, and a client PFX was refused under VerifyCA
The certificate authority (CA) does not matchPEM route, with the wrong CAThe fix
No file path has been providedSslCa isn't setThe fix

Conclusion​

On macOS and Linux, the PFX route refused correct servers under VerifyCA and VerifyFull in every test I ran. Use a PEM CA file, and it works.

Additional Resources​

Stay Updated

Subscribe to our newsletter for the latest tutorials, tech insights, and developer news.

By subscribing, you agree to our privacy policy. Unsubscribe at any time.