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 for getting master key for raw public key OTM.
63 * Callback is expected to set *rpkMasterKey pointer to binary data buffer
64 * containing the key. Master key lenght must not exceed OXM_RPK_MASTER_KEY_MAX_SIZE.
66 typedef void (*GetRPKMasterKeyCallback)(char **rpkMasterKey, size_t *rpkMasterKeyLen);
69 * Function pointer to close the displied PIN.
71 typedef void (*ClosePinDisplayCallback)(void);
74 * Function to setting generate PIN callback from user.
76 * @param pinCB implementation of generate PIN callback.
78 void SetGeneratePinCB(GeneratePinCallback pinCB);
81 * Function to set preconfigured PIN value.
83 * @param[in] pin PIN data
84 * @param[in] pinLen byte length of PIN
86 OCStackResult SetPin(const char * pin, size_t pinLen);
89 * Function to unset preconfigured PIN.
91 OCStackResult UnSetPin();
94 * Function to setting input PIN callback from user.
96 * @param pinCB implementation of input PIN callback.
98 void SetInputPinCB(InputPinCallback pinCB);
101 * Function to set the close PIN callback
102 * This callback will be invoked when PIN based OTM is finished.
104 * @param closeCB implementation of close PIN callback.
106 void SetClosePinDisplayCB(ClosePinDisplayCallback closeCB);
109 * Function to unset the input PIN callback.
110 * NOTE : Do not call this function while PIN based ownership transfer.
112 void UnsetInputPinCB();
115 * Function to unset the PIN generation callback.
116 * NOTE : Do not call this function while PIN based ownership transfer.
118 void UnsetGeneratePinCB();
121 * Function to unset the PIN close callback.
122 * NOTE : Do not call this function while PIN based ownership transfer is in progress.
124 void UnsetClosePinCB();
127 * Function to generate random PIN.
128 * This function will send generated PIN to user via callback.
130 * @param pinBuffer is the reference to the buffer to store the generated PIN data.
131 * @param bufferSize is the size of buffer.
133 * @return ::OC_STACK_OK in case of success or other value in case of error.
135 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
138 * Function to input PIN callback via input callback.
140 * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
141 * @param[in] bufferSize is the size of buffer.
143 * @return ::OC_STACK_OK in case of success or other value in ccase of error.
145 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
148 * Function to invoke the callback for close a PIN dispaly.
149 * NOTE : This function will be invoked from SRM while OTM
151 void ClosePinDisplay();
153 #ifdef MULTIPLE_OWNER
155 * Function to save the Pre-configured PIN.
157 * @param[in] pinBuffer PIN data
158 * @param[in] pinLength byte length of PIN
160 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
162 OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength);
166 * Function to setting the policy for random PIN generation
168 * @param[in] pinSize Byte length of random PIN
169 * @param[in] pinType Type of random PIN (ref OicSecPinType)
171 * @return ::OC_STACK_OK in case of success or other value in case of error.
173 OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
178 * This function is used by OTM and SRM to
179 * register device UUID is required to derive the temporal PSK.
181 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
184 * This internal callback is used while Random PIN based OTM.
185 * This callback will be used to establish a temporary secure session according to
186 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
188 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
189 * @param[in] UNUSED1 UNUSED.
190 * @param[in] UNUSED2 UNUSED.
191 * @param[out] result Must be filled with the requested information.
192 * @param[in] result_length Maximum size of @p result.
194 * @return The number of bytes written to @p result or a value
195 * less than zero on error.
197 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
198 const unsigned char *UNUSED1, size_t UNUSED2,
199 unsigned char *result, size_t result_length);
201 #ifdef MULTIPLE_OWNER
203 * This internal callback is used while Random PIN based MOT.
204 * This callback will be used to establish a temporary secure session according to
205 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
207 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
208 * @param[in] UNUSED1 UNUSED.
209 * @param[in] UNUSED2 UNUSED.
210 * @param[out] result Must be filled with the requested information.
211 * @param[in] result_length Maximum size of @p result.
213 * @return The number of bytes written to @p result or a value
214 * less than zero on error.
216 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
217 const unsigned char *UNUSED1, size_t UNUSED2,
218 unsigned char *result, size_t result_length);
222 * This internal callback is used while Preconfigured-PIN OTM.
223 * This callback will be used to establish a temporary secure session according to
224 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
226 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
227 * @param[in] UNUSED1 UNUSED.
228 * @param[in] UNUSED2 UNUSED.
229 * @param[out] result Must be filled with the requested information.
230 * @param[in] result_length Maximum size of @p result.
232 * @return The number of bytes written to @p result or a value
233 * less than zero on error.
235 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
236 const unsigned char *UNUSED1, size_t UNUSED2,
237 unsigned char *result, size_t result_length);
241 * This internal callback is used while Preconfigured-PIN MOT.
242 * This callback will be used to establish a temporary secure session according to
243 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
245 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
246 * @param[in] UNUSED1 UNUSED.
247 * @param[in] UNUSED2 UNUSED.
248 * @param[out] result Must be filled with the requested information.
249 * @param[in] result_length Maximum size of @p result.
251 * @return The number of bytes written to @p result or a value
252 * less than zero on error.
254 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
255 const unsigned char *UNUSED1, size_t UNUSED2,
256 unsigned char *result, size_t result_length);
258 #endif //MULTIPLE_OWNER
261 * API to derive the PSK based on PIN and new device's UUID.
262 * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
264 * @param[out] result generated PSK
266 * @return 0 for success, otherwise error.
268 int DerivePSKUsingPIN(uint8_t* result);
270 #endif //__WITH_DTLS__
276 #endif //PIN_CALLBACK_DEF_H_