[CONC-419] mysql_real_connect to MySQL (oracle) server fails with tlsv1 alert unknown ca Created: 2019-06-12 Updated: 2019-06-30 Resolved: 2019-06-30 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 3.0.10 |
| Fix Version/s: | N/A |
| Type: | Bug | Priority: | Major |
| Reporter: | Manvendra Bhangui | Assignee: | Georg Richter |
| Resolution: | Not a Bug | Votes: | 0 |
| Labels: | Compatibility | ||
| Environment: |
MariaDB-client 10.2.24 and applications using MariaDB-shared-10.2.24 are unable to connect to any server running mysql-community-server with secure-transport = ON Server fedora30 running MySQL Community Server 8.0.16 with require-secure-transport = ON Certificates are self-signed created using openssl (script attached) NOTE: |
||
| Attachments: |
|
| Description |
MariaDB Client Environment 172.17.0.2
The client also runs a mariadb server to which I am able to connect without issues
I have the following in my ini file on my MariaDB client machine
Even the mariadb command line client fails with the same error
All my applications which dynamically load /usr/lib64/libmariadb.so.3 give the same error.
However I am able to connect to other MariaDB servers. e.g.
|
| Comments |
| Comment by Georg Richter [ 2019-06-12 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, "TLS alert unknown ca" error message indicates, that the server doesn't accept the client certificate. It could be the wrong certificate or wrong certiticate chain. Questiions:
Thx for your help! | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-13 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
> "TLS alert unknown ca" error message indicates, that the server doesn't accept the client certificate. It could be the wrong certificate or wrong certiticate chain. This is what I suspected, but I am unable to figure out the issue. The moment I change the libs/client to mysql-community-libs/mysql-community-client, the problem dissapears. Also with the same certificates I'm able to connect to any MariaDB $ mysql -u indimail -p indimail -h 172.17.0.2 --ssl --silent Connection id: 11 Threads: 7 Questions: 36 Slow queries: 2 Opens: 26 Flush tables: 1 Open tables: 20 Queries per second avg: 0.012 > According to the examples and the server configuration it's not mandatory that the client has to send a certiticate. Did you try to connect without client cert/key? Yes. But since the server has require-secure-transport = ON, I have to specify --ssl on the command line. But I get this strange error $ mysql -u indimail -p indimail -h 172.17.0.1 --ssl > can you provide a tcpdump/pcap (wireshark) for getting more information? Here are two sets of tcpdump files for both client & server. I used -vv -A arguments to tcpdump. If I need to specify something else, let me know. This is what I used 1) on the server 2) on the client The first set is where the client key is specified in the ini files.The second set is without any keys and just with the -ssl argument to mysql comm and line client. I am also including the mysql-communityserver and ini file in mysql-communit-server_details.txt. Something I forgot to mention is that I am using a centos docker image for the mariadb-client testing. Appreciate the help. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-06-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
The dumpfiles aren't very useful in text format, would it be possible to provide them in binary format (You can capture them either by wireshark or by tcpdump with -w option (for binary format). I created certificate and keys with your script, and didn't get any error:
Client is from MariaDB Server 10.4, using OpenSSL 1.1.1 | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I am goint to attach the files as tcpdump_server.out and tcpdump_client.out. Meanwhile, I have done some more troubleshooting. Here are my results From Centos7 (docker machine), I am able to connect to a mysqld server from oracle using mysql_real_connect() API from both libmysqlclient.so.18.0.0 and libmariadb.so.3
however mysql client isn't able to connect. /usr/bin/mysql is linked with openssl 1.0.2
I have tried the same test by installing mariadb client on Debian 9 Stretch and Fedora 30 install and I don't find the issue. I have also installed centos7 from DVD into a virtual box image and tthat too has the mariadb mysql client connecting to mysqld oracle server without any issue. So it looks like a localized issue with the docker centos7:latest image or mariadb client Ver 15.1 Distrib 10.2.24-MariaDB My opesource project which can load either libmariadb or libmysqlclient is able to connect with ssl without any issue. It's just the mysql command line client which fails to connect to mysqld server with require_secure_transport = ON. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-26 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I was doing something with the C APIs and I stumbled upon something that suggests that this could be a docker issue
If I use mysql_real_connect() from /usr/lib64/libmariadb.so.3, with the host as 172.17.0.1 I get the error
The above error is the same error that the mariadb mysql client is printing on the screen If I use mysql_real_connect() with the host as 192.168.0.8 (which is on the same host that has 172.17.0.1), I am able to connect without any error Now it gets even wierd if I use mysql_real_connect() by loading /usr/lib64/libmysqlclient.so.18.0.0.0 and host as 172.17.0.1
The above error is actually an error returned by the openssl library. $ rpm -qf /usr/lib64/libmariadb.so.3 /usr/lib64/libmysqlclient.so.18.0.0
I am now totally lost. This error looks like some combination of centos7 docker + openssl + mariadb client libs | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi, as you can see in attached screenshot the server refuses to accept the client certificate (alert 21). | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hi.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
EDIT to the above comment:
As of now, my application, which can load the MariaDB or MySQL shared libs using dlopen is working fine under all possible permutation combination if I call mysql_ssl_set(). So this issue is solved as far as I am concerned. But I am curious to find out why the mariadb mysql client is unable to connect. I will try with a lower version of mariadb client and see if this issue persists. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
can you attach also your my.cnf file? | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
I have attached the cnf file with the name indimail.cnf | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Hmm... this could be related to CONC-396. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
No luck even by specifying --defaults-extra-file. I can confim that the indimail.cnf is being read. The strace output shows this
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Georg Richter [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Are there any ssl/tls options in mysql-clients.cnf ? If so, previous settings will be overwritten. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
No ssl/tls options. The file is installation default
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-27 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
One more discovery. All this time I have been saying that the APIs are working. Just found out that they are working because they are not reading the indimail.cnf file. The moment I include a call to mysql_options(), my applicaitons fail with the same error that is being reported by the mysql client. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Finally found something that makes it work. I used mysql_ssl_rsa_setup binary from mysql-community-server package to generate the certs. If I copy the certs, I am able to connect to any mysql-community-server using the command line mysql client from mariadb. If I use the command openssl x509 -text -in client-cert.pem to capture the output and do a diff, there is what I observe. It looks like the client certificate generated by mysql_ssl_rsa_setup has x509_v3 extension but the ones generated by hand do not.
| |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-28 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Finally some good news. The certificates also work if I do the opposite. i.e. Copy the certicate generated using openssl command to the datadir of the mysql-community-server I have managed to fix the issue and also find the situation in which this bug happens. First, the situation in which this bug happens.
I have found three ways to make mariadb clients talk to the mysql-community-server, which has secure transport turned on
This seems to be more a problem with oracle's mysql_ssl_rsa_setup. You can close the ticket. I will take this up with Oracle. | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| Comment by Manvendra Bhangui [ 2019-06-29 ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||
|
FWIW, I did some reverse engineering of mysql_ssl_rsa_setup utility using strace. I am putting down exactly what it does in the form of a shell script. If I use the same ca.pem an ca-key.pem to generate certicates, I am able to successfully use the client-cert certs/keys with MariaDB client and applications using MariaDB connectors
|