Multiple Ownership Transfer support.
[platform/upstream/iotivity.git] / resource / csdk / security / include / pinoxmcommon.h
1 //******************************************************************
2 //
3 // Copyright 2015 Samsung Electronics 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 PIN_CALLBACK_DEF_H_
22 #define PIN_CALLBACK_DEF_H_
23
24 #include "securevirtualresourcetypes.h"
25 #include "casecurityinterface.h"
26
27 #ifdef __cplusplus
28  extern "C" {
29 #endif // __cplusplus
30
31 #define OXM_RANDOM_PIN_SIZE (8)
32 #define OXM_PRECONFIG_PIN_SIZE (OXM_RANDOM_PIN_SIZE)
33
34
35 /**
36  * Function pointer to print pin code.
37  */
38 typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize);
39
40 /**
41  * Function pointer to input pin code.
42  */
43 typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
44
45 /**
46  * Function to setting generate PIN callback from user.
47  *
48  * @param pinCB implementation of generate PIN callback.
49  */
50 void SetGeneratePinCB(GeneratePinCallback pinCB);
51
52 /**
53  * Function to setting input PIN callback from user.
54  *
55  * @param pinCB implementation of input PIN callback.
56  */
57 void SetInputPinCB(InputPinCallback pinCB);
58
59 #ifdef _ENABLE_MULTIPLE_OWNER_
60 /**
61  * Function to save the preconfig PIN getter from user.
62  *
63  * @param pinCB implementation of preconfig PIN function.
64  */
65 void SetGetPreconfigPinCB(InputPinCallback pinCB);
66 #endif //_ENABLE_MULTIPLE_OWNER_
67
68 /**
69  * Function to generate random PIN.
70  * This function will send generated PIN to user via callback.
71  *
72  * @param pinBuffer is the reference to the buffer to store the generated PIN data.
73  * @param bufferSize is the size of buffer.
74  *
75  * @return ::OC_STACK_SUCCESS in case of success or other value in case of error.
76  */
77 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
78
79 /**
80  * Function to input PIN callback via input callback.
81  *
82  * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
83  * @param[in] bufferSize is the size of buffer.
84  *
85  * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
86  */
87 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
88
89
90 #ifdef _ENABLE_MULTIPLE_OWNER_
91 /**
92  * Function to save the Pre-configured PIN.
93  *
94  * @param[in] pinBuffer PIN data
95  * @param[in] pinLength byte length of PIN
96  *
97  * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
98  */
99 OCStackResult SetPreconfigPin(const char* pinBuffer, size_t pinLength);
100
101 /**
102  * Function to read preconfig PIN.
103  *
104  * @param[in,out] pinBuffer is the reference to the buffer to store the preconfigured PIN.
105  * @param[in] bufferSize is the size of buffer.
106  *
107  * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
108  */
109 OCStackResult GetPreconfigPin(char* pinBuffer, size_t bufferSize);
110 #endif
111
112 #ifdef __WITH_DTLS__
113
114 /**
115  * This function is used by OTM and SRM to
116  * register device UUID is required to derive the temporal PSK.
117  */
118 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
119
120 /**
121  * This internal callback is used while Random PIN based OTM.
122  * This callback will be used to establish a temporary secure session according to
123  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
124  *
125  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
126  * @param[in]  UNUSED1 UNUSED.
127  * @param[in]  UNUSED2 UNUSED.
128  * @param[out] result  Must be filled with the requested information.
129  * @param[in]  result_length  Maximum size of @p result.
130  *
131  * @return The number of bytes written to @p result or a value
132  *         less than zero on error.
133  */
134 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
135               const unsigned char *UNUSED1, size_t UNUSED2,
136               unsigned char *result, size_t result_length);
137
138 #ifdef _ENABLE_MULTIPLE_OWNER_
139 /**
140  * This internal callback is used while Random PIN based MOT.
141  * This callback will be used to establish a temporary secure session according to
142  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
143  *
144  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
145  * @param[in]  UNUSED1 UNUSED.
146  * @param[in]  UNUSED2 UNUSED.
147  * @param[out] result  Must be filled with the requested information.
148  * @param[in]  result_length  Maximum size of @p result.
149  *
150  * @return The number of bytes written to @p result or a value
151  *         less than zero on error.
152  */
153 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
154               const unsigned char *UNUSED1, size_t UNUSED2,
155               unsigned char *result, size_t result_length);
156
157
158 /**
159  * This internal callback is used while Preconfigured-PIN OTM.
160  * This callback will be used to establish a temporary secure session according to
161  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
162  *
163  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
164  * @param[in]  UNUSED1 UNUSED.
165  * @param[in]  UNUSED2 UNUSED.
166  * @param[out] result  Must be filled with the requested information.
167  * @param[in]  result_length  Maximum size of @p result.
168  *
169  * @return The number of bytes written to @p result or a value
170  *         less than zero on error.
171  */
172 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
173               const unsigned char *UNUSED1, size_t UNUSED2,
174               unsigned char *result, size_t result_length);
175
176
177 /**
178  * This internal callback is used while Preconfigured-PIN MOT.
179  * This callback will be used to establish a temporary secure session according to
180  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
181  *
182  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
183  * @param[in]  UNUSED1 UNUSED.
184  * @param[in]  UNUSED2 UNUSED.
185  * @param[out] result  Must be filled with the requested information.
186  * @param[in]  result_length  Maximum size of @p result.
187  *
188  * @return The number of bytes written to @p result or a value
189  *         less than zero on error.
190  */
191 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
192               const unsigned char *UNUSED1, size_t UNUSED2,
193               unsigned char *result, size_t result_length);
194
195 #endif //_ENABLE_MULTIPLE_OWNER_
196
197
198 /**
199  * API to derive the PSK based on PIN and new device's UUID.
200  * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
201  *
202  * @param[out] result generated PSK
203  *
204  * @return 0 for success, otherwise error.
205  */
206 int DerivePSKUsingPIN(uint8_t* result);
207
208 #endif //__WITH_DTLS__
209
210 #ifdef __cplusplus
211 }
212 #endif
213
214 #endif //PIN_CALLBACK_DEF_H_