| 1 |
# This test verifies MySQL can handle chained ssl certificate |
| 2 |
# This test uses chained ssl certificates which is depicted as |
| 3 |
# below:- |
| 4 |
# |
| 5 |
# +---------+ |
| 6 |
# | Root CA | |
| 7 |
# +---------+ |
| 8 |
# | |
| 9 |
# /------------+-----------\ |
| 10 |
# | | |
| 11 |
# +------------------+ +------------------+ |
| 12 |
# | Intermediate CA1 | | Intermediate CA2 | |
| 13 |
# +------------------+ +------------------+ |
| 14 |
# | | |
| 15 |
# +-------------+ +-------------+ |
| 16 |
# | Server | | Client | |
| 17 |
# | certificate | | certificate | |
| 18 |
# +-------------+ +-------------+ |
| 19 |
# |
| 20 |
# From mysql-8.0+, server validates its own certificate and |
| 21 |
# throws a warning into the error log if the certificate |
| 22 |
# doesn't validate [see the function, verify_store_cert()]. |
| 23 |
# The validation operation reads only one certificate, the |
| 24 |
# first one, from the server chain certificate file, and |
| 25 |
# checks for its validation aganist a set of certificates |
| 26 |
# serving as trust anchors, a list of non-trusted |
| 27 |
# certificates that may be helpful for chain construction. |
| 28 |
# In order to validate server cert correctly, we need to |
| 29 |
# provide the trusted root certificate and the untrusted |
| 30 |
# intermediate certificates as part of ssl-ca. Hence |
| 31 |
# root_intermediate_ca1.crt (trusted root certificate + |
| 32 |
# untrusted intermediate ca1 certificate) is passed as with |
| 33 |
# --ssl-ca option |
| 34 |
|
| 35 |
#Suppress warning by the server certificate verification check: unrelated CA |
| 36 |
call mtr.add_suppression("Server SSL certificate doesn't verify"); |
| 37 |
|
| 38 |
--source include/allowed_ciphers.inc |
| 39 |
|
| 40 |
CREATE USER 'user1'@'%' REQUIRE SSL; |
| 41 |
|
| 42 |
--replace_regex $ALLOWED_CIPHERS_REGEX |
| 43 |
--exec $MYSQL --host=localhost -P $MASTER_MYPORT --user=user1 --ssl-mode=REQUIRED --ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/root.crt --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/client.cachain --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/client.key -e "SHOW STATUS LIKE 'ssl_cipher'" |
| 44 |
|
| 45 |
--replace_regex $ALLOWED_CIPHERS_REGEX |
| 46 |
--exec $MYSQL --host=localhost -P $MASTER_MYPORT --user=user1 --ssl-mode=VERIFY_CA --ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/root.crt --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/client.cachain --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/client.key -e "SHOW STATUS LIKE 'ssl_cipher'" |
| 47 |
|
| 48 |
--replace_regex $ALLOWED_CIPHERS_REGEX |
| 49 |
--exec $MYSQL --host=localhost -P $MASTER_MYPORT --user=user1 --ssl-mode=VERIFY_IDENTITY --ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/root.crt --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/client.cachain --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/client.key -e "SHOW STATUS LIKE 'ssl_cipher'" |
| 50 |
|
| 51 |
#Restart server with same ssl-ca. |
| 52 |
--echo Restart server and provide same ssl-ca at server startup |
| 53 |
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 54 |
--shutdown_server |
| 55 |
--source include/wait_until_disconnected.inc |
| 56 |
|
| 57 |
--exec echo "restart:--ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/root_intermediate_ca1.crt --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/server.key --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/server_to_root.cachain " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 58 |
--enable_reconnect |
| 59 |
--source include/wait_until_connected_again.inc |
| 60 |
|
| 61 |
--replace_regex $ALLOWED_CIPHERS_REGEX |
| 62 |
--exec $MYSQL --host=localhost -P $MASTER_MYPORT --user=user1 --ssl-mode=VERIFY_CA --ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/root.crt --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/client_to_root.cachain --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/client.key -e "SHOW STATUS LIKE 'ssl_cipher'" |
| 63 |
|
| 64 |
#Restart server with unrelated ssl-ca |
| 65 |
--echo Restart server and provide same ssl-ca at server startup |
| 66 |
--exec echo "wait" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 67 |
--shutdown_server |
| 68 |
--source include/wait_until_disconnected.inc |
| 69 |
|
| 70 |
--exec echo "restart:--ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/unrelated_root.crt --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/server.key --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/server_to_root.cachain " > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 71 |
--enable_reconnect |
| 72 |
--source include/wait_until_connected_again.inc |
| 73 |
|
| 74 |
--replace_regex /SSL connection error: error:.*:SSL routines:.*:certificate verify failed/SSL connection error: error:ERRCODE:SSL routines:ERRMSG:certificate verify failed/ |
| 75 |
--error 1 |
| 76 |
--exec $MYSQL --host=localhost -P $MASTER_MYPORT --user=user1 --ssl-mode=VERIFY_CA --ssl-ca=$MYSQL_TEST_DIR/std_data/bug27491518/unrelated_root.crt --ssl-cert=$MYSQL_TEST_DIR/std_data/bug27491518/client_to_root.cachain --ssl-key=$MYSQL_TEST_DIR/std_data/bug27491518/client.key -e "SHOW STATUS LIKE 'ssl_cipher'" 2>&1 |
| 77 |
|
| 78 |
# Cleanup |
| 79 |
DROP USER 'user1'; |
| 80 |
|
| 81 |
# Clear extra options added above |
| 82 |
--let $restart_parameters = restart: |
| 83 |
--source include/restart_mysqld_no_echo.inc |