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 pointer to close the displied PIN.
64 typedef void (*ClosePinDisplayCallback)(void);
67 * Function to setting generate PIN callback from user.
69 * @param pinCB implementation of generate PIN callback.
71 void SetGeneratePinCB(GeneratePinCallback pinCB);
74 * Function to setting input PIN callback from user.
76 * @param pinCB implementation of input PIN callback.
78 void SetInputPinCB(InputPinCallback pinCB);
81 * Function to set the close PIN callback
82 * This callback will be invoked when PIN based OTM is finished.
84 * @param closeCB implementation of close PIN callback.
86 void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB);
89 * Function to unset the input PIN callback.
90 * NOTE : Do not call this function while PIN based ownership transfer.
92 void UnsetInputPinCB();
95 * Function to unset the PIN generation callback.
96 * NOTE : Do not call this function while PIN based ownership transfer.
98 void UnsetGeneratePinCB();
101 * Function to unset the PIN close callback.
102 * NOTE : Do not call this function while PIN based ownership transfer is in progress.
104 void UnsetClosePinCB();
107 * Function to generate random PIN.
108 * This function will send generated PIN to user via callback.
110 * @param pinBuffer is the reference to the buffer to store the generated PIN data.
111 * @param bufferSize is the size of buffer.
113 * @return ::OC_STACK_OK in case of success or other value in case of error.
115 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
118 * Function to input PIN callback via input callback.
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.
123 * @return ::OC_STACK_OK in case of success or other value in ccase of error.
125 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
128 * Function to invoke the callback for close a PIN dispaly.
129 * NOTE : This function will be invoked from SRM while OTM
131 void ClosePinDisplay();
133 #ifdef MULTIPLE_OWNER
135 * Function to save the Pre-configured PIN.
137 * @param[in] pinBuffer PIN data
138 * @param[in] pinLength byte length of PIN
140 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
142 OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength);
146 * Function to setting the policy for random PIN generation
148 * @param[in] pinSize Byte length of random PIN
149 * @param[in] pinType Type of random PIN (ref OicSecPinType)
151 * @return ::OC_STACK_OK in case of success or other value in case of error.
153 OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
158 * This function is used by OTM and SRM to
159 * register device UUID is required to derive the temporal PSK.
161 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
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.
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.
174 * @return The number of bytes written to @p result or a value
175 * less than zero on error.
177 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
178 const unsigned char *UNUSED1, size_t UNUSED2,
179 unsigned char *result, size_t result_length);
181 #ifdef MULTIPLE_OWNER
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.
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.
193 * @return The number of bytes written to @p result or a value
194 * less than zero on error.
196 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
197 const unsigned char *UNUSED1, size_t UNUSED2,
198 unsigned char *result, size_t result_length);
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.
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.
212 * @return The number of bytes written to @p result or a value
213 * less than zero on error.
215 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
216 const unsigned char *UNUSED1, size_t UNUSED2,
217 unsigned char *result, size_t result_length);
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.
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.
231 * @return The number of bytes written to @p result or a value
232 * less than zero on error.
234 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
235 const unsigned char *UNUSED1, size_t UNUSED2,
236 unsigned char *result, size_t result_length);
238 #endif //MULTIPLE_OWNER
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.
244 * @param[out] result generated PSK
246 * @return 0 for success, otherwise error.
248 int DerivePSKUsingPIN(uint8_t* result);
250 #endif //__WITH_DTLS__
256 #endif //PIN_CALLBACK_DEF_H_