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);
103 #if defined(__WITH_DTLS__)
105 * This internal callback is used by lower stack (i.e. CA layer) to
106 * retrieve PSK credentials from RI security layer.
108 * Note: When finished, caller should initialize memory to zeroes and
109 * invoke OCFree to delete @p credInfo.
112 * binary blob containing PSK credentials
116 void GetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
117 #endif /* __WITH_DTLS__ */
120 * Function to deallocate allocated memory to OicSecCred_t
122 * @param cred pointer to cred type
125 void DeleteCredList(OicSecCred_t* cred);
131 #endif //IOTVT_SRM_CREDR_H