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_SIZE (8)
32 #define OXM_PRECONFIG_PIN_SIZE (OXM_RANDOM_PIN_SIZE)
36 * Function pointer to print pin code.
38 typedef void (*GeneratePinCallback)(char* pinData, size_t pinSize);
41 * Function pointer to input pin code.
43 typedef void (*InputPinCallback)(char* pinBuf, size_t bufSize);
46 * Function to setting generate PIN callback from user.
48 * @param pinCB implementation of generate PIN callback.
50 void SetGeneratePinCB(GeneratePinCallback pinCB);
53 * Function to setting input PIN callback from user.
55 * @param pinCB implementation of input PIN callback.
57 void SetInputPinCB(InputPinCallback pinCB);
59 #ifdef _ENABLE_MULTIPLE_OWNER_
61 * Function to save the preconfig PIN getter from user.
63 * @param pinCB implementation of preconfig PIN function.
65 void SetGetPreconfigPinCB(InputPinCallback pinCB);
66 #endif //_ENABLE_MULTIPLE_OWNER_
69 * Function to generate random PIN.
70 * This function will send generated PIN to user via callback.
72 * @param pinBuffer is the reference to the buffer to store the generated PIN data.
73 * @param bufferSize is the size of buffer.
75 * @return ::OC_STACK_SUCCESS in case of success or other value in case of error.
77 OCStackResult GeneratePin(char* pinBuffer, size_t bufferSize);
80 * Function to input PIN callback via input callback.
82 * @param[in,out] pinBuffer is the reference to the buffer to store the inputed PIN data.
83 * @param[in] bufferSize is the size of buffer.
85 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
87 OCStackResult InputPin(char* pinBuffer, size_t bufferSize);
90 #ifdef _ENABLE_MULTIPLE_OWNER_
92 * Function to save the Pre-configured PIN.
94 * @param[in] pinBuffer PIN data
95 * @param[in] pinLength byte length of PIN
97 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
99 OCStackResult SetPreconfigPin(const char* pinBuffer, size_t pinLength);
102 * Function to read preconfig PIN.
104 * @param[in,out] pinBuffer is the reference to the buffer to store the preconfigured PIN.
105 * @param[in] bufferSize is the size of buffer.
107 * @return ::OC_STACK_SUCCESS in case of success or other value in ccase of error.
109 OCStackResult GetPreconfigPin(char* pinBuffer, size_t bufferSize);
115 * This function is used by OTM and SRM to
116 * register device UUID is required to derive the temporal PSK.
118 void SetUuidForPinBasedOxm(const OicUuid_t* uuid);
121 * This internal callback is used while Random PIN based OTM.
122 * This callback will be used to establish a temporary secure session according to
123 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
125 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
126 * @param[in] UNUSED1 UNUSED.
127 * @param[in] UNUSED2 UNUSED.
128 * @param[out] result Must be filled with the requested information.
129 * @param[in] result_length Maximum size of @p result.
131 * @return The number of bytes written to @p result or a value
132 * less than zero on error.
134 int32_t GetDtlsPskForRandomPinOxm( CADtlsPskCredType_t type,
135 const unsigned char *UNUSED1, size_t UNUSED2,
136 unsigned char *result, size_t result_length);
138 #ifdef _ENABLE_MULTIPLE_OWNER_
140 * This internal callback is used while Random PIN based MOT.
141 * This callback will be used to establish a temporary secure session according to
142 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
144 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
145 * @param[in] UNUSED1 UNUSED.
146 * @param[in] UNUSED2 UNUSED.
147 * @param[out] result Must be filled with the requested information.
148 * @param[in] result_length Maximum size of @p result.
150 * @return The number of bytes written to @p result or a value
151 * less than zero on error.
153 int32_t GetDtlsPskForMotRandomPinOxm( CADtlsPskCredType_t type,
154 const unsigned char *UNUSED1, size_t UNUSED2,
155 unsigned char *result, size_t result_length);
159 * This internal callback is used while Preconfigured-PIN OTM.
160 * This callback will be used to establish a temporary secure session according to
161 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
163 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
164 * @param[in] UNUSED1 UNUSED.
165 * @param[in] UNUSED2 UNUSED.
166 * @param[out] result Must be filled with the requested information.
167 * @param[in] result_length Maximum size of @p result.
169 * @return The number of bytes written to @p result or a value
170 * less than zero on error.
172 int32_t GetDtlsPskForPreconfPinOxm( CADtlsPskCredType_t type,
173 const unsigned char *UNUSED1, size_t UNUSED2,
174 unsigned char *result, size_t result_length);
178 * This internal callback is used while Preconfigured-PIN MOT.
179 * This callback will be used to establish a temporary secure session according to
180 * TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256.
182 * @param[in] type type of PSK data required by tinyDTLS layer during DTLS handshake.
183 * @param[in] UNUSED1 UNUSED.
184 * @param[in] UNUSED2 UNUSED.
185 * @param[out] result Must be filled with the requested information.
186 * @param[in] result_length Maximum size of @p result.
188 * @return The number of bytes written to @p result or a value
189 * less than zero on error.
191 int32_t GetDtlsPskForMotPreconfPinOxm( CADtlsPskCredType_t type,
192 const unsigned char *UNUSED1, size_t UNUSED2,
193 unsigned char *result, size_t result_length);
195 #endif //_ENABLE_MULTIPLE_OWNER_
199 * API to derive the PSK based on PIN and new device's UUID.
200 * New device's UUID should be set through SetUuidForPinBasedOxm() API before this API is invoked.
202 * @param[out] result generated PSK
204 * @return 0 for success, otherwise error.
206 int DerivePSKUsingPIN(uint8_t* result);
208 #endif //__WITH_DTLS__
214 #endif //PIN_CALLBACK_DEF_H_