diff options
Diffstat (limited to 'TC/scenario1')
-rwxr-xr-x | TC/scenario1/Makefile | 27 | ||||
-rwxr-xr-x | TC/scenario1/tslist | 5 | ||||
-rwxr-xr-x | TC/scenario1/utc_SecurityFW_ssm_delete_file_func.c | 137 | ||||
-rwxr-xr-x | TC/scenario1/utc_SecurityFW_ssm_getinfo_func.c | 144 | ||||
-rwxr-xr-x | TC/scenario1/utc_SecurityFW_ssm_read_func.c | 187 | ||||
-rwxr-xr-x | TC/scenario1/utc_SecurityFW_ssm_write_buffer_func.c | 155 | ||||
-rwxr-xr-x | TC/scenario1/utc_SecurityFW_ssm_write_file_func.c | 147 |
7 files changed, 802 insertions, 0 deletions
diff --git a/TC/scenario1/Makefile b/TC/scenario1/Makefile new file mode 100755 index 0000000..454fc3e --- /dev/null +++ b/TC/scenario1/Makefile @@ -0,0 +1,27 @@ +CC ?= gcc + +TARGETS = \ + utc_SecurityFW_ssm_write_file_func \ + utc_SecurityFW_ssm_write_buffer_func \ + utc_SecurityFW_ssm_read_func \ + utc_SecurityFW_ssm_getinfo_func \ + utc_SecurityFW_ssm_delete_file_func + +PKGS = secure-storage + +LDFLAGS = `pkg-config --libs $(PKGS)` +LDFLAGS += $(TET_ROOT)/lib/tet3/tcm_s.o +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -ltcm_s +LDFLAGS += -L$(TET_ROOT)/lib/tet3 -lapi_s + +CFLAGS = -I. `pkg-config --cflags $(PKGS)` +CFLAGS += -I$(TET_ROOT)/inc/tet3 +CFLAGS += -Wall + +all: $(TARGETS) + +$(TARGETS): %: %.c + $(CC) -o $@ $< $(CFLAGS) $(LDFLAGS) + +clean: + rm -f $(TARGETS) *~ diff --git a/TC/scenario1/tslist b/TC/scenario1/tslist new file mode 100755 index 0000000..c04c3f0 --- /dev/null +++ b/TC/scenario1/tslist @@ -0,0 +1,5 @@ +/scenario1/utc_SecurityFW_ssm_write_file_func +/scenario1/utc_SecurityFW_ssm_write_buffer_func +/scenario1/utc_SecurityFW_ssm_read_func +/scenario1/utc_SecurityFW_ssm_getinfo_func +/scenario1/utc_SecurityFW_ssm_delete_file_func diff --git a/TC/scenario1/utc_SecurityFW_ssm_delete_file_func.c b/TC/scenario1/utc_SecurityFW_ssm_delete_file_func.c new file mode 100755 index 0000000..88f782c --- /dev/null +++ b/TC/scenario1/utc_SecurityFW_ssm_delete_file_func.c @@ -0,0 +1,137 @@ +/* + * 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 <ss_manager.h> +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SecurityFW_ssm_delete_file_func_01(void); +static void utc_SecurityFW_ssm_delete_file_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SecurityFW_ssm_delete_file_func_01, POSITIVE_TC_IDX }, + { utc_SecurityFW_ssm_delete_file_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + printf("Make temporary directory - /opt/secure-storage/test/\n"); + system("mkdir -p /opt/secure-storage/test"); + printf("Make temporary file\n"); + system("touch /opt/secure-storage/test/input.txt"); + system("echo \"abcdefghij\" > /opt/secure-storage/test/input.txt"); + system("cp /opt/secure-storage/test/input.txt /opt/secure-storage/test/input2.txt"); +} + +static void cleanup(void) +{ + printf("Remove tamporary file and directory\n"); + system("rm -rf /opt/secure-storage/test"); +} + +/** + * @brief Positive test case of ssm_delete_file() + */ +static void utc_SecurityFW_ssm_delete_file_func_01(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_delete_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* delete file */ + ret = ssm_delete_file(filepath, flag, group_id); + if(ret == 0) + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} + +/** + * @brief Negative test case of ssm_delete_file() + */ +static void utc_SecurityFW_ssm_delete_file_func_02(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_delete_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input2.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + printf("[%s] checkpoint1\n", __func__); + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + printf("[%s] checkpoint2 [%d]\n", __func__, ret); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* delete file */ + ret = ssm_delete_file(NULL, flag, group_id); + printf("[%s] checkpoint3 [%d]\n", __func__, ret); + if(ret != 0) + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + printf("[%s] checkpoint4 [%d]\n", __func__, ret); + if(ret != 0) + tetResult = TET_UNINITIATED; + +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} diff --git a/TC/scenario1/utc_SecurityFW_ssm_getinfo_func.c b/TC/scenario1/utc_SecurityFW_ssm_getinfo_func.c new file mode 100755 index 0000000..fb6064f --- /dev/null +++ b/TC/scenario1/utc_SecurityFW_ssm_getinfo_func.c @@ -0,0 +1,144 @@ +/* + * 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 <ss_manager.h> +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SecurityFW_ssm_getinfo_func_01(void); +static void utc_SecurityFW_ssm_getinfo_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SecurityFW_ssm_getinfo_func_01, POSITIVE_TC_IDX }, + { utc_SecurityFW_ssm_getinfo_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + printf("Make temporary directory - /opt/secure-storage/test/\n"); + system("mkdir -p /opt/secure-storage/test"); + printf("Make temporary file\n"); + system("touch /opt/secure-storage/test/input.txt"); + system("echo \"abcdefghij\" > /opt/secure-storage/test/input.txt"); + system("cp /opt/secure-storage/test/input.txt /opt/secure-storage/test/input2.txt"); +} + +static void cleanup(void) +{ + printf("Remove tamporary file and directory\n"); + system("rm -rf /opt/secure-storage/test"); +} + +/** + * @brief Positive test case of ssm_getinfo() + */ +static void utc_SecurityFW_ssm_getinfo_func_01(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + ssm_file_info_t sfi; + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* get information */ + ret = ssm_getinfo(filepath, &sfi, flag, group_id); + if(ret == 0) // success + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + if(ret != 0) + tetResult = TET_UNINITIATED; + +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} + +/** + * @brief Negative test case of ssm_getinfo() + */ +static void utc_SecurityFW_ssm_getinfo_func_02(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input2.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + ssm_file_info_t sfi; + + printf("[%s] checkpoint1\n", __func__); + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + printf("[%s] checkpoint2 [%d]\n", __func__, ret); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* get information */ + ret = ssm_getinfo(NULL, &sfi, flag, group_id); + printf("[%s] checkpoint3 [%d]\n", __func__, ret); + if(ret == 0) // success + tetResult = TET_FAIL; + else + tetResult = TET_PASS; + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + printf("[%s] checkpoint4 [%d]\n", __func__, ret); + if(ret != 0) + tetResult = TET_UNINITIATED; + +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} diff --git a/TC/scenario1/utc_SecurityFW_ssm_read_func.c b/TC/scenario1/utc_SecurityFW_ssm_read_func.c new file mode 100755 index 0000000..e976f06 --- /dev/null +++ b/TC/scenario1/utc_SecurityFW_ssm_read_func.c @@ -0,0 +1,187 @@ +/* + * 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 <ss_manager.h> +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SecurityFW_ssm_read_func_01(void); +static void utc_SecurityFW_ssm_read_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SecurityFW_ssm_read_func_01, POSITIVE_TC_IDX }, + { utc_SecurityFW_ssm_read_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + printf("Make temporary directory - /opt/secure-storage/test/\n"); + system("mkdir -p /opt/secure-storage/test"); + printf("Make temporary file\n"); + system("touch /opt/secure-storage/test/input.txt"); + system("echo \"abcdefghij\" > /opt/secure-storage/test/input.txt"); + system("cp /opt/secure-storage/test/input.txt /opt/secure-storage/test/input2.txt"); +} + +static void cleanup(void) +{ + printf("Remove tamporary file and directory\n"); + system("rm -rf /opt/secure-storage/test"); +} + +/** + * @brief Positive test case of ssm_read() + */ +static void utc_SecurityFW_ssm_read_func_01(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + /* variables for ssm_read */ + FILE* fp_original = NULL; + char buf[20]; + char* retbuf = NULL; + int readlen = 0; + ssm_file_info_t sfi; + + /* get original file content. after encrypting, original file will be deleted */ + memset(buf, 0x00, 20); + fp_original = fopen(filepath, "r"); + fgets(buf, 20, fp_original); + fclose(fp_original); + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* read and compare */ + ssm_getinfo(filepath, &sfi, flag, group_id); + retbuf = (char*)malloc(sizeof(char) * (sfi.originSize + 1)); + memset(retbuf, 0x00, (sfi.originSize + 1)); + ret = ssm_read(filepath, retbuf, sfi.originSize, &readlen, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto free_error; + } + + if(tetResult != TET_UNINITIATED) + { + if(!memcmp(buf, retbuf, strlen(retbuf))) // if same + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + } + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + if(ret != 0) + tetResult = TET_UNINITIATED; + +free_error: + free(retbuf); +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} + +/** + * @brief Negative test case of ssm_read() + */ +static void utc_SecurityFW_ssm_read_func_02(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input2.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + /* variables for ssm_read */ + FILE* fp_original = NULL; + char buf[20]; + char* retbuf = NULL; + int readlen = 0; + ssm_file_info_t sfi; + + /* get original file content. after encrypting, original file will be deleted */ + memset(buf, 0x00, 20); + fp_original = fopen(filepath, "r"); + fgets(buf, 20, fp_original); + fclose(fp_original); + + printf("[%s] checkpoint1\n", __func__); + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + printf("[%s] checkpoint2 [%d]\n", __func__, ret); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* read and compare */ + ret = ssm_getinfo(filepath, &sfi, flag, group_id); + printf("[%s] checkpoint3 [%d]\n", __func__, ret); + retbuf = (char*)malloc(sizeof(char) * (sfi.originSize + 1)); + memset(retbuf, 0x00, (sfi.originSize + 1)); + ret = ssm_read(NULL, retbuf, sfi.originSize, &readlen, flag, group_id); + printf("[%s] checkpoint4 [%d]\n", __func__, ret); + if(ret != 0) // if fail, + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + printf("[%s] checkpoint5 [%d]\n", __func__, ret); + if(ret != 0) + tetResult = TET_UNINITIATED; + + free(retbuf); +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} diff --git a/TC/scenario1/utc_SecurityFW_ssm_write_buffer_func.c b/TC/scenario1/utc_SecurityFW_ssm_write_buffer_func.c new file mode 100755 index 0000000..50faf2c --- /dev/null +++ b/TC/scenario1/utc_SecurityFW_ssm_write_buffer_func.c @@ -0,0 +1,155 @@ +/* + * 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 <ss_manager.h> +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SecurityFW_ssm_write_buffer_func_01(void); +static void utc_SecurityFW_ssm_write_buffer_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SecurityFW_ssm_write_buffer_func_01, POSITIVE_TC_IDX }, + { utc_SecurityFW_ssm_write_buffer_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + printf("Make temporary directory - /opt/secure-storage/test/\n"); + system("mkdir -p /opt/secure-storage/test"); + printf("Make temporary file\n"); + system("touch /opt/secure-storage/test/input.txt"); + system("echo \"abcdefghij\" > /opt/secure-storage/test/input.txt"); +} + +static void cleanup(void) +{ + printf("Remove tamporary file and directory\n"); + system("rm -rf /opt/secure-storage/test"); +} + +/** + * @brief Positive test case of ssm_write_buffer() + */ +static void utc_SecurityFW_ssm_write_buffer_func_01(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_buffer */ + int ret = -1; + char oribuf[20]; + ssm_flag flag = SSM_FLAG_SECRET_OPERATION; + char* group_id = NULL; + char* filename = "write_buffer.txt"; + int buflen = 0; + + /* variables for ssm_read */ + char buf[20]; + char* retbuf = NULL; + int readlen = 0; + ssm_file_info_t sfi; + + /* set contents in buffers */ + memset(oribuf, 0x00, 20); + memset(buf, 0x00, 20); + strncpy(oribuf, "abcdefghij", 10); // original buffer + strncpy(buf, "abcdefghij", 10); // encrypting + + buflen = strlen(buf); + + /* write file to secure-storage */ + ret = ssm_write_buffer(buf, buflen, filename, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto error; + } + + /* read and compare */ + ssm_getinfo(filename, &sfi, flag, group_id); + retbuf = (char*)malloc(sizeof(char) * (sfi.originSize + 1)); + memset(retbuf, 0x00, (sfi.originSize + 1)); + + ret = ssm_read(filename, retbuf, sfi.originSize, &readlen, flag, group_id); + if(ret != 0) // if fail, + { + tetResult = TET_UNINITIATED; + goto free_error; + } + + if(tetResult != TET_UNINITIATED) + { + if(!memcmp(oribuf, retbuf, strlen(retbuf))) // if same + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + } + + /* delete encrypted file */ + ret = ssm_delete_file(filename, flag, group_id); + if(ret != 0) + tetResult = TET_UNINITIATED; + +free_error: + free(retbuf); +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} + +/** + * @brief Negative test case of ssm_write_buffer() + */ +static void utc_SecurityFW_ssm_write_buffer_func_02(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_buffer */ + int ret = -1; + char* filename = "write_buffer.txt"; + ssm_flag flag = SSM_FLAG_SECRET_OPERATION; + char buf[20]; + int buflen = 0; + char* group_id = NULL; + + /* write file to secure-storage */ + ret = ssm_write_buffer(NULL, buflen, filename, flag, group_id); + if(ret != 0) // if fail, + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} diff --git a/TC/scenario1/utc_SecurityFW_ssm_write_file_func.c b/TC/scenario1/utc_SecurityFW_ssm_write_file_func.c new file mode 100755 index 0000000..a502992 --- /dev/null +++ b/TC/scenario1/utc_SecurityFW_ssm_write_file_func.c @@ -0,0 +1,147 @@ +/* + * 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 <ss_manager.h> +#include <tet_api.h> + +static void startup(void); +static void cleanup(void); + +void (*tet_startup)(void) = startup; +void (*tet_cleanup)(void) = cleanup; + +static void utc_SecurityFW_ssm_write_file_func_01(void); +static void utc_SecurityFW_ssm_write_file_func_02(void); + +enum { + POSITIVE_TC_IDX = 0x01, + NEGATIVE_TC_IDX, +}; + +struct tet_testlist tet_testlist[] = { + { utc_SecurityFW_ssm_write_file_func_01, POSITIVE_TC_IDX }, + { utc_SecurityFW_ssm_write_file_func_02, NEGATIVE_TC_IDX }, + { NULL, 0 } +}; + +static void startup(void) +{ + printf("Make temporary directory - /opt/secure-storage/test/\n"); + system("mkdir -p /opt/secure-storage/test"); + printf("Make temporary file\n"); + system("touch /opt/secure-storage/test/input.txt"); + system("echo \"abcdefghij\" > /opt/secure-storage/test/input.txt"); +} + +static void cleanup(void) +{ + printf("Remove tamporary file and directory\n"); + system("rm -rf /opt/secure-storage/test"); +} + +/** + * @brief Positive test case of ssm_write_file() + */ +static void utc_SecurityFW_ssm_write_file_func_01(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + /* variables for ssm_read */ + FILE* fp_original = NULL; + char buf[20]; + char* retbuf = NULL; + int readlen = 0; + ssm_file_info_t sfi; + + /* get original file content. after encrypting, original file will be deleted */ + memset(buf, 0x00, 20); + fp_original = fopen(filepath, "r"); + fgets(buf, 20, fp_original); + fclose(fp_original); + + /* write file to secure-storage */ + ret = ssm_write_file(filepath, flag, group_id); + if(ret != 0) { // if fail, + tetResult = TET_UNINITIATED; + goto error; + } + + /* read and compare */ + ssm_getinfo(filepath, &sfi, flag, group_id); + retbuf = (char*)malloc(sizeof(char) * (sfi.originSize + 1)); + memset(retbuf, 0x00, (sfi.originSize + 1)); + ret = ssm_read(filepath, retbuf, sfi.originSize, &readlen, flag, group_id); + if(ret != 0) { // if fail, + tetResult = TET_UNINITIATED; + goto free_error; + } + + if(tetResult != TET_UNINITIATED) + { + if(!memcmp(buf, retbuf, strlen(retbuf))) // if same + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + } + + /* delete encrypted file */ + ret = ssm_delete_file(filepath, flag, group_id); + if(ret != 0) + tetResult = TET_UNINITIATED; + +free_error: + free(retbuf); +error: + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} + +/** + * @brief Negative test case of ssm_write_file() + */ +static void utc_SecurityFW_ssm_write_file_func_02(void) +{ + int tetResult = TET_FAIL; + /* variables for ssm_write_file */ + int ret = -1; + char* filepath = "/opt/secure-storage/test/input.txt"; + ssm_flag flag = SSM_FLAG_DATA; + char* group_id = NULL; + + /* write file to secure-storage */ + ret = ssm_write_file(NULL, flag, group_id); + if(ret != 0) // if fail, + tetResult = TET_PASS; + else + tetResult = TET_FAIL; + + printf("[%d] [%s]\n", tetResult, __FILE__); + tet_result(tetResult); +} |