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