From: greatim Date: Fri, 25 Nov 2016 06:33:00 +0000 (+0900) Subject: refactor calling encryption functions of plugin X-Git-Tag: accepted/tizen/3.0/common/20161129.102835^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=34ed53befff4507579eebad21922a4524696af74;p=sdk%2Ftarget%2Fsdbd.git refactor calling encryption functions of plugin modify the implementation of encryption function according to new plugin architecture Change-Id: I62c142b5bf95fe7c4d8529c9272213274883b0a5 Signed-off-by: greatim --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 47edfd9..83b0a0a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,7 @@ SET(SDBD_SRCS src/default_plugin_appcmd.c src/hashtable.c src/plugin.c - src/transport_security.c + src/plugin_encrypt.c ) include(FindPkgConfig) diff --git a/src/plugin.c b/src/plugin.c index bee7aa4..68a02c6 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -172,7 +172,7 @@ int is_supported_by_plugin ( int cmd ) return ret; } -static int request_sync_cmd ( int cmd, parameters* in, parameters* out ) +int request_sync_cmd ( int cmd, parameters* in, parameters* out ) { int ret, pr; diff --git a/src/plugin.h b/src/plugin.h index fa8288e..47ed3dc 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -28,6 +28,8 @@ int default_plugin_async_proc ( int cmd, parameters* in, int out_fd ); void load_sdbd_plugin(); void unload_sdbd_plugin(); +int request_sync_cmd ( int cmd, parameters* in, parameters* out ); + // return 1 if plugin support given command // return 0 if plugin does not support given command int is_supported_by_plugin ( int cmd ); diff --git a/src/plugin_encrypt.c b/src/plugin_encrypt.c new file mode 100644 index 0000000..1c6b34a --- /dev/null +++ b/src/plugin_encrypt.c @@ -0,0 +1,234 @@ + +#include + +//#define LOG_TAG "SDBD" +//#include +#define TRACE_TAG TRACE_SDB +#include "log.h" + +#include "plugin.h" +#include "plugin_encrypt.h" +#include "parameter.h" +#include "sdbd_plugin.h" + +#define SAKEP_AKE_MSG_RECORD_FIXED_LEN 36 +#define SAKEP_AES_ECB_ADDED_PADDING_SIZE 16 + +// return 1 if success +// return 0 otherwise +int security_init(const int nSessionID, const char* pUserID) +{ + int success = 0; + int ret; + parameters in, out; + + if (pUserID == NULL) { + in.number_of_parameter = 1; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + } else { + in.number_of_parameter = 2; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + in.array_of_parameter[1].type = type_string; + in.array_of_parameter[1].v_string.length = strlen(pUserID); + in.array_of_parameter[1].v_string.data = strdup(pUserID); + } + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_INIT, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_deinit(const int nSessionID) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 1; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DEINIT, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_parse_server_hello(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 2; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + in.array_of_parameter[1].type = type_chunk; + in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length; + in.array_of_parameter[1].v_chunk.data = pApacket->data; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_HELLO, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + success = 1; + release_parameters ( &out ); + } + + // avoid to free + in.array_of_parameter[1].v_chunk.data = NULL; + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_gen_client_hello(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 1; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_HELLO, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size); + pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size; + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_parse_server_ack(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 2; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + in.array_of_parameter[1].type = type_chunk; + in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length; + in.array_of_parameter[1].v_chunk.data = pApacket->data; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_ACK, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + success = 1; + release_parameters ( &out ); + } + + // avoid to free + in.array_of_parameter[1].v_chunk.data = NULL; + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_gen_client_ack(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 1; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_ACK, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size); + pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size; + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_encrypt(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 2; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + in.array_of_parameter[1].type = type_chunk; + in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length; + in.array_of_parameter[1].v_chunk.data = pApacket->data; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_ENCRYPT, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size); + pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size; + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + +// return 1 if success +// return 0 otherwise +int security_decrypt(const int nSessionID, apacket* pApacket) +{ + int success = 0; + int ret; + parameters in, out; + + in.number_of_parameter = 2; + in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) ); + in.array_of_parameter[0].type = type_int32; + in.array_of_parameter[0].v_int32 = nSessionID; + in.array_of_parameter[1].type = type_chunk; + in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length; + in.array_of_parameter[1].v_chunk.data = pApacket->data; + + ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DECRYPT, &in, &out ); + if ( ret == PLUGIN_CMD_SUCCESS ) { + memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size); + pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size; + success = 1; + release_parameters ( &out ); + } + + release_parameters ( &in ); + return success; +} + diff --git a/src/transport_security.h b/src/plugin_encrypt.h similarity index 89% rename from src/transport_security.h rename to src/plugin_encrypt.h index 12fd689..c54ff2b 100644 --- a/src/transport_security.h +++ b/src/plugin_encrypt.h @@ -1,11 +1,8 @@ #ifndef __TRANSPORT_SECURITY_H__ #define __TRANSPORT_SECURITY_H__ -#include #include "sdb.h" -int load_sdbd_plugin_security(); - int security_init(const int nID, const char* pUserID); int security_deinit(const int nSessionID); int security_parse_server_hello(const int nSessionID, apacket* pApacket); diff --git a/src/sdb.c b/src/sdb.c index 50cf9ed..ac7f573 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -45,7 +45,7 @@ #include "sdbd_plugin.h" #ifdef SUPPORT_ENCRYPT -#include "transport_security.h" +#include "plugin_encrypt.h" #endif #if !SDB_HOST @@ -392,19 +392,21 @@ void send_encr_fail(apacket* p, atransport *t, unsigned failed_value){ /* desc. : 암호화 메시지 핸들링 parameter : [in] apacket* p : sdbd로 들어온 메시지 - [in/out] apacket* enc_p : sdb server로 전송할 메시지 [in/out] atransport *t : 현재 연결에 대한 atransport ret : 0 : 정상적으로 메시지 전송 -1: 메시지 전송 실패 */ -int handle_encr_packet(apacket* p, apacket* enc_p, atransport *t){ +int handle_encr_packet(apacket* p, atransport *t){ static int sessionID = 0; int retVal = 0; + apacket* enc_p = NULL; + if(p->msg.arg0 == ENCR_SET_ON_REQ){ // hello 메시지인 경우 t->sessionID = sessionID; if((retVal = security_init(t->sessionID, NULL)) == 1){ // 암호화 handshaking을 위한 init if(security_parse_server_hello(t->sessionID, p) == 1){ // hello 메시지 파싱 D("security_parse_server_hello success\n"); + enc_p = get_apacket(); if(security_gen_client_hello(t->sessionID, enc_p) == 1){ // hello 메시지 생성 D("security_gen_client_hello success\n"); enc_p->msg.command = A_ENCR; @@ -443,6 +445,7 @@ int handle_encr_packet(apacket* p, apacket* enc_p, atransport *t){ } else if(p->msg.arg0 == ENCR_SET_ON_OK){ // ack 메시지인 경우 if(security_parse_server_ack(t->sessionID, p) == 1){ // ack 메시지 파싱 + enc_p = get_apacket(); if(security_gen_client_ack(t->sessionID, enc_p) == 1){ // ack 메시지 생성 D("security_gen_client_ack success\n"); enc_p->msg.command = A_ENCR; @@ -890,9 +893,7 @@ void handle_packet(apacket *p, atransport *t) #ifdef SUPPORT_ENCRYPT case A_ENCR: // 암호화 메시지인 경우 if(t->connection_state != CS_OFFLINE) { - apacket* enc_p = get_apacket(); - handle_encr_packet(p, enc_p, t); - //put_apacket(enc_p); + handle_encr_packet(p, t); } break; #endif diff --git a/src/sdbd_plugin.h b/src/sdbd_plugin.h index bcaaa8d..e98ef69 100644 --- a/src/sdbd_plugin.h +++ b/src/sdbd_plugin.h @@ -35,6 +35,15 @@ #define PLUGIN_SYNC_CMD_GET_LOCK_STATE 1008 #define PLUGIN_SYNC_CMD_GET_SHELL_ENV 1009 +#define PLUGIN_SYNC_CMD_SEC_INIT 1100 +#define PLUGIN_SYNC_CMD_SEC_DEINIT 1101 +#define PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_HELLO 1102 +#define PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_HELLO 1103 +#define PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_ACK 1104 +#define PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_ACK 1105 +#define PLUGIN_SYNC_CMD_SEC_ENCRYPT 1106 +#define PLUGIN_SYNC_CMD_SEC_DECRYPT 1107 + // asynchronous command #define PLUGIN_ASYNC_CMD_AUTH_CONFIRM_PUBLIC 2000 #define PLUGIN_ASYNC_CMD_APPCMD_SERVICE 2001 diff --git a/src/transport.c b/src/transport.c index bc471d6..470e55f 100644 --- a/src/transport.c +++ b/src/transport.c @@ -28,7 +28,7 @@ #include "sdb.h" #ifdef SUPPORT_ENCRYPT -#include "transport_security.h" +#include "plugin_encrypt.h" #endif static void transport_unref(atransport *t); diff --git a/src/transport_security.c b/src/transport_security.c deleted file mode 100644 index 37d3b58..0000000 --- a/src/transport_security.c +++ /dev/null @@ -1,261 +0,0 @@ -#include -#include "transport_security.h" - -#define LOG_TAG "SDBD" -#include - -#define SAKEP_AKE_MSG_RECORD_FIXED_LEN 36 -#define SAKEP_AES_ECB_ADDED_PADDING_SIZE 16 - -extern void* g_plugin_handle; - -typedef int (*SDBD_PLUGIN_CMD_SECURITY_INIT_PROC_PTR)(const int nID, const char* pUserID); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_DEINIT_PROC_PTR)(const int nID); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_PROC_PTR)(const int nID, const unsigned char* pSrc, const unsigned int nSrcLen, - unsigned char* pDst, unsigned int* pnDstLen); -typedef int (*SDBD_PLUGIN_CMD_SECURITY_DECRYPT_PROC_PTR)(const int nID, const unsigned char* pSrc, const unsigned int nSrcLen, - unsigned char* pDst, unsigned int* pnDstLen); - -SDBD_PLUGIN_CMD_SECURITY_INIT_PROC_PTR sdbd_plugin_cmd_security_init = NULL; -SDBD_PLUGIN_CMD_SECURITY_DEINIT_PROC_PTR sdbd_plugin_cmd_security_deinit = NULL; -SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_PROC_PTR sdbd_plugin_cmd_security_parse_server_hello = NULL; -SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_PROC_PTR sdbd_plugin_cmd_security_gen_client_hello = NULL; -SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_PROC_PTR sdbd_plugin_cmd_security_parse_server_ack = NULL; -SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_PROC_PTR sdbd_plugin_cmd_security_gen_client_ack = NULL; -SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_PROC_PTR sdbd_plugin_cmd_security_encrypt = NULL; -SDBD_PLUGIN_CMD_SECURITY_DECRYPT_PROC_PTR sdbd_plugin_cmd_security_decrypt = NULL; - -#define SDBD_PLUGIN_CMD_SECURITY_INIT_INTF "sdbd_plugin_cmd_security_init" -#define SDBD_PLUGIN_CMD_SECURITY_DEINIT_INTF "sdbd_plugin_cmd_security_deinit" -#define SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_INTF "sdbd_plugin_cmd_security_parse_server_hello" -#define SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_INTF "sdbd_plugin_cmd_security_gen_client_hello" -#define SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_INTF "sdbd_plugin_cmd_security_parse_server_ack" -#define SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_INTF "sdbd_plugin_cmd_security_gen_client_ack" -#define SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_INTF "sdbd_plugin_cmd_security_encrypt" -#define SDBD_PLUGIN_CMD_SECURITY_DECRYPT_INTF "sdbd_plugin_cmd_security_decrypt" - -int load_sdbd_plugin_security() { - - if( sdbd_plugin_cmd_security_init == NULL ) { - LOGI("sdbd_plugin_cmd_security_init == NULL, dlsym sdbd_plugin_cmd_security_init"); - sdbd_plugin_cmd_security_init = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_INIT_INTF); - if( sdbd_plugin_cmd_security_init == NULL ) { - LOGI("sdbd_plugin_cmd_security_init == NULL, dlerror = [%s]", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_init = [0x%p]", sdbd_plugin_cmd_security_init); - - - if( sdbd_plugin_cmd_security_deinit == NULL ) { - LOGI("sdbd_plugin_cmd_security_deinit == NULL, dlsym sdbd_plugin_cmd_security_deinit\n"); - sdbd_plugin_cmd_security_deinit = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_DEINIT_INTF); - if( sdbd_plugin_cmd_security_deinit == NULL ) { - LOGI("sdbd_plugin_cmd_security_deinit == NULL, dlerror = [%s]\n", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_deinit = [0x%p]\n", sdbd_plugin_cmd_security_deinit); -// - if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, dlsym sdbd_plugin_cmd_security_parse_server_hello\n"); - sdbd_plugin_cmd_security_parse_server_hello = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_INTF); - if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, dlerror = [%s]\n", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_parse_server_hello = [0x%p]\n", sdbd_plugin_cmd_security_parse_server_hello); -// - if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, dlsym sdbd_plugin_cmd_security_gen_client_hello\n"); - sdbd_plugin_cmd_security_gen_client_hello = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_INTF); - if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, dlerror = [%s]\n", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_gen_client_hello = [0x%p]\n", sdbd_plugin_cmd_security_gen_client_hello); -// - if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, dlsym sdbd_plugin_cmd_security_parse_server_ack\n"); - sdbd_plugin_cmd_security_parse_server_ack = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_INTF); - if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, dlerror = [%s]\n", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_parse_server_ack = [0x%p]\n", sdbd_plugin_cmd_security_parse_server_ack); -// - if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, dlsym sdbd_plugin_cmd_security_gen_client_ack\n"); - sdbd_plugin_cmd_security_gen_client_ack = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_INTF); - if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, dlerror = [%s]\n", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_gen_client_ack = [0x%p]\n", sdbd_plugin_cmd_security_gen_client_ack); - - if( sdbd_plugin_cmd_security_encrypt == NULL ) { - LOGI("sdbd_plugin_cmd_security_encrypt == NULL, dlsym sdbd_plugin_cmd_security_encrypt"); - sdbd_plugin_cmd_security_encrypt = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_INTF); - if( sdbd_plugin_cmd_security_encrypt == NULL ) { - LOGI("sdbd_plugin_cmd_security_encrypt == NULL, dlerror = [%s]", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_encrypt = [0x%p]", sdbd_plugin_cmd_security_encrypt); - - if( sdbd_plugin_cmd_security_decrypt == NULL ) { - LOGI("sdbd_plugin_cmd_security_decrypt == NULL, dlsym sdbd_plugin_cmd_security_decrypt"); - sdbd_plugin_cmd_security_decrypt = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_DECRYPT_INTF); - if( sdbd_plugin_cmd_security_decrypt == NULL ) { - LOGI("sdbd_plugin_cmd_security_decrypt == NULL, dlerror = [%s]", dlerror()); - } - } - LOGI("sdbd_plugin_cmd_security_decrypt = [0x%p]", sdbd_plugin_cmd_security_decrypt); - - return 1; -} - - -int security_init(const int nSessionID, const char* pUserID) { - - if( sdbd_plugin_cmd_security_init == NULL ) { - LOGI("sdbd_plugin_cmd_security_init == NULL, return 0"); - return 0; - } - - return sdbd_plugin_cmd_security_init(nSessionID, pUserID); -} - -int security_deinit(const int nSessionID) { - if( sdbd_plugin_cmd_security_deinit == NULL ) { - LOGI("sdbd_plugin_cmd_security_deinit == NULL, return 0\n"); - return 0; - } - - return sdbd_plugin_cmd_security_deinit(nSessionID); -} - - -int security_parse_server_hello(const int nSessionID, apacket* pApacket){ - if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, return 0\n"); - return 0; - } - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0\n"); - return 0; - } - - if( 0 == sdbd_plugin_cmd_security_parse_server_hello(nSessionID, pApacket->data, &pApacket->msg.data_length) ) { - LOGI("sdbd_plugin_cmd_security_parse_server_hello return 0\n"); - return 0; - } - return 1; -} - -int security_gen_client_hello(const int nSessionID, apacket* pApacket){ - if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, return 0\n"); - return 0; - } - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0\n"); - return 0; - } - - if( 0 == sdbd_plugin_cmd_security_gen_client_hello(nSessionID, pApacket->data, &pApacket->msg.data_length) ) { - LOGI("sdbd_plugin_cmd_security_gen_client_hello return 0\n"); - return 0; - } - return 1; -} - -int security_parse_server_ack(const int nSessionID, apacket* pApacket){ - if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, return 0\n"); - return 0; - } - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0\n"); - return 0; - } - - if( 0 == sdbd_plugin_cmd_security_parse_server_ack(nSessionID, pApacket->data, &pApacket->msg.data_length) ) { - LOGI("sdbd_plugin_cmd_security_parse_server_ack return 0\n"); - return 0; - } - return 1; -} - -int security_gen_client_ack(const int nSessionID, apacket* pApacket){ - if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) { - LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, return 0\n"); - return 0; - } - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0\n"); - return 0; - } - - if( 0 == sdbd_plugin_cmd_security_gen_client_ack(nSessionID, pApacket->data, &pApacket->msg.data_length) ) { - LOGI("sdbd_plugin_cmd_security_gen_client_ack return 0\n"); - return 0; - } - return 1; -} - - -int security_encrypt(const int nSessionID, apacket* pApacket) { - - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0"); - return 0; - } - - unsigned char *szTemp; - szTemp = (unsigned char *)malloc(pApacket->msg.data_length + SAKEP_AKE_MSG_RECORD_FIXED_LEN + SAKEP_AES_ECB_ADDED_PADDING_SIZE); - memset(szTemp, 0x00, pApacket->msg.data_length + SAKEP_AKE_MSG_RECORD_FIXED_LEN + SAKEP_AES_ECB_ADDED_PADDING_SIZE); - - unsigned int nDstLen = 0; - if( 0 == sdbd_plugin_cmd_security_encrypt(nSessionID, pApacket->data, pApacket->msg.data_length, szTemp, &nDstLen) ) { - LOGI("sdbd_plugin_cmd_security_encrypt return 0"); - return 0; - } - - int i=0; - for(i=0 ; idata[i] = szTemp[i]; - } - - pApacket->msg.data_length = nDstLen; - free(szTemp); - return 1; - -} - -int security_decrypt(const int nSessionID, apacket* pApacket) { - - if( pApacket == NULL ) { - LOGI("pApacket == NULL, return 0"); - return 0; - } - - unsigned char *szTemp; - szTemp = (unsigned char *)malloc(pApacket->msg.data_length); - memset(szTemp, 0x00, pApacket->msg.data_length); - unsigned int nDstLen = 0; - if( 0 == sdbd_plugin_cmd_security_decrypt(nSessionID, pApacket->data, pApacket->msg.data_length, szTemp, &nDstLen) ) { - LOGI("sdbd_plugin_cmd_security_decrypt return 0"); - return 0; - } - - int i = 0; - for(i=0 ; idata[i] = szTemp[i]; - } - - pApacket->msg.data_length = nDstLen; - free(szTemp); - return 1; -}