1 //******************************************************************
3 // Copyright 2015 Intel Mobile Communications GmbH All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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 IOTVT_SRM_CREDR_H
22 #define IOTVT_SRM_CREDR_H
24 #include "ocsecurityconfig.h"
25 #include "cainterface.h"
26 #include "securevirtualresourcetypes.h"
34 * Initialize credential resource by loading data from persistent storage.
37 * OC_STACK_OK - no errors
38 * OC_STACK_ERROR - stack process error
40 OCStackResult InitCredResource();
43 * Perform cleanup for credential resources.
46 * OC_STACK_OK - no errors
47 * OC_STACK_ERROR - stack process error
48 * OC_STACK_NO_RESOURCE - resource not found
49 * OC_STACK_INVALID_PARAM - invalid param
51 OCStackResult DeInitCredResource();
54 * This method is used by tinydtls/SRM to retrieve credential for given Subject.
56 * @param subject - subject for which credential is required.
59 * reference to OicSecCred_t - if credential is found
60 * NULL - if credential not found
62 const OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
65 * This function converts credential data into JSON format.
66 * Caller needs to invoke 'free' when done using
68 * @param cred pointer to instance of OicSecCred_t structure.
71 * pointer to JSON credential representation - if credential for subjectId found
72 * NULL - if credential for subjectId not found
74 char* BinToCredJSON(const OicSecCred_t* cred);
77 * This function generates the bin credential data.
79 * @param subject pointer to subject of this credential.
80 * @param credType credential type.
81 * @param publicData public data such as public key.
82 * @param privateData private data such as private key.
83 * @param ownersLen length of owners array
84 * @param owners array of owners.
87 * pointer to instance of OicSecCred_t - success
90 OicSecCred_t * GenerateCredential(const OicUuid_t* subject, OicSecCredType_t credType,
91 const char * publicData, const char * privateData, size_t ownersLen,
92 const OicUuid_t * owners);
95 * This function adds the new cred to the credential list.
97 * @param cred pointer to new credential.
100 * OC_STACK_OK - cred not NULL and persistent storage gets updated
101 * OC_STACK_ERROR - cred is NULL or fails to update persistent storage
103 OCStackResult AddCredential(OicSecCred_t * cred);
106 * Function to remove the credential from SVR DB.
108 * @param credId Credential ID to be deleted.
110 * @return OC_STACK_OK for success and errorcode otherwise.
112 OCStackResult RemoveCredential(const OicUuid_t* credId);
114 #if defined(__WITH_DTLS__)
116 * This internal callback is used by lower stack (i.e. CA layer) to
117 * retrieve PSK credentials from RI security layer.
119 * Note: When finished, caller should initialize memory to zeroes and
120 * invoke OCFree to delete @p credInfo.
123 * binary blob containing PSK credentials
127 void GetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
130 * Add temporal PSK to PIN based OxM
132 * @param[in] tmpSubject UUID of target device
133 * @param[in] credType Type of credential to be added
134 * @param[in] pin numeric characters
135 * @param[in] pinSize length of 'pin'
136 * @param[in] ownersLen Number of owners
137 * @param[in] owners Array of owners
138 * @param[out] tmpCredSubject Generated credential's subject.
140 * @return OC_STACK_OK for success and errorcode otherwise.
142 OCStackResult AddTmpPskWithPIN(const OicUuid_t* tmpSubject, OicSecCredType_t credType,
143 const char * pin, size_t pinSize,
144 size_t ownersLen, const OicUuid_t * owners, OicUuid_t* tmpCredSubject);
146 #endif /* __WITH_DTLS__ */
150 * This function is used toretrieve certificate credentials from RI security layer.
153 * binary structure containing certificate credentials
155 * @retval 0 on scuccess
157 int GetDtlsX509Credentials(CADtlsX509Creds_t *credInfo);
158 #endif /*__WITH_X509__*/
161 * Function to deallocate allocated memory to OicSecCred_t
163 * @param cred pointer to cred type
166 void DeleteCredList(OicSecCred_t* cred);
172 #endif //IOTVT_SRM_CREDR_H