You've already forked mariadb-connector-c
mirror of
https://github.com/mariadb-corporation/mariadb-connector-c.git
synced 2025-08-07 02:42:49 +03:00
Implementation of SHA256 authentication plugin (CONC-229).
On Windows the sha256 plugin doesn't need any external TLS/Crypto libraries, it uses windows cryto library. On non Windws platforms the plugin requires OpenSSL (GnuTLS doesn't support OAEP v2.0 padding yet)
This commit is contained in:
@@ -34,7 +34,7 @@ static int test_conc66(MYSQL *my)
|
||||
FILE *fp;
|
||||
char query[1024];
|
||||
|
||||
if (!(fp= fopen("./ma_test.cnf", "w")))
|
||||
if (!(fp= fopen("./my.cnf", "w")))
|
||||
return FAIL;
|
||||
|
||||
fprintf(fp, "[notmygroup]\n");
|
||||
@@ -49,7 +49,7 @@ static int test_conc66(MYSQL *my)
|
||||
|
||||
rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66");
|
||||
check_mysql_rc(rc, mysql);
|
||||
rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./ma_test.cnf");
|
||||
rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname ? hostname : "localhost");
|
||||
@@ -69,7 +69,6 @@ static int test_conc66(MYSQL *my)
|
||||
|
||||
check_mysql_rc(rc, my);
|
||||
mysql_close(mysql);
|
||||
remove("./ma_test.cnf");
|
||||
return OK;
|
||||
}
|
||||
|
||||
@@ -449,7 +448,7 @@ static int test_bug31669(MYSQL *mysql)
|
||||
static int test_bug33831(MYSQL *mysql)
|
||||
{
|
||||
FAIL_IF(my_test_connect(mysql, hostname, username,
|
||||
password, schema, port, socketname, 0),
|
||||
password, schema, port, socketname, 0),
|
||||
"Error expected");
|
||||
|
||||
return OK;
|
||||
@@ -694,7 +693,7 @@ int test_connection_timeout3(MYSQL *unused __attribute__((unused)))
|
||||
mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (unsigned int *)&read_write_timeout);
|
||||
mysql_options(mysql, MYSQL_INIT_COMMAND, "set @a:=SLEEP(6)");
|
||||
start= time(NULL);
|
||||
if (my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS))
|
||||
if (my_test_connect(mysql, hostname, username, password, schema, port, NULL, CLIENT_REMEMBER_OPTIONS))
|
||||
{
|
||||
diag("timeout error expected");
|
||||
elapsed= time(NULL) - start;
|
||||
@@ -711,7 +710,7 @@ int test_connection_timeout3(MYSQL *unused __attribute__((unused)))
|
||||
mysql_options(mysql, MYSQL_OPT_READ_TIMEOUT, (unsigned int *)&read_write_timeout);
|
||||
mysql_options(mysql, MYSQL_OPT_WRITE_TIMEOUT, (unsigned int *)&read_write_timeout);
|
||||
|
||||
if (!my_test_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_REMEMBER_OPTIONS))
|
||||
if (!my_test_connect(mysql, hostname, username, password, schema, port, NULL, CLIENT_REMEMBER_OPTIONS))
|
||||
{
|
||||
diag("Error: %s", mysql_error(mysql));
|
||||
return FAIL;
|
||||
@@ -824,8 +823,6 @@ static int test_bind_address(MYSQL *my)
|
||||
return FAIL;
|
||||
}
|
||||
diag("%s", mysql_get_host_info(mysql));
|
||||
sprintf(query, "DROP USER '%s'@'%s'", username, bind_addr);
|
||||
rc= mysql_query(my, query);
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
}
|
||||
@@ -837,7 +834,7 @@ static int test_get_options(MYSQL *unused __attribute__((unused)))
|
||||
MYSQL_OPT_PROTOCOL, MYSQL_OPT_READ_TIMEOUT, MYSQL_OPT_WRITE_TIMEOUT, 0};
|
||||
my_bool options_bool[]= {MYSQL_OPT_RECONNECT, MYSQL_REPORT_DATA_TRUNCATION,
|
||||
MYSQL_OPT_COMPRESS, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, MYSQL_SECURE_AUTH,
|
||||
#ifdef _WIN32
|
||||
#ifdef _WIN32
|
||||
MYSQL_OPT_NAMED_PIPE,
|
||||
#endif
|
||||
0};
|
||||
@@ -922,10 +919,6 @@ static int test_sess_track_db(MYSQL *mysql)
|
||||
int rc;
|
||||
const char *data;
|
||||
size_t len;
|
||||
char query[140];
|
||||
|
||||
diag("fixes not merged");
|
||||
return SKIP;
|
||||
|
||||
if (!(mysql->server_capabilities & CLIENT_SESSION_TRACKING))
|
||||
{
|
||||
@@ -941,17 +934,13 @@ static int test_sess_track_db(MYSQL *mysql)
|
||||
"session_track_get_first failed");
|
||||
FAIL_IF(strncmp(data, "mysql", len), "Expected new schema 'mysql'");
|
||||
|
||||
snprintf(query, 139, "USE %s", schema);
|
||||
rc= mysql_query(mysql, query);
|
||||
rc= mysql_query(mysql, "USE test");
|
||||
check_mysql_rc(rc, mysql);
|
||||
FAIL_IF(strcmp(mysql->db, schema), "Expected new schema 'testc'");
|
||||
FAIL_IF(strcmp(mysql->db, "test"), "Expected new schema 'test'");
|
||||
|
||||
FAIL_IF(mysql_session_track_get_first(mysql, SESSION_TRACK_SCHEMA, &data, &len),
|
||||
"session_track_get_first failed");
|
||||
FAIL_IF(strncmp(data, schema, len), "Expected new schema 'testc'");
|
||||
|
||||
rc= mysql_query(mysql, "DROP SCHEMA testc");
|
||||
check_mysql_rc(rc, mysql);
|
||||
FAIL_IF(strncmp(data, "test", len), "Expected new schema 'test'");
|
||||
|
||||
diag("charset: %s", mysql->charset->csname);
|
||||
rc= mysql_query(mysql, "SET NAMES utf8");
|
||||
@@ -988,7 +977,7 @@ static int test_sess_track_db(MYSQL *mysql)
|
||||
|
||||
return OK;
|
||||
}
|
||||
#ifndef WIN32
|
||||
|
||||
static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
|
||||
{
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
@@ -1016,7 +1005,6 @@ static int test_unix_socket_close(MYSQL *unused __attribute__((unused)))
|
||||
mysql_close(mysql);
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int test_reset(MYSQL *mysql)
|
||||
{
|
||||
@@ -1037,13 +1025,13 @@ static int test_reset(MYSQL *mysql)
|
||||
rc= mysql_reset_connection(mysql);
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
FAIL_IF(mysql_affected_rows(mysql) != ~(my_ulonglong)0, "Expected 0 rows");
|
||||
FAIL_IF(mysql_affected_rows(mysql) != ~(unsigned long)0, "Expected 0 rows");
|
||||
|
||||
rc= mysql_query(mysql, "SELECT a FROM t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(mysql, "SELECT 1 FROM DUAL");
|
||||
FAIL_IF(!rc, "Error expected");
|
||||
FAIL_IF(!rc, "Error expected");
|
||||
|
||||
rc= mysql_reset_connection(mysql);
|
||||
check_mysql_rc(rc, mysql);
|
||||
@@ -1064,38 +1052,60 @@ static int test_reset(MYSQL *mysql)
|
||||
|
||||
mysql_free_result(res);
|
||||
|
||||
rc= mysql_query(mysql, "DROP TABLE t1");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int test_mdev12446(MYSQL *my __attribute__((unused)))
|
||||
static int test_auth256(MYSQL *my)
|
||||
{
|
||||
/*
|
||||
if specified file didn't exist, valgrind reported a leak,
|
||||
if no file was specified and no default file is installed,
|
||||
C/C crashed due to double free.
|
||||
*/
|
||||
MYSQL *mysql= mysql_init(NULL);
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "file.notfound");
|
||||
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname, 0), mysql_error(mysql));
|
||||
int rc;
|
||||
MYSQL_RES *res;
|
||||
int num_rows= 0;
|
||||
|
||||
rc= mysql_query(my, "SELECT * FROM information_schema.plugins where plugin_name='sha256_password'");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
res= mysql_store_result(my);
|
||||
num_rows= mysql_num_rows(res);
|
||||
mysql_free_result(res);
|
||||
|
||||
if (!num_rows)
|
||||
{
|
||||
diag("server doesn't support sha256 authentication");
|
||||
return SKIP;
|
||||
}
|
||||
|
||||
rc= mysql_query(my, "DROP USER IF EXISTS sha256user@localhost");
|
||||
check_mysql_rc(rc, mysql);
|
||||
|
||||
rc= mysql_query(my, "CREATE user sha256user@localhost identified with sha256_password by 'foo'");
|
||||
check_mysql_rc(rc, my);
|
||||
if (!mysql_real_connect(mysql, hostname, "sha256user", "foo", NULL, port, socketname, 0))
|
||||
{
|
||||
diag("error: %s", mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return FAIL;
|
||||
}
|
||||
mysql_close(mysql);
|
||||
|
||||
mysql= mysql_init(NULL);
|
||||
mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "notfound");
|
||||
FAIL_IF(!my_test_connect(mysql, hostname, username, password, schema,
|
||||
port, socketname, 0), mysql_error(mysql));
|
||||
mysql_options(mysql, MYSQL_SERVER_PUBLIC_KEY, "rsa_public_key.pem");
|
||||
if (!mysql_real_connect(mysql, hostname, "sha256user", "foo", NULL, port, socketname, 0))
|
||||
{
|
||||
diag("error: %s", mysql_error(mysql));
|
||||
mysql_close(mysql);
|
||||
return FAIL;
|
||||
}
|
||||
mysql_close(mysql);
|
||||
rc= mysql_query(my, "DROP USER sha256user@localhost");
|
||||
check_mysql_rc(rc, mysql);
|
||||
return OK;
|
||||
}
|
||||
|
||||
struct my_tests_st my_tests[] = {
|
||||
{"test_mdev12446", test_mdev12446, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_auth256", test_auth256, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_reset", test_reset, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
#ifndef WIN32
|
||||
{"test_unix_socket_close", test_unix_socket_close, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
#endif
|
||||
{"test_sess_track_db", test_sess_track_db, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_get_options", test_get_options, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
{"test_wrong_bind_address", test_wrong_bind_address, TEST_CONNECTION_DEFAULT, 0, NULL, NULL},
|
||||
@@ -1114,7 +1124,6 @@ struct my_tests_st my_tests[] = {
|
||||
{"test_connection_timeout", test_connection_timeout, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_connection_timeout2", test_connection_timeout2, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
{"test_connection_timeout3", test_connection_timeout3, TEST_CONNECTION_NONE, 0, NULL, NULL},
|
||||
|
||||
{NULL, NULL, 0, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user