--- /dev/null
+\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
+++ /dev/null
-#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