Merge branch 'plugin-interface' into master
[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 #include "securevirtualresourcetypes.h"
27 #include "octypes.h"
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 /**
34  * Initialize credential resource by loading data from persistent storage.
35  *
36  * @retval
37  *     OC_STACK_OK    - no errors
38  *     OC_STACK_ERROR - stack process error
39  */
40 OCStackResult InitCredResource();
41
42 /**
43  * Perform cleanup for credential resources.
44  *
45  * @retval
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
50  */
51 OCStackResult DeInitCredResource();
52
53 /**
54  * This method is used by tinydtls/SRM to retrieve credential for given Subject.
55  *
56  * @param subject - subject for which credential is required.
57  *
58  * @retval
59  *     reference to OicSecCred_t - if credential is found
60  *     NULL                      - if credential not found
61  */
62 const OicSecCred_t* GetCredResourceData(const OicUuid_t* subjectId);
63
64 /**
65  * This function converts credential data into JSON format.
66  * Caller needs to invoke 'free' when done using
67  * returned string.
68  * @param cred  pointer to instance of OicSecCred_t structure.
69  *
70  * @retval
71  *      pointer to JSON credential representation - if credential for subjectId found
72  *      NULL                                      - if credential for subjectId not found
73  */
74 char* BinToCredJSON(const OicSecCred_t* cred);
75
76 /**
77  * This function generates the bin credential data.
78  *
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.
85  *
86  * @retval
87  *      pointer to instance of OicSecCred_t  - success
88  *      NULL                                 - error
89  */
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);
93
94 /**
95  * This function adds the new cred to the credential list.
96  *
97  * @param cred pointer to new credential.
98  *
99  * @retval
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
102  */
103 OCStackResult AddCredential(OicSecCred_t * cred);
104
105 /**
106  * Function to remove the credential from SVR DB.
107  *
108  * @param credId Credential ID to be deleted.
109  *
110  * @return OC_STACK_OK for success and errorcode otherwise.
111  */
112 OCStackResult RemoveCredential(const OicUuid_t* credId);
113
114 #if defined(__WITH_DTLS__)
115 /**
116  * This internal callback is used by lower stack (i.e. CA layer) to
117  * retrieve PSK credentials from RI security layer.
118  *
119  * Note: When finished, caller should initialize memory to zeroes and
120  * invoke OCFree to delete @p credInfo.
121  *
122  * @param credInfo
123  *     binary blob containing PSK credentials
124  *
125  * @retval none
126  */
127 void GetDtlsPskCredentials(CADtlsPskCredsBlob_t **credInfo);
128
129 /**
130  * Add temporal PSK to PIN based OxM
131  *
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.
139  *
140  * @return OC_STACK_OK for success and errorcode otherwise.
141  */
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);
145
146 #endif /* __WITH_DTLS__ */
147
148 #ifdef __WITH_X509__
149 /**
150  * This function is used toretrieve certificate credentials from RI security layer.
151  *
152  * @param credInfo
153  *     binary structure containing certificate credentials
154  *
155  * @retval 0  on scuccess
156  */
157 int GetDtlsX509Credentials(CADtlsX509Creds_t *credInfo);
158 #endif /*__WITH_X509__*/
159
160 /**
161  * Function to deallocate allocated memory to OicSecCred_t
162  *
163  * @param cred pointer to cred type
164  *
165  */
166 void DeleteCredList(OicSecCred_t* cred);
167
168 #ifdef __cplusplus
169 }
170 #endif
171
172 #endif //IOTVT_SRM_CREDR_H
173
174