1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
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;
}
|