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