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)
40 * Reads the Secure Virtual Database from PS into dynamically allocated
43 * @note Caller of this method MUST use OCFree() method to release memory
44 * referenced by return value.
46 * @return char * reference to memory buffer containing SVR database.
48 char * GetSVRDatabase();
51 * This method is used by a entity handlers of SVR's to update
54 * @param rsrcName string denoting the SVR name ("acl", "cred", "pstat" etc).
55 * @param jsonObj JSON object containing the SVR contents.
57 * @return ::OC_STACK_OK for Success, otherwise some error value
59 OCStackResult UpdateSVRDatabase(const char* rsrcName, cJSON* jsonObj);
62 * Reads the Secure Virtual Database from PS
64 * @note Caller of this method MUST use OCFree() method to release memory
65 * referenced by return value.
67 * @param rsrcName is the name of the field for which file content are read.
68 if the value is NULL it will send the content of the whole file.
69 * @param data is the pointer to the file contents read from the database.
70 * @param size is the size to the file contents read.
72 * @return ::OC_STACK_OK for Success, otherwise some error value
74 OCStackResult GetSecureVirtualDatabaseFromPS(const char *rsrcName, uint8_t **data, size_t *size);
77 * Gets the Secure Virtual Database from the Persistent Storage
79 * @param ps - Persistent Storage handler
80 * @param rsrcName - pointer of character string for the SVR name (e.g. "acl")
81 * @param data - pointer of the returned Secure Virtual Resource(s)
82 * @param size - pointer of the returned size of Secure Virtual Resource(s)
84 * @return OCStackResult - result of getting Secure Virtual Resource(s)
86 OCStackResult GetSecureVirtualDatabaseFromPS2(OCPersistentStorage* ps, const char *rsrcName,
87 uint8_t **data, size_t *size);
91 * This method converts updates the persistent storage.
93 * @param rsrcName is the name of the secure resource that will be updated.
94 * @param cborPayload is the pointer holding cbor payload.
95 * @param cborPayload is the size of the cbor payload.
97 * @return ::OC_STACK_OK for Success, otherwise some error value
99 OCStackResult UpdateSecureResourceInPS(const char* rsrcName, const uint8_t* cborPayload, size_t size);
102 * This method resets the secure resources according to the reset profile.
104 * @return ::OC_STACK_OK for Success, otherwise some error value
106 OCStackResult ResetSecureResourceInPS(void);
109 * This method creates the reset profile from the persistent storage.
110 * The reset profile is the copy of the initial state of SVR resources
111 * when secure resources are initiated at first.
112 * In remote reset, the SVR will be reset according to the reset profile.
114 * @return ::OC_STACK_OK for Success, otherwise some error value
116 OCStackResult CreateResetProfile(void);
119 * This method sets the persistent storage status.
121 * @param status is the current persistent storage status
123 void SetPSStatus(PSStatus_t status);
126 * This method prints debug log that displays persistent storage status.
128 void PrintPSStatus(void);
131 * Init the Persistent Storage Database.
133 OCStackResult InitPersistentStorageInterface(void);
136 * DeInit the Persistent Storage Database.
138 void DeinitPersistentStorageInterface(void);
141 * API to encrypt the un-encrypted DB file before OCRegisterPersistentStorageHandler
142 * If the API is successful, un-encrypted file will be removed, and if the encrypted file
143 * is currupted, then it restores encrypted file using rescue file.
145 * @param[in] key key used for encryption
146 * @param[in] psPlain OCPersistentStorage for the plain DB
147 * @param[in] psEnc OCPersistentStorage for the encrypted DB
148 * @param[in] psRescue OCPersistentStorage for the rescue DB
150 * @return ::OC_STACK_OK on success and other value otherwise.
152 OCStackResult setSecurePSI(const unsigned char *key, const OCPersistentStorage *psPlain,
153 const OCPersistentStorage *psEnc, const OCPersistentStorage *psRescue);
155 #endif //IOTVT_SRM_PSI_H