| 1 |
# Save the initial number of concurrent sessions |
| 2 |
--source include/count_sessions.inc |
| 3 |
|
| 4 |
|
| 5 |
#------------------------------------------------------------------------------ |
| 6 |
|
| 7 |
|
| 8 |
--echo # Test cases for mysql_ssl_rsa_setup binary |
| 9 |
--echo # Setup |
| 10 |
let DATADIR_LOCATION=$MYSQLTEST_VARDIR/mysqld.1/data; |
| 11 |
#We let mysql_ssl_rsa_setup write to $wl7706_log |
| 12 |
let wl7706_log= $MYSQLTEST_VARDIR/log/wl7706_log.txt; |
| 13 |
let SEARCH_FILE= $wl7706_log; |
| 14 |
|
| 15 |
# remove files |
| 16 |
--error 0,1 |
| 17 |
--remove_file $wl7706_log |
| 18 |
--error 0,1 |
| 19 |
--remove_file $DATADIR_LOCATION/ca.pem |
| 20 |
--error 0,1 |
| 21 |
--remove_file $DATADIR_LOCATION/ca-key.pem |
| 22 |
--error 0,1 |
| 23 |
--remove_file $DATADIR_LOCATION/server-cert.pem |
| 24 |
--error 0,1 |
| 25 |
--remove_file $DATADIR_LOCATION/server-key.pem |
| 26 |
--error 0,1 |
| 27 |
--remove_file $DATADIR_LOCATION/client-cert.pem |
| 28 |
--error 0,1 |
| 29 |
--remove_file $DATADIR_LOCATION/client-key.pem |
| 30 |
--error 0,1 |
| 31 |
--remove_file $DATADIR_LOCATION/private_key.pem |
| 32 |
--error 0,1 |
| 33 |
--remove_file $DATADIR_LOCATION/public_key.pem |
| 34 |
|
| 35 |
|
| 36 |
#------------------------------------------------------------------------------ |
| 37 |
|
| 38 |
|
| 39 |
--echo # Case 1 : Generate Files |
| 40 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION > $wl7706_log |
| 41 |
--file_exists $DATADIR_LOCATION/ca.pem |
| 42 |
--file_exists $DATADIR_LOCATION/ca-key.pem |
| 43 |
--file_exists $DATADIR_LOCATION/server-cert.pem |
| 44 |
--file_exists $DATADIR_LOCATION/server-key.pem |
| 45 |
--file_exists $DATADIR_LOCATION/client-cert.pem |
| 46 |
--file_exists $DATADIR_LOCATION/client-key.pem |
| 47 |
--file_exists $DATADIR_LOCATION/private_key.pem |
| 48 |
--file_exists $DATADIR_LOCATION/public_key.pem |
| 49 |
|
| 50 |
--remove_file $wl7706_log |
| 51 |
|
| 52 |
|
| 53 |
#------------------------------------------------------------------------------ |
| 54 |
|
| 55 |
|
| 56 |
--echo # Case 2 : Files are present : Generation should be skipped |
| 57 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 58 |
let SEARCH_PATTERN= Certificate files are present in given dir. Skipping generation.; |
| 59 |
--source include/search_pattern.inc |
| 60 |
let SEARCH_PATTERN= RSA key files are present in given dir. Skipping generation.; |
| 61 |
--source include/search_pattern.inc |
| 62 |
|
| 63 |
--remove_file $wl7706_log |
| 64 |
|
| 65 |
|
| 66 |
#------------------------------------------------------------------------------ |
| 67 |
|
| 68 |
|
| 69 |
--echo # Case 3 : Certificate files are not present but RSA key files are present. |
| 70 |
--echo # Only SSL certificates and keys should be generated. |
| 71 |
--remove_file $DATADIR_LOCATION/ca.pem |
| 72 |
--remove_file $DATADIR_LOCATION/ca-key.pem |
| 73 |
--remove_file $DATADIR_LOCATION/server-cert.pem |
| 74 |
--remove_file $DATADIR_LOCATION/server-key.pem |
| 75 |
--remove_file $DATADIR_LOCATION/client-cert.pem |
| 76 |
--remove_file $DATADIR_LOCATION/client-key.pem |
| 77 |
|
| 78 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 79 |
--file_exists $DATADIR_LOCATION/ca.pem |
| 80 |
--file_exists $DATADIR_LOCATION/ca-key.pem |
| 81 |
--file_exists $DATADIR_LOCATION/server-cert.pem |
| 82 |
--file_exists $DATADIR_LOCATION/server-key.pem |
| 83 |
--file_exists $DATADIR_LOCATION/client-cert.pem |
| 84 |
--file_exists $DATADIR_LOCATION/client-key.pem |
| 85 |
|
| 86 |
let SEARCH_PATTERN= Executing : openssl x509; |
| 87 |
--source include/search_pattern.inc |
| 88 |
let SEARCH_PATTERN= Executing : openssl req; |
| 89 |
--source include/search_pattern.inc |
| 90 |
let SEARCH_PATTERN= RSA key files are present in given dir. Skipping generation.; |
| 91 |
--source include/search_pattern.inc |
| 92 |
|
| 93 |
--remove_file $wl7706_log |
| 94 |
|
| 95 |
|
| 96 |
#------------------------------------------------------------------------------ |
| 97 |
|
| 98 |
|
| 99 |
--echo # Case 4 : Certificate files are present but RSA key files are not present. |
| 100 |
--echo # Only RSA key files should be generated. |
| 101 |
--remove_file $DATADIR_LOCATION/private_key.pem |
| 102 |
--remove_file $DATADIR_LOCATION/public_key.pem |
| 103 |
|
| 104 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 105 |
--file_exists $DATADIR_LOCATION/private_key.pem |
| 106 |
--file_exists $DATADIR_LOCATION/public_key.pem |
| 107 |
|
| 108 |
let SEARCH_PATTERN= Certificate files are present in given dir. Skipping generation.; |
| 109 |
--source include/search_pattern.inc |
| 110 |
let SEARCH_PATTERN= Executing : openssl genrsa; |
| 111 |
--source include/search_pattern.inc |
| 112 |
|
| 113 |
--remove_file $wl7706_log |
| 114 |
|
| 115 |
|
| 116 |
#------------------------------------------------------------------------------ |
| 117 |
|
| 118 |
|
| 119 |
--echo # Case 5 : Remove only client-cert.pem and client-key.pem. |
| 120 |
--echo # Certificate files should not be generated. |
| 121 |
--remove_file $DATADIR_LOCATION/client-cert.pem |
| 122 |
--remove_file $DATADIR_LOCATION/client-key.pem |
| 123 |
|
| 124 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 125 |
let SEARCH_PATTERN= Certificate files are present in given dir. Skipping generation.; |
| 126 |
--source include/search_pattern.inc |
| 127 |
|
| 128 |
--remove_file $wl7706_log |
| 129 |
|
| 130 |
|
| 131 |
#------------------------------------------------------------------------------ |
| 132 |
|
| 133 |
|
| 134 |
--echo # Case 6 : Remove server-key.pem and public_key.pem. |
| 135 |
--echo # Certificates and RSA keys should not be generated. |
| 136 |
--remove_file $DATADIR_LOCATION/server-key.pem |
| 137 |
--remove_file $DATADIR_LOCATION/public_key.pem |
| 138 |
|
| 139 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 140 |
let SEARCH_PATTERN= Certificate files are present in given dir. Skipping generation.; |
| 141 |
--source include/search_pattern.inc |
| 142 |
let SEARCH_PATTERN= RSA key files are present in given dir. Skipping generation.; |
| 143 |
--source include/search_pattern.inc |
| 144 |
|
| 145 |
--remove_file $wl7706_log |
| 146 |
|
| 147 |
|
| 148 |
#------------------------------------------------------------------------------ |
| 149 |
|
| 150 |
|
| 151 |
--echo # Case 7 : Provide Invalid directory |
| 152 |
|
| 153 |
--error 1 |
| 154 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$MYSQLTEST_VARDIR/doesnotexist --verbose 2> $wl7706_log |
| 155 |
let SEARCH_PATTERN= Failed to access directory pointed by; |
| 156 |
--source include/search_pattern.inc |
| 157 |
|
| 158 |
--remove_file $wl7706_log |
| 159 |
|
| 160 |
|
| 161 |
#------------------------------------------------------------------------------ |
| 162 |
|
| 163 |
|
| 164 |
--echo # Case 8 : Custom suffix of invalid length |
| 165 |
--remove_file $DATADIR_LOCATION/ca.pem |
| 166 |
--remove_file $DATADIR_LOCATION/ca-key.pem |
| 167 |
--remove_file $DATADIR_LOCATION/server-cert.pem |
| 168 |
--remove_file $DATADIR_LOCATION/private_key.pem |
| 169 |
|
| 170 |
--error 1 |
| 171 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --suffix=string_greater_than_17_characters 2> $wl7706_log |
| 172 |
let SEARCH_PATTERN= Maximum number of characters allowed as the value for --suffix are 17; |
| 173 |
--source include/search_pattern.inc |
| 174 |
|
| 175 |
--remove_file $wl7706_log |
| 176 |
|
| 177 |
|
| 178 |
#------------------------------------------------------------------------------ |
| 179 |
|
| 180 |
|
| 181 |
--echo # Case 9 : Custom suffix of valid length |
| 182 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --suffix=wl7706_test --verbose > $wl7706_log |
| 183 |
let SEARCH_PATTERN= MySQL_Server_wl7706_test_Auto_Generated_CA_Certificate; |
| 184 |
--source include/search_pattern.inc |
| 185 |
let SEARCH_PATTERN= MySQL_Server_wl7706_test_Auto_Generated_Server_Certificate; |
| 186 |
--source include/search_pattern.inc |
| 187 |
let SEARCH_PATTERN= MySQL_Server_wl7706_test_Auto_Generated_Server_Certificate; |
| 188 |
--source include/search_pattern.inc |
| 189 |
|
| 190 |
--remove_file $wl7706_log |
| 191 |
|
| 192 |
|
| 193 |
#------------------------------------------------------------------------------ |
| 194 |
|
| 195 |
|
| 196 |
--echo # Case 10 : Custom suffix with invalid characters |
| 197 |
|
| 198 |
--remove_file $DATADIR_LOCATION/ca.pem |
| 199 |
--remove_file $DATADIR_LOCATION/ca-key.pem |
| 200 |
--remove_file $DATADIR_LOCATION/server-cert.pem |
| 201 |
--remove_file $DATADIR_LOCATION/private_key.pem |
| 202 |
|
| 203 |
--error 1 |
| 204 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --suffix=ab@c!de-gh 2> $wl7706_log |
| 205 |
let SEARCH_PATTERN=Invalid string; |
| 206 |
--source include/search_pattern.inc |
| 207 |
|
| 208 |
--remove_file $wl7706_log |
| 209 |
|
| 210 |
|
| 211 |
#------------------------------------------------------------------------------ |
| 212 |
|
| 213 |
|
| 214 |
--echo # Case 11 : Help and Version information |
| 215 |
|
| 216 |
--exec $MYSQL_SSL_RSA_SETUP --help > $wl7706_log |
| 217 |
let SEARCH_PATTERN=MySQL SSL Certificate and RSA Key Generation Utility; |
| 218 |
--source include/search_pattern.inc |
| 219 |
|
| 220 |
--remove_file $wl7706_log |
| 221 |
|
| 222 |
--exec $MYSQL_SSL_RSA_SETUP -? > $wl7706_log |
| 223 |
let SEARCH_PATTERN=MySQL SSL Certificate and RSA Key Generation Utility; |
| 224 |
--source include/search_pattern.inc |
| 225 |
|
| 226 |
--remove_file $wl7706_log |
| 227 |
|
| 228 |
--exec $MYSQL_SSL_RSA_SETUP --version > $wl7706_log |
| 229 |
let SEARCH_PATTERN=Ver ; |
| 230 |
--source include/search_pattern.inc |
| 231 |
|
| 232 |
--remove_file $wl7706_log |
| 233 |
|
| 234 |
--exec $MYSQL_SSL_RSA_SETUP -V > $wl7706_log |
| 235 |
let SEARCH_PATTERN=Ver ; |
| 236 |
--source include/search_pattern.inc |
| 237 |
|
| 238 |
--remove_file $wl7706_log |
| 239 |
|
| 240 |
|
| 241 |
#------------------------------------------------------------------------------ |
| 242 |
|
| 243 |
|
| 244 |
--echo # Case 12 : Very long path |
| 245 |
|
| 246 |
let $LONG_PATH=`SELECT REPEAT('/asdfg', 100)`; |
| 247 |
|
| 248 |
--error 1 |
| 249 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$LONG_PATH 2> $wl7706_log |
| 250 |
let SEARCH_PATTERN=Dir path is too long; |
| 251 |
--source include/search_pattern.inc |
| 252 |
|
| 253 |
--remove_file $wl7706_log |
| 254 |
|
| 255 |
|
| 256 |
#------------------------------------------------------------------------------ |
| 257 |
|
| 258 |
|
| 259 |
--echo # |
| 260 |
--echo # Bug#21087116 : MYSQL_SSL_RSA_SETUP CREATES CLIENT-CERT.PEM WITH INCORRECT CN |
| 261 |
--echo # |
| 262 |
|
| 263 |
--remove_file $DATADIR_LOCATION/server-key.pem |
| 264 |
--remove_file $DATADIR_LOCATION/client-cert.pem |
| 265 |
--remove_file $DATADIR_LOCATION/client-key.pem |
| 266 |
--remove_file $DATADIR_LOCATION/public_key.pem |
| 267 |
|
| 268 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$DATADIR_LOCATION --verbose > $wl7706_log |
| 269 |
|
| 270 |
--echo # CN of CA certificate should be MySQL_Server_.*_Auto_Generated_CA_Certificate |
| 271 |
let SEARCH_PATTERN= MySQL_Server_.*_Auto_Generated_CA_Certificate; |
| 272 |
--source include/search_pattern.inc |
| 273 |
|
| 274 |
--echo # CN of Server certificate should be MySQL_Server_.*_Auto_Generated_Server_Certificate |
| 275 |
let SEARCH_PATTERN= MySQL_Server_.*_Auto_Generated_Server_Certificate; |
| 276 |
--source include/search_pattern.inc |
| 277 |
|
| 278 |
--echo # CN of Client certificate should be MySQL_Server_.*_Auto_Generated_Client_Certificate |
| 279 |
let SEARCH_PATTERN= MySQL_Server_.*_Auto_Generated_Client_Certificate; |
| 280 |
--source include/search_pattern.inc |
| 281 |
|
| 282 |
|
| 283 |
#------------------------------------------------------------------------------ |
| 284 |
|
| 285 |
--echo # Global Cleanup |
| 286 |
--remove_file $wl7706_log |
| 287 |
--remove_file $DATADIR_LOCATION/ca.pem |
| 288 |
--remove_file $DATADIR_LOCATION/ca-key.pem |
| 289 |
--remove_file $DATADIR_LOCATION/server-cert.pem |
| 290 |
--remove_file $DATADIR_LOCATION/server-key.pem |
| 291 |
--remove_file $DATADIR_LOCATION/client-cert.pem |
| 292 |
--remove_file $DATADIR_LOCATION/client-key.pem |
| 293 |
--remove_file $DATADIR_LOCATION/private_key.pem |
| 294 |
--remove_file $DATADIR_LOCATION/public_key.pem |
| 295 |
|
| 296 |
# Wait till all disconnects are completed |
| 297 |
--source include/wait_until_count_sessions.inc |
| 298 |
|
| 299 |
|
| 300 |
#------------------------------------------------------------------------------ |
| 301 |
|
| 302 |
|
| 303 |
--echo # |
| 304 |
--echo # Bug#21025377: CAN'T CONNECT TO SSL ENABLED SERVER FIRST 30 SEC AFTER |
| 305 |
--echo # INITIAL STARTUP |
| 306 |
--echo # |
| 307 |
|
| 308 |
let mysqladmin_log=$MYSQLTEST_VARDIR/log/mysqladmin_log.txt; |
| 309 |
--error 0, 1 |
| 310 |
--remove_file $mysqladmin_log |
| 311 |
let CADIR_LOCATION=$MYSQLTEST_VARDIR/tmp/certs; |
| 312 |
|
| 313 |
--error 0, 1 |
| 314 |
--rmdir $CADIR_LOCATION |
| 315 |
--mkdir $CADIR_LOCATION |
| 316 |
--exec $MYSQL_SSL_RSA_SETUP --datadir=$CADIR_LOCATION > /dev/null 2>&1 |
| 317 |
|
| 318 |
--echo # Restart the server |
| 319 |
|
| 320 |
let server_log= $MYSQLTEST_VARDIR/log/mysql_ssl_rsa_setup.err; |
| 321 |
let $restart_file= $MYSQLTEST_VARDIR/tmp/mysqld.1.expect; |
| 322 |
--exec echo "wait" > $restart_file |
| 323 |
--shutdown_server |
| 324 |
--source include/wait_until_disconnected.inc |
| 325 |
|
| 326 |
--exec echo "restart: --log-error=$server_log --ssl-ca=$CADIR_LOCATION/ca.pem --ssl-cert=$CADIR_LOCATION/server-cert.pem --ssl-key=$CADIR_LOCATION/server-key.pem" > $MYSQLTEST_VARDIR/tmp/mysqld.1.expect |
| 327 |
--enable_reconnect |
| 328 |
--source include/wait_until_connected_again.inc |
| 329 |
--disable_reconnect |
| 330 |
--echo # Restart completed. |
| 331 |
|
| 332 |
--exec $MYSQLADMIN --no-defaults --host=127.0.0.1 -P $MASTER_MYPORT --user=unknown_mysql_user ping --ssl-mode=REQUIRED > $mysqladmin_log 2>&1 |
| 333 |
|
| 334 |
--perl |
| 335 |
my $file= $ENV{'mysqladmin_log'}; |
| 336 |
my $pattern= "SSL connection error"; |
| 337 |
open(FILE, "$file") or die("unable to open $file: $!\n"); |
| 338 |
my $count = 0; |
| 339 |
while (<FILE>) { |
| 340 |
if ($_ =~ m/$pattern/) { |
| 341 |
$count++; |
| 342 |
break; |
| 343 |
} |
| 344 |
} |
| 345 |
if ($count == 0){ |
| 346 |
print "No ssl errors found after running mysql server with newely created certs.\n"; |
| 347 |
} else { |
| 348 |
print "test failed.\n"; |
| 349 |
} |
| 350 |
close(file); |
| 351 |
EOF |
| 352 |
|
| 353 |
# cleanup |
| 354 |
|
| 355 |
# Restore default settings in opt file and clean up |
| 356 |
--let $restart_parameters = restart: |
| 357 |
--source include/restart_mysqld.inc |
| 358 |
|
| 359 |
--remove_file $mysqladmin_log |
| 360 |
--remove_file $CADIR_LOCATION/ca.pem |
| 361 |
--remove_file $CADIR_LOCATION/ca-key.pem |
| 362 |
--remove_file $CADIR_LOCATION/server-cert.pem |
| 363 |
--remove_file $CADIR_LOCATION/server-key.pem |
| 364 |
--remove_file $CADIR_LOCATION/client-cert.pem |
| 365 |
--remove_file $CADIR_LOCATION/client-key.pem |
| 366 |
--remove_file $CADIR_LOCATION/private_key.pem |
| 367 |
--remove_file $CADIR_LOCATION/public_key.pem |
| 368 |
--rmdir $CADIR_LOCATION |
| 369 |
|
| 370 |
#------------------------------------------------------------------------------ |
| 371 |
|
| 372 |
--echo # |
| 373 |
--echo # WL#15668: Deprecate mysql_ssl_rsa_setup |
| 374 |
--echo # |
| 375 |
|
| 376 |
--exec $MYSQL_SSL_RSA_SETUP --help > $MYSQLTEST_VARDIR/tmp/wl15668.out 2>&1 |
| 377 |
--let $assert_text=Looking for a deprecation message |
| 378 |
--let $assert_match=mysql_ssl_rsa_setup is deprecated |
| 379 |
--let $assert_select=WARNING |
| 380 |
--let $assert_file=$MYSQLTEST_VARDIR/tmp/wl15668.out |
| 381 |
--source include/assert_grep.inc |
| 382 |
--remove_file $MYSQLTEST_VARDIR/tmp/wl15668.out |