Merge "Remove unused openssl-devel dependency" into tizen
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / ca_adapter_net_ssl.h
1 /* *****************************************************************
2  *
3  * Copyright 2016 Samsung Electronics All Rights Reserved.
4  *
5  *
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  ******************************************************************/
20 #ifndef CA_ADAPTER_NET_SSL_H_
21 #define CA_ADAPTER_NET_SSL_H_
22
23 #ifdef __cplusplus
24 extern "C" {
25 #endif //__cplusplus
26
27 #include "cacommon.h"
28 #include "casecurityinterface.h"
29
30 /**
31  * Currently TLS supported adapters(3) WIFI, ETHENET and BLE for linux platform.
32  */
33 #define MAX_SUPPORTED_ADAPTERS 3
34
35 typedef CAResult_t (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep,
36                                          const void *data, size_t dataLength);
37
38 typedef ssize_t (*CAPacketSendCallback)(CAEndpoint_t *endpoint,
39                                         const void *data, size_t dataLength);
40
41 /**
42  * Select the cipher suite for dtls handshake
43  *
44  * @param[in] cipher    cipher suite
45  *                        TLS_RSA_WITH_AES_256_CBC_SHA256          0x3D
46  *                        TLS_RSA_WITH_AES_128_GCM_SHA256          0x009C
47  *                        TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256  0xC02B
48  *                        TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8       0xC0AE
49  *                        TLS_ECDHE_ECDSA_WITH_AES_128_CCM         0xC0AC
50  *                        TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256  0xC023
51  *                        TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384  0xC024
52  *                        TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384  0xC02C
53  *                        TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256    0xC037
54  *                        TLS_ECDH_anon_WITH_AES_128_CBC_SHA       0xC018
55  *
56  * @retval  ::CA_STATUS_OK for success, otherwise some error value
57  */
58 CAResult_t CAsetTlsCipherSuite(const uint32_t cipher);
59
60 /**
61  * Used set send and recv callbacks for different adapters(WIFI,EtherNet).
62  *
63  * @param[in]  recvCallback    packet received callback.
64  * @param[in]  sendCallback    packet sent callback.
65  * @param[in]  type  type of adapter.
66  *
67  */
68 void CAsetSslAdapterCallbacks(CAPacketReceivedCallback recvCallback,
69                               CAPacketSendCallback sendCallback,
70                               CATransportAdapter_t type);
71
72 /**
73  * Register callback to get credentials types.
74  * @param[in]   credTypesCallback    callback to get credential types.
75  */
76 void CAsetCredentialTypesCallback(CAgetCredentialTypesHandler credTypesCallback);
77 /**
78  * Register callback to get credential types.
79  * @param[in]  typesCallback    callback to get credential types.
80  */
81 void CAsetSslCredentialsCallback(CAgetPskCredentialsHandler credCallback);
82
83 /**
84  * Close the TLS session
85  *
86  * @param[in] endpoint  information of network address
87  *
88  * @retval  ::CA_STATUS_OK for success, otherwise some error value
89  */
90 CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
91
92 #ifdef __TIZEN__
93 /**
94  * Close the DTLS session and free endpoint.
95  *
96  * @param[in] endpoint  information of network address;
97  *            CAcloseSslConnectionWrapper takes ownership of endpoint
98  *
99  * @retval  ::CA_STATUS_OK    Successful.
100  * @retval  ::CA_STATUS_FAILED Operation failed.
101  */
102 CAResult_t CAcloseSslConnectionFreeEndpoint(CAEndpoint_t *endpoint);
103 #endif //__TIZEN__
104
105 /**
106  * initialize mbedTLS library and other necessary initialization.
107  *
108  * @return  0 on success otherwise a positive error value.
109  * @retval  ::CA_STATUS_OK  Successful.
110  * @retval  ::CA_MEMORY_ALLOC_FAILED  Memory allocation failed.
111  * @retval  ::CA_STATUS_FAILED Operation failed.
112  *
113  */
114 CAResult_t CAinitSslAdapter();
115
116 /**
117  * de-inits mbedTLS library and free the allocated memory.
118  */
119 void CAdeinitSslAdapter();
120
121 /**
122  * Performs TLS encryption of the CoAP PDU.
123  *
124  * If a DTLS session does not exist yet with the @dst,
125  * a TLS handshake will be started. In case where a new TLS handshake
126  * is started, pdu info is cached to be send when session setup is finished.
127  *
128  * @param[in]  endpoint  address to which data will be sent.
129  * @param[in]  data  length of data.
130  * @param[in]  dataLen  length of given data
131  *
132  * @return  0 on success otherwise a positive error value.
133  * @retval  ::CA_STATUS_OK  Successful.
134  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
135  * @retval  ::CA_STATUS_FAILED Operation failed.
136  *
137  */
138
139 CAResult_t CAencryptSsl(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen);
140
141 /**
142  * Performs TLS decryption of the data.
143  *
144  * @param[in]  sep  address and flags for which data will be decrypted.
145  * @param[in]  data  length of data.
146  * @param[in]  dataLen  length of given data
147  *
148  * @return  0 on success otherwise a positive error value.
149  * @retval  ::CA_STATUS_OK  Successful.
150  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
151  * @retval  ::CA_STATUS_FAILED Operation failed.
152  *
153  */
154 CAResult_t CAdecryptSsl(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen);
155
156 /**
157  * Initiate TLS handshake with selected cipher suite.
158  *
159  * @param[in] endpoint  information of network address
160  *
161  * @retval  ::CA_STATUS_OK for success, otherwise some error value
162  */
163 CAResult_t CAinitiateSslHandshake(const CAEndpoint_t *endpoint);
164
165 /**
166  * Register callback to deliver the result of TLS handshake
167  * @param[in] tlsHandshakeCallback Callback to receive the result of TLS handshake.
168  */
169 void CAsetSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback);
170
171 /**
172  * Generate ownerPSK using PRF
173  * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
174  *                                    'ID of new device(Resource Server)',
175  *                                    'ID of owner smart-phone(Provisioning Server)')
176  *
177  * @param[in] endpoint  information of network address
178  * @param[in] label  Ownership transfer method e.g)"oic.sec.doxm.jw"
179  * @param[in] labelLen  Byte length of label
180  * @param[in] rsrcServerDeviceID  ID of new device(Resource Server)
181  * @param[in] rsrcServerDeviceIDLen  Byte length of rsrcServerDeviceID
182  * @param[in] provServerDeviceID  label of previous owner
183  * @param[in] provServerDeviceIDLen  byte length of provServerDeviceID
184  * @param[in,out] ownerPSK  Output buffer for owner PSK
185  * @param[in] ownerPSKSize  Byte length of the ownerPSK to be generated
186  *
187  * @retval  ::CA_STATUS_OK for success, otherwise some error value
188  */
189 CAResult_t CAsslGenerateOwnerPsk(const CAEndpoint_t *endpoint,
190                     const uint8_t* label, const size_t labelLen,
191                     const uint8_t* rsrcServerDeviceId, const size_t rsrcServerDeviceIdLen,
192                     const uint8_t* provServerDeviceId, const size_t provServerDeviceIdLen,
193                     uint8_t* ownerPsk, const size_t ownerPskSize);
194
195 #ifdef MULTIPLE_OWNER
196 /**
197  * Gets CA secure endpoint info corresponding for endpoint.
198  *
199  * @param[in]  peer    remote address
200  *
201  * @return  CASecureEndpoint or NULL
202  */
203 const CASecureEndpoint_t *GetCASecureEndpointData(const CAEndpoint_t* peer);
204 #endif
205
206 /**
207  * Sets CA secure endpoint identity with uuid.
208  *
209  * @param[in]  peer    remote address
210  * @param[in]  uuid    UUID data to set
211  *
212  * @retval  ::CA_STATUS_OK for success, otherwise some error value
213  */
214 CAResult_t SetCASecureEndpointUuid(const CAEndpoint_t *peer, const char *uuid);
215
216 bool CAIsExistSslPeer(const CAEndpoint_t *peer);
217
218 #ifdef __cplusplus
219 }
220 #endif //__cplusplus
221
222 #endif /* CA_ADAPTER_NET_SSL_H_ */
223
224