refactor calling encryption functions of plugin 01/100101/1 accepted/tizen/3.0/common/20161129.102835 accepted/tizen/3.0/ivi/20161129.001726 accepted/tizen/3.0/mobile/20161129.001637 accepted/tizen/3.0/tv/20161129.001656 accepted/tizen/3.0/wearable/20161129.001709 submit/tizen_3.0/20161128.031728
authorgreatim <jaewon81.lim@samsung.com>
Fri, 25 Nov 2016 06:33:00 +0000 (15:33 +0900)
committergreatim <jaewon81.lim@samsung.com>
Fri, 25 Nov 2016 06:33:00 +0000 (15:33 +0900)
modify the implementation of encryption function according to new plugin architecture

Change-Id: I62c142b5bf95fe7c4d8529c9272213274883b0a5
Signed-off-by: greatim <jaewon81.lim@samsung.com>
CMakeLists.txt
src/plugin.c
src/plugin.h
src/plugin_encrypt.c [new file with mode: 0644]
src/plugin_encrypt.h [moved from src/transport_security.h with 89% similarity]
src/sdb.c
src/sdbd_plugin.h
src/transport.c
src/transport_security.c [deleted file]

index 47edfd9..83b0a0a 100644 (file)
@@ -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)
index bee7aa4..68a02c6 100644 (file)
@@ -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;
 
index fa8288e..47ed3dc 100644 (file)
@@ -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 (file)
index 0000000..1c6b34a
--- /dev/null
@@ -0,0 +1,234 @@
+\r
+#include <string.h>\r
+\r
+//#define LOG_TAG "SDBD"\r
+//#include <dlog.h>\r
+#define TRACE_TAG TRACE_SDB\r
+#include "log.h"\r
+\r
+#include "plugin.h"\r
+#include "plugin_encrypt.h"\r
+#include "parameter.h"\r
+#include "sdbd_plugin.h"\r
+\r
+#define SAKEP_AKE_MSG_RECORD_FIXED_LEN          36\r
+#define SAKEP_AES_ECB_ADDED_PADDING_SIZE        16\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_init(const int nSessionID, const char* pUserID)\r
+{\r
+    int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    if (pUserID == NULL) {\r
+        in.number_of_parameter = 1;\r
+        in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+        in.array_of_parameter[0].type = type_int32;\r
+        in.array_of_parameter[0].v_int32 = nSessionID;\r
+    } else {\r
+        in.number_of_parameter = 2;\r
+        in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+        in.array_of_parameter[0].type = type_int32;\r
+        in.array_of_parameter[0].v_int32 = nSessionID;\r
+        in.array_of_parameter[1].type = type_string;\r
+        in.array_of_parameter[1].v_string.length = strlen(pUserID);\r
+        in.array_of_parameter[1].v_string.data = strdup(pUserID);\r
+    }\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_INIT, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_deinit(const int nSessionID)\r
+{\r
+    int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 1;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DEINIT, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_parse_server_hello(const int nSessionID, apacket* pApacket)\r
+{\r
+    int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 2;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+    in.array_of_parameter[1].type = type_chunk;\r
+    in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
+    in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_HELLO, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    // avoid to free\r
+    in.array_of_parameter[1].v_chunk.data = NULL;\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_gen_client_hello(const int nSessionID, apacket* pApacket)\r
+{\r
+    int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 1;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_HELLO, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
+        pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_parse_server_ack(const int nSessionID, apacket* pApacket)\r
+{\r
+       int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 2;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+    in.array_of_parameter[1].type = type_chunk;\r
+    in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
+    in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_ACK, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    // avoid to free\r
+    in.array_of_parameter[1].v_chunk.data = NULL;\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_gen_client_ack(const int nSessionID, apacket* pApacket)\r
+{\r
+    int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 1;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_ACK, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
+        pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_encrypt(const int nSessionID, apacket* pApacket)\r
+{\r
+       int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 2;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+    in.array_of_parameter[1].type = type_chunk;\r
+    in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
+    in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_ENCRYPT, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
+        pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
+// return 1 if success\r
+// return 0 otherwise\r
+int security_decrypt(const int nSessionID, apacket* pApacket)\r
+{\r
+       int success = 0;\r
+    int ret;\r
+    parameters in, out;\r
+\r
+    in.number_of_parameter = 2;\r
+    in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
+    in.array_of_parameter[0].type = type_int32;\r
+    in.array_of_parameter[0].v_int32 = nSessionID;\r
+    in.array_of_parameter[1].type = type_chunk;\r
+    in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
+    in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
+\r
+    ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DECRYPT, &in, &out );\r
+    if ( ret == PLUGIN_CMD_SUCCESS ) {\r
+        memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
+        pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
+        success = 1;\r
+        release_parameters ( &out );\r
+    }\r
+\r
+    release_parameters ( &in );\r
+    return success;\r
+}\r
+\r
similarity index 89%
rename from src/transport_security.h
rename to src/plugin_encrypt.h
index 12fd689..c54ff2b 100644 (file)
@@ -1,11 +1,8 @@
 #ifndef __TRANSPORT_SECURITY_H__\r
 #define __TRANSPORT_SECURITY_H__\r
 \r
-#include <stdio.h>\r
 #include "sdb.h"\r
 \r
-int load_sdbd_plugin_security();\r
-\r
 int security_init(const int nID, const char* pUserID);\r
 int security_deinit(const int nSessionID);\r
 int security_parse_server_hello(const int nSessionID, apacket* pApacket);\r
index 50cf9ed..ac7f573 100644 (file)
--- 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
index bcaaa8d..e98ef69 100644 (file)
 #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
index bc471d6..470e55f 100644 (file)
@@ -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 (file)
index 37d3b58..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-#include <dlfcn.h>\r
-#include "transport_security.h"\r
-\r
-#define LOG_TAG "SDBD"\r
-#include <dlog.h>\r
-\r
-#define SAKEP_AKE_MSG_RECORD_FIXED_LEN                                                                                         36\r
-#define SAKEP_AES_ECB_ADDED_PADDING_SIZE                                                                               16\r
-\r
-extern void* g_plugin_handle;\r
-\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_INIT_PROC_PTR)(const int nID, const char* pUserID);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_DEINIT_PROC_PTR)(const int nID);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_PROC_PTR)(const int nID, unsigned char* pSrc, unsigned int* nSrcLen);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_PROC_PTR)(const int nID, const unsigned char* pSrc, const unsigned int nSrcLen,\r
-               unsigned char* pDst, unsigned int* pnDstLen);\r
-typedef int (*SDBD_PLUGIN_CMD_SECURITY_DECRYPT_PROC_PTR)(const int nID, const unsigned char* pSrc, const unsigned int nSrcLen,\r
-               unsigned char* pDst, unsigned int* pnDstLen);\r
-\r
-SDBD_PLUGIN_CMD_SECURITY_INIT_PROC_PTR sdbd_plugin_cmd_security_init = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_DEINIT_PROC_PTR sdbd_plugin_cmd_security_deinit = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_PROC_PTR sdbd_plugin_cmd_security_parse_server_hello = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_PROC_PTR sdbd_plugin_cmd_security_gen_client_hello = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_PROC_PTR sdbd_plugin_cmd_security_parse_server_ack = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_PROC_PTR sdbd_plugin_cmd_security_gen_client_ack = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_PROC_PTR sdbd_plugin_cmd_security_encrypt = NULL;\r
-SDBD_PLUGIN_CMD_SECURITY_DECRYPT_PROC_PTR sdbd_plugin_cmd_security_decrypt = NULL;\r
-\r
-#define SDBD_PLUGIN_CMD_SECURITY_INIT_INTF "sdbd_plugin_cmd_security_init"\r
-#define SDBD_PLUGIN_CMD_SECURITY_DEINIT_INTF "sdbd_plugin_cmd_security_deinit"\r
-#define SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_INTF "sdbd_plugin_cmd_security_parse_server_hello"\r
-#define SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_INTF "sdbd_plugin_cmd_security_gen_client_hello"\r
-#define SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_INTF "sdbd_plugin_cmd_security_parse_server_ack"\r
-#define SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_INTF "sdbd_plugin_cmd_security_gen_client_ack"\r
-#define SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_INTF "sdbd_plugin_cmd_security_encrypt"\r
-#define SDBD_PLUGIN_CMD_SECURITY_DECRYPT_INTF "sdbd_plugin_cmd_security_decrypt"\r
-\r
-int load_sdbd_plugin_security() {\r
-\r
-       if( sdbd_plugin_cmd_security_init == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_init == NULL, dlsym sdbd_plugin_cmd_security_init");\r
-               sdbd_plugin_cmd_security_init = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_INIT_INTF);\r
-               if( sdbd_plugin_cmd_security_init == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_init == NULL, dlerror = [%s]", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_init = [0x%p]", sdbd_plugin_cmd_security_init);\r
-\r
-       \r
-       if( sdbd_plugin_cmd_security_deinit == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_deinit == NULL, dlsym sdbd_plugin_cmd_security_deinit\n");\r
-               sdbd_plugin_cmd_security_deinit = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_DEINIT_INTF);\r
-               if( sdbd_plugin_cmd_security_deinit == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_deinit == NULL, dlerror = [%s]\n", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_deinit = [0x%p]\n", sdbd_plugin_cmd_security_deinit);\r
-//\r
-       if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, dlsym sdbd_plugin_cmd_security_parse_server_hello\n");\r
-               sdbd_plugin_cmd_security_parse_server_hello = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_HELLO_INTF);\r
-               if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, dlerror = [%s]\n", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_parse_server_hello = [0x%p]\n", sdbd_plugin_cmd_security_parse_server_hello);\r
-//\r
-       if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, dlsym sdbd_plugin_cmd_security_gen_client_hello\n");\r
-               sdbd_plugin_cmd_security_gen_client_hello = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_HELLO_INTF);\r
-               if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, dlerror = [%s]\n", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_gen_client_hello = [0x%p]\n", sdbd_plugin_cmd_security_gen_client_hello);\r
-//\r
-       if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, dlsym sdbd_plugin_cmd_security_parse_server_ack\n");\r
-               sdbd_plugin_cmd_security_parse_server_ack = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_PARSE_SERVER_ACK_INTF);\r
-               if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, dlerror = [%s]\n", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_parse_server_ack = [0x%p]\n", sdbd_plugin_cmd_security_parse_server_ack);\r
-//\r
-       if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, dlsym sdbd_plugin_cmd_security_gen_client_ack\n");\r
-               sdbd_plugin_cmd_security_gen_client_ack = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_GEN_CLIENT_ACK_INTF);\r
-               if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, dlerror = [%s]\n", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_gen_client_ack = [0x%p]\n", sdbd_plugin_cmd_security_gen_client_ack);\r
-\r
-       if( sdbd_plugin_cmd_security_encrypt == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_encrypt == NULL, dlsym sdbd_plugin_cmd_security_encrypt");\r
-               sdbd_plugin_cmd_security_encrypt = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_ENCRYPT_INTF);\r
-               if( sdbd_plugin_cmd_security_encrypt == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_encrypt == NULL, dlerror = [%s]", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_encrypt = [0x%p]", sdbd_plugin_cmd_security_encrypt);\r
-\r
-       if( sdbd_plugin_cmd_security_decrypt == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_decrypt == NULL, dlsym sdbd_plugin_cmd_security_decrypt");\r
-               sdbd_plugin_cmd_security_decrypt = dlsym(g_plugin_handle, SDBD_PLUGIN_CMD_SECURITY_DECRYPT_INTF);\r
-               if( sdbd_plugin_cmd_security_decrypt == NULL ) {\r
-                       LOGI("sdbd_plugin_cmd_security_decrypt == NULL, dlerror = [%s]", dlerror());\r
-               }\r
-       }\r
-       LOGI("sdbd_plugin_cmd_security_decrypt = [0x%p]", sdbd_plugin_cmd_security_decrypt);\r
-\r
-       return 1;\r
-}\r
-\r
-\r
-int security_init(const int nSessionID, const char* pUserID) {\r
-\r
-       if( sdbd_plugin_cmd_security_init == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_init == NULL, return 0");\r
-               return 0;\r
-       }\r
-\r
-       return sdbd_plugin_cmd_security_init(nSessionID, pUserID);\r
-}\r
-\r
-int security_deinit(const int nSessionID) {\r
-       if( sdbd_plugin_cmd_security_deinit == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_deinit == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-\r
-       return sdbd_plugin_cmd_security_deinit(nSessionID);\r
-}\r
-\r
-\r
-int security_parse_server_hello(const int nSessionID, apacket* pApacket){\r
-       if( sdbd_plugin_cmd_security_parse_server_hello == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_hello == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-       if( pApacket == NULL ) {\r
-               LOGI("pApacket == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-\r
-       if( 0 == sdbd_plugin_cmd_security_parse_server_hello(nSessionID, pApacket->data, &pApacket->msg.data_length) ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_hello return 0\n");\r
-               return 0;\r
-       }\r
-       return 1;\r
-}\r
-\r
-int security_gen_client_hello(const int nSessionID, apacket* pApacket){\r
-       if( sdbd_plugin_cmd_security_gen_client_hello == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_hello == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-       if( pApacket == NULL ) {\r
-               LOGI("pApacket == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-\r
-       if( 0 == sdbd_plugin_cmd_security_gen_client_hello(nSessionID, pApacket->data, &pApacket->msg.data_length) ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_hello return 0\n");\r
-               return 0;\r
-       }\r
-       return 1;\r
-}\r
-\r
-int security_parse_server_ack(const int nSessionID, apacket* pApacket){\r
-       if( sdbd_plugin_cmd_security_parse_server_ack == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_ack == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-       if( pApacket == NULL ) {\r
-               LOGI("pApacket == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-\r
-       if( 0 == sdbd_plugin_cmd_security_parse_server_ack(nSessionID, pApacket->data, &pApacket->msg.data_length) ) {\r
-               LOGI("sdbd_plugin_cmd_security_parse_server_ack return 0\n");\r
-               return 0;\r
-       }\r
-       return 1;\r
-}\r
-\r
-int security_gen_client_ack(const int nSessionID, apacket* pApacket){\r
-       if( sdbd_plugin_cmd_security_gen_client_ack == NULL ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_ack == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-       if( pApacket == NULL ) {\r
-               LOGI("pApacket == NULL, return 0\n");\r
-               return 0;\r
-       }\r
-\r
-       if( 0 == sdbd_plugin_cmd_security_gen_client_ack(nSessionID, pApacket->data, &pApacket->msg.data_length) ) {\r
-               LOGI("sdbd_plugin_cmd_security_gen_client_ack return 0\n");\r
-               return 0;\r
-       }\r
-       return 1;\r
-}\r
-\r
-\r
-int security_encrypt(const int nSessionID, apacket* pApacket) {\r
-\r
-       if( pApacket == NULL ) {\r
-               LOGI("pApacket == NULL, return 0");\r
-               return 0;\r
-       }\r
-\r
-       unsigned char *szTemp;\r
-       szTemp = (unsigned char *)malloc(pApacket->msg.data_length + SAKEP_AKE_MSG_RECORD_FIXED_LEN + SAKEP_AES_ECB_ADDED_PADDING_SIZE);\r
-       memset(szTemp, 0x00, pApacket->msg.data_length + SAKEP_AKE_MSG_RECORD_FIXED_LEN + SAKEP_AES_ECB_ADDED_PADDING_SIZE);\r
-\r
-       unsigned int nDstLen = 0;\r
-       if( 0 == sdbd_plugin_cmd_security_encrypt(nSessionID, pApacket->data, pApacket->msg.data_length, szTemp, &nDstLen) ) {\r
-               LOGI("sdbd_plugin_cmd_security_encrypt return 0");\r
-               return 0;\r
-       }\r
-\r
-       int i=0;\r
-       for(i=0 ; i<nDstLen ; ++i) {\r
-               pApacket->data[i] = szTemp[i];\r
-       }\r
-\r
-       pApacket->msg.data_length = nDstLen;\r
-       free(szTemp);\r
-       return 1;\r
-\r
-}\r
-\r
-int security_decrypt(const int nSessionID, apacket* pApacket) {\r
-\r
-       if( pApacket == NULL ) {\r
-                       LOGI("pApacket == NULL, return 0");\r
-                       return 0;\r
-       }\r
-\r
-       unsigned char *szTemp;\r
-       szTemp = (unsigned char *)malloc(pApacket->msg.data_length);\r
-       memset(szTemp, 0x00, pApacket->msg.data_length);\r
-       unsigned int nDstLen = 0;\r
-       if( 0 == sdbd_plugin_cmd_security_decrypt(nSessionID, pApacket->data, pApacket->msg.data_length, szTemp, &nDstLen) ) {\r
-               LOGI("sdbd_plugin_cmd_security_decrypt return 0");\r
-               return 0;\r
-       }\r
-\r
-       int i = 0;\r
-       for(i=0 ; i<nDstLen ; ++i) {\r
-               pApacket->data[i] = szTemp[i];\r
-       }\r
-\r
-       pApacket->msg.data_length = nDstLen;\r
-       free(szTemp);\r
-       return 1;\r
-}\r