replace : iotivity -> iotivity-sec
[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] selectedDeviceInfo Selected target device.
39  * @param[in] acl ACL to provision.
40  * @param[in] resultCallback callback provided by API user, callback will be called when
41  *            provisioning request recieves a response from resource server.
42  * @return OC_STACK_OK in case of success and other value otherwise.
43  */
44 OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
45                                         OicSecAcl_t *acl, OCProvisionResultCB resultCallback);
46
47 /**
48  * API to save ACL which has several ACE into Acl of SVR.
49  *
50  * @param acl ACL to be saved in Acl of SVR.
51  * @return  OC_STACK_OK in case of success and other value otherwise.
52  */
53 OCStackResult SRPSaveACL(const OicSecAcl_t *acl);
54
55 /**
56  * API to request CRED information to resource.
57  *
58  * @param[in] selectedDeviceInfo Selected target device.
59  * @param[in] resultCallback callback provided by API user, callback will be called when
60  *            provisioning request recieves a response from resource server.
61  * @return OC_STACK_OK in case of success and other value otherwise.
62  */
63 OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
64         OCProvisionResultCB resultCallback);
65
66 /**
67  * API to request ACL information to resource.
68  *
69  * @param[in] selectedDeviceInfo Selected target device.
70  * @param[in] resultCallback callback provided by API user, callback will be called when
71  *            provisioning request recieves a response from resource server.
72  * @return OC_STACK_OK in case of success and other value otherwise.
73  */
74 OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
75         OCProvisionResultCB resultCallback);
76
77 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
78
79 /**
80  * function to provision Trust certificate chain to devices.
81  *
82  * @param[in] ctx Application context would be returned in result callback.
83  * @param[in] type Type of credentials to be provisioned to the device.
84  * @param[in] credId CredId of trust certificate chain to be provisioned to the device.
85  * @param[in] selectedDeviceInfo Pointer to OCProvisionDev_t instance,respresenting resource to be provsioned.
86  * @param[in] resultCallback callback provided by API user, callback will be called when
87  *            provisioning request recieves a response from first resource server.
88  * @return  OC_STACK_OK in case of success and other value otherwise.
89  */
90 OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
91                                       const OCProvisionDev_t *selectedDeviceInfo,
92                                       OCProvisionResultCB resultCallback);
93
94 /**
95  * function to save Trust certificate chain into Cred of SVR.
96  *
97  * @param[in] trustCertChain Trust certificate chain to be saved in Cred of SVR.
98  * @param[in] chainSize Size of trust certificate chain to be saved in Cred of SVR
99  * @param[in] encodingType Encoding type of trust certificate chain to be saved in Cred of SVR
100  * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
101  * @return  OC_STACK_OK in case of success and other value otherwise.
102  */
103 OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
104                                         OicEncodingType_t encodingType,uint16_t *credId);
105
106 /**
107  * function to save own certificate chain into Cred of SVR.
108  *
109  * @param[in] cert own certificate chain to be saved in Cred of SVR.
110  * @param[in] key own secret key to be saved in Cred of SVR.
111  * @param[out] credId CredId of saved trust certificate chain in Cred of SVR.
112  * @return  OC_STACK_OK in case of success and other value otherwise.
113  */
114 OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_t *credId);
115
116 /**
117  * function to register callback, for getting notification for TrustCertChain change.
118  *
119  * @param[in] ctx user context to be passed.
120  * @param[in] TrustCertChainChangeCB notifier callback function
121  * @return OC_STACK_OK in case of success and other value otherwise.
122  */
123 OCStackResult SRPRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB callback);
124
125 /**
126  * function to de-register TrustCertChain notification callback.
127  */
128 void SRPRemoveTrustCertChainNotifier(void);
129
130 #endif // __WITH_DTLS__ || __WITH_TLS__
131 /**
132  * API to send Direct-Pairing Configuration to a device.
133  *
134  * @param[in] selectedDeviceInfo Selected target device.
135  * @param[in] pconf PCONF pointer.
136  * @param[in] resultCallback callback provided by API user, callback will be called when
137  *            provisioning request recieves a response from resource server.
138  * @return OC_STACK_OK in case of success and other value otherwise.
139  */
140 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
141                                         OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
142
143 /**
144  * API to send Direct-Pairing Configuration to a device.
145  *
146  * @param[in] selectedDeviceInfo Selected target device.
147  * @param[in] pconf PCONF pointer.
148  * @param[in] resultCallback callback provided by API user, callback will be called when
149  *            provisioning request recieves a response from resource server.
150  * @return OC_STACK_OK in case of success and other value otherwise.
151  */
152 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
153                                         OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
154
155 /**
156  * API to provision credential to devices.
157  *
158  * @param[in] type Type of credentials to be provisioned to the device.
159  * @param[in] pDev1 Pointer to PMOwnedDeviceInfo_t instance,respresenting resource to be provsioned.
160    @param[in] pDev2 Pointer to PMOwnedDeviceInfo_t instance,respresenting resource to be provsioned.
161  * @param[in] resultCallback callback provided by API user, callback will be called when
162  *            provisioning request recieves a response from first resource server.
163  * @return OC_STACK_OK in case of success and other value otherwise.
164  */
165 OCStackResult SRPProvisionCredentials(void *ctx,OicSecCredType_t type, size_t keySize,
166                                       const OCProvisionDev_t *pDev1,
167                                       const OCProvisionDev_t *pDev2,
168                                       OCProvisionResultCB resultCallback);
169
170 /**
171  * Function to unlink devices.
172  * This function will remove the credential & relationship between the two devices.
173  *
174  * @param[in] ctx Application context would be returned in result callback
175  * @param[in] pTargetDev1 first device information to be unlinked.
176  * @param[in] pTargetDev2 second device information to be unlinked.
177  * @param[in] resultCallback callback provided by API user, callback will be called when
178  *            device unlink is finished.
179  *            when there is an error, this user callback is called immediately.
180  * @return OC_STACK_OK in case of success and other value otherwise.
181  */
182 OCStackResult SRPUnlinkDevices(void* ctx,
183                               const OCProvisionDev_t* pTargetDev1,
184                               const OCProvisionDev_t* pTargetDev2,
185                               OCProvisionResultCB resultCallback);
186
187 /*
188  * Function to device revocation.
189  * This function will remove credential of target device from all devices in subnet.
190  *
191  * @param[in] ctx Application context would be returned in result callback
192  * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
193  * @param[in] pTargetDev Device information to be revoked.
194  * @param[in] resultCallback callback provided by API user, callback will be called when
195  *            credential revocation is finished.
196  *            when there is an error, this user callback is called immediately.
197  * @return OC_STACK_OK in case of success and other value otherwise.
198  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
199  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
200  */
201 OCStackResult SRPRemoveDevice(void* ctx,
202                               unsigned short waitTimeForOwnedDeviceDiscovery,
203                               const OCProvisionDev_t* pTargetDev,
204                               OCProvisionResultCB resultCallback);
205
206 /*
207 * Function to device revocation
208 * This function will remove credential of target device from all devices in subnet.
209 *
210 * @param[in] ctx Application context would be returned in result callback
211 * @param[in] pOwnedDevList List of owned devices
212 * @param[in] pTargetDev Device information to be revoked.
213 * @param[in] resultCallback callback provided by API user, callback will be called when
214 *            credential revocation is finished.
215 * @return  OC_STACK_OK in case of success and other value otherwise.
216 *          If OC_STACK_OK is returned, the caller of this API should wait for callback.
217 *          OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
218 */
219 OCStackResult SRPRemoveDeviceWithoutDiscovery(void* ctx, const OCProvisionDev_t* pOwnedDevList,
220                              const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
221
222 /*
223  * Function to sync-up credential and ACL of the target device.
224  * This function will remove credential and ACL of target device from all devices in subnet.
225  *
226  * @param[in] ctx Application context would be returned in result callback
227  * @param[in] waitTimeForOwnedDeviceDiscovery Maximum wait time for owned device discovery.(seconds)
228  * @param[in] pTargetDev Device information to be revoked.
229  * @param[in] resultCallback callback provided by API user, callback will be called when
230  *            credential revocation is finished.
231  *            when there is an error, this user callback is called immediately.
232  * @return OC_STACK_OK in case of success and other value otherwise.
233  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
234  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
235  */
236 OCStackResult SRPSyncDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
237                          const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
238
239 /*
240  * Function for remote reset
241  * This function will send pstat POST(modify) message to the target device
242  * to change current mode to reset state in order to initiate remote reset.
243  *
244  * @param[in] pTargetDev Device information to be revoked.
245  * @param[in] resultCallback callback provided by API user, callback will be called when
246  *            credential revocation is finished.
247  *            when there is an error, this user callback is called immediately.
248  * @return OC_STACK_OK in case of success and other value otherwise.
249  *         If OC_STACK_OK is returned, the caller of this API should wait for callback.
250  *         OC_STACK_CONTINUE means operation is success but no request is need to be initiated.
251  */
252 OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
253         OCProvisionResultCB resultCallback);
254
255 /*
256  * Function to read Trust certificate chain from SVR.
257  * Caller must free when done using the returned trust certificate
258  * @param[in] credId CredId of trust certificate chain in SVR.
259  * @param[out] trustCertChain Trust certificate chain.
260  * @param[out] chainSize Size of trust certificate chain
261  * @return  OC_STACK_OK in case of success and other value otherwise.
262  */
263 OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
264                                      size_t *chainSize);
265 #ifdef __cplusplus
266 }
267 #endif
268 #endif //SRP_SECURERESOURCEPROVIDER_H