summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rwxr-xr-x[-rw-r--r--]client/non-tz/include/ss_client_intf.h (renamed from client/include/ss_client_intf.h)12
-rw-r--r--client/non-tz/include/ss_client_ipc.h (renamed from client/include/ss_client_ipc.h)2
-rwxr-xr-xclient/non-tz/src/ss_client_intf.c576
-rw-r--r--client/non-tz/src/ss_client_ipc.c (renamed from client/src/ss_client_ipc.c)25
-rwxr-xr-xclient/non-tz/src/ss_manager.c592
-rw-r--r--client/src/ss_client_intf.c417
-rw-r--r--client/src/ss_manager.c214
7 files changed, 1191 insertions, 647 deletions
diff --git a/client/include/ss_client_intf.h b/client/non-tz/include/ss_client_intf.h
index 21ff92b..f59d448 100644..100755
--- a/client/include/ss_client_intf.h
+++ b/client/non-tz/include/ss_client_intf.h
@@ -1,7 +1,7 @@
/*
* secure storage
*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Kidong Kim <kd0228.kim@samsung.com>
*
@@ -66,3 +66,13 @@ int SsClientDataRead(const char* filepath, char* pRetBuf, size_t bufLen, size_t
int SsClientGetInfo(const char* filepath, ssm_file_info_t* sfi, ssm_flag flag, const char* group_id);
int SsClientDeleteFile(const char* pFilePath, ssm_flag flag, const char* group_id);
+
+int SsClientEncryptApplication(const char* pAppId, int idLen, const char* pBuffer, int bufLen, char** pEncryptedBuffer, int* pEncryptedBufLen);
+
+int SsClientDecryptApplication(const char* pBuffer, int bufLen, char** pDecryptedBuffer, int* pDecryptedBufLen);
+
+int SsClientEncryptPreloadedApplication(const char* pBuffer, int bufLen, char** ppEncryptedBuffer, int* pEncryptedBufLen);
+
+int SsClientDecryptPreloadedApplication(const char* pBuffer, int bufLen, char** ppDecryptedBuffer, int* pEncryptedBufLen);
+
+int DoCipher(const char* pInputBuf, int inputLen, char** ppOutBuf, int* pOutBufLen, char* pKey, int encryption);
diff --git a/client/include/ss_client_ipc.h b/client/non-tz/include/ss_client_ipc.h
index eb2f777..036d49b 100644
--- a/client/include/ss_client_ipc.h
+++ b/client/non-tz/include/ss_client_ipc.h
@@ -1,7 +1,7 @@
/*
* secure storage
*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Kidong Kim <kd0228.kim@samsung.com>
*
diff --git a/client/non-tz/src/ss_client_intf.c b/client/non-tz/src/ss_client_intf.c
new file mode 100755
index 0000000..6464a0d
--- /dev/null
+++ b/client/non-tz/src/ss_client_intf.c
@@ -0,0 +1,576 @@
+/*
+ * secure storage
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Kidong Kim <kd0228.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <openssl/evp.h>
+#include <openssl/crypto.h>
+
+#include "secure_storage.h"
+#include "ss_client_intf.h"
+#include "ss_client_ipc.h"
+#include "ss_manager.h"
+
+int SsClientDataStoreFromFile(const char* filepath, ssm_flag flag, const char* group_id)
+{
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ int temp_len = 0;
+
+ if(!filepath)
+ {
+ SLOGE("Parameter error in SsClientDataStoreFromFile..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail in SsClientDataStoreFromFile..\n");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ send_data->req_type = 1; // file store
+ send_data->enc_type = 1; // initial type
+ send_data->count = 0;
+ send_data->flag = flag; // flag
+ temp_len = strlen(filepath);
+ if(temp_len <= MAX_FILENAME_SIZE)
+ {
+ strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_SIZE);
+ send_data->data_infilepath[temp_len] = '\0';
+ }
+ else
+ {
+ SLOGE("filepath is too long.\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Free_and_Error;
+ }
+ memset(send_data->group_id, 0x00, MAX_GROUP_ID_SIZE+1);
+ if(group_id)
+ strncpy(send_data->group_id, group_id, MAX_GROUP_ID_SIZE);
+ else
+ strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_SIZE);
+
+ memset(send_data->buffer, 0x00, MAX_SEND_DATA_SIZE + 1);
+ recv_data = SsClientComm(send_data);
+
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientDataStoreFromBuffer(char* writebuffer, size_t bufLen, const char* filename, ssm_flag flag, const char* group_id)
+{
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ int temp_len = 0;
+
+ if(!writebuffer || !filename)
+ {
+ SLOGE("Parameter error in SsClientDataStoreFromBuffer..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail in SsClientDataStoreFromBuffer..\n");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ send_data->req_type = 2; // buffer store
+ send_data->enc_type = 1;
+ send_data->count = bufLen;
+ send_data->flag = flag;
+ temp_len = strlen(filename);
+ if(temp_len <= MAX_FILENAME_SIZE)
+ {
+ strncpy(send_data->data_infilepath, filename, MAX_FILENAME_SIZE);
+ send_data->data_infilepath[temp_len] = '\0';
+ }
+ else
+ {
+ SLOGE("filepath is too long.\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Free_and_Error;
+ }
+ memset(send_data->group_id, 0x00, MAX_GROUP_ID_SIZE+1);
+ if(group_id)
+ strncpy(send_data->group_id, group_id, MAX_GROUP_ID_SIZE);
+ else
+ strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_SIZE);
+
+ memcpy(send_data->buffer, writebuffer, bufLen);
+ recv_data = SsClientComm(send_data);
+
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientDataRead(const char* filepath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id)
+{
+ unsigned int count = (unsigned int)(bufLen / MAX_RECV_DATA_SIZE + 1);
+ unsigned int rest = (unsigned int)(bufLen % MAX_RECV_DATA_SIZE);
+ char* buffer;
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ int temp_len = 0;
+
+ if(!filepath)
+ {
+ SLOGE("filepath Parameter error in SsClientDataRead..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+ if(!readLen)
+ {
+ SLOGE("readLen Parameter error in SsClientDataRead..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ *readLen = 0;
+ buffer = pRetBuf;
+
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail in SsClientDataRead..\n");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ // fill send_data
+ send_data->req_type = 3; // read data from storage
+ send_data->enc_type = 1; // initial type
+ send_data->count = 0;
+ send_data->flag = flag & 0x000000ff; //flag;
+ temp_len = strlen(filepath);
+ if(temp_len <= MAX_FILENAME_SIZE)
+ {
+ strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_SIZE);
+ send_data->data_infilepath[temp_len] = '\0';
+ }
+ else
+ {
+ SLOGE("filepath is too long.\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Free_and_Error;
+ }
+ memset(send_data->group_id, 0x00, MAX_GROUP_ID_SIZE+1);
+ if(group_id)
+ strncpy(send_data->group_id, group_id, MAX_GROUP_ID_SIZE);
+ else
+ strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_SIZE);
+ memset(send_data->buffer, 0x00, MAX_SEND_DATA_SIZE+1);
+
+ // Call Server per 4KB data (count from 0 to ~)
+ for ( ; send_data->count < count; send_data->count++)
+ {
+ //receive data from server
+ recv_data = SsClientComm(send_data);
+
+ // check response type
+ if(recv_data.rsp_type != 1)
+ {
+ SLOGE("data read error from server...\n");
+ goto Free_and_Error;
+ }
+ // copy the last data (last count)
+ if(send_data->count == (count - 1))
+ {
+ memcpy(buffer, recv_data.buffer, rest);
+ *readLen += (size_t)rest;
+ goto Last;
+ //break;
+ }
+
+ memcpy(buffer, recv_data.buffer, MAX_RECV_DATA_SIZE);
+ *readLen += (size_t)recv_data.readLen;
+ buffer += recv_data.readLen;
+ }
+Last :
+ if(bufLen != *readLen)
+ {
+ SLOGE("Decrypted abnormally\n");
+ recv_data.rsp_type = SS_DECRYPTION_ERROR;
+ goto Free_and_Error;
+ }
+
+ SECURE_SLOGE("Decrypted file name : %s\n", recv_data.data_filepath);
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientGetInfo(const char* filepath, ssm_file_info_t* sfi, ssm_flag flag, const char* group_id)
+{
+
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ ssm_file_info_convert_t sfic;
+ int temp_len = 0;
+
+ if(!filepath || !sfi)
+ {
+ SLOGE("Parameter error in SsClientGetInfo..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail in SsClientGetInfo..\n");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ // fill send_data
+ send_data->req_type = 4; // get info type
+ send_data->enc_type = 1; // initial type
+ send_data->count = 0;
+ send_data->flag = flag & 0x000000ff; //flag;
+ temp_len = strlen(filepath);
+ if(temp_len <= MAX_FILENAME_SIZE)
+ {
+ strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_SIZE);
+ send_data->data_infilepath[temp_len] = '\0';
+ }
+ else
+ {
+ SLOGE("filepath is too long.\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Free_and_Error;
+ }
+ memset(send_data->group_id, 0x00, MAX_GROUP_ID_SIZE + 1);
+ if(group_id)
+ strncpy(send_data->group_id, group_id, MAX_GROUP_ID_SIZE);
+ else
+ strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_SIZE);
+ memset(send_data->buffer, 0x00, MAX_SEND_DATA_SIZE + 1);
+
+ recv_data = SsClientComm(send_data);
+
+ memcpy(sfic.fInfoArray, recv_data.buffer, sizeof(ssm_file_info_t));
+ sfi->originSize = sfic.fInfoStruct.originSize;
+ sfi->storedSize = sfic.fInfoStruct.storedSize;
+ memcpy(sfi->reserved, sfic.fInfoStruct.reserved, 8);
+
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientDeleteFile(const char *pFilePath, ssm_flag flag, const char* group_id)
+{
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ int temp_len = 0;
+
+ if(!pFilePath)
+ {
+ SLOGE("Parameter error in SsClientDeleteFile..\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail in SsClientDeleteFile..\n");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ send_data->req_type = 10; // delete file
+ send_data->enc_type = 1; // initial type
+ send_data->count = 0;
+ send_data->flag = flag; // flag
+ temp_len = strlen(pFilePath);
+ if(temp_len <= MAX_FILENAME_SIZE)
+ {
+ strncpy(send_data->data_infilepath, pFilePath, MAX_FILENAME_SIZE);
+ send_data->data_infilepath[temp_len] = '\0';
+ }
+ else
+ {
+ SLOGE("filepath is too long.\n");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Free_and_Error;
+ }
+ memset(send_data->group_id, 0x00, MAX_GROUP_ID_SIZE+1);
+ if(group_id)
+ strncpy(send_data->group_id, group_id, MAX_GROUP_ID_SIZE);
+ else
+ strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_SIZE);
+ memset(send_data->buffer, 0x00, MAX_SEND_DATA_SIZE+1);
+
+ recv_data = SsClientComm(send_data);
+
+Free_and_Error:
+ free(send_data);
+
+ SECURE_SLOGE("Deleted file name: %s\n", recv_data.data_filepath);
+
+Error:
+ return recv_data.rsp_type;
+}
+
+
+//////////////////////////////
+__attribute__((visibility("hidden")))
+int DoCipher(const char* pInputBuf, int inputLen, char** ppOutBuf, int* pOutBufLen, char* pKey, int encryption)
+{
+ static const unsigned char iv[16] = {0xbd, 0xc3, 0xc5, 0xa5, 0xb8, 0xae, 0xc6, 0xbc, 0x20, 0xb3, 0xeb, 0xb0, 0xe6, 0xbf, 0xec, 0x20};
+ struct evp_cipher_st* pCipherAlgorithm = NULL;
+ EVP_CIPHER_CTX cipherCtx;
+ int tempLen = 0;
+ int result = 0;
+ int finalLen = 0;
+
+ pCipherAlgorithm = EVP_aes_256_cbc();
+ tempLen = (int)((inputLen / pCipherAlgorithm->block_size + 1) * pCipherAlgorithm->block_size);
+
+ *ppOutBuf = (char*)calloc(tempLen, 1);
+ EVP_CIPHER_CTX_init(&cipherCtx);
+
+ result = EVP_CipherInit(&cipherCtx, pCipherAlgorithm, (const unsigned char*)pKey, iv, encryption);
+ if(result != 1)
+ {
+ SLOGE("[%d] EVP_CipherInit failed", result);
+ goto Error;
+ }
+
+ result = EVP_CIPHER_CTX_set_padding(&cipherCtx, 1);
+ if(result != 1)
+ {
+ SLOGE("[%d] EVP_CIPHER_CTX_set_padding failed", result);
+ goto Error;
+ }
+
+ //cipher update operation
+ result = EVP_CipherUpdate(&cipherCtx, (unsigned char*)*ppOutBuf, pOutBufLen, (const unsigned char*)pInputBuf, inputLen);
+ if(result != 1)
+ {
+ SLOGE("[%d] EVP_CipherUpdate failed", result);
+ goto Error;
+ }
+
+ //cipher final operation
+ result = EVP_CipherFinal(&cipherCtx, (unsigned char*)*ppOutBuf + *pOutBufLen, &finalLen);
+ if(result != 1)
+ {
+ SLOGE("[%d] EVP_CipherFinal failed", result);
+ goto Error;
+ }
+ *pOutBufLen = *pOutBufLen + finalLen;
+ goto Last;
+Error:
+ result = SS_ENCRYPTION_ERROR;
+ free(*ppOutBuf);
+
+Last:
+ EVP_CIPHER_CTX_cleanup(&cipherCtx);
+ if((result != 1) && (encryption != 1))
+ result = SS_DECRYPTION_ERROR;
+
+ return result;
+}
+
+int SsClientEncryptApplication(const char* pAppId, int idLen, const char* pBuffer, int bufLen, char** ppEncryptedBuffer, int* pEncryptedBufLen)
+{
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ static char duk[32];
+ static int dukExist = 0;
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ if(!dukExist)
+ {
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ send_data->req_type = 5; //request key
+ send_data->enc_type = 0;
+ send_data->count = 0;
+ send_data->flag = 1;
+ memset(send_data->group_id, 0, MAX_GROUP_ID_SIZE+1);
+ memcpy(send_data->group_id, pAppId, idLen);
+
+ recv_data = SsClientComm(send_data);
+
+ if(recv_data.rsp_type != 1)
+ {
+ SLOGE("failed to get data from server");
+ recv_data.rsp_type = SS_TZ_ERROR;
+ goto Free_and_Error;
+ }
+ memcpy(duk, recv_data.buffer, 32);
+ dukExist = 1;
+ }
+
+ if(DoCipher(pBuffer, bufLen, ppEncryptedBuffer, pEncryptedBufLen, duk, 1) != 1)
+ {
+ SLOGE("failed to encrypt data");
+ recv_data.rsp_type = SS_ENCRYPTION_ERROR;
+ goto Free_and_Error;
+ }
+
+ recv_data.rsp_type = 1;
+
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientDecryptApplication(const char* pBuffer, int bufLen, char** ppDecryptedBuffer, int* pDecryptedBufLen)
+{
+ ReqData_t* send_data = NULL;
+ RspData_t recv_data;
+ static char duk[32];
+ static int dukExist = 0;
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error");
+ recv_data.rsp_type = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ if(!dukExist)
+ {
+ send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
+ if(!send_data)
+ {
+ SLOGE("Memory allocation fail");
+ recv_data.rsp_type = SS_MEMORY_ERROR;
+ goto Error;
+ }
+
+ send_data->req_type = 5; //request key
+ send_data->enc_type = 0;
+ send_data->count = 0;
+ send_data->flag = 0;
+
+ recv_data = SsClientComm(send_data);
+
+ if(recv_data.rsp_type != 1)
+ {
+ SLOGE("Failed to get data from server");
+ recv_data.rsp_type = SS_TZ_ERROR;
+ goto Free_and_Error;
+ }
+ memcpy(duk, recv_data.buffer, 32);
+ dukExist = 1;
+ }
+
+ if(DoCipher(pBuffer, bufLen, ppDecryptedBuffer, pDecryptedBufLen, duk, 0) != 1)
+ {
+ SLOGE("failed to decrypt data");
+ recv_data.rsp_type = SS_DECRYPTION_ERROR;
+ goto Free_and_Error;
+ }
+ recv_data.rsp_type = 1;
+
+Free_and_Error:
+ free(send_data);
+Error:
+ return recv_data.rsp_type;
+}
+
+int SsClientEncryptPreloadedApplication(const char* pBuffer, int bufLen, char** ppEncryptedBuffer, int* pEncryptedBufLen)
+{
+ int result = 0;
+ char duk[36] = {0,};
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error");
+ result = SS_PARAM_ERROR;
+ goto Final;
+ }
+
+ if(DoCipher(pBuffer, bufLen, ppEncryptedBuffer, pEncryptedBufLen, duk, 1) != 1)
+ {
+ SLOGE("failed to decrypt data");
+ result = SS_ENCRYPTION_ERROR;
+ goto Final;
+ }
+
+ result = 1;
+
+Final:
+ return result;
+}
+
+int SsClientDecryptPreloadedApplication(const char* pBuffer, int bufLen, char** ppDecryptedBuffer, int* pDecryptedBufLen)
+{
+ int result = 0;
+ char duk[36] = {0,};
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error");
+ result = SS_PARAM_ERROR;
+ goto Final;
+ }
+
+ if(DoCipher(pBuffer, bufLen, ppDecryptedBuffer, pDecryptedBufLen, duk, 0) != 1)
+ {
+ SLOGE("failed to decrypt data");
+ result = SS_DECRYPTION_ERROR;
+ goto Final;
+ }
+
+ result = 1;
+
+Final:
+ return result;
+}
diff --git a/client/src/ss_client_ipc.c b/client/non-tz/src/ss_client_ipc.c
index 71cd05f..b986274 100644
--- a/client/src/ss_client_ipc.c
+++ b/client/non-tz/src/ss_client_ipc.c
@@ -1,7 +1,7 @@
/*
* secure storage
*
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Kidong Kim <kd0228.kim@samsung.com>
*
@@ -32,8 +32,6 @@
#include "ss_client_ipc.h"
#include "secure_storage.h"
-#include "security-server.h"
-
RspData_t SsClientComm(ReqData_t* client_data)
{
int sockfd = 0;
@@ -43,7 +41,7 @@ RspData_t SsClientComm(ReqData_t* client_data)
RspData_t recv_data = {0, };
int temp_len_in = 0;
int temp_len_sock = 0;
- int cookie_size = 0;
+ int read_len = 0;
send_data.req_type = client_data->req_type;
send_data.enc_type = client_data->enc_type;
@@ -52,18 +50,16 @@ RspData_t SsClientComm(ReqData_t* client_data)
temp_len_in = strlen(client_data->data_infilepath);
- strncpy(send_data.data_infilepath, client_data->data_infilepath, MAX_FILENAME_LEN - 1);
+ strncpy(send_data.data_infilepath, client_data->data_infilepath, MAX_FILENAME_SIZE);
send_data.data_infilepath[temp_len_in] = '\0';
- cookie_size = security_server_get_cookie_size();
- memcpy(send_data.cookie, client_data->cookie, cookie_size);
- strncpy(send_data.group_id, client_data->group_id, MAX_GROUP_ID_LEN - 1);
+ strncpy(send_data.group_id, client_data->group_id, MAX_GROUP_ID_SIZE);
- memcpy(send_data.buffer, client_data->buffer, MAX_SEND_DATA_LEN);
+ memcpy(send_data.buffer, client_data->buffer, MAX_SEND_DATA_SIZE);
if((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
{
- SLOGE("[%s] Error in function socket()..\n", __func__);
+ SLOGE("Error in function socket()..\n");
recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error
goto Error_exit;
}
@@ -78,21 +74,22 @@ RspData_t SsClientComm(ReqData_t* client_data)
if(connect(sockfd, (struct sockaddr*)&clientaddr, client_len) < 0)
{
- SLOGE("[%s] Error in function connect()..\n", __func__);
+ SLOGE("Error in function connect()..\n");
recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error
goto Error_close_exit;
}
if(write(sockfd, (char*)&send_data, sizeof(send_data)) < 0)
{
- SLOGE("[%s] Error in function write()..\n", __func__);
+ SLOGE("Error in function write()..\n");
recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error
goto Error_close_exit;
}
- if(read(sockfd, (char*)&recv_data, sizeof(recv_data)) < 0)
+ read_len = read(sockfd, (char*)&recv_data, sizeof(recv_data));
+ if(read_len < 0)
{
- SLOGE("[%s] Error in function read()..\n", __func__);
+ SLOGE("Error in function read()..\n");
recv_data.rsp_type = SS_SOCKET_ERROR; // ipc error
goto Error_close_exit;
}
diff --git a/client/non-tz/src/ss_manager.c b/client/non-tz/src/ss_manager.c
new file mode 100755
index 0000000..46662f2
--- /dev/null
+++ b/client/non-tz/src/ss_manager.c
@@ -0,0 +1,592 @@
+/*
+ * secure storage
+ *
+ * Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Kidong Kim <kd0228.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "secure_storage.h"
+#include "ss_client_intf.h"
+
+#ifndef SS_API
+#define SS_API __attribute__((visibility("default")))
+#endif
+
+/*****************************************************************************
+ * Internal Functions
+ *****************************************************************************/
+SS_API
+int ssm_getinfo(const char* pFilePath, ssm_file_info_t *sfi, ssm_flag flag, const char* group_id)
+{
+ int ret = 0;
+
+ if(!pFilePath || !sfi)
+ {
+ SLOGE("Parameter error in ssm_getinfo()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientGetInfo(pFilePath, sfi, flag, group_id);
+
+ if(ret == 1)
+ {
+ SLOGI("Getinfo Success.\n");
+ ret = 0; // return true
+ }
+ else
+ SLOGE("Getinfo Fail.\n");
+
+Error:
+ return ret;
+}
+
+/*****************************************************************************
+ * Manager APIs
+ *****************************************************************************/
+SS_API
+int ssm_write_file(const char* pFilePath, ssm_flag flag, const char* group_id)
+{
+ int ret = 0;
+
+ if(!pFilePath)
+ {
+ SLOGE("Parameter error in ssm_write_file()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX)
+ {
+ SLOGE("Parameter error in ssm_write_file()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDataStoreFromFile(pFilePath, flag, group_id);
+ if(ret == 1)
+ {
+ if(unlink(pFilePath) != 0) // if fail
+ {
+ SLOGE("unlink fail. [%s]\n", pFilePath);
+ return -1; // return false
+ }
+ SLOGI("Write file Success.\n");
+ return 0; // return true
+ }
+ else
+ SLOGE("Write file Fail.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_write_buffer(char* pWriteBuffer, size_t bufLen, const char* pFileName, ssm_flag flag, const char* group_id)
+{
+ int ret = 0;
+
+ if(!pWriteBuffer || !pFileName)
+ {
+ SLOGE("Parameter error in ssm_write_buffer()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+ if(bufLen <= 0 || bufLen > 4096)
+ {
+ SLOGE("Parameter error in ssm_write_buffer()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+ if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX)
+ {
+ SLOGE("Parameter error in ssm_write_buffer()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDataStoreFromBuffer(pWriteBuffer, bufLen, pFileName, flag, group_id);
+ if(ret == 1)
+ {
+ SLOGI("Write buffer Success.\n");
+ return 0; // return true
+ }
+ else
+ SLOGE("Write buffer Fail.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_read(const char* pFilePath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id)
+{
+ int ret = 0;
+ ssm_file_info_t sfi;
+
+ if(!pFilePath || !pRetBuf)
+ {
+ SLOGE("Parameter error in ssm_read()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+ if(!readLen)
+ {
+ SLOGE("Parameter error in ssm_read()...\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ // get info
+ ret = ssm_getinfo(pFilePath, &sfi, flag, group_id);
+ if(ret != 0) // ret != true?
+ {
+ SLOGE("getinfo error in ssm_read()..\n");
+ goto Error;
+ }
+ // in case of flag mismatch...
+ // check flag...
+ // To do :
+ if((bufLen > sfi.originSize) || (sfi.reserved[0] != (flag & 0x000000ff)))
+ {
+ SLOGE("Flag mismatch or buffer length error in ssm_read()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDataRead(pFilePath, pRetBuf, sfi.originSize, readLen, flag, group_id);
+
+ if(ret == 1)
+ {
+ SLOGI("Read Success.\n");
+ return 0; // return true
+ }
+ else
+ SLOGE("Read Fail.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_delete_file(const char *pFilePath, ssm_flag flag, const char* group_id)
+{
+ int ret = 0;
+
+ if(!pFilePath)
+ {
+ SLOGE("Parameter error in ssm_delete_file()..\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDeleteFile(pFilePath, flag, group_id);
+
+ if(ret == 1) // success
+ {
+ SLOGI("Delete file Success.\n");
+ return 0;
+ }
+ else // fail
+ SLOGE("Delete file Fail.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_encrypt_application(const char* pAppId, int idLen, const char* pBuffer, int bufLen, char** pEncryptedBuffer, int* pEncryptedBufLen)
+{
+ int ret = 0;
+
+ if(!pBuffer || bufLen ==0 || !pAppId || idLen == 0 || idLen+1 > MAX_GROUP_ID_SIZE)
+ {
+ SLOGE("Parameter error.\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientEncryptApplication(pAppId, idLen, pBuffer, bufLen, pEncryptedBuffer, pEncryptedBufLen);
+
+ if(ret == 1) // success
+ {
+ SLOGI("Application encryption succeeded.\n");
+ return 0;
+ }
+ else // fail
+ SLOGE("Application encryption failed.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_decrypt_application(const char* pBuffer, int bufLen, char** pDecryptedBuffer, int* pDecryptedBufLen)
+{
+ int ret = 0;
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error.\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDecryptApplication(pBuffer, bufLen, pDecryptedBuffer, pDecryptedBufLen);
+
+ if(ret == 1) // success
+ {
+ SLOGI("Application decryption succeeded.\n");
+ return 0;
+ }
+ else // fail
+ SLOGE("Application decryption failed.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_encrypt_preloaded_application(const char* pBuffer, int bufLen, char** ppEncryptedBuffer, int* pEncryptedBufLen)
+{
+ int ret = 0;
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error.\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientEncryptPreloadedApplication(pBuffer, bufLen, ppEncryptedBuffer, pEncryptedBufLen);
+ if(ret == 1) // success
+ {
+ SLOGI("Application decryption succeeded.\n");
+ return 0;
+ }
+ else // fail
+ SLOGE("Application decryption failed.\n");
+
+Error:
+ return ret;
+}
+
+SS_API
+int ssm_decrypt_preloaded_application(const char* pBuffer, int bufLen, char** ppDecryptedBuffer, int* pDecryptedBufLen)
+{
+ int ret = 0;
+
+ if(!pBuffer || bufLen ==0)
+ {
+ SLOGE("Parameter error.\n");
+ ret = SS_PARAM_ERROR;
+ goto Error;
+ }
+
+ ret = SsClientDecryptPreloadedApplication(pBuffer, bufLen, ppDecryptedBuffer, pDecryptedBufLen);
+ if(ret == 1) // success
+ {
+ SLOGI("Application decryption succeeded.\n");
+ return 0;
+ }
+ else // fail
+ SLOGE("Application decryption failed.\n");
+
+Error:
+ return ret;
+}
+
+
+//////////////
+//agent
+/////////////
+//
+//
+
+int ConvertErrorCode(int error)
+{
+ int convertedError = 0;
+
+ switch(error)
+ {
+ case SS_FILE_OPEN_ERROR:
+ case SS_PARAM_ERROR:
+ convertedError = SSA_PARAM_ERROR;
+ break;
+ case SS_FILE_TYPE_ERROR:
+ case SS_FILE_READ_ERROR:
+ case SS_FILE_WRITE_ERROR:
+ convertedError = SSA_IO_ERROR;
+ break;
+ case SS_MEMORY_ERROR:
+ convertedError = SSA_UNKNOWN_ERROR;
+ break;
+ case SS_SOCKET_ERROR:
+ convertedError = SSA_SOCKET_ERROR;
+ break;
+ case SS_ENCRYPTION_ERROR:
+ case SS_DECRYPTION_ERROR:
+ convertedError = SSA_CIPHER_ERROR;
+ break;
+ case SS_SIZE_ERROR:
+ convertedError = SSA_UNKNOWN_ERROR;
+ break;
+ case SS_SECURE_STORAGE_ERROR:
+ convertedError = SSA_TZ_ERROR;
+ break;
+ case SS_PERMISSION_DENIED:
+ convertedError = SSA_PERMISSION_ERROR;
+ break;
+ case SS_TZ_ERROR:
+ convertedError = SSA_TZ_ERROR;
+ break;
+ default:
+ convertedError = SSA_UNKNOWN_ERROR;
+ break;
+ }
+
+ SLOGE("error code = %d", convertedError);
+
+ return convertedError;
+}
+
+
+SS_API
+int ssa_put(const char* pDataName, const char* pDataBlock, size_t inDataBlockLen, const char* pGroupId, const char* pPassword)
+{
+ int ret = 0;
+
+ if(pPassword && (strlen(pPassword) > MAX_PASSWORD_SIZE))
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ if(!pDataName || !pDataBlock)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ if(inDataBlockLen <= 0 || inDataBlockLen > MAX_SEND_DATA_SIZE)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ ret = ssm_write_buffer(pDataBlock, inDataBlockLen, pDataName, SSM_FLAG_SECRET_OPERATION, pGroupId);
+
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ return inDataBlockLen;
+}
+
+SS_API
+int ssa_get(const char* pDataName, char** ppOutDataBlock, const char* pGroupId, const char* pPassword)
+{
+ ssm_file_info_t info;
+ size_t readLen = 0;
+ int ret = 0;
+
+ if(pPassword && (strlen(pPassword) > MAX_PASSWORD_SIZE))
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ if(!pDataName)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ ret = ssm_getinfo(pDataName, &info, SSM_FLAG_SECRET_OPERATION, pGroupId);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ *ppOutDataBlock = (char*)malloc(sizeof(char)*(info.originSize+1));
+ if(ppOutDataBlock == NULL)
+ {
+ SLOGE("Fail to allocate memory");
+ return SS_MEMORY_ERROR;
+ }
+
+ memset(*ppOutDataBlock, 0, info.originSize+1);
+
+ ret = ssm_read(pDataName, *ppOutDataBlock, info.originSize, &readLen, SSM_FLAG_SECRET_OPERATION, pGroupId);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ free(*ppOutDataBlock);
+ return ret;
+ }
+
+ return (int)readLen;
+}
+
+
+SS_API
+int ssa_delete(const char* pDataName, const char* pGroupId)
+{
+ int ret = 0;
+
+ if(!pDataName)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ ret = ssm_delete_file(pDataName, SSM_FLAG_SECRET_OPERATION, pGroupId);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ }
+
+ return ret;
+}
+
+SS_API
+int ssa_encrypt(const char* pInDataBlock, size_t inDataBlockLen, char** ppOutDataBlock, const char* pPassword)
+{
+ int ret = 0;
+ int outLen = 0;
+ char* pKey = "0123456789abcdef0123456789abcdef";
+
+ if(pPassword && (strlen(pPassword) > MAX_PASSWORD_SIZE))
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ if(!pInDataBlock || inDataBlockLen == 0 || inDataBlockLen > MAX_SEND_DATA_SIZE)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ ret = DoCipher(pInDataBlock, inDataBlockLen, ppOutDataBlock, &outLen, pKey, 1);
+ if(ret != 1)
+ {
+ return SSA_CIPHER_ERROR;
+ }
+
+ return outLen;
+}
+
+
+SS_API
+int ssa_decrypt(const char* pInDataBlock, size_t inDataBlockLen, char** ppOutDataBlock, const char* pPassword)
+{
+ int ret = 0;
+ int outLen = 0;
+ char* pKey = "0123456789abcdef0123456789abcdef";
+
+ if(pPassword && (strlen(pPassword) > MAX_PASSWORD_SIZE))
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ if(!pInDataBlock || inDataBlockLen == 0)
+ {
+ SLOGE("Invalid input argument.");
+ return SSA_PARAM_ERROR;
+ }
+
+ ret = DoCipher(pInDataBlock, inDataBlockLen, ppOutDataBlock, &outLen, pKey, 0);
+ if(ret != 1)
+ {
+ return SSA_CIPHER_ERROR;
+ }
+
+ return outLen;
+}
+
+SS_API
+int ssa_encrypt_web_application(const char* pAppId, int idLen, const char* pData, int dataLen, char** ppEncryptedData, int isPreloaded)
+{
+ int ret = 0;
+ int outLen = 0;
+
+ if(isPreloaded)
+ {
+ ret = ssm_encrypt_preloaded_application(pData, dataLen, ppEncryptedData, &outLen);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ return outLen;
+ }
+
+ else
+ {
+ ret = ssm_encrypt_application(pAppId, idLen, pData, dataLen, ppEncryptedData, &outLen);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ return outLen;
+ }
+}
+
+
+SS_API
+int ssa_decrypt_web_application(const char* pData, int dataLen, char** ppDecryptedData, int isPreloaded)
+{
+ int ret = 0;
+ int outLen = 0;
+
+ if(isPreloaded)
+ {
+ ret = ssm_decrypt_preloaded_application(pData, dataLen, ppDecryptedData, &outLen);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ return outLen;
+ }
+
+ else
+ {
+ ret = ssm_decrypt_application(pData, dataLen, ppDecryptedData, &outLen);
+ if(ret != 0)
+ {
+ ret = ConvertErrorCode(ret);
+ return ret;
+ }
+
+ return outLen;
+ }
+}
diff --git a/client/src/ss_client_intf.c b/client/src/ss_client_intf.c
deleted file mode 100644
index 50a01d8..0000000
--- a/client/src/ss_client_intf.c
+++ /dev/null
@@ -1,417 +0,0 @@
-/*
- * secure storage
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Kidong Kim <kd0228.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "secure_storage.h"
-#include "ss_client_intf.h"
-#include "ss_client_ipc.h"
-#include "ss_manager.h"
-
-#include "security-server.h"
-
-int SsClientDataStoreFromFile(const char* filepath, ssm_flag flag, const char* group_id)
-{
- ReqData_t* send_data = NULL;
- RspData_t recv_data;
- int temp_len = 0;
- int cookie_size;
-
- cookie_size = security_server_get_cookie_size();
- char cookie_content[cookie_size];
-
- if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie
- {
- SLOGE("[%s] Fail to get cookie\n", __func__);
- recv_data.rsp_type = SS_SECURE_STORAGE_ERROR;
- goto Error;
- }
-
- if(!filepath)
- {
- SLOGE( "[%s] Parameter error in SsClientDataStoreFromFile..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
-
- send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
-
- if(!send_data)
- {
- SLOGE( "[%s] Memory allocation fail in SsClientDataStoreFromFile..\n", __func__);
- recv_data.rsp_type = SS_MEMORY_ERROR;
- goto Error;
- }
-
- send_data->req_type = 1; // file store
- send_data->enc_type = 1; // initial type
- send_data->count = 0;
- send_data->flag = flag; // flag
- temp_len = strlen(filepath);
- if(temp_len < MAX_FILENAME_LEN)
- {
- strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1);
- send_data->data_infilepath[temp_len] = '\0';
- }
- else
- {
- SLOGE("[%s] filepath is too long.\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Free_and_Error;
- }
- memset(send_data->cookie, 0x00, MAX_COOKIE_LEN);
- memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN);
- memcpy(send_data->cookie, cookie_content, cookie_size);
- if(group_id)
- strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1);
- else
- strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1);
-
- memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN + 1);
- recv_data = SsClientComm(send_data);
-
-Free_and_Error:
- free(send_data);
-Error:
- return recv_data.rsp_type;
-}
-
-int SsClientDataStoreFromBuffer(char* writebuffer, size_t bufLen, const char* filename, ssm_flag flag, const char* group_id)
-{
- ReqData_t* send_data = NULL;
- RspData_t recv_data;
- int temp_len = 0;
- int cookie_size;
-
- cookie_size = security_server_get_cookie_size();
- char cookie_content[cookie_size];
-
- if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie
- {
- SLOGE("[%s] Fail to get cookie\n", __func__);
- recv_data.rsp_type = SS_SECURE_STORAGE_ERROR;
- goto Error;
- }
-
- if(!writebuffer || !filename)
- {
- SLOGE("[%s] Parameter error in SsClientDataStoreFromBuffer..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
-
- send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
- if(!send_data)
- {
- SLOGE("[%s] Memory allocation fail in SsClientDataStoreFromBuffer..\n", __func__);
- recv_data.rsp_type = SS_MEMORY_ERROR;
- goto Error;
- }
-
- send_data->req_type = 2; // buffer store
- send_data->enc_type = 1;
- send_data->count = bufLen;
- send_data->flag = flag;
- temp_len = strlen(filename);
- if(temp_len < MAX_FILENAME_LEN)
- {
- strncpy(send_data->data_infilepath, filename, MAX_FILENAME_LEN - 1);
- send_data->data_infilepath[temp_len] = '\0';
- }
- else
- {
- SLOGE("[%s] filepath is too long.\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Free_and_Error;
- }
- memset(send_data->cookie, 0x00, MAX_COOKIE_LEN);
- memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN);
- memcpy(send_data->cookie, cookie_content, cookie_size);
- if(group_id)
- strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1);
- else
- strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1);
-
- memcpy(send_data->buffer, writebuffer, bufLen);
- recv_data = SsClientComm(send_data);
-
-Free_and_Error:
- free(send_data);
-Error:
- return recv_data.rsp_type;
-}
-
-int SsClientDataRead(const char* filepath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id)
-{
- unsigned int count = (unsigned int)(bufLen / MAX_RECV_DATA_LEN + 1);
- unsigned int rest = (unsigned int)(bufLen % MAX_RECV_DATA_LEN);
- char* buffer;
- ReqData_t* send_data = NULL;
- RspData_t recv_data;
- int temp_len = 0;
- int cookie_size;
-
- cookie_size = security_server_get_cookie_size();
- char cookie_content[cookie_size];
-
- if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie
- {
- SLOGE("[%s] Fail to get cookie\n", __func__);
- recv_data.rsp_type = SS_SECURE_STORAGE_ERROR;
- goto Error;
- }
-
- if(!filepath)
- {
- SLOGE("[%s] filepath Parameter error in SsClientDataRead..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
- if(!readLen)
- {
- SLOGE("[%s] readLen Parameter error in SsClientDataRead..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
-
- *readLen = 0;
- buffer = pRetBuf;
-
- send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
-
- if(!send_data)
- {
- SLOGE("[%s] Memory allocation fail in SsClientDataRead..\n", __func__);
- recv_data.rsp_type = SS_MEMORY_ERROR;
- goto Error;
- }
-
- // fill send_data
- send_data->req_type = 3; // read data from storage
- send_data->enc_type = 1; // initial type
- send_data->count = 0;
- send_data->flag = flag & 0x000000ff; //flag;
- temp_len = strlen(filepath);
- if(temp_len < MAX_FILENAME_LEN)
- {
- strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1);
- send_data->data_infilepath[temp_len] = '\0';
- }
- else
- {
- SLOGE("[%s] filepath is too long.\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Free_and_Error;
- }
- memset(send_data->cookie, 0x00, MAX_COOKIE_LEN);
- memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN);
- memcpy(send_data->cookie, cookie_content, MAX_COOKIE_LEN);
- if(group_id)
- strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1);
- else
- strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1);
- memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN+1);
-
- // Call Server per 4KB data (count from 0 to ~)
- for ( ; send_data->count < count; send_data->count++)
- {
- //receive data from server
- recv_data = SsClientComm(send_data);
-
- // check response type
- if(recv_data.rsp_type != 1)
- {
- SLOGE("[%s] data read error from server...\n", __func__);
- goto Free_and_Error;
- }
- // copy the last data (last count)
- if(send_data->count == (count - 1))
- {
- memcpy(buffer, recv_data.buffer, rest);
- *readLen += (size_t)rest;
- goto Last;
- //break;
- }
-
- memcpy(buffer, recv_data.buffer, MAX_RECV_DATA_LEN);
- *readLen += (size_t)recv_data.readLen;
- buffer += recv_data.readLen;
- }
-Last :
- if(bufLen != *readLen)
- {
- SLOGE( "[%s] Decrypted abnormally\n", __func__);
- recv_data.rsp_type = SS_DECRYPTION_ERROR;
- goto Free_and_Error;
- }
-
- SLOGE("[%s] Decrypted file name : %s\n", __func__, recv_data.data_filepath);
-Free_and_Error:
- free(send_data);
-Error:
- return recv_data.rsp_type;
-}
-
-int SsClientGetInfo(const char* filepath, ssm_file_info_t* sfi, ssm_flag flag, const char* group_id)
-{
-
- ReqData_t* send_data = NULL;
- RspData_t recv_data;
- ssm_file_info_convert_t sfic;
- int temp_len = 0;
- int cookie_size;
-
- cookie_size = security_server_get_cookie_size();
- char cookie_content[cookie_size];
-
- if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie
- {
- SLOGE("[%s] Fail to get cookie\n", __func__);
- recv_data.rsp_type = SS_SECURE_STORAGE_ERROR;
- goto Error;
- }
-
- if(!filepath || !sfi)
- {
- SLOGE("[%s] Parameter error in SsClientGetInfo..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
-
- send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
-
- if(!send_data)
- {
- SLOGE("[%s] Memory allocation fail in SsClientGetInfo..\n", __func__);
- recv_data.rsp_type = SS_MEMORY_ERROR;
- goto Error;
- }
-
- // fill send_data
- send_data->req_type = 4; // get info type
- send_data->enc_type = 1; // initial type
- send_data->count = 0;
- send_data->flag = flag & 0x000000ff; //flag;
- temp_len = strlen(filepath);
- if(temp_len < MAX_FILENAME_LEN)
- {
- strncpy(send_data->data_infilepath, filepath, MAX_FILENAME_LEN - 1);
- send_data->data_infilepath[temp_len] = '\0';
- }
- else
- {
- SLOGE("[%s] filepath is too long.\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Free_and_Error;
- }
- memset(send_data->cookie, 0x00, MAX_COOKIE_LEN);
- memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN);
- memcpy(send_data->cookie, cookie_content, cookie_size);
- if(group_id)
- strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1);
- else
- strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1);
- memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN + 1);
-
- recv_data = SsClientComm(send_data);
-
- memcpy(sfic.fInfoArray, recv_data.buffer, sizeof(ssm_file_info_t));
- sfi->originSize = sfic.fInfoStruct.originSize;
- sfi->storedSize = sfic.fInfoStruct.storedSize;
- memcpy(sfi->reserved, sfic.fInfoStruct.reserved, 8);
-
-Free_and_Error:
- free(send_data);
-Error:
- return recv_data.rsp_type;
-}
-
-int SsClientDeleteFile(const char *pFilePath, ssm_flag flag, const char* group_id)
-{
- ReqData_t* send_data = NULL;
- RspData_t recv_data;
- int temp_len = 0;
- int cookie_size;
-
- cookie_size = security_server_get_cookie_size();
- char cookie_content[cookie_size];
-
- if(security_server_request_cookie(cookie_content, cookie_size) < 0) // error while getting cookie
- {
- SLOGE("[%s] Fail to get cookie\n", __func__);
- recv_data.rsp_type = SS_SECURE_STORAGE_ERROR;
- goto Error;
- }
-
- if(!pFilePath)
- {
- SLOGE("[%s] Parameter error in SsClientDeleteFile..\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Error;
- }
-
- send_data = (ReqData_t*)malloc(sizeof(ReqData_t));
-
- if(!send_data)
- {
- SLOGE("[%s] Memory allocation fail in SsClientDeleteFile..\n", __func__);
- recv_data.rsp_type = SS_MEMORY_ERROR;
- goto Error;
- }
-
- send_data->req_type = 10; // delete file
- send_data->enc_type = 1; // initial type
- send_data->count = 0;
- send_data->flag = flag; // flag
- temp_len = strlen(pFilePath);
- if(temp_len < MAX_FILENAME_LEN)
- {
- strncpy(send_data->data_infilepath, pFilePath, MAX_FILENAME_LEN - 1);
- send_data->data_infilepath[temp_len] = '\0';
- }
- else
- {
- SLOGE("[%s] filepath is too long.\n", __func__);
- recv_data.rsp_type = SS_PARAM_ERROR;
- goto Free_and_Error;
- }
- memset(send_data->cookie, 0x00, MAX_COOKIE_LEN);
- memset(send_data->group_id, 0x00, MAX_GROUP_ID_LEN);
- memcpy(send_data->cookie, cookie_content, cookie_size);
- if(group_id)
- strncpy(send_data->group_id, group_id, MAX_GROUP_ID_LEN - 1);
- else
- strncpy(send_data->group_id, "NOTUSED", MAX_GROUP_ID_LEN - 1);
- memset(send_data->buffer, 0x00, MAX_SEND_DATA_LEN+1);
-
- recv_data = SsClientComm(send_data);
-
-Free_and_Error:
- free(send_data);
-
- SLOGE("[%s] Deleted file name: %s\n", __func__, recv_data.data_filepath);
-
-Error:
- return recv_data.rsp_type;
-}
diff --git a/client/src/ss_manager.c b/client/src/ss_manager.c
deleted file mode 100644
index 8415a6f..0000000
--- a/client/src/ss_manager.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * secure storage
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Contact: Kidong Kim <kd0228.kim@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "secure_storage.h"
-#include "ss_client_intf.h"
-
-#ifndef SS_API
-#define SS_API __attribute__((visibility("default")))
-#endif
-
-/*****************************************************************************
- * Internal Functions
- *****************************************************************************/
-SS_API
-int ssm_getinfo(const char* pFilePath, ssm_file_info_t *sfi, ssm_flag flag, const char* group_id)
-{
- int ret = 0;
-
- if(!pFilePath || !sfi)
- {
- SLOGE("[%s] Parameter error in ssm_getinfo()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- ret = SsClientGetInfo(pFilePath, sfi, flag, group_id);
-
- if(ret == 1)
- {
- SLOGI("[%s] Getinfo Success.\n", __func__);
- ret = 0; // return true
- }
- else
- SLOGE("[%s] Getinfo Fail.\n", __func__);
-
-Error:
- return -(ret);
-}
-
-/*****************************************************************************
- * Manager APIs
- *****************************************************************************/
-SS_API
-int ssm_write_file(const char* pFilePath, ssm_flag flag, const char* group_id)
-{
- int ret = 0;
-
- if(!pFilePath)
- {
- SLOGE("[%s] Parameter error in ssm_write_file()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX)
- {
- SLOGE("[%s] Parameter error in ssm_write_file()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- ret = SsClientDataStoreFromFile(pFilePath, flag, group_id);
- if(ret == 1)
- {
- if(unlink(pFilePath) != 0) // if fail
- {
- SLOGE("[%s] unlink fail. [%s]\n", __func__, pFilePath);
- return -1; // return false
- }
- SLOGI("[%s] Write file Success.\n", __func__);
- return 0; // return true
- }
- else
- SLOGE( "[%s] Write file Fail.\n", __func__);
-
-Error:
- return -(ret);
-}
-
-SS_API
-int ssm_write_buffer(char* pWriteBuffer, size_t bufLen, const char* pFileName, ssm_flag flag, const char* group_id)
-{
- int ret = 0;
-
- if(!pWriteBuffer || !pFileName || (pFileName[0] == '/'))
- {
- SLOGE("[%s] Parameter error in ssm_write_buffer()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
- if(bufLen <= 0 || bufLen > 4096)
- {
- SLOGE( "[%s] Parameter error in ssm_write_buffer()..\n", __func__ );
- ret = SS_PARAM_ERROR;
- goto Error;
- }
- if(flag <= SSM_FLAG_NONE || flag >= SSM_FLAG_MAX)
- {
- SLOGE( "[%s] Parameter error in ssm_write_buffer()..\n", __func__ );
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- ret = SsClientDataStoreFromBuffer(pWriteBuffer, bufLen, pFileName, flag, group_id);
- if(ret == 1)
- {
- SLOGI("[%s] Write buffer Success.\n", __func__);
- return 0; // return true
- }
- else
- SLOGE("[%s] Write buffer Fail.\n", __func__);
-
-Error:
- return -(ret);
-}
-
-SS_API
-int ssm_read(const char* pFilePath, char* pRetBuf, size_t bufLen, size_t *readLen, ssm_flag flag, const char* group_id)
-{
- int ret = 0;
- ssm_file_info_t sfi;
-
- if(!pFilePath || !pRetBuf)
- {
- SLOGE( "[%s] Parameter error in ssm_read()..\n", __func__ );
- ret = SS_PARAM_ERROR;
- goto Error;
- }
- if(!readLen)
- {
- SLOGE("[%s] Parameter error in ssm_read()...\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- // get info
- ret = ssm_getinfo(pFilePath, &sfi, flag, group_id);
- if(ret != 0) // ret != true?
- {
- SLOGE("[%s] getinfo error in ssm_read()..\n", __func__);
- goto Error;
- }
- // in case of flag mismatch...
- // check flag...
- // To do :
- if((bufLen > sfi.originSize) || (sfi.reserved[0] != (flag & 0x000000ff)))
- {
- SLOGE("[%s] Flag mismatch or buffer length error in ssm_read()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- ret = SsClientDataRead(pFilePath, pRetBuf, sfi.originSize, readLen, flag, group_id);
-
- if(ret == 1)
- {
- SLOGI("[%s] Read Success.\n", __func__);
- return 0; // return true
- }
- else
- SLOGE("[%s] Read Fail.\n", __func__);
-
-Error:
- return -(ret);
-}
-
-SS_API
-int ssm_delete_file(const char *pFilePath, ssm_flag flag, const char* group_id)
-{
- int ret = 0;
-
- if(!pFilePath)
- {
- SLOGE("[%s] Parameter error in ssm_delete_file()..\n", __func__);
- ret = SS_PARAM_ERROR;
- goto Error;
- }
-
- ret = SsClientDeleteFile(pFilePath, flag, group_id);
-
- if(ret == 1) // success
- {
- SLOGI("[%s] Delete file Success.\n", __func__);
- return 0;
- }
- else // fail
- SLOGE("[%s] Delete file Fail.\n", __func__);
-
-Error:
- return -(ret);
-}