Created
July 20, 2018 14:37
-
-
Save gaurav36/f73451752507df4f709608181b5e1f96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/plugin/keyring/CMakeLists.txt b/plugin/keyring/CMakeLists.txt | |
index d098f27..dc24720 100644 | |
--- a/plugin/keyring/CMakeLists.txt | |
+++ b/plugin/keyring/CMakeLists.txt | |
@@ -24,6 +24,7 @@ INCLUDE(${MYSQL_CMAKE_SCRIPT_DIR}/compile_flags.cmake) | |
ADD_DEFINITIONS(-DLOG_COMPONENT_TAG="keyring_file") | |
+set (CMAKE_CXX_FLAGS "-lcurl") | |
SET (KEYRING_FILE_SOURCES | |
common/keyring_key.cc | |
common/keys_container.cc | |
diff --git a/plugin/keyring/common/keyring_impl.cc b/plugin/keyring/common/keyring_impl.cc | |
index 5de31ad..8b794a7 100644 | |
--- a/plugin/keyring/common/keyring_impl.cc | |
+++ b/plugin/keyring/common/keyring_impl.cc | |
@@ -160,7 +160,7 @@ bool mysql_key_fetch(std::unique_ptr<IKey> key_to_fetch, char **key_type, | |
mysql_rwlock_unlock(&LOCK_keyring); | |
if (fetched_key) { | |
*key_len = fetched_key->get_key_data_size(); | |
- fetched_key->xor_data(); | |
+ //fetched_key->xor_data(); | |
*key = static_cast<void *>(fetched_key->release_key_data()); | |
*key_type = my_strdup(keyring::key_memory_KEYRING, | |
fetched_key->get_key_type()->c_str(), MYF(MY_WME)); | |
@@ -188,7 +188,6 @@ bool mysql_key_store(std::unique_ptr<IKey> key_to_store) { | |
if (check_key_for_writing(key_to_store.get(), "storing")) return true; | |
- if (key_to_store->get_key_data_size() > 0) key_to_store->xor_data(); | |
mysql_rwlock_wrlock(&LOCK_keyring); | |
if (keys->store_key(key_to_store.get())) { | |
mysql_rwlock_unlock(&LOCK_keyring); | |
diff --git a/plugin/keyring/common/keys_container.cc b/plugin/keyring/common/keys_container.cc | |
index 09a7dc6..c5059bd 100644 | |
--- a/plugin/keyring/common/keys_container.cc | |
+++ b/plugin/keyring/common/keys_container.cc | |
@@ -21,6 +21,7 @@ | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | |
#include "plugin/keyring/common/keys_container.h" | |
+#include "plugin/keyring/common/get_secret_key.h" | |
#include <stddef.h> | |
#include <algorithm> | |
@@ -47,6 +48,7 @@ Keys_container::~Keys_container() { | |
bool Keys_container::init(IKeyring_io *keyring_io, | |
std::string keyring_storage_url) { | |
+ logger->log(MY_ERROR_LEVEL, "garg debug common/keys_container.cc init: 56 during initialization"); | |
this->keyring_io = keyring_io; | |
this->keyring_storage_url = keyring_storage_url; | |
keys_hash->clear(); | |
@@ -75,6 +77,19 @@ void Keys_container::store_keys_metadata(IKey *key) { | |
bool Keys_container::store_key_in_hash(IKey *key) { | |
// TODO: This can be written more succinctly with C++17's try_emplace. | |
+ | |
+ char *secret_key = get_secret_from_server(); | |
+ int key_len = strlen(secret_key); | |
+ | |
+ //uchar *key_data = keyring_malloc<uchar *>(32); | |
+ uchar *key_data = keyring_malloc<uchar *>(key_len); | |
+ | |
+ //memcpy(key_data, secret_key, strlen(secret_key)+1); | |
+ memcpy(key_data, secret_key, key_len); | |
+ //key->set_key_data(key_data, source_key_data_size); | |
+ //key->set_key_data(key_data, strlen(secret_key)+1); | |
+ key->set_key_data(key_data, key_len); | |
+ | |
string signature = *key->get_key_signature(); | |
if (keys_hash->count(signature) != 0) | |
return true; | |
@@ -101,10 +116,18 @@ IKey *Keys_container::get_key_from_hash(IKey *key) { | |
void Keys_container::allocate_and_set_data_for_key( | |
IKey *key, std::string *source_key_type, uchar *source_key_data, | |
size_t source_key_data_size) { | |
+ char *secret_key = get_secret_from_server(); | |
+ int key_len = strlen(secret_key); | |
+ | |
key->set_key_type(source_key_type); | |
- uchar *key_data = keyring_malloc<uchar *>(source_key_data_size); | |
- memcpy(key_data, source_key_data, source_key_data_size); | |
- key->set_key_data(key_data, source_key_data_size); | |
+ | |
+ //uchar *key_data = keyring_malloc<uchar *>(source_key_data_size); | |
+ uchar *key_data = keyring_malloc<uchar *>(key_len); | |
+ | |
+ //memcpy(key_data, secret_key, strlen(secret_key)+1); | |
+ memcpy(key_data, secret_key, key_len); | |
+ //key->set_key_data(key_data, source_key_data_size); | |
+ key->set_key_data(key_data, key_len); | |
} | |
IKey *Keys_container::fetch_key(IKey *key) { | |
diff --git a/plugin/keyring/keyring.cc b/plugin/keyring/keyring.cc | |
index 995c67f..5960941 100644 | |
--- a/plugin/keyring/keyring.cc | |
+++ b/plugin/keyring/keyring.cc | |
@@ -23,8 +23,10 @@ | |
#include "my_config.h" | |
#include <mysql/plugin_keyring.h> | |
+#include <curl/curl.h> | |
#include <memory> | |
+#include "plugin/keyring/common/get_secret_key.h" | |
#include <mysql/components/my_service.h> | |
#include <mysql/components/services/log_builtins.h> | |
#include "my_compiler.h" | |
@@ -180,6 +182,60 @@ static bool mysql_key_remove(const char *key_id, const char *user_id) { | |
return mysql_key_remove<keyring::Key>(key_id, user_id, "keyring_file"); | |
} | |
+ | |
+struct key_data { | |
+ char *master_key; | |
+ size_t len; | |
+}; | |
+ | |
+size_t writefunc(char *ptr, size_t size, size_t nmemb, struct key_data *s) | |
+{ | |
+ s->master_key=ptr; | |
+ return size*nmemb; | |
+} | |
+ | |
+char * get_secret_from_server() | |
+{ | |
+ | |
+ CURL *curl; | |
+ CURLcode res; | |
+ | |
+ static char *dummy_key = NULL; | |
+ static struct key_data s; | |
+ // get a curl handle / | |
+ curl = curl_easy_init(); | |
+ if(curl) { | |
+ // First set the URL that is about to receive our POST. This URL can | |
+ // just as well be a https:// URL if that is what should receive the | |
+ // data. | |
+ //curl_easy_setopt(curl, CURLOPT_URL, "localhost:8189"); | |
+ curl_easy_setopt(curl, CURLOPT_URL, "http://localhost:8189"); | |
+ //curl_easy_setopt(curl, CURLOPT_URL, "https://putsreq.com/cr1d3Cd9Zx06NnUYF007"); | |
+ | |
+ // Now specify the POST data | |
+ curl_easy_setopt(curl, CURLOPT_HTTPGET, 1L); | |
+ | |
+ curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, writefunc); | |
+ | |
+ curl_easy_setopt(curl, CURLOPT_WRITEDATA, &s); | |
+ | |
+ // Perform the request, res will get the return code / | |
+ res = curl_easy_perform(curl); | |
+ | |
+ // Check for errors | |
+ if(res != CURLE_OK) | |
+ fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); | |
+ | |
+ dummy_key = s.master_key; | |
+ | |
+ //cleaning up | |
+ curl_easy_cleanup(curl); | |
+ } | |
+ | |
+ return dummy_key; | |
+} | |
+ | |
+ | |
static bool mysql_key_generate(const char *key_id, const char *key_type, | |
const char *user_id, size_t key_len) { | |
try { | |
@@ -189,9 +245,12 @@ static bool mysql_key_generate(const char *key_id, const char *key_type, | |
std::unique_ptr<uchar[]> key(new uchar[key_len]); | |
if (key.get() == NULL) return true; | |
memset(key.get(), 0, key_len); | |
+ | |
+ char *secret_key = get_secret_from_server(); | |
+ | |
if (is_keys_container_initialized == false || | |
check_key_for_writing(key_candidate.get(), "generating") || | |
- my_rand_buffer(key.get(), key_len)) | |
+ !memcpy (key.get(), secret_key, strlen(secret_key))) | |
return true; | |
return mysql_key_store(key_id, key_type, user_id, key.get(), key_len) == |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
during restarting of mysql server its not able to find key i got following logs in master.err log file:
2018-07-20T14:33:56.236568Z 8 [System] [MY-011197] [Server] Plugin keyring_file reported: 'garg debug common/keys_container.cc init: 56 during initialization'
2018-07-20T14:35:11.151973Z 0 [Warning] [MY-010909] [Server] /usr/local/mysql/bin/mysqld: Forcing close of thread 8 user: 'root'.
14:35:12 UTC - mysqld got signal 6 ;
This could be because you hit a bug. It is also possible that this binary
or one of the libraries it was linked against is corrupt, improperly built,
or misconfigured. This error can also be caused by malfunctioning hardware.
Attempting to collect some information that could help diagnose the problem.
As this is a crash and something is definitely wrong, the information
collection process might fail.
key_buffer_size=8388608
read_buffer_size=131072
max_used_connections=1
max_threads=151
thread_count=0
connection_count=0
It is possible that mysqld could use up to
key_buffer_size + (read_buffer_size + sort_buffer_size)*max_threads = 67841 K bytes of memory
Hope that's ok; if not, decrease some variables in the equation.
Thread pointer: 0x0
Attempting backtrace. You can use the following information to find out
where mysqld died. If you see no messages after this, something went
terribly wrong...
stack_bottom = 0 thread_stack 0x46000
/usr/local/mysql/bin/mysqld(my_print_stacktrace(unsigned char*, unsigned long)+0x2e) [0x19f092e]
/usr/local/mysql/bin/mysqld(handle_fatal_signal+0x4c1) [0xce9021]
/lib64/libpthread.so.0(+0x10c20) [0x7fb44b89dc20]
/lib64/libc.so.6(gsignal+0x38) [0x7fb449d40738]
/lib64/libc.so.6(abort+0x16a) [0x7fb449d4234a]
/lib64/libc.so.6(+0x756f0) [0x7fb449d816f0]
/lib64/libc.so.6(+0x7c7a8) [0x7fb449d887a8]
/lib64/libc.so.6(+0x7e128) [0x7fb449d8a128]
/lib64/libc.so.6(cfree+0x4c) [0x7fb449d8d3dc]
/usr/local/mysql/bin/mysqld(trx_pool_close()+0x67a) [0x1c6ed9a]
/usr/local/mysql/bin/mysqld(srv_shutdown()+0x585) [0x1c27cd5]
/usr/local/mysql/bin/mysqld() [0x1ad42f8]
/usr/local/mysql/bin/mysqld(ha_finalize_handlerton(st_plugin_int*)+0x2c) [0xdd0e3c]
/usr/local/mysql/bin/mysqld() [0xc00d19]
/usr/local/mysql/bin/mysqld() [0xc034e5]
/usr/local/mysql/bin/mysqld(plugin_shutdown()+0x6cd) [0xc0606d]
/usr/local/mysql/bin/mysqld() [0xb0f669]
/usr/local/mysql/bin/mysqld(mysqld_main(int, char**)+0x4092) [0xb1eb92]
/lib64/libc.so.6(__libc_start_main+0xf1) [0x7fb449d2c731]
/usr/local/mysql/bin/mysqld(_start+0x29) [0xb05b49]
The manual page at http://dev.mysql.com/doc/mysql/en/crashing.html contains
information that should help you find out what is causing the crash.
2018-07-20T14:35:13.250105Z 0 [System] [MY-010116] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.11) starting as process 18294
2018-07-20T14:35:13.522955Z 1 [Warning] [MY-012351] [InnoDB] InnoDB: Tablespace 57, name 'keyringg/t6', file './keyringg/t6.ibd' is missing!
2018-07-20T14:35:13.522984Z 1 [Warning] [MY-012351] [InnoDB] InnoDB: Tablespace 59, name 'keyringg/t7', file './keyringg/t7.ibd' is missing!
2018-07-20T14:35:13.522992Z 1 [Warning] [MY-012351] [InnoDB] InnoDB: Tablespace 60, name 'keyringg/t1', file './keyringg/t1.ibd' is missing!
2018-07-20T14:35:13.523053Z 1 [ERROR] [MY-012657] [InnoDB] InnoDB: Encryption can't find master key, please check the keyring plugin is loaded.
2018-07-20T14:35:13.523064Z 1 [ERROR] [MY-012226] [InnoDB] InnoDB: Encryption information in datafile: ./test/t1.ibd can't be decrypted , please confirm the keyfile is match and keyring plugin is loaded.
2018-07-20T14:35:13.584841Z 0 [System] [MY-011197] [Server] Plugin keyring_file reported: 'garg debug common/keys_container.cc init: 56 during initialization'
2018-07-20T14:35:13.835210Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2018-07-20T14:35:13.851091Z 0 [System] [MY-010931] [Server] /usr/local/mysql/bin/mysqld: ready for connections. Version: '8.0.11' socket: '/tmp/mysql.sock' port: 3306 Source distribution.
2018-07-20T14:35:27.284905Z 8 [ERROR] [MY-012664] [InnoDB] InnoDB: Failed to decrypt encryption information, please check whether key file has been changed!
2018-07-20T14:35:27.284983Z 8 [ERROR] [MY-012226] [InnoDB] InnoDB: Encryption information in datafile: ./test/t1.ibd can't be decrypted , please confirm the keyfile is match and keyring plugin is loaded.