summaryrefslogtreecommitdiff
path: root/testcases
diff options
context:
space:
mode:
Diffstat (limited to 'testcases')
-rw-r--r--testcases/ss_test.c243
-rw-r--r--testcases/test_manager.c138
-rw-r--r--testcases/unit_test.c487
3 files changed, 868 insertions, 0 deletions
diff --git a/testcases/ss_test.c b/testcases/ss_test.c
new file mode 100644
index 0000000..46b118d
--- /dev/null
+++ b/testcases/ss_test.c
@@ -0,0 +1,243 @@
+/*
+ * secure storage
+ *
+ * Copyright (c) 2000 - 2010 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Kidong Kim <kd0228.kim@samsung.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+
+#include "ss_manager.h"
+
+#define MAX_FILENAME_SIZE 256
+
+void usage(void)
+{
+ printf("\n == Secure Storage Test Usage ==\n\n");
+ printf(" ./ss_test\n");
+}
+
+void prepare_test(void)
+{
+ // 1. make some directories
+ // 2. make test file
+ printf("Make directory - /opt/secure-storage/test\n");
+ mkdir("/opt/secure-storage", 0777);
+ mkdir("/opt/secure-storage/test", 0777);
+
+ printf("Make test file\n");
+ system("touch /opt/secure-storage/test/input.txt");
+ system("echo \"abcdefghijklnmopqrstuvwxyz\" > /opt/secure-storage/test/input.txt");
+}
+
+int test_ssm_write_file()
+{
+ /*
+ * input : const char* pFilePath
+ * ssm_flag flag
+ * return : if 0, success
+ * if < 0, fail
+ */
+ printf("the file '/opt/secure-storage/test/input.txt' will be stored in secure-storage\n");
+
+ int ret = -1;
+ char *infilepath = "/opt/secure-storage/test/input.txt";
+ ssm_flag flag = SSM_FLAG_DATA;
+
+ ret = ssm_write_file(infilepath, flag, NULL);
+ printf("test function end\n");
+
+ return ret;
+}
+
+int test_ssm_write_buffer()
+{
+ /*
+ * input : char* pWriteBuffer
+ * size_t bufLen
+ * const char* pFileName
+ * ssm_flag flag
+ * return : if 0, success
+ * if < 0, fail
+ */
+ printf("the buffer will be stored in secure-storage\n");
+
+ int ret = -1;
+ char buf[27] = "abcdefghijklmnopqrstuvwxyz\0";
+ int buflen = strlen(buf);
+ char *filename = "res_write_buf.txt";
+ ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+
+ printf(" ** buffer content : [%s]\n", buf);
+ printf(" ** buffer length : [%d]\n", buflen);
+
+ ret = ssm_write_buffer(buf, buflen, filename, flag, NULL);
+ printf("test function end\n");
+
+ return ret;
+}
+
+int test_ssm_getinfo()
+{
+ /*
+ * input : const char* pFilePath
+ * ssm_flag flag
+ * ssm_file_info_t* sfi
+ * return : if 0, success
+ * if < 0, fail
+ */
+ printf("get information of encrypted file. your input in plaintext\n");
+
+ int ret = -1;
+ char *filepath = "/opt/secure-storage/test/input.txt";
+ ssm_flag flag = SSM_FLAG_DATA;
+ ssm_file_info_t sfi;
+
+ ret = ssm_getinfo(filepath, &sfi, flag, NULL);
+ printf(" ** original size: [%d]\n", sfi.originSize);
+ printf(" ** stored size: [%d]\n", sfi.storedSize);
+ printf(" ** reserved: [%s]\n", sfi.reserved);
+ printf("test function end\n");
+
+ return ret;
+}
+
+int test_ssm_read()
+{
+ /*
+ * input : const char* pFilePath
+ * size_t bufLen
+ * ssm_flag flag
+ * output : char* pRetBuf
+ * size_t readLen
+ * return : if 0, success
+ * if < 0, fail
+ */
+ printf("decrypt content from encrypted file\n");
+
+ int ret = -1;
+ char *filepath = "/opt/secure-storage/test/input.txt";
+// char *filepath = "res_write_buf.txt";
+ int buflen = 128;
+ ssm_flag flag = SSM_FLAG_DATA;
+// ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+ char* retbuf = NULL;
+ int readlen = 0;
+ ssm_file_info_t sfi;
+
+// ssm_getinfo(filepath, &sfi, SSM_FLAG_DATA);
+ ssm_getinfo(filepath, &sfi, flag, NULL);
+ retbuf = (char*)malloc(sizeof(char) * (sfi.originSize + 1));
+ memset(retbuf, 0x00, (sfi.originSize + 1));
+
+// ret = ssm_read(filepath, retbuf, sfi.originSize, &readlen, SSM_FLAG_DATA);
+ ret = ssm_read(filepath, retbuf, sfi.originSize, &readlen, flag, NULL);
+
+ printf(" ** decrypted data: [%s][%d]\n", retbuf, strlen(retbuf));
+ free(retbuf);
+ printf("test function end\n");
+
+ return ret;
+}
+
+int test_ssm_delete_file()
+{
+ /*
+ * input : const char* pFilePath
+ * ssm_flag flag
+ * return : if 0, success
+ * if < 0, fail
+ */
+ printf("the file '/opt/secure-storage/test/input.txt' will be stored in secure-storage\n");
+ printf(" and encrypted one of this file will be deleted\n");
+
+ int ret = -1;
+ char *infilepath = "/opt/secure-storage/test/input.txt";
+ ssm_flag flag = SSM_FLAG_DATA;
+// char *infilepath = "res_write_buf.txt";
+// ssm_flag flag = SSM_FLAG_SECRET_OPERATION;
+
+ ret = ssm_delete_file(infilepath, flag, NULL);
+ printf("test function end\n");
+
+ return ret;
+}
+
+int main(int argc, char* argv[])
+{
+ int ret = -1;
+ int choice;
+
+ char in_filepath[MAX_FILENAME_SIZE] = {0, };
+ char out_filepath[MAX_FILENAME_SIZE] = {0, };
+
+ if(argc != 1)
+ {
+ printf("Error...input argument error\n");
+ usage();
+ }
+
+ printf("\n= This is Secure Storage test program. =\n");
+ printf(" 0. Prepare Secure Storage test\n");
+ printf(" 1. Data Store\n");
+ printf(" 11. ssm_write_file()\n");
+ printf(" 12. ssm_write_buffer()\n");
+ printf(" 2. Data Information\n");
+ printf(" 21. ssm_getinfo()\n");
+ printf(" 3. Data Read\n");
+ printf(" 31. ssm_read()\n");
+ printf(" 4. Delete encrypted file\n");
+ printf(" 41. ssm_delete_file()\n");
+ printf(" 5. Exit\n");
+
+ printf("\nselect num: ");
+ scanf("%d", &choice);
+
+ switch( choice )
+ {
+ case 0:
+ printf("\nYou select \"Prepare test\"\n");
+ prepare_test();
+ break;
+ case 11:
+ printf("\nYou select \"ssm_write_file()\"\n");
+ ret = test_ssm_write_file();
+ printf( "return: %d\n", ret );
+ break;
+ case 12:
+ printf("\nYou select \"ssm_write_buffer()\"\n");
+ ret = test_ssm_write_buffer();
+ printf( "return: %d\n", ret );
+ break;
+ case 21:
+ printf("\nYou select \"ssm_getinfo()\"\n");
+ ret = test_ssm_getinfo();
+ printf( "return: %d\n", ret );
+ break;
+ case 31:
+ printf("\nYou select \"ssm_read()\"\n");
+ ret = test_ssm_read();
+ printf( "return: %d\n", ret );
+ break;
+ case 41:
+ printf("\nYou select \"ssm_delete_file()\"\n");
+ ret = test_ssm_delete_file();
+ printf("return: %d\n", ret);
+ break;
+ case 5:
+ printf("\nYou select \"Exit\"\n");
+ printf( "Bye~\n");
+ break;
+ default:
+ printf( "\nError...select wrong number\n" );
+ usage();
+ break;
+ }
+
+ return 0;
+}
diff --git a/testcases/test_manager.c b/testcases/test_manager.c
new file mode 100644
index 0000000..0fea648
--- /dev/null
+++ b/testcases/test_manager.c
@@ -0,0 +1,138 @@
+/*
+ * secure storage
+ *
+ * Copyright (c) 2000 - 2010 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Kidong Kim <kd0228.kim@samsung.com>
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ss_manager.h"
+
+
+void format_mount_csa(void)
+{
+ system("mkdir /tmp/csa");
+// system("insmod /lib/modules/yaffs2.ko yaffs_format=1");
+ system("ffdisk -a /dev/bml2");
+ system("fformat -s 1 -S 512 16 /dev/stl2");
+ system("mount -t rfs /dev/bml2 /tmp/csa");
+
+ printf("format_mount_csa...\n");
+}
+
+void mount_csa(void)
+{
+ system("mkdir /tmp/csa");
+// system("insmod /lib/modules/yaffs2.ko");
+ system("mount -t rfs /dev/bml2 /tmp/csa");
+
+ printf("mount_csa...\n");
+}
+
+void umount_csa(void)
+{
+ system("umount /tmp/csa");
+// system("rmmod /lib/modules/yaffs2.ko");
+ printf("umount_csa...\n");
+}
+
+
+int main( int argc, char* argv[] )
+{
+ int ret;
+ int choice;
+
+ FILE *fp;
+
+ char in_filepath[50];
+ char writebuffer[31] = "abcdefghijklmnopqrstuvwxyz1234";
+ char *retBuf = NULL;
+
+ size_t readSize = 0;
+
+ ssm_file_info_t sfi;
+
+ system("mkdir -p /opt/share/secure-storage/");
+
+ do {
+ printf( "= This is Secure Storage test program. =\n" );
+ printf( " 1. Secure Storage WriteFile() API\n" );
+ printf( " 2. Secure Storage WriteBuffer() API \n" );
+ printf( " 3. Secure Storage Read() API\n");
+ printf( " 4. view rfs partition\n" );
+ printf( " 5. Exit\n" );
+ printf( "\nselect num: " );
+ scanf( "%d", &choice );
+
+ switch( choice )
+ {
+ case 1:
+ printf("Call SSM_Store with /tmp/csa/cert.cp...\n");
+ mount_csa();
+ system("cp /opt/var/drm/cert.cp /tmp/csa/");
+
+ ret = SSM_WriteFile("/tmp/csa/cert.cp", SSM_FLAG_SECRET_PRESERVE);
+ umount_csa();
+ printf( "You select 'WriteFile'\n" );
+ printf( "\nreturn: %d\n", ret );
+ break;
+ case 2:
+ ret = SSM_WriteBuffer(writebuffer, 30, "writebuf.txt", SSM_FLAG_SECRET_OPERATION);
+ printf( "You select 'WriteBuffer'\n" );
+ printf( "return: %d\n", ret );
+ break;
+ case 3:
+ printf("Call SSM_Read for OMA_DRM_CERT in secure storage...\n");
+ //retBuf = (char*) malloc (50);
+ printf("- read cert.cp\n");
+ mount_csa();
+ SSM_GetInfo("/tmp/csa/cert.cp", &sfi, SSM_FLAG_SECRET_PRESERVE);
+ retBuf = (char*)malloc(sfi.originSize + 1);
+ ret = SSM_Read("/tmp/csa/cert.cp", retBuf, sfi.originSize, &readSize, SSM_FLAG_SECRET_PRESERVE);
+ //free(retBuf);
+ umount();
+ printf( "You select 'read1' : read Size = %u \n", readSize);
+
+ fp = fopen("/opt/var/ss_test_result","wb");
+ fwrite(retBuf, 1, readSize, fp);
+ fclose(fp);
+
+ printf( "address of retBuf : %x\n", retBuf);
+ printf( "\nreturn: %d\n", ret );
+
+ free(retBuf);
+
+ printf("- read writebuf.txt");
+ SSM_GetInfo("writebuf.txt", &sfi, SSM_FLAG_SECRET_OPERATION);
+ retBuf = (char*)malloc(sfi.originSize);
+ ret = SSM_Read("writebuf.txt", retBuf, sfi.originSize, &readSize, SSM_FLAG_SECRET_OPERATION);
+
+ printf("You select 'read2' : read size %u \n", readSize);
+ printf("return : %d, original data : %s\n", ret, retBuf);
+
+ free(retBuf);
+
+ break;
+
+ case 4:
+ mount_csa();
+ system("df -h");
+ system("ls -alF /tmp/csa");
+ break;
+ case 5:
+ printf( "You select 'Exit'\n" );
+ exit(1);
+ default:
+ printf( "Error...select wrong number\n" );
+ break;
+ }
+ }
+ while(choice > 0 && choice < 5);
+
+ return 0;
+}
diff --git a/testcases/unit_test.c b/testcases/unit_test.c
new file mode 100644
index 0000000..9c43175
--- /dev/null
+++ b/testcases/unit_test.c
@@ -0,0 +1,487 @@
+/*
+ * secure storage
+ *
+ * Copyright (c) 2000 - 2010 Samsung Electronics Co., Ltd.
+ *
+ * Contact: Kidong Kim <kd0228.kim@samsung.com>
+ *
+ */
+
+/* unit test for secure storage manager */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ss_manager.h"
+
+
+#define LOG_FILE "/opt/var/drm/unit_test_log.txt"
+#define TEST_PATH "/tmp/csa/"
+#define OMA_DRM_CERT "/tmp/csa/cert.cp"
+#define TEST_FILE_NORMAL "/opt/var/drm/normal"
+
+#define TEST_SUCCESS "test success!"
+#define TEST_FAIL "test fail!"
+
+const char* testcases[] = {
+ "unit_test_write_file",
+ "unit_test_write_buffer",
+ "unit_test_read",
+ "unit_test_all",
+ "unit_test_pid",
+ NULL
+};
+
+void mount_csa(void)
+{
+ system("mkdir /tmp/csa");
+// system("insmod /lib/modules/yaffs2.ko");
+ system("mount -t rfs /dev/bml2 /tmp/csa");
+
+ printf("mount_csa\n");
+}
+
+void umount_csa(void)
+{
+ system("umount /tmp/csa");
+// system("rmmod /lib/modules/yaffs2.ko");
+ printf("umount_csa\n");
+}
+
+int write_log(FILE *fp, char *data, unsigned int len)
+{
+ size_t writelen;
+
+ if(!fp)
+ {
+ printf("Error... log file open fail...\n");
+ exit(0);
+ }
+
+ writelen = fwrite(data, 1, (size_t)len, fp);
+
+ fputc('\n', fp);
+
+ if(writelen == len)
+ {
+ printf("log write %u bytes...\n", writelen);
+ return 0;
+ }
+ else
+ {
+ printf("Error... log write fail...\n");
+ return -1;
+ }
+}
+
+void unit_test_write_file(FILE *fp)
+{
+ char* store_cases[] = {
+ "1. invalid filepath = NULL",
+ "2. invalid flag = -1",
+ "3. invalid flag = 10",
+ "4. filepath = cert.cp",
+ "5. filepath = otherfile",
+ NULL
+ };
+ char text[1024];
+ int ret;
+
+ sprintf(text, "----- %s Start -----", testcases[0]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+
+ // # store case 1. invalid filepath = NULL
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[0], strlen(store_cases[0]));
+ ret = SSM_WriteFile(NULL, SSM_FLAG_DATA);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 2. invalid flag = -1
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[1], strlen(store_cases[1]));
+ ret = SSM_WriteFile(TEST_FILE_NORMAL, -1);
+ if(ret != SSM_FALSE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 3. invalid flag = 10
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[2], strlen(store_cases[2]));
+ ret = SSM_WriteFile(TEST_FILE_NORMAL, 10);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 4. filepath = cert.cp
+ // expected result ==> SSM_TRUE
+ write_log(fp, store_cases[3], strlen(store_cases[3]));
+ ret = SSM_WriteFile(OMA_DRM_CERT, SSM_FLAG_SECRET_PRESERVE);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 5. filepath = otherfile
+ // expected result ==> SSM_TRUE
+ write_log(fp, store_cases[4], strlen(store_cases[4]));
+ ret = SSM_WriteFile(TEST_FILE_NORMAL, SSM_FLAG_DATA);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ sprintf(text, "----- %s End -----", testcases[0]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+}
+
+void unit_test_write_buffer(FILE *fp)
+{
+ char* store_cases[] = {
+ "1. invalid pWriteBuffer = NULL",
+ "2. invalid bufLen = 0",
+ "3. invalid pFileName = NULL",
+ "4. invalid pFileName = /xxxxxxx",
+ "5. invalud flag = -1",
+ "6. invalid flag = 10",
+ "7. a buffer input",
+ NULL
+ };
+ char text[1024] = "This is a test buffer. WoW. that's wonderful.";
+ int ret;
+
+ sprintf(text, "----- %s Start -----", testcases[1]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+
+ // # store case 1. invalid pWriteBuffer = NULL
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[0], strlen(store_cases[0]));
+ ret = SSM_WriteBuffer(NULL, strlen(text), "text.txt", SSM_FLAG_SECRET_OPERATION);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 2. invalid bufLen = 0
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[1], strlen(store_cases[1]));
+ ret = SSM_WriteBuffer(text, 0, "text.txt", SSM_FLAG_SECRET_OPERATION);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 3. invalid pFileName = NULL
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[2], strlen(store_cases[2]));
+ ret = SSM_WriteBuffer(text, strlen(text), NULL, SSM_FLAG_SECRET_OPERATION);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 4. invalid pFileName = /xxxxxx
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[3], strlen(store_cases[3]));
+ ret = SSM_WriteBuffer(text, strlen(text), "/opt/var/text.txt", SSM_FLAG_SECRET_OPERATION);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 5. invalid flag = -1
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[4], strlen(store_cases[4]));
+ ret = SSM_WriteBuffer(text, strlen(text), "text.txt", -1);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 6. invalid flag = 10
+ // expected result ==> SSM_FALSE
+ write_log(fp, store_cases[5], strlen(store_cases[5]));
+ ret = SSM_WriteBuffer(text, strlen(text), "text.txt", 10);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ // # store case 7. a buffer input
+ // expected result ==> SSM_TRUE
+ write_log(fp, store_cases[6], strlen(store_cases[6]));
+ ret = SSM_WriteBuffer(text, strlen(text), "text.txt", SSM_FLAG_SECRET_OPERATION);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+
+ sprintf(text, "----- %s End -----", testcases[1]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+}
+
+void unit_test_read(FILE *fp)
+{
+ char* read_cases[] = {
+ "1. invalid filepath = NULL",
+ "2. invalid readLen = NULL",
+ "3. invalid flag = -1",
+ "4. invalid flag = 10",
+ "5. proper parameters = cert.cp",
+ "6. proper parameters = otherfile",
+ "7. proper parameters = text.txt",
+ NULL
+ };
+ char text[1024];
+ char *retBuf = NULL;
+ int ret;
+ size_t readLen = 0, bufLen = 1024;
+ ssm_file_info_t sfi;
+
+ sprintf(text, "----- %s Start -----", testcases[2]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+
+ // # read case 1. invalid filepath = NULL
+ // expected result ==> SSM_FALSE
+ write_log(fp, read_cases[0], strlen(read_cases[0]));
+ ret = SSM_Read(NULL, retBuf, bufLen, &readLen, SSM_FLAG_DATA);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ //if(retBuf)
+ // free(retBuf);
+ }
+
+ // # read case 2. invalid readLen = NULL
+ // expected result ==> SSM_FALSE
+ write_log(fp, read_cases[1], strlen(read_cases[1]));
+ ret = SSM_Read(TEST_FILE_NORMAL, retBuf, bufLen, NULL, SSM_FLAG_DATA);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ //if(retBuf)
+ // free(retBuf);
+ }
+
+ // # read case 3. invalid flag = -1
+ // expected result ==> SSM_FALSE
+ write_log(fp, read_cases[2], strlen(read_cases[2]));
+ ret = SSM_Read(TEST_FILE_NORMAL, retBuf, bufLen, &readLen, -1);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ //if(retBuf)
+ // free(retBuf);
+ }
+
+ // # read case 4. invalid flag = 10
+ // expected result ==> SSM_FALSE
+ write_log(fp, read_cases[3], strlen(read_cases[3]));
+ ret = SSM_Read(TEST_FILE_NORMAL, retBuf, bufLen, &readLen, 10);
+ if(ret != SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ //if(retBuf)
+ // free(retBuf);
+ }
+
+ // # read case 5. proper parameters = cert.cp
+ // expected result ==> SSM_TRUE
+ write_log(fp, read_cases[4], strlen(read_cases[4]));
+ SSM_GetInfo(OMA_DRM_CERT, &sfi, SSM_FLAG_SECRET_PRESERVE);
+ retBuf = (char*)malloc(sfi.originSize+1);
+ ret = SSM_Read(OMA_DRM_CERT, retBuf, sfi.originSize, &readLen, SSM_FLAG_SECRET_PRESERVE);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+ if(retBuf)
+ free(retBuf);
+
+ // # read case 6. proper parameters = otherfile
+ // expected result ==> SSM_TRUE
+ write_log(fp, read_cases[5], strlen(read_cases[5]));
+ SSM_GetInfo(TEST_FILE_NORMAL, &sfi, SSM_FLAG_DATA);
+ retBuf = (char*)malloc(sfi.originSize+1);
+ ret = SSM_Read(TEST_FILE_NORMAL, retBuf, sfi.originSize, &readLen, SSM_FLAG_DATA);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+ if(retBuf)
+ free(retBuf);
+
+ // # read case 7. proper parameters = text.txt
+ // expected result ==> SSM_TRUE
+ write_log(fp, read_cases[6], strlen(read_cases[6]));
+ SSM_GetInfo("text.txt", &sfi, SSM_FLAG_SECRET_OPERATION);
+ retBuf = (char*)malloc(sfi.originSize+1);
+ ret = SSM_Read("text.txt", retBuf, sfi.originSize, &readLen, SSM_FLAG_SECRET_OPERATION);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+ }
+ if(retBuf)
+ free(retBuf);
+
+
+ sprintf(text, "----- %s End -----", testcases[2]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+}
+
+
+void unit_test_pid(FILE *fp)
+{
+#define ENCRYPT_PID 1
+#define DECRYPT_PID 0
+
+ int ret = 0;
+ int i;
+ char* pid_cases[] = {
+ "1. encrypt pid",
+ "2. decrypt pid",
+ NULL
+ };
+ char text[256];
+ int encSize = 0;
+ unsigned long pid = 1111, newPid;
+ unsigned char testPid[16] = {0,};
+
+ write_log(fp, pid_cases[0], strlen(pid_cases[0]));
+ ret = SSM_EncryptPid(&pid, testPid, &encSize, ENCRYPT_PID);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+
+ printf("%s result : pid - %u, size - %u\nencrypted pid -", pid_cases[0], pid, encSize);
+ for(i = 0; i < 16; i++)
+ printf("%.2x ", testPid[i]);
+ printf("\n");
+ }
+
+ write_log(fp, pid_cases[1], strlen(pid_cases[1]));
+ ret = SSM_EncryptPid(&newPid, testPid, &encSize, DECRYPT_PID);
+ if(ret == SSM_TRUE)
+ {
+ sprintf(text, " result = %s", TEST_SUCCESS);
+ write_log(fp, text, strlen(text));
+
+ printf("%s result : pid - %u, size - %u\n", pid_cases[1], newPid, encSize);
+
+ }
+
+}
+
+void unit_test_all(FILE *fp)
+{
+ char text[1024];
+
+ sprintf(text, "----- %s Start -----", testcases[3]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+
+ unit_test_write_file(fp);
+ unit_test_write_buffer(fp);
+ unit_test_read(fp);
+
+ sprintf(text, "----- %s End -----", testcases[3]);
+ write_log(fp, text, strlen(text));
+ printf("%s\n", text);
+}
+
+int main( int argc, char* argv[] )
+{
+ int ret;
+ int choice;
+
+ char in_filepath[50];
+
+ FILE *log = NULL;
+
+system("mkdir -p /opt/share/secure-storage/");
+
+ printf( " 1. " ); printf(testcases[0]); printf( " \n" );
+ printf( " 2. " ); printf(testcases[1]); printf( " \n" );
+ printf( " 3. " ); printf(testcases[2]); printf( " \n" );
+ printf( " 4. " ); printf(testcases[3]); printf( " \n" );
+ printf( " 5. " ); printf(testcases[4]); printf( " \n" );
+ printf( " 6. Exit\n" );
+
+ printf( "\nselect num: " );
+ scanf( "%d", &choice );
+
+mount_csa();
+system("cp /opt/var/drm/cert.cp /tmp/csa/"); // cert.cp
+system("cp /opt/var/drm/cert.cp /opt/var/drm/normal"); // normal
+
+ log = fopen(LOG_FILE, "wb");
+
+ if(!log)
+ {
+ printf("Error... log file open fail...\n");
+ exit(0);
+ }
+
+ switch( choice )
+ {
+ case 1:
+ unit_test_write_file(log);
+ break;
+ case 2:
+ unit_test_write_buffer(log);
+ break;
+ case 3:
+ unit_test_read(log);
+ break;
+ case 4:
+ unit_test_all(log);
+ break;
+ case 5:
+ unit_test_pid(log);
+ break;
+ case 6:
+ printf( "You select 'Exit'\n" );
+ break;
+ default:
+ printf( "Error...select wrong number\n" );
+ break;
+ }
+
+umount_csa();
+
+ if(log)
+ fclose(log);
+
+ return 0;
+}