2 * Copyright (c) 2013-2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "secure_file.h"
26 int ss_init(int strategy) {
30 int ss_set_credential(ss_credential_s * cred, const char* uuid,
31 const char* module_name, unsigned long major_ver, unsigned long minor_ver) {
32 if ((NULL == cred) || (NULL == uuid) || (NULL == module_name)) {
33 SLOGE("[%s] input param error.\n", __FUNCTION__);
34 return SS_RET_INVALID_PARAM;
37 int uuid_size = strnlen(uuid, SS_MAX_UUID_LEN) + 1;
38 int mn_size = strnlen(module_name, SS_MAX_MODULE_NAME_LEN) + 1;
40 if (uuid_size > SS_MAX_UUID_LEN || mn_size > SS_MAX_MODULE_NAME_LEN) {
41 SLOGE("[%s] length of uuid or module name error.\n", __FUNCTION__);
42 return SS_RET_INVALID_PARAM;
45 strncpy(cred->uuid, uuid, uuid_size);
46 strncpy(cred->module_name, module_name, mn_size);
48 cred->version.major = major_ver;
49 cred->version.minor = minor_ver;
51 return SS_RET_SUCCESS;
54 int ss_write(unsigned char* buffer, unsigned int data_size, unsigned int offset,
55 const char* data_name, const ss_credential_s * cred, unsigned int options) {
57 int ret = sec_file.initialize(cred, data_name, options);
58 if (SS_RET_SUCCESS != ret) {
62 return sec_file.write(buffer, data_size, offset);
65 int ss_read(unsigned char** ret_buf, unsigned int* data_size,
66 unsigned int offset, const char* data_name, const ss_credential_s * cred,
67 unsigned int options) {
69 int ret = sec_file.initialize(cred, data_name, options);
70 if (SS_RET_SUCCESS != ret) {
74 return sec_file.read(ret_buf, data_size, offset);
77 int ss_write_ex(unsigned char* buffer, unsigned int data_size,
78 unsigned int offset, const char* data_name, const ss_credential_s* cred,
79 unsigned int options, const unsigned char* rsa_n_data,
80 unsigned long rsa_n_len, const unsigned char* rsa_e_data,
81 unsigned long rsa_e_len) {
83 int ret = sec_file.initialize(cred, data_name, options);
84 if (SS_RET_SUCCESS != ret) {
88 return sec_file.write_ex(buffer, data_size, offset, rsa_n_data, rsa_n_len,
89 rsa_e_data, rsa_e_len);
92 int ss_read_ex(unsigned char** ret_buf, unsigned int* data_size,
93 unsigned int offset, const char* data_name, const ss_credential_s* cred,
94 unsigned int options, const unsigned char* rsa_n_data,
95 unsigned long rsa_n_len, const unsigned char* rsa_d_data,
96 unsigned long rsa_d_len) {
98 int ret = sec_file.initialize(cred, data_name, options);
99 if (SS_RET_SUCCESS != ret) {
103 return sec_file.read_ex(ret_buf, data_size, offset, rsa_n_data, rsa_n_len,
104 rsa_d_data, rsa_d_len);
107 int ss_validate(const char* data_name, const ss_credential_s* cred,
108 unsigned int options) {
109 secure_file sec_file;
110 int ret = sec_file.initialize(cred, data_name, options);
111 if (SS_RET_SUCCESS != ret) {
115 return sec_file.validate();
118 int ss_delete(const char* data_name, const ss_credential_s* cred,
119 unsigned int options) {
120 secure_file sec_file;
121 int ret = sec_file.initialize(cred, data_name, options);
122 if (SS_RET_SUCCESS != ret) {
126 return sec_file.remove();
129 int ss_clear_storage(const ss_credential_s* cred, unsigned int options) {
130 secure_file sec_file;
131 int ret = sec_file.initialize(cred, NULL, options);
132 if (SS_RET_SUCCESS != ret) {
136 return sec_file.clear_storage();
139 int ss_free_buffer(unsigned char* buffer) {
140 if (NULL != buffer) {
144 return SS_RET_SUCCESS;