1# MDEV-16266 Reload SSL certificate
2# This test reloads server SSL certs FLUSH SSL, and checks that
3# 1. old SSL connections (that existed before FLUSH) still work and use old certificate
4# 2. new SSL connection use new certificate
5# 3. if FLUSH SSL runs into error, SSL is still functioning
6# SWtatus variable Ssl_server_not_after is used to tell the old certificate from new.
7
8
9source include/have_ssl_communication.inc;
10
11# Restart server with cert. files located in temp directory
12# We are going to remove / replace them within the test,
13# so we can't use the ones in std_data directly.
14
15let $ssl_cert=$MYSQLTEST_VARDIR/tmp/ssl_cert.pem;
16let $ssl_key=$MYSQLTEST_VARDIR/tmp/ssl_key.pem;
17
18copy_file $MYSQL_TEST_DIR/std_data/server-key.pem $ssl_key;
19copy_file $MYSQL_TEST_DIR/std_data/server-cert.pem $ssl_cert;
20
21let $restart_parameters=--ssl-key=$ssl_key --ssl-cert=$ssl_cert;
22--source include/kill_mysqld.inc
23--source include/start_mysqld.inc
24
25connect  ssl_con,localhost,root,,,,,SSL;
26SELECT VARIABLE_VALUE INTO @ssl_not_after FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_server_not_after';
27let $ssl_not_after=`SELECT @ssl_not_after`;
28
29remove_file $ssl_cert;
30remove_file $ssl_key;
31
32--echo # Use a different certificate ("Not after" certificate field changed)
33copy_file $MYSQL_TEST_DIR/std_data/server-new-key.pem $ssl_key;
34copy_file $MYSQL_TEST_DIR/std_data/server-new-cert.pem $ssl_cert;
35
36FLUSH SSL;
37
38--echo # Check new certificate used by new connection
39exec $MYSQL --ssl  -e  "SELECT IF(VARIABLE_VALUE <> '$ssl_not_after', 'OK', 'FAIL') as Result FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_server_not_after'";
40
41--echo # Check that existing SSL connection still works, and uses old certificate, even if new one is loaded in FLUSH SSL
42connection ssl_con;
43SELECT IF(VARIABLE_VALUE=@ssl_not_after,'OK','FAIL') as Result FROM INFORMATION_SCHEMA.SESSION_STATUS WHERE VARIABLE_NAME='Ssl_server_not_after';
44
45disconnect ssl_con;
46connection default;
47
48SELECT VARIABLE_NAME NAME, VARIABLE_VALUE VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME in ('Ssl_accepts', 'Ssl_finished_accepts');
49FLUSH SSL;
50#Check that accepts are zeroed by FLUSH SSL.
51SELECT VARIABLE_NAME NAME, VARIABLE_VALUE VALUE FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME in ('Ssl_accepts', 'Ssl_finished_accepts');
52
53--echo # Cleanup
54remove_file $ssl_cert;
55remove_file $ssl_key;
56# restart with usuall SSL
57let $restart_parameters=;
58--source include/kill_mysqld.inc
59--source include/start_mysqld.inc
60
61
62