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);
76 * Function to unset the input PIN callback.
77 * NOTE : Do not call this function while PIN based ownership transfer.
79 void UnsetInputPinCB();
82 * Function to unset the PIN generation callback.
83 * NOTE : Do not call this function while PIN based ownership transfer.
85 void UnsetGeneratePinCB();
88 * Function to generate random PIN.
89 * This function will send generated PIN to user via callback.
91 * @param pinBuffer is the reference to the buffer to store the generated PIN data.
92 * @param bufferSize is the size of buffer.
94 * @return ::OC_STACK_OK in case of success or other value in case of error.
96 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
99 * Function to input PIN callback via input callback.
101 * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
102 * @param[in] bufferSize is the size of buffer.
104 * @return ::OC_STACK_OK in case of success or other value in ccase of error.
106 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
108 #ifdef _ENABLE_MULTIPLE_OWNER_
110 * Function to save the Pre-configured PIN.
112 * @param[in] pinBuffer PIN data
113 * @param[in] pinLength byte length of PIN
115 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
117 OCStackResult SetPreconfigPin(const char *pinBuffer, size_t pinLength);
121 * Function to setting the policy for random PIN generation
123 * @param[in] pinSize Byte length of random PIN
124 * @param[in] pinType Type of random PIN (ref OicSecPinType)
126 * @return ::OC_STACK_OK in case of success or other value in case of error.
128 OCStackResult SetRandomPinPolicy(size_t pinSize, OicSecPinType_t pinType);
133 * This function is used by OTM and SRM to
134 * register device UUID is required to derive the temporal PSK.
136 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
139 * This internal callback is used while Random PIN based OTM.
140 * This callback will be used to establish a temporary secure session according to
141 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
143 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
144 * @param[in] UNUSED1 UNUSED.
145 * @param[in] UNUSED2 UNUSED.
146 * @param[out] result Must be filled with the requested information.
147 * @param[in] result_length Maximum size of @p result.
149 * @return The number of bytes written to @p result or a value
150 * less than zero on error.
152 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
153 const unsigned char *UNUSED1, size_t UNUSED2,
154 unsigned char *result, size_t result_length);
156 #ifdef _ENABLE_MULTIPLE_OWNER_
158 * This internal callback is used while Random PIN based MOT.
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 GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
172 const unsigned char *UNUSED1, size_t UNUSED2,
173 unsigned char *result, size_t result_length);
177 * This internal callback is used while Preconfigured-PIN OTM.
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 GetDtlsPskForPreconfPinOxm( 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 MOT.
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 GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
210 const unsigned char *UNUSED1, size_t UNUSED2,
211 unsigned char *result, size_t result_length);
213 #endif //_ENABLE_MULTIPLE_OWNER_
217 * API to derive the PSK based on PIN and new device's UUID.
218 * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
220 * @param[out] result generated PSK
222 * @return 0 for success, otherwise error.
224 int DerivePSKUsingPIN(uint8_t* result);
226 #endif //__WITH_DTLS__
232 #endif //PIN_CALLBACK_DEF_H_