1 //******************************************************************
3 // Copyright 2015 Samsung Electronics 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 PIN_CALLBACK_DEF_H_
22 #define PIN_CALLBACK_DEF_H_
24 #include "securevirtualresourcetypes.h"
25 #include "casecurityinterface.h"
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)
37 /** Number of PIN type */
38 #define OXM_PIN_TYPE_COUNT 3
41 * PIN type definition.
42 * This type supports multiple bit set.
43 * e.g.) NUM_PIN | UPPERCASE_CHAR_PIN
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
52 * Function pointer to print pin code.
54 typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize);
57 * Function pointer to input pin code.
59 typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
62 * Function to setting generate PIN callback from user.
64 * @param pinCB implementation of generate PIN callback.
66 void SetGeneratePinCB(GeneratePinCallback pinCB);
69 * Function to setting input PIN callback from user.
71 * @param pinCB implementation of input PIN callback.
73 void SetInputPinCB(InputPinCallback pinCB);
75 #ifdef _ENABLE_MULTIPLE_OWNER_
77 * Function to save the preconfig PIN getter from user.
79 * @param pinCB implementation of preconfig PIN function.
81 void SetGetPreconfigPinCB(InputPinCallback pinCB);
82 #endif //_ENABLE_MULTIPLE_OWNER_
85 * Function to unset the input PIN callback.
86 * NOTE : Do not call this function while PIN based ownership transfer.
88 void UnsetInputPinCB();
91 * Function to unset the PIN generation callback.
92 * NOTE : Do not call this function while PIN based ownership transfer.
94 void UnsetGeneratePinCB();
97 * Function to generate random PIN.
98 * This function will send generated PIN to user via callback.
100 * @param pinBuffer is the reference to the buffer to store the generated PIN data.
101 * @param bufferSize is the size of buffer.
103 * @return ::OC_STACK_OK in case of success or other value in case of error.
105 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
108 * Function to input PIN callback via input callback.
110 * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
111 * @param[in] bufferSize is the size of buffer.
113 * @return ::OC_STACK_OK in case of success or other value in ccase of error.
115 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
117 #ifdef _ENABLE_MULTIPLE_OWNER_
119 * Function to save the Pre-configured PIN.
121 * @param[in] pinBuffer PIN data
122 * @param[in] pinLength byte length of PIN
124 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
126 OCStackResult SetPreconfigPin(const char* pinBuffer, size_t pinLength);
129 * Function to read preconfig PIN.
131 * @param[in,out] pinBuffer is the reference to the buffer to store the preconfigured PIN.
132 * @param[in] bufferSize is the size of buffer.
134 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
136 OCStackResult GetPreconfigPin(char* pinBuffer, size_t bufferSize);
140 * Function to setting the policy for random PIN generation
142 * @param[in] pinSize Byte length of random PIN
143 * @param[in] pinType Type of random PIN (ref OicSecPinType)
145 * @return ::OC_STACK_OK in case of success or other value in case of error.
147 OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
152 * This function is used by OTM and SRM to
153 * register device UUID is required to derive the temporal PSK.
155 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
158 * This internal callback is used while Random PIN based OTM.
159 * This callback will be used to establish a temporary secure session according to
160 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
162 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
163 * @param[in] UNUSED1 UNUSED.
164 * @param[in] UNUSED2 UNUSED.
165 * @param[out] result Must be filled with the requested information.
166 * @param[in] result_length Maximum size of @p result.
168 * @return The number of bytes written to @p result or a value
169 * less than zero on error.
171 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
172 const unsigned char *UNUSED1, size_t UNUSED2,
173 unsigned char *result, size_t result_length);
175 #ifdef _ENABLE_MULTIPLE_OWNER_
177 * This internal callback is used while Random PIN based MOT.
178 * This callback will be used to establish a temporary secure session according to
179 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
181 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
182 * @param[in] UNUSED1 UNUSED.
183 * @param[in] UNUSED2 UNUSED.
184 * @param[out] result Must be filled with the requested information.
185 * @param[in] result_length Maximum size of @p result.
187 * @return The number of bytes written to @p result or a value
188 * less than zero on error.
190 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
191 const unsigned char *UNUSED1, size_t UNUSED2,
192 unsigned char *result, size_t result_length);
196 * This internal callback is used while Preconfigured-PIN OTM.
197 * This callback will be used to establish a temporary secure session according to
198 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
200 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
201 * @param[in] UNUSED1 UNUSED.
202 * @param[in] UNUSED2 UNUSED.
203 * @param[out] result Must be filled with the requested information.
204 * @param[in] result_length Maximum size of @p result.
206 * @return The number of bytes written to @p result or a value
207 * less than zero on error.
209 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
210 const unsigned char *UNUSED1, size_t UNUSED2,
211 unsigned char *result, size_t result_length);
215 * This internal callback is used while Preconfigured-PIN MOT.
216 * This callback will be used to establish a temporary secure session according to
217 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
219 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
220 * @param[in] UNUSED1 UNUSED.
221 * @param[in] UNUSED2 UNUSED.
222 * @param[out] result Must be filled with the requested information.
223 * @param[in] result_length Maximum size of @p result.
225 * @return The number of bytes written to @p result or a value
226 * less than zero on error.
228 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
229 const unsigned char *UNUSED1, size_t UNUSED2,
230 unsigned char *result, size_t result_length);
232 #endif //_ENABLE_MULTIPLE_OWNER_
236 * API to derive the PSK based on PIN and new device's UUID.
237 * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
239 * @param[out] result generated PSK
241 * @return 0 for success, otherwise error.
243 int DerivePSKUsingPIN(uint8_t* result);
245 #endif //__WITH_DTLS__
251 #endif //PIN_CALLBACK_DEF_H_