Bug #61727 Failed to get a SSL Connection with MySQL Connector NET
Submitted: 2 Jul 2011 19:24 Modified: 4 Jul 2011 18:20
Reporter: dragon of hell Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.3.7 OS:Windows (XP)
Assigned to: Bogdan Degtyariov CPU Architecture:Any
Tags: NET, SSL

[2 Jul 2011 19:24] dragon of hell
Description:
Hi,
excuse me but do not write properly in English. This the problem:

I've mysql 5.5.11 server properly configured to receive SSL connections, in fact, I've no problem connecting from "MySQL Workbench" with client certificates. When I try to connect from "Connector Net 6.3.7" with the same certificates (exported to .pfx format) i get the following error when calling the method "AuthenticateAsClient (Settings.Server, certs, SslProtocols.Default, false);" as NativeDriver.cs in line 333.

"Could not perform the handshake due to unexpected packet format"

How to repeat:
1) Create a user for SSL connections and apply the following permissions
   GRANT ALL PRIVILEGES ON myschema.* TO 'myuser'@'%' REQUIRE SSL;
2) Start the MySQL server with ssl support (my.ini) without errors

   ssl-ca="D:/SSL/ca-cert.pem"
   ssl-cert="D:/SSL/server-cert.pem"
   ssl-key="D:/SSL/server-key.pem"
   ssl-cipher=DHE-RSA-AES256-SHA
   ssl

3) Export client certificates to PFX format
   openssl pkcs12 -export -in client-cert.pem -inkey client-key.pem -certfile ca-cert.pem -out client.pfx

4) Try to make connection
   new MySqlConnection("host=MY_SERVER;database=myschema;user=myuser;Password=mypassword;CertificateFile=PATH_TO_PFX_CERTIFICATE;CertificatePassword=PFX_EXPORTATION_PASSWORD;SSL Mode=Required";

The client throws a exception with a message "Could not perform the handshake due to unexpected packet format"
[4 Jul 2011 9:36] Bogdan Degtyariov
Did you have this problem with older versions of Connector/NET such as 6.3.6?
Try adding ssl-capath=D:/SSL/ and removing ssl-cipher=DHE-RSA-AES256-SHA from the server config.
[4 Jul 2011 18:20] dragon of hell
It's alive!!

One millions of thanks

1) Edit my.ini:

ssl-ca="D:/SSL/ca-cert.pem"
ssl-cert="D:/SSL/server-cert.pem"
ssl-key="D:/SSL/server-key.pem"
ssl-capath=D:/SSL/
#ssl-cipher=DHE-RSA-AES256-SHA
ssl

Now i can connect without problemas.
[20 Feb 2012 19:01] ismael almonte
I got the error: 
System.Security.Cryptography.CryptographicException: An internal error occurred.

The issue was that iis7 (win2008) does something weird with the app pool. i found 2 fixes:

1. On advanced settings leave the "Identity" as ApplicationPoolIdentity and change "Load User Profile" to true. this should work.

2. On advanced settings change the "Identity" to one of the local accounts "LocalSystem"...

i was using the entity framework.