1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #ifndef IOTVT_SRM_PSI_H
22 #define IOTVT_SRM_PSI_H
24 #if defined (__TIZENRT__)
25 #include <apps/netutils/cJSON.h>
30 // Persistent Storage status definition
33 PS_NORMAL = 0, // Persistent Storage operating normally
34 PS_OPEN_FAIL, // Failed to open persistent storage
35 PS_PARSE_FAIL, // Failed to cbor parse persistent storage
36 PS_NO_EXTERNAL_DB_SET = 99, // no external DB set (initial state)
39 //SVR DB Validity status
44 SVRDB_NOT_CHECKED = 255
48 * Reads the Secure Virtual Database from PS into dynamically allocated
51 * @note Caller of this method MUST use OCFree() method to release memory
52 * referenced by return value.
54 * @return char * reference to memory buffer containing SVR database.
56 char * GetSVRDatabase();
59 * This method is used by a entity handlers of SVR's to update
62 * @param rsrcName string denoting the SVR name ("acl", "cred", "pstat" etc).
63 * @param jsonObj JSON object containing the SVR contents.
65 * @return ::OC_STACK_OK for Success, otherwise some error value
67 OCStackResult UpdateSVRDatabase(const char* rsrcName, cJSON* jsonObj);
70 * Reads the Secure Virtual Database from PS
72 * @note Caller of this method MUST use OCFree() method to release memory
73 * referenced by return value.
75 * @param rsrcName is the name of the field for which file content are read.
76 if the value is NULL it will send the content of the whole file.
77 * @param data is the pointer to the file contents read from the database.
78 * @param size is the size to the file contents read.
80 * @return ::OC_STACK_OK for Success, otherwise some error value
82 OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **data, size_t *size);
85 * Gets the Secure Virtual Database from the Persistent Storage
87 * @param ps - Persistent Storage handler
88 * @param rsrcName - pointer of character string for the SVR name (e.g. "acl")
89 * @param data - pointer of the returned Secure Virtual Resource(s)
90 * @param size - pointer of the returned size of Secure Virtual Resource(s)
92 * @return OCStackResult - result of getting Secure Virtual Resource(s)
94 OCStackResult GetSecureVirtualDatabaseFromPS2(OCPersistentStorage* ps, const char *rsrcName,
95 uint8_t **data, size_t *size);
99 * This method converts updates the persistent storage.
101 * @param rsrcName is the name of the secure resource that will be updated.
102 * @param cborPayload is the pointer holding cbor payload.
103 * @param cborPayload is the size of the cbor payload.
105 * @return ::OC_STACK_OK for Success, otherwise some error value
107 OCStackResult UpdateSecureResourceInPS(const char* rsrcName, const uint8_t* cborPayload, size_t size);
110 * This method resets the secure resources according to the reset profile.
112 * @return ::OC_STACK_OK for Success, otherwise some error value
114 OCStackResult ResetSecureResourceInPS(void);
117 * This method creates the reset profile from the persistent storage.
118 * The reset profile is the copy of the initial state of SVR resources
119 * when secure resources are initiated at first.
120 * In remote reset, the SVR will be reset according to the reset profile.
122 * @return ::OC_STACK_OK for Success, otherwise some error value
124 OCStackResult CreateResetProfile(void);
127 * This method sets the persistent storage status.
129 * @param status is the current persistent storage status
131 void SetPSStatus(PSStatus_t status);
134 * This function return SVR DB state: valid, not valid or was not checked yet
136 * @return Status of SVR DB
138 SVRDBValidStatus_t GetSVRDBValidStatus(void);
141 * This method prints debug log that displays persistent storage status.
143 void PrintPSStatus(void);
146 * Init the Persistent Storage Database.
148 OCStackResult InitPersistentStorageInterface(void);
151 * DeInit the Persistent Storage Database.
153 void DeinitPersistentStorageInterface(void);
156 * API to encrypt the un-encrypted DB file before OCRegisterPersistentStorageHandler
157 * If the API is successful, un-encrypted file will be removed, and if the encrypted file
158 * is currupted, then it restores encrypted file using rescue file.
160 * @param[in] key key used for encryption
161 * @param[in] psPlain OCPersistentStorage for the plain DB
162 * @param[in] psEnc OCPersistentStorage for the encrypted DB
163 * @param[in] psRescue OCPersistentStorage for the rescue DB
165 * @return ::OC_STACK_OK on success and other value otherwise.
167 OCStackResult setSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
168 const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue);
172 * @return pointer on resetSVRDB structure for manipulating with callback
174 resetSVRDBCB_t* GetResetSVRDBCB(void);
177 * API to validate data in SVR DB.
178 * @return ::OC_STACK_OK on success and other value otherwise.
180 OCStackResult CheckSVRDBValidity(void);
183 * This function check if ResetPF are created
184 * @return true in positive case, false otherwise.
186 bool isResetPFExist(void);
188 #endif //IOTVT_SRM_PSI_H