Question

I am trying to build mysql-5.0.33 client library with SSL support. For which I am using

./configure --prefix=<some dir> --exec-prefix=<some dir> --with-openssl=<path to openssl dir> --without-server` 

to configure and then make and make install

Version of OpenSSL linked to is 1.0.0a. There is no problem or error in above process.

Now I have program as follows

#include <mysql.h>
#include <stdio.h>
int main() {
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;
   char *server = "192.168.1.62";
   char *user = "testssl";
   char *password = "testssl"; /* set me first */
   char *database = "mysql";
   int port = 3321;
   conn = mysql_init(NULL);
   mysql_ssl_set(conn, "client-key.pem", "client-cert.pem", "ca-cert.pem", NULL, "DHE-RSA-AES256-SHA");

   mysql_options(conn, MYSQL_OPT_CONNECT_TIMEOUT, "30");

   /* Connect to database */
   if (!mysql_real_connect(conn, server,
         user, password, database, port, NULL, 0)) {
      fprintf(stderr, "Real connect: %d: %s\n", mysql_errno(conn), mysql_error(conn));
      return 1;
   }

   printf("SSL cipher used: %s \n", mysql_get_ssl_cipher(conn));

   /* send SQL query */
   if (mysql_query(conn, "show tables;")) {
      fprintf(stderr, "\nQuery: %s\n", mysql_error(conn));
      return 1;
   }
   res = mysql_use_result(conn);
   /* output table name */
   printf("Results:\n");
   while ((row = mysql_fetch_row(res)) != NULL)
      printf("%s \n", row[0]);


   /* close connection */
   mysql_free_result(res);
   mysql_close(conn);
   return 0;
}

This program is build as follows :

gcc -o mysql-ssl-test -I <some dir>/include/mysql/ mysql-ssl-test.c -L <some dir>/lib/mysql/ -lmysqlclient -lpthread -lz -lm -lrt -lssl -lcrypto -ldl`

The mysql server (192.168.1.62) which i am connecting has ssl enabled and the User testssl can connect over ssl only (GRANT ... REQUIRE SSL). I have no problem connecting to the server using mysql command line or other mysql client line like Sqlyog.

Now i am getting error Real connect: 2026: SSL connection error, when i trying to run the program with this command LD_LIBRARY_PATH=<some dir>/lib/mysql/ ./mysql-ssl-test but it runs fine when tring to run with this command ./mysql-ssl-test (Here it trys to link with system libmysqlclient which is v5.5.25 and OpenSSL 1.0.0-fips)

Interestingly if i replace the line

mysql_ssl_set(conn, "client-key.pem", "client-cert.pem", "ca-cert.pem", NULL, "DHE-RSA-AES256-SHA");` 

with

mysql_ssl_set(conn, "client-key.pem", "client-cert.pem", "ca-cert.pem", NULL, NULL);` 

it runs fine even with LD_LIBRARY_PATH=<some dir>/lib/mysql/ ./mysql-ssl-test.

Is this a bug of mysql 5.0.33 or OpenSSL 1.0.0a that i have came across (googling for such bug was of no help) or I am doing some blunder while building libmysqlclient.

Was it helpful?

Solution

Fixed : It was some kind of bug in MySQL 5.0.33. Fixed by upgrading to 5.0.86.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top