From 0ca8efffd312c8a3c54b5e2635bfc98b41efb1dc Mon Sep 17 00:00:00 2001 From: WangFengTu Date: Tue, 21 Jul 2020 14:40:34 +0800 Subject: [PATCH] create aes key file path in aes module Signed-off-by: WangFengTu --- src/daemon/modules/image/oci/registry/aes.c | 18 +++++++++++++++--- src/daemon/modules/image/oci/registry/aes.h | 2 +- src/daemon/modules/image/oci/registry/auths.c | 8 +------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/daemon/modules/image/oci/registry/aes.c b/src/daemon/modules/image/oci/registry/aes.c index d3f464f..86eacdd 100644 --- a/src/daemon/modules/image/oci/registry/aes.c +++ b/src/daemon/modules/image/oci/registry/aes.c @@ -24,11 +24,23 @@ static char *g_aeskey = DEFAULT_AUTH_AESKEY; -void aes_set_key_path(char *key_path) +void aes_set_key_dir(char *key_dir) { - if (key_path != NULL) { - g_aeskey = util_strdup_s(key_path); + int sret = 0; + char path[PATH_MAX] = {0}; + + if (key_dir == NULL) { + return; + } + + sret = snprintf(path, sizeof(path), "%s/%s", key_dir, AUTH_AESKEY_NAME); + if (sret < 0 || (size_t)sret >= sizeof(path)) { + ERROR("Failed to sprintf auths %s/%s", key_dir, AUTH_AESKEY_NAME); + return; } + + g_aeskey = util_strdup_s(path); + return; } diff --git a/src/daemon/modules/image/oci/registry/aes.h b/src/daemon/modules/image/oci/registry/aes.h index 17e5f10..b58fce0 100644 --- a/src/daemon/modules/image/oci/registry/aes.h +++ b/src/daemon/modules/image/oci/registry/aes.h @@ -23,7 +23,7 @@ extern "C" { #define AUTH_AESKEY_NAME "aeskey" #define DEFAULT_AUTH_AESKEY "/root/.isulad/" AUTH_AESKEY_NAME -void aes_set_key_path(char *key_path); +void aes_set_key_dir(char *key_dir); // output length is "input_len+AES_256_CFB_IV_LEN" int aes_encode(unsigned char *input, size_t input_len, unsigned char **output); // output length is "input_len-AES_256_CFB_IV_LEN" diff --git a/src/daemon/modules/image/oci/registry/auths.c b/src/daemon/modules/image/oci/registry/auths.c index deecf9b..c879693 100644 --- a/src/daemon/modules/image/oci/registry/auths.c +++ b/src/daemon/modules/image/oci/registry/auths.c @@ -52,13 +52,7 @@ void auths_set_dir(char *auth_dir) g_auth_path = util_strdup_s(path); - sret = snprintf(path, sizeof(path), "%s/%s", auth_dir, AUTH_AESKEY_NAME); - if (sret < 0 || (size_t)sret >= sizeof(path)) { - ERROR("Failed to sprintf auths aeskey, auth dir: %s", auth_dir); - return; - } - - aes_set_key_path(path); + aes_set_key_dir(auth_dir); return; } -- GitLab