MCPcopy Create free account
hub / github.com/Tencent/phxsql / read_key_file

Method read_key_file

phx_percona/percona/sql/sql_acl.cc:11979–12036  ·  view source on GitHub ↗

@brief Read a key file and store its value in RSA structure @param key_ptr[out] Address of pointer to RSA. This is set to point to a non null value if key is correctly read. @param is_priv_key[in] Whether we are reading private key or public key. @param key_text_buffer[ou

Source from the content-addressed store, hash-verified

11977 @retval true Failure : An appropriate error is raised.
11978 */
11979 bool read_key_file(RSA **key_ptr, bool is_priv_key, char **key_text_buffer)
11980 {
11981 String key_file_path;
11982 char *key;
11983 const char *key_type;
11984 FILE *key_file= NULL;
11985
11986 key= is_priv_key ? auth_rsa_private_key_path : auth_rsa_public_key_path;
11987 key_type= is_priv_key ? "private" : "public";
11988 *key_ptr= NULL;
11989
11990 get_key_file_path(key, &key_file_path);
11991
11992 /*
11993 Check for existance of private key/public key file.
11994 */
11995 if ((key_file= fopen(key_file_path.c_ptr(), "r")) == NULL)
11996 {
11997 sql_print_information("RSA %s key file not found: %s."
11998 " Some authentication plugins will not work.",
11999 key_type, key_file_path.c_ptr());
12000 }
12001 else
12002 {
12003 *key_ptr= is_priv_key ? PEM_read_RSAPrivateKey(key_file, 0, 0, 0) :
12004 PEM_read_RSA_PUBKEY(key_file, 0, 0, 0);
12005
12006 if (!(*key_ptr))
12007 {
12008 char error_buf[MYSQL_ERRMSG_SIZE];
12009 ERR_error_string_n(ERR_get_error(), error_buf, MYSQL_ERRMSG_SIZE);
12010 sql_print_error("Failure to parse RSA %s key (file exists): %s:"
12011 " %s", key_type, key_file_path.c_ptr(), error_buf);
12012
12013 /*
12014 Call ERR_clear_error() just in case there are more than 1 entry in the
12015 OpenSSL thread's error queue.
12016 */
12017 ERR_clear_error();
12018
12019 return true;
12020 }
12021
12022 /* For public key, read key file content into a char buffer. */
12023 if (!is_priv_key)
12024 {
12025 int filesize;
12026 fseek(key_file, 0, SEEK_END);
12027 filesize= ftell(key_file);
12028 fseek(key_file, 0, SEEK_SET);
12029 *key_text_buffer= new char[filesize+1];
12030 (void) fread(*key_text_buffer, filesize, 1, key_file);
12031 (*key_text_buffer)[filesize]= '\0';
12032 }
12033 fclose(key_file);
12034 }
12035 return false;
12036 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected