replace : iotivity -> iotivity-sec
[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_DEFAULT_SIZE (8)
32 #define OXM_RANDOM_PIN_DEFAULT_PIN_TYPE (NUM_PIN | LOWERCASE_CHAR_PIN | UPPERCASE_CHAR_PIN)
33 #define OXM_RANDOM_PIN_MIN_SIZE (4)
34 #define OXM_RANDOM_PIN_MAX_SIZE (32)
35 #define OXM_PRECONFIG_PIN_MAX_SIZE (OXM_RANDOM_PIN_MAX_SIZE)
36
37 /** Number of PIN type */
38 #define OXM_PIN_TYPE_COUNT 3
39
40 /**
41  * PIN type definition.
42  * This type supports multiple bit set.
43  * e.g.) NUM_PIN | UPPERCASE_CHAR_PIN
44  */
45 typedef enum OicSecPinType{
46     NUM_PIN            = (0x1 << 0),    //Numeric PIN
47     UPPERCASE_CHAR_PIN = (0x1 << 1),    //uppercase character PIN
48     LOWERCASE_CHAR_PIN = (0x1 << 2)     //lowercase character PIN
49 }OicSecPinType_t;
50
51 /**
52  * Function pointer to print pin code.
53  */
54 typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize);
55
56 /**
57  * Function pointer to input pin code.
58  */
59 typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
60
61 /**
62  * Function pointer to close the displied PIN.
63  */
64 typedef void (*ClosePinDisplayCallback)(void);
65
66 /**
67  * Function to setting generate PIN callback from user.
68  *
69  * @param pinCB implementation of generate PIN callback.
70  */
71 void SetGeneratePinCB(GeneratePinCallback pinCB);
72
73 /**
74  * Function to setting input PIN callback from user.
75  *
76  * @param pinCB implementation of input PIN callback.
77  */
78 void SetInputPinCB(InputPinCallback pinCB);
79
80 /**
81  * Function to set the close PIN callback
82  * This callback will be invoked when PIN based OTM is finished.
83  *
84  * @param closeCB implementation of close PIN callback.
85  */
86 void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB);
87
88 /**
89  * Function to unset the input PIN callback.
90  * NOTE : Do not call this function while PIN based ownership transfer.
91  */
92 void UnsetInputPinCB();
93
94 /**
95  * Function to unset the PIN generation callback.
96  * NOTE : Do not call this function while PIN based ownership transfer.
97  */
98 void UnsetGeneratePinCB();
99
100 /**
101  * Function to unset the PIN close callback.
102  * NOTE : Do not call this function while PIN based ownership transfer is in progress.
103  */
104 void UnsetClosePinCB();
105
106 /**
107  * Function to generate random PIN.
108  * This function will send generated PIN to user via callback.
109  *
110  * @param pinBuffer is the reference to the buffer to store the generated PIN data.
111  * @param bufferSize is the size of buffer.
112  *
113  * @return ::OC_STACK_OK in case of success or other value in case of error.
114  */
115 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
116
117 /**
118  * Function to input PIN callback via input callback.
119  *
120  * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
121  * @param[in] bufferSize is the size of buffer.
122  *
123  * @return ::OC_STACK_OK in case of success or other value in ccase of error.
124  */
125 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
126
127 /**
128  * Function to invoke the callback for close a PIN dispaly.
129  * NOTE : This function will be invoked from SRM while OTM
130  */
131 void ClosePinDisplay();
132
133 #ifdef MULTIPLE_OWNER
134 /**
135  * Function to save the Pre-configured PIN.
136  *
137  * @param[in] pinBuffer PIN data
138  * @param[in] pinLength byte length of PIN
139  *
140  * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
141  */
142 OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength);
143 #endif
144
145 /**
146  * Function to setting the policy for random PIN generation
147  *
148  * @param[in] pinSize Byte length of random PIN
149  * @param[in] pinType Type of random PIN (ref OicSecPinType)
150  *
151  * @return ::OC_STACK_OK in case of success or other value in case of error.
152  */
153 OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
154
155 #ifdef __WITH_DTLS__
156
157 /**
158  * This function is used by OTM and SRM to
159  * register device UUID is required to derive the temporal PSK.
160  */
161 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
162
163 /**
164  * This internal callback is used while Random PIN based OTM.
165  * This callback will be used to establish a temporary secure session according to
166  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
167  *
168  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
169  * @param[in]  UNUSED1 UNUSED.
170  * @param[in]  UNUSED2 UNUSED.
171  * @param[out] result  Must be filled with the requested information.
172  * @param[in]  result_length  Maximum size of @p result.
173  *
174  * @return The number of bytes written to @p result or a value
175  *         less than zero on error.
176  */
177 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
178               const unsigned char *UNUSED1, size_t UNUSED2,
179               unsigned char *result, size_t result_length);
180
181 #ifdef MULTIPLE_OWNER
182 /**
183  * This internal callback is used while Random PIN based MOT.
184  * This callback will be used to establish a temporary secure session according to
185  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
186  *
187  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
188  * @param[in]  UNUSED1 UNUSED.
189  * @param[in]  UNUSED2 UNUSED.
190  * @param[out] result  Must be filled with the requested information.
191  * @param[in]  result_length  Maximum size of @p result.
192  *
193  * @return The number of bytes written to @p result or a value
194  *         less than zero on error.
195  */
196 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
197               const unsigned char *UNUSED1, size_t UNUSED2,
198               unsigned char *result, size_t result_length);
199
200
201 /**
202  * This internal callback is used while Preconfigured-PIN OTM.
203  * This callback will be used to establish a temporary secure session according to
204  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
205  *
206  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
207  * @param[in]  UNUSED1 UNUSED.
208  * @param[in]  UNUSED2 UNUSED.
209  * @param[out] result  Must be filled with the requested information.
210  * @param[in]  result_length  Maximum size of @p result.
211  *
212  * @return The number of bytes written to @p result or a value
213  *         less than zero on error.
214  */
215 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
216               const unsigned char *UNUSED1, size_t UNUSED2,
217               unsigned char *result, size_t result_length);
218
219
220 /**
221  * This internal callback is used while Preconfigured-PIN MOT.
222  * This callback will be used to establish a temporary secure session according to
223  * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
224  *
225  * @param[in]  type type of PSK data required by tinyDTLS layer during DTLS handshake.
226  * @param[in]  UNUSED1 UNUSED.
227  * @param[in]  UNUSED2 UNUSED.
228  * @param[out] result  Must be filled with the requested information.
229  * @param[in]  result_length  Maximum size of @p result.
230  *
231  * @return The number of bytes written to @p result or a value
232  *         less than zero on error.
233  */
234 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
235               const unsigned char *UNUSED1, size_t UNUSED2,
236               unsigned char *result, size_t result_length);
237
238 #endif //MULTIPLE_OWNER
239
240 /**
241  * API to derive the PSK based on PIN and new device's UUID.
242  * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
243  *
244  * @param[out] result generated PSK
245  *
246  * @return 0 for success, otherwise error.
247  */
248 int DerivePSKUsingPIN(uint8_t* result);
249
250 #endif //__WITH_DTLS__
251
252 #ifdef __cplusplus
253 }
254 #endif
255
256 #endif //PIN_CALLBACK_DEF_H_