How to add a custom SSL verification to MySql Connector/NET

137
October 09, 2018, at 03:50 AM

As you know, there is a

System.Net.Security.RemoteCertificateValidationCallback

in .NET that allows you to decide whether to trust the certificate sent by the server. You can use this in SslStream and ServicePointManager.

Now im trying to use the same pattern during MySql Connector/NET. In MySql server-side, i set a self-signed certificate. When i use the option SslMode=VerifyCA in client(based on MySql Connector/NET), the connecting failed because my CA is not trusted in client side.

I know i can just simply add the CA certificate to client's system trustzone, but this solution is not portable.

So the problem is: Is there any MySql Connector/NET API that allows user to provide a RemoteCertificateValidationCallback or something like that?

Thanks a lot :)

Answer 1

Is there any MySql Connector/NET API that allows user to provide a RemoteCertificateValidationCallback or something like that?

No, there is not. Either the certificate must be acceptable to the machine, or you use an unencrypted connection.

I know i can just simply add the CA certificate to client's system trustzone, but this solution is not portable.

If you need this to be portable, you'll need to get a certificate from a trusted certificate authority like Symantec, DigiCert, GeoTrust, etc. Otherwise, you'll just have to bite the bullet on adding your self-signed cert to the certificate store on each computer that connects to the DB.

Answer 2

Switch to the MySqlConnector library, which adds a CACertificateFile option to the connection string (more info here).

When you use this setting and specify a PEM file for the CA Certificate, this will make SslMode=VerifyCA in your connection string have the desired effect of validating your custom SSL certificate.

READ ALSO
MYSQL Query Language [duplicate]

MYSQL Query Language [duplicate]

This question already has an answer here:

131
MySQL Retrieving data from different tables and counting that data to different columns

MySQL Retrieving data from different tables and counting that data to different columns

Hi I'm trying to retrieve some data from different tables in mysql but it get error for some reasonsI want to retrieve the total number of travelers who have traveled to brisbane and sydney

76
Assigning an alias to SQL [on hold]

Assigning an alias to SQL [on hold]

In the library database there's a patrons table listing all the users of the libraryThe columns are id, first_name, last_name, address, email, library_id and zip_code

113