Skip to content

Commit 5bb1544

Browse files
Bug#21335818 : MYSQL_SSL_RSA_SETUP CREATES UNWANTED .RND FILE IN DATADIR
Description : When generating RSA keys, OpenSSL generated .rnd file in $HOME directory. In case of mysql_ssl_rsa_setup being executed as one of the initialization steps, these file should be removed from data directory after the generation of certificates/keys is complete. Solution : Remove .rnd file from current working directory before and after generation. If certificates/keys are already present, no attempt will be made to remove this file. Reviewed-By : Georgi Kodinov <[email protected]> Reviewed-By : Terje Rosten <[email protected]>
1 parent 0404fb7 commit 5bb1544

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

client/mysql_ssl_rsa_setup.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ enum certs
6767
CLIENT_KEY,
6868
CLIENT_REQ,
6969
PRIVATE_KEY,
70-
PUBLIC_KEY
70+
PUBLIC_KEY,
71+
OPENSSL_RND
7172
};
7273

7374
Sql_string_t cert_files[] =
@@ -82,7 +83,8 @@ Sql_string_t cert_files[] =
8283
create_string("client-key.pem"),
8384
create_string("client-req.pem"),
8485
create_string("private_key.pem"),
85-
create_string("public_key.pem")
86+
create_string("public_key.pem"),
87+
create_string(".rnd")
8688
};
8789

8890
#define MAX_PATH_LEN (FN_REFLEN - strlen(FN_DIRSEP) \
@@ -550,12 +552,13 @@ int main(int argc, char *argv[])
550552
X509_key x509_key(suffix_string);
551553
X509_cert x509_cert;
552554

553-
/* Delete existing files : Window may have problem if we don't */
555+
/* Delete existing files if any */
554556
remove_file(cert_files[CA_REQ], false);
555557
remove_file(cert_files[SERVER_REQ], false);
556558
remove_file(cert_files[CLIENT_REQ], false);
557559
remove_file(cert_files[CLIENT_CERT], false);
558560
remove_file(cert_files[CLIENT_KEY], false);
561+
remove_file(cert_files[OPENSSL_RND], false);
559562

560563
/* Generate CA Key and Certificate */
561564
if ((ret_val= execute_command(x509_key("_Auto_Generated_CA_Certificate",
@@ -617,6 +620,8 @@ int main(int argc, char *argv[])
617620

618621
if ((ret_val= remove_file(cert_files[CLIENT_REQ])))
619622
goto end;
623+
624+
remove_file(cert_files[OPENSSL_RND], false);
620625
}
621626

622627
/*
@@ -638,6 +643,10 @@ int main(int argc, char *argv[])
638643
{
639644
RSA_priv rsa_priv;
640645
RSA_pub rsa_pub;
646+
647+
/* Remove existing file if any */
648+
remove_file(cert_files[OPENSSL_RND], false);
649+
641650
if ((ret_val= execute_command(rsa_priv(cert_files[PRIVATE_KEY]),
642651
"Error generating private_key.pem")))
643652
goto end;
@@ -650,6 +659,8 @@ int main(int argc, char *argv[])
650659
if ((ret_val= set_file_pair_permission(cert_files[PRIVATE_KEY],
651660
cert_files[PUBLIC_KEY])))
652661
goto end;
662+
663+
remove_file(cert_files[OPENSSL_RND], false);
653664
}
654665

655666
if (my_setwd(save_wd, MYF(MY_WME)))

0 commit comments

Comments
 (0)