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"
32 * Initialize credential resource by loading data from persistent storage.
35 * OC_STACK_OK - no errors
36 * OC_STACK_ERROR - stack process error
38 OCStackResult InitCredResource();
41 * Perform cleanup for credential resources.
44 * OC_STACK_OK - no errors
45 * OC_STACK_ERROR - stack process error
46 * OC_STACK_NO_RESOURCE - resource not found
47 * OC_STACK_INVALID_PARAM - invalid param
49 OCStackResult DeInitCredResource();
52 * This method is used by tinydtls/SRM to retrieve credential for given Subject.
54 * @param subject - subject for which credential is required.
57 * reference to OicSecCred_t - if credential is found
58 * NULL - if credential not found
60 const OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
63 * This function converts credential data into JSON format.
64 * Caller needs to invoke 'free' when done using
66 * @param cred pointer to instance of OicSecCred_t structure.
69 * pointer to JSON credential representation - if credential for subjectId found
70 * NULL - if credential for subjectId not found
72 char* BinToCredJSON(const OicSecCred_t* cred);
75 * This function generates the bin credential data.
77 * @param subject pointer to subject of this credential.
78 * @param credType credential type.
79 * @param publicData public data such as public key.
80 * @param privateData private data such as private key.
81 * @param ownersLen length of owners array
82 * @param owners array of owners.
85 * pointer to instance of OicSecCred_t - success
88 OicSecCred_t * GenerateCredential(const OicUuid_t* subject, OicSecCredType_t credType,
89 const char * publicData, const char * privateData, size_t ownersLen,
90 const OicUuid_t * owners);
93 * This function adds the new cred to the credential list.
95 * @param cred pointer to new credential.
98 * OC_STACK_OK - cred not NULL and persistent storage gets updated
99 * OC_STACK_ERROR - cred is NULL or fails to update persistent storage
101 OCStackResult AddCredential(OicSecCred_t * cred);
104 * Function to remove the credential from SVR DB.
106 * @param credId Credential ID to be deleted.
108 * @return OC_STACK_OK for success and errorcode otherwise.
110 OCStackResult RemoveCredential(const OicUuid_t* credId);
112 #if defined(__WITH_DTLS__)
114 * This internal callback is used by lower stack (i.e. CA layer) to
115 * retrieve PSK credentials from RI security layer.
117 * Note: When finished, caller should initialize memory to zeroes and
118 * invoke OCFree to delete @p credInfo.
121 * binary blob containing PSK credentials
125 void GetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
128 * Add temporal PSK to PIN based OxM
130 * @param[in] tmpSubject UUID of target device
131 * @param[in] credType Type of credential to be added
132 * @param[in] pin numeric characters
133 * @param[in] pinSize length of 'pin'
134 * @param[in] ownersLen Number of owners
135 * @param[in] owners Array of owners
136 * @param[out] tmpCredSubject Generated credential's subject.
138 * @return OC_STACK_OK for success and errorcode otherwise.
140 OCStackResult AddTmpPskWithPIN(const OicUuid_t* tmpSubject, OicSecCredType_t credType,
141 const char * pin, size_t pinSize,
142 size_t ownersLen, const OicUuid_t * owners, OicUuid_t* tmpCredSubject);
144 #endif /* __WITH_DTLS__ */
147 * Function to deallocate allocated memory to OicSecCred_t
149 * @param cred pointer to cred type
152 void DeleteCredList(OicSecCred_t* cred);
158 #endif //IOTVT_SRM_CREDR_H