1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 SRP_SECURERESOURCEPROVIDER_H
22 #define SRP_SECURERESOURCEPROVIDER_H
25 #include "securevirtualresourcetypes.h"
36 * API to send ACL information to resource.
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.
46 OCStackResult SRPProvisionACL(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
47 OicSecAcl_t *acl, OicSecAclVersion_t aclVersion, OCProvisionResultCB resultCallback);
50 * API to save ACL which has several ACE into Acl of SVR.
52 * @param acl ACL to be saved in Acl of SVR.
53 * @return OC_STACK_OK in case of success and other value otherwise.
55 OCStackResult SRPSaveACL(const OicSecAcl_t *acl);
58 * API to request CRED information to resource.
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.
66 OCStackResult SRPGetCredResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
67 OCProvisionResultCB resultCallback);
70 * API to request ACL information to resource.
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.
79 OCStackResult SRPGetACLResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
80 OicSecAclVersion_t aclVersion, OCProvisionResultCB resultCallback);
83 * API to request the Certificate Signing Request (CSR) resource.
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.
91 OCStackResult SRPGetCSRResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
92 OCGetCSRResultCB resultCallback);
95 * API to request the Roles resource.
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.
103 OCStackResult SRPGetRolesResource(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
104 OCGetRolesResultCB resultCallback);
107 * This function requests the device delete a particular role certificate by credId.
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.
115 * @return OC_STACK_OK in case of success, and error value otherwise.
117 OCStackResult SRPDeleteRoleCertificateByCredId(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
118 OCProvisionResultCB resultCallback, uint32_t credId);
120 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
123 * function to provision Trust certificate chain to devices.
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.
133 OCStackResult SRPProvisionTrustCertChain(void *ctx, OicSecCredType_t type, uint16_t credId,
134 const OCProvisionDev_t *selectedDeviceInfo,
135 OCProvisionResultCB resultCallback);
138 * function to save Trust certificate chain into Cred of SVR.
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.
146 OCStackResult SRPSaveTrustCertChain(uint8_t *trustCertChain, size_t chainSize,
147 OicEncodingType_t encodingType,uint16_t *credId);
150 * function to save own certificate chain into Cred of SVR.
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.
157 OCStackResult SRPSaveOwnCertChain(OicSecKey_t * cert, OicSecKey_t * key, uint16_t *credId);
160 * function to register callback, for getting notification for TrustCertChain change.
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.
166 OCStackResult SRPRegisterTrustCertChainNotifier(void *ctx, TrustCertChainChangeCB callback);
169 * function to de-register TrustCertChain notification callback.
171 void SRPRemoveTrustCertChainNotifier(void);
173 #endif // __WITH_DTLS__ || __WITH_TLS__
175 * API to send Direct-Pairing Configuration to a device.
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.
184 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
185 OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
188 * API to send Direct-Pairing Configuration to a device.
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.
196 OCStackResult SRPProvisionDirectPairing(void *ctx, const OCProvisionDev_t *selectedDeviceInfo,
197 OicSecPconf_t *pconf, OCProvisionResultCB resultCallback);
200 * API to provision credential to devices.
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.
213 OCStackResult SRPProvisionCredentials(void *ctx,OicSecCredType_t type, size_t keySize,
214 const OCProvisionDev_t *pDev1,
215 const OCProvisionDev_t *pDev2,
217 OCProvisionResultCB resultCallback);
220 * Function to unlink devices.
221 * This function will remove the credential & relationship between the two devices.
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.
231 OCStackResult SRPUnlinkDevices(void* ctx,
232 const OCProvisionDev_t* pTargetDev1,
233 const OCProvisionDev_t* pTargetDev2,
234 OCProvisionResultCB resultCallback);
237 * Function to device revocation.
238 * This function will remove credential of target device from all devices in subnet.
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.
250 OCStackResult SRPRemoveDevice(void* ctx,
251 unsigned short waitTimeForOwnedDeviceDiscovery,
252 const OCProvisionDev_t* pTargetDev,
253 OCProvisionResultCB resultCallback);
256 * Function to device revocation
257 * This function will remove credential of target device from all devices in subnet.
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.
268 OCStackResult SRPRemoveDeviceWithoutDiscovery(void* ctx, const OCProvisionDev_t* pOwnedDevList,
269 const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
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.
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.
285 OCStackResult SRPSyncDevice(void* ctx, unsigned short waitTimeForOwnedDeviceDiscovery,
286 const OCProvisionDev_t* pTargetDev, OCProvisionResultCB resultCallback);
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.
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.
301 OCStackResult SRPResetDevice(const OCProvisionDev_t* pTargetDev,
302 OCProvisionResultCB resultCallback);
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.
312 OCStackResult SRPReadTrustCertChain(uint16_t credId, uint8_t **trustCertChain,
317 #endif //SRP_SECURERESOURCEPROVIDER_H