From 128632e7780805cfb1b20c93d9d0ca1782e6fa45 Mon Sep 17 00:00:00 2001 From: lvntky Date: Sun, 13 Jun 2021 20:45:00 +0300 Subject: [PATCH 1/5] tiny functions added/implemented ( #139 ) --- src/c_api.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/c_api.cpp b/src/c_api.cpp index 06413e3..b34e5c0 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -142,3 +142,6 @@ extern "C" void opaque_decrypt_data(char **encrypted_files, plaintext_file, key_file); *result = status; } + +extern "C" size_t cipher_key_size() {return CIPHER_KEY_SIZE} +// extern "C" int generate_symmetric_key(cipher_key_size()) {} \ No newline at end of file From b6ab02647034027000da1618932ec982c1cd85d7 Mon Sep 17 00:00:00 2001 From: lvntky Date: Mon, 14 Jun 2021 11:16:27 +0300 Subject: [PATCH 2/5] core.py and c_api modified ( #139 ) --- python-package/mc2client/core.py | 5 +++-- src/c_api.cpp | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/python-package/mc2client/core.py b/python-package/mc2client/core.py index 6fa033c..6bdd1a4 100644 --- a/python-package/mc2client/core.py +++ b/python-package/mc2client/core.py @@ -582,7 +582,7 @@ def generate_keypair(expiration=10 * 365 * 24 * 60 * 60): logger.info("Generated certificate and outputted to {}".format(cert_path)) -def generate_symmetric_key(num_bytes=32): +def generate_symmetric_key(): """ Generate a new symmetric key and save it path specified by user in config YAML passed to `set_config()` @@ -591,6 +591,7 @@ def generate_symmetric_key(num_bytes=32): num_bytes : int Number of bytes for key """ + if _CONF.get("general_config") is None: raise MC2ClientConfigError("Configuration not set") @@ -603,7 +604,7 @@ def generate_symmetric_key(num_bytes=32): ) return - key = AESGCM.generate_key(bit_length=num_bytes * 8) + key = AESGCM.generate_key(bit_length= _LIB.cipher_key_size() * 8) with open(symmetric_key_path, "wb") as symm_key: symm_key.write(key) diff --git a/src/c_api.cpp b/src/c_api.cpp index b34e5c0..f1e538f 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -143,5 +143,4 @@ extern "C" void opaque_decrypt_data(char **encrypted_files, *result = status; } -extern "C" size_t cipher_key_size() {return CIPHER_KEY_SIZE} -// extern "C" int generate_symmetric_key(cipher_key_size()) {} \ No newline at end of file +extern "C" size_t cipher_key_size() {return CIPHER_KEY_SIZE} \ No newline at end of file From e7e9b37f8ac84f0c13b872e8a7e2e0a23cde57e9 Mon Sep 17 00:00:00 2001 From: lvntky Date: Mon, 14 Jun 2021 20:40:25 +0300 Subject: [PATCH 3/5] num_bytes variable added for readibility (#139) --- python-package/mc2client/core.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/python-package/mc2client/core.py b/python-package/mc2client/core.py index 6bdd1a4..9ec93d3 100644 --- a/python-package/mc2client/core.py +++ b/python-package/mc2client/core.py @@ -591,6 +591,7 @@ def generate_symmetric_key(): num_bytes : int Number of bytes for key """ + num_bytes = _LIB.cipher_key_size() if _CONF.get("general_config") is None: raise MC2ClientConfigError("Configuration not set") @@ -604,7 +605,7 @@ def generate_symmetric_key(): ) return - key = AESGCM.generate_key(bit_length= _LIB.cipher_key_size() * 8) + key = AESGCM.generate_key(bit_length= num_bytes * 8) with open(symmetric_key_path, "wb") as symm_key: symm_key.write(key) From 62a63744fc964a8a4ed2db2aac8bb58b59abcc02 Mon Sep 17 00:00:00 2001 From: lvntky Date: Mon, 14 Jun 2021 21:27:53 +0300 Subject: [PATCH 4/5] comments added(#139) --- python-package/mc2client/core.py | 8 ++++++++ src/c_api.cpp | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/python-package/mc2client/core.py b/python-package/mc2client/core.py index 9ec93d3..2019f46 100644 --- a/python-package/mc2client/core.py +++ b/python-package/mc2client/core.py @@ -591,6 +591,14 @@ def generate_symmetric_key(): num_bytes : int Number of bytes for key """ + + """ + Due the issue #139, + we do note allow the user to specifiy + cipher key size. + instead of this, we get the cipher_key_size from c_api.cpp + and assign it to num_bytes variable. + """ num_bytes = _LIB.cipher_key_size() if _CONF.get("general_config") is None: diff --git a/src/c_api.cpp b/src/c_api.cpp index f1e538f..042ea99 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -143,4 +143,6 @@ extern "C" void opaque_decrypt_data(char **encrypted_files, *result = status; } -extern "C" size_t cipher_key_size() {return CIPHER_KEY_SIZE} \ No newline at end of file +// function created for to not to allow user specifies cipher key +// due to issue #139 +extern "C" size_t cipher_key_size() { return CIPHER_KEY_SIZE; } \ No newline at end of file From d4be33919762568aca16368b9f0c898073e4f88c Mon Sep 17 00:00:00 2001 From: lvntky Date: Mon, 14 Jun 2021 23:08:16 +0300 Subject: [PATCH 5/5] minor changes and formatting --- python-package/mc2client/core.py | 10 +--------- src/c_api.cpp | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/python-package/mc2client/core.py b/python-package/mc2client/core.py index 2019f46..8e6d6d7 100644 --- a/python-package/mc2client/core.py +++ b/python-package/mc2client/core.py @@ -591,14 +591,6 @@ def generate_symmetric_key(): num_bytes : int Number of bytes for key """ - - """ - Due the issue #139, - we do note allow the user to specifiy - cipher key size. - instead of this, we get the cipher_key_size from c_api.cpp - and assign it to num_bytes variable. - """ num_bytes = _LIB.cipher_key_size() if _CONF.get("general_config") is None: @@ -613,7 +605,7 @@ def generate_symmetric_key(): ) return - key = AESGCM.generate_key(bit_length= num_bytes * 8) + key = AESGCM.generate_key(bit_length=num_bytes * 8) with open(symmetric_key_path, "wb") as symm_key: symm_key.write(key) diff --git a/src/c_api.cpp b/src/c_api.cpp index 042ea99..052fb79 100644 --- a/src/c_api.cpp +++ b/src/c_api.cpp @@ -143,6 +143,4 @@ extern "C" void opaque_decrypt_data(char **encrypted_files, *result = status; } -// function created for to not to allow user specifies cipher key -// due to issue #139 extern "C" size_t cipher_key_size() { return CIPHER_KEY_SIZE; } \ No newline at end of file