Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / credresource.h
1 //******************************************************************
2 //
3 // Copyright 2015 Intel Mobile Communications GmbH 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 IOTVT_SRM_CREDR_H
22 #define IOTVT_SRM_CREDR_H
23
24 #include "ocsecurityconfig.h"
25 #include "cainterface.h"
26
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30
31 /**
32  * Initialize credential resource by loading data from persistent storage.
33  *
34  * @retval
35  *     OC_STACK_OK    - no errors
36  *     OC_STACK_ERROR - stack process error
37  */
38 OCStackResult InitCredResource();
39
40 /**
41  * Perform cleanup for credential resources.
42  *
43  * @retval
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
48  */
49 OCStackResult DeInitCredResource();
50
51 /**
52  * This method is used by tinydtls/SRM to retrieve credential for given Subject.
53  *
54  * @param subject - subject for which credential is required.
55  *
56  * @retval
57  *     reference to OicSecCred_t - if credential is found
58  *     NULL                      - if credential not found
59  */
60 const OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
61
62 /**
63  * This function converts credential data into JSON format.
64  * Caller needs to invoke 'free' when done using
65  * returned string.
66  * @param cred  pointer to instance of OicSecCred_t structure.
67  *
68  * @retval
69  *      pointer to JSON credential representation - if credential for subjectId found
70  *      NULL                                      - if credential for subjectId not found
71  */
72 char* BinToCredJSON(const OicSecCred_t* cred);
73
74 /**
75  * This function generates the bin credential data.
76  *
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.
83  *
84  * @retval
85  *      pointer to instance of OicSecCred_t  - success
86  *      NULL                                 - error
87  */
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);
91
92 /**
93  * This function adds the new cred to the credential list.
94  *
95  * @param cred pointer to new credential.
96  *
97  * @retval
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
100  */
101 OCStackResult AddCredential(OicSecCred_t * cred);
102
103 #if defined(__WITH_DTLS__)
104 /**
105  * This internal callback is used by lower stack (i.e. CA layer) to
106  * retrieve PSK credentials from RI security layer.
107  *
108  * Note: When finished, caller should initialize memory to zeroes and
109  * invoke OCFree to delete @p credInfo.
110  *
111  * @param credInfo
112  *     binary blob containing PSK credentials
113  *
114  * @retval none
115  */
116 void GetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
117 #endif /* __WITH_DTLS__ */
118
119 /**
120  * Function to deallocate allocated memory to OicSecCred_t
121  *
122  * @param cred pointer to cred type
123  *
124  */
125 void DeleteCredList(OicSecCred_t* cred);
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif //IOTVT_SRM_CREDR_H
132
133