[APR-5656]kernel_netlink: Hide a Encryption/integrity key val
authorsz.kim <sz.kim@samsung.com>
Thu, 17 Sep 2020 10:38:41 +0000 (19:38 +0900)
committerrobot <robot@samsung.com>
Wed, 21 Oct 2020 14:10:13 +0000 (23:10 +0900)
Change-Id: I010fbf93d7edd8ce29c755ea16b1f3bde165b016
Signed-off-by: sz.kim <sz.kim@samsung.com>
src/libcharon/Android.mk
src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/libcharon/re_key/re_key.c [new file with mode: 0644]
src/libcharon/sa/ikev2/keymat_v2.c

index 5ff87631f3470fd9ee774a46ab4e4a041ebd503e..3edd59484a4a8dd5be4c2ff3f22e1293813a3de5 100755 (executable)
@@ -147,7 +147,8 @@ libcharon_la_SOURCES += \
        comm/comm_msg.c comm/alerts.c \
        comm/vendor_request_data.c \
        comm/vendor_response_data.c \
-       comm/vendor_request_list.c
+       comm/vendor_request_list.c \
+       re_key/re_key.c
 endif
 LOCAL_SRC_FILES := $(filter %.c,$(libcharon_la_SOURCES))
 
@@ -255,6 +256,7 @@ ifneq ($(call plugin_enabled, stroke),)
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/../stroke/ $(LOCAL_PATH)/plugins/counters
 ifneq ($(strongswan_BUILD_VoWiFi),)
 LOCAL_C_INCLUDES += $(LOCAL_PATH)/comm/
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/re_key/
 endif
 endif
 
index 983b09842b89fb2e2186b6b6ae3295d4893d7822..8f7f30ee5e205eb66d6bf003161b8e6b9095e601 100755 (executable)
@@ -1606,7 +1606,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
        memset(&request, 0, sizeof(request));
        format_mark(markstr, sizeof(markstr), id->mark);
 
-       DBG2(DBG_KNL, "adding SAD entry with SPI %.8x and reqid {%u}%s",
+       DBG1(DBG_KNL, "adding SAD entry with SPI %.8x and reqid {%u}%s",
                 ntohl(id->spi), data->reqid, markstr);
 
        hdr = &request.hdr;
@@ -1744,9 +1744,12 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
                                                 encryption_algorithm_names, data->enc_alg);
                                        goto failed;
                        }
-                       DBG2(DBG_KNL, "  using encryption algorithm %N with key size %d",
+                       DBG1(DBG_KNL, "  using encryption algorithm %N with key size %d",
                                 encryption_algorithm_names, data->enc_alg,
                                 data->enc_key.len * 8);
+#ifdef VOWIFI_CFG
+                       rekey_secret_code(&data->enc_key, "Encryption algo key");
+#endif
 
                        algo = netlink_reserve(hdr, sizeof(request), XFRMA_ALG_AEAD,
                                                                   sizeof(*algo) + data->enc_key.len);
@@ -1772,9 +1775,12 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
                                         encryption_algorithm_names, data->enc_alg);
                                goto failed;
                        }
-                       DBG2(DBG_KNL, "  using encryption algorithm %N with key size %d",
+                       DBG1(DBG_KNL, "  using encryption algorithm %N with key size %d",
                                 encryption_algorithm_names, data->enc_alg,
                                 data->enc_key.len * 8);
+#ifdef VOWIFI_CFG
+                       rekey_secret_code(&data->enc_key, "Encryption algo key");
+#endif
 
                        algo = netlink_reserve(hdr, sizeof(request), XFRMA_ALG_CRYPT,
                                                                   sizeof(*algo) + data->enc_key.len);
@@ -1800,8 +1806,11 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
                                 integrity_algorithm_names, data->int_alg);
                        goto failed;
                }
-               DBG2(DBG_KNL, "  using integrity algorithm %N with key size %d",
+               DBG1(DBG_KNL, "  using integrity algorithm %N with key size %d",
                         integrity_algorithm_names, data->int_alg, data->int_key.len * 8);
+#ifdef VOWIFI_CFG
+               rekey_secret_code(&data->int_key, "Integrity algo key");
+#endif
 
                switch (data->int_alg)
                {
diff --git a/src/libcharon/re_key/re_key.c b/src/libcharon/re_key/re_key.c
new file mode 100644 (file)
index 0000000..a3f9ebb
--- /dev/null
@@ -0,0 +1,41 @@
+\r
+#include <string.h>\r
+#include <stdio.h>\r
+#include <utils/chunk.h>\r
+#include <utils/debug.h>\r
+\r
+#define REKEY_MAX_BYTE 256\r
+#define HEX_STR_LEN 4\r
+\r
+#define E_NUM 7\r
+#define N_NUM 407\r
+\r
+/**\r
+ * Computes a^b mod c\r
+ */\r
+int powmod(long long a, long long b, int c) {\r
+       int res = 1;\r
+       while(b > 0) {\r
+               if(b & 1) {\r
+                       res = (res * a) % c;\r
+               }\r
+               b = b >> 1;\r
+               a = (a * a) % c;\r
+       }\r
+       return res;\r
+}\r
+\r
+/**\r
+ * Print Encrypt original secret codes\r
+ */\r
+void rekey_secret_code(chunk_t *ori_chunk, char *key_name) {\r
+       char rekey_str[REKEY_MAX_BYTE] = {0};\r
+       char val[HEX_STR_LEN];\r
+\r
+       for(int i = 0; i < ori_chunk->len ; i++) {\r
+               sprintf(val,"%03d", powmod(ori_chunk->ptr[i], E_NUM, N_NUM) );\r
+               strncat(rekey_str, val, 3);\r
+       }\r
+\r
+       DBG1(DBG_IKE, "%s : %s", key_name, rekey_str);\r
+}
\ No newline at end of file
index c0a13d1f4de85dd4d49d9467467bb49680567058..23cddf06785b46f38c86333a19f54ff0d5faa34b 100755 (executable)
 #include <crypto/prf_plus.h>
 #include <crypto/hashers/hash_algorithm_set.h>
 
-#ifdef VOWIFI_CFG
-
-#define REKEY_MAX_BYTE 256
-#define HEX_STR_LEN 4
-
-#define E_NUM 7
-#define N_NUM 407
-
-#endif
-
 typedef struct private_keymat_v2_t private_keymat_v2_t;
 
 /**
@@ -106,39 +96,6 @@ METHOD(keymat_t, create_nonce_gen, nonce_gen_t*,
        return lib->crypto->create_nonce_gen(lib->crypto);
 }
 
-
-#ifdef VOWIFI_CFG
-/**
- * Computes a^b mod c
- */
-int powmod(long long a, long long b, int c) {
-       int res = 1;
-       while(b > 0) {
-               if(b & 1) {
-                       res = (res * a) % c;
-               }
-               b = b >> 1;
-               a = (a * a) % c;
-       }
-       return res;
-}
-
-/**
- * Print Encrypt original secret codes
- */
-void rekey_secret_code(chunk_t *ori_chunk, char *sk_name) {
-       char rekey_str[REKEY_MAX_BYTE] = {0};
-       char val[HEX_STR_LEN];
-
-       for(int i = 0; i < ori_chunk->len ; i++) {
-               sprintf(val,"%03d", powmod(ori_chunk->ptr[i], E_NUM, N_NUM) );
-               strncat(rekey_str, val, 3);
-       }
-
-       DBG1(DBG_IKE, "%s : %s", sk_name, rekey_str);
-}
-#endif
-
 /**
  * Derive IKE keys for a combined AEAD algorithm
  */