f4cd241faf868a2f361fbccbc5ed89ee0b087cde
[platform/upstream/iotivity.git] / resource / csdk / security / provisioning / include / internal / secureresourceprovider.h
1 /* *****************************************************************
2  *
3  * Copyright 2015 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  * *****************************************************************/
20
21 #ifndef SRP_SECURERESOURCEPROVIDER_H
22 #define SRP_SECURERESOURCEPROVIDER_H
23
24 #include "ocstack.h"
25 #include "securevirtualresourcetypes.h"
26 #include "pmtypes.h"
27 #include "octypes.h"
28
29
30 #ifdef __cplusplus
31 extern "C"
32 {
33 #endif
34
35 /**
36  * API to send ACL information to resource.
37  *
38  * @param[in] ctx Application context to be returned in result callback.
39  * @param[in] selectedDeviceInfo Selected target device.
40  * @param[in] aclVersion Version of the ACL resource to access
41  * @param[in] acl ACL to provision.
42  * @param[in] resultCallback callback provided by API user, callback will be called when
43  *            provisioning request recieves a response from resource server.
44  * @return OC_STACK_OK in case of success and other value otherwise.
45  */
46 OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
47                                         OicSecAcl_t *acl, OicSecAclVersion_t aclVersion, OCProvisionResultCB resultCallback);
48
49 /**
50  * API to save ACL which has several ACE into Acl of SVR.
51  *
52  * @param acl ACL to be saved in Acl of SVR.
53  * @return  OC_STACK_OK in case of success and other value otherwise.
54  */
55 OCStackResult SRPSaveACL(const OicSecAcl_t *acl);
56
57 /**
58  * API to request CRED information to resource.
59  *
60  * @param[in] ctx Application context to be returned in result callback.
61  * @param[in] selectedDeviceInfo Selected target device.
62  * @param[in] resultCallback callback provided by API user, callback will be called when
63  *            provisioning request recieves a response from resource server.
64  * @return OC_STACK_OK in case of success and other value otherwise.
65  */
66 OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
67         OCProvisionResultCB resultCallback);
68
69 /**
70  * API to request ACL information to resource.
71  *
72  * @param[in] ctx Application context to be returned in result callback.
73  * @param[in] selectedDeviceInfo Selected target device.
74  * @param[in] aclVersion Version of ACL resource to query
75  * @param[in] resultCallback callback provided by API user, callback will be called when
76  *            provisioning request recieves a response from resource server.
77  * @return OC_STACK_OK in case of success and other value otherwise.
78  */
79 OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
80         OicSecAclVersion_t aclVersion, OCProvisionResultCB resultCallback);
81
82 /**
83  * API to request the Certificate Signing Request (CSR) resource.
84  *
85  * @param[in] ctx Application context to be returned in result callback.
86  * @param[in] selectedDeviceInfo Selected target device.
87  * @param[in] resultCallback callback provided by API user, callback will be called when
88  *            provisioning request recieves a response from resource server.
89  * @return OC_STACK_OK in case of success and other value otherwise.
90  */
91 OCStackResult SRPGetCSRResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
92                                 OCGetCSRResultCB resultCallback);
93
94 /**
95  * API to request the Roles resource.
96  *
97  * @param[in] ctx Application context to be returned in result callback.
98  * @param[in] selectedDeviceInfo Selected target device.
99  * @param[in] resultCallback Callback provided by API user. Callback will be called when
100  *            provisioning request receives a response from resource server.
101  * @return OC_STACK_OK in case of success or error value otherwise.
102  */
103 OCStackResult SRPGetRolesResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
104                                   OCGetRolesResultCB resultCallback);
105
106 /**
107  * This function requests the device delete a particular role certificate by credId.
108  *
109  * @param[in] ctx Application context that is returned in the result callback.
110  * @param[in] selectedDeviceInfo Selected target device.
111  * @param[in] resultCallback callback provided by the API user. Callback will be called when request receives
112  *            a response from the resource server.
113  * @param[in] credId credId to request be deleted.
114  *
115  * @return OC_STACK_OK in case of success, and error value otherwise.
116  */
117 OCStackResult SRPDeleteRoleCertificateByCredId(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
118                                                OCProvisionResultCB resultCallback, uint32_t credId);
119
120 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
121
122 /**
123  * function to provision Trust certificate chain to devices.
124  *
125  * @param[in] ctx Application context to be returned in result callback.
126  * @param[in] type Type of credentials to be provisioned to the device.
127  * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
128  * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
129  * @param[in] resultCallback callback provided by API user, callback will be called when
130  *            provisioning request recieves a response from first resource server.
131  * @return  OC_STACK_OK in case of success and other value otherwise.
132  */
133 OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
134                                       const OCProvisionDev_t *selectedDeviceInfo,
135                                       OCProvisionResultCB resultCallback);
136
137 /**
138  * function to save Trust certificate chain into Cred of SVR.
139  *
140  * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
141  * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
142  * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
143  * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
144  * @return  OC_STACK_OK in case of success and other value otherwise.
145  */
146 OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
147                                         OicEncodingType_t encodingType,uint16_t *credId);
148
149 /**
150  * function to save own certificate chain into Cred of SVR.
151  *
152  * @param[in] cert own certificate chain to be saved in Cred of SVR.
153  * @param[in] key own secret key to be saved in Cred of SVR.
154  * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
155  * @return  OC_STACK_OK in case of success and other value otherwise.
156  */
157 OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_t *credId);
158
159 /**
160  * function to register callback, for getting notification for TrustCertChain change.
161  *
162  * @param[in] ctx user context to be passed.
163  * @param[in] TrustCertChainChangeCB notifier callback function
164  * @return OC_STACK_OK in case of success and other value otherwise.
165  */
166 OCStackResult SRPRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB callback);
167
168 /**
169  * function to de-register TrustCertChain notification callback.
170  */
171 void SRPRemoveTrustCertChainNotifier(void);
172
173 #endif // __WITH_DTLS__ || __WITH_TLS__
174 /**
175  * API to send Direct-Pairing Configuration to a device.
176  *
177  * @param[in] ctx Application context to be returned in result callback.
178  * @param[in] selectedDeviceInfo Selected target device.
179  * @param[in] pconf PCONF pointer.
180  * @param[in] resultCallback callback provided by API user, callback will be called when
181  *            provisioning request recieves a response from resource server.
182  * @return OC_STACK_OK in case of success and other value otherwise.
183  */
184 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
185                                         OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
186
187 /**
188  * API to send Direct-Pairing Configuration to a device.
189  *
190  * @param[in] selectedDeviceInfo Selected target device.
191  * @param[in] pconf PCONF pointer.
192  * @param[in] resultCallback callback provided by API user, callback will be called when
193  *            provisioning request recieves a response from resource server.
194  * @return OC_STACK_OK in case of success and other value otherwise.
195  */
196 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
197                                         OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
198
199 /**
200  * API to provision credential to devices.
201  *
202  * @param[in] ctx Application context to be returned in result callback.
203  * @param[in] type Type of credentials to be provisioned to the device.
204  * @param[in] keySize size of key
205  * @param[in] pDev1 Pointer to PMOwnedDeviceInfo_t instance, respresenting resource to be provsioned.
206  * @param[in] pDev2 Pointer to PMOwnedDeviceInfo_t instance, respresenting resource to be provsioned.
207  * @param[in] pemCert When provisioning a certificate (type is SIGNED_ASYMMETRIC_KEY), this is the 
208  *                    certificate, encoded as PEM. 
209  * @param[in] resultCallback callback provided by API user, callback will be called when
210  *            provisioning request recieves a response from first resource server.
211  * @return OC_STACK_OK in case of success and other value otherwise.
212  */
213 OCStackResult SRPProvisionCredentials(void *ctx,OicSecCredType_t type, size_t keySize,
214                                       const OCProvisionDev_t *pDev1,
215                                       const OCProvisionDev_t *pDev2,
216                                       const char* pemCert,
217                                       OCProvisionResultCB resultCallback);
218
219 /**
220  * Function to unlink devices.
221  * This function will remove the credential & relationship between the two devices.
222  *
223  * @param[in] ctx Application context to be returned in result callback
224  * @param[in] pTargetDev1 first device information to be unlinked.
225  * @param[in] pTargetDev2 second device information to be unlinked.
226  * @param[in] resultCallback callback provided by API user, callback will be called when
227  *            device unlink is finished.
228  *            when there is an error, this user callback is called immediately.
229  * @return OC_STACK_OK in case of success and other value otherwise.
230  */
231 OCStackResult SRPUnlinkDevices(void* ctx,
232                               const OCProvisionDev_t* pTargetDev1,
233                               const OCProvisionDev_t* pTargetDev2,
234                               OCProvisionResultCB resultCallback);
235
236 /**
237  * Function to device revocation.
238  * This function will remove credential of target device from all devices in subnet.
239  *
240  * @param[in] ctx Application context to be returned in result callback
241  * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
242  * @param[in] pTargetDev Device information to be revoked.
243  * @param[in] resultCallback callback provided by API user, callback will be called when
244  *            credential revocation is finished.
245  *            when there is an error, this user callback is called immediately.
246  * @return OC_STACK_OK in case of success and other value otherwise.
247  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
248  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
249  */
250 OCStackResult SRPRemoveDevice(void* ctx,
251                               unsigned short waitTimeForOwnedDeviceDiscovery,
252                               const OCProvisionDev_t* pTargetDev,
253                               OCProvisionResultCB resultCallback);
254
255 /**
256  * Function to device revocation
257  * This function will remove credential of target device from all devices in subnet.
258  *
259  * @param[in] ctx Application context to be returned in result callback
260  * @param[in] pOwnedDevList List of owned devices
261  * @param[in] pTargetDev Device information to be revoked.
262  * @param[in] resultCallback callback provided by API user, callback will be called when
263  *            credential revocation is finished.
264  * @return  OC_STACK_OK in case of success and other value otherwise.
265  *          If OC_STACK_OK is returned, the caller of this API should wait for callback.
266  *          OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
267  */
268 OCStackResult SRPRemoveDeviceWithoutDiscovery(void* ctx, const OCProvisionDev_t* pOwnedDevList,
269                              const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
270
271 /**
272  * Function to sync-up credential and ACL of the target device.
273  * This function will remove credential and ACL of target device from all devices in subnet.
274  *
275  * @param[in] ctx Application context to be returned in result callback
276  * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
277  * @param[in] pTargetDev Device information to be revoked.
278  * @param[in] resultCallback callback provided by API user, callback will be called when
279  *            credential revocation is finished.
280  *            when there is an error, this user callback is called immediately.
281  * @return OC_STACK_OK in case of success and other value otherwise.
282  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
283  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
284  */
285 OCStackResult SRPSyncDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
286                          const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
287
288 /**
289  * Function for remote reset
290  * This function will send pstat POST(modify) message to the target device
291  * to change current mode to reset state in order to initiate remote reset.
292  *
293  * @param[in] pTargetDev Device information to be revoked.
294  * @param[in] resultCallback callback provided by API user, callback will be called when
295  *            credential revocation is finished.
296  *            when there is an error, this user callback is called immediately.
297  * @return OC_STACK_OK in case of success and other value otherwise.
298  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
299  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
300  */
301 OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
302         OCProvisionResultCB resultCallback);
303
304 /**
305  * Function to read Trust certificate chain from SVR.
306  * Caller must free when done using the returned trust certificate
307  * @param[in] credId CredId of trust certificate chain in SVR.
308  * @param[out] trustCertChain Trust certificate chain.
309  * @param[out] chainSize Size of trust certificate chain
310  * @return  OC_STACK_OK in case of success and other value otherwise.
311  */
312 OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
313                                      size_t *chainSize);
314 #ifdef __cplusplus
315 }
316 #endif
317 #endif //SRP_SECURERESOURCEPROVIDER_H