Disable security version discovery
[platform/upstream/iotivity.git] / resource / csdk / connectivity / inc / ca_adapter_net_tls.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_TLS_H_
21 #define CA_ADAPTER_NET_TLS_H_
22
23 #include "caadapterutils.h"
24 #include "cainterface.h"
25
26 /**
27  * Currently TLS supported adapters(2) WIFI and ETHENET for linux platform.
28  */
29 #define MAX_SUPPORTED_ADAPTERS 2
30
31 typedef void (*CAPacketReceivedCallback)(const CASecureEndpoint_t *sep,
32                                          const void *data, uint32_t dataLength);
33
34 typedef void (*CAPacketSendCallback)(CAEndpoint_t *endpoint,
35                                          const void *data, uint32_t dataLength);
36
37 /**
38  * Select the cipher suite for dtls handshake
39  *
40  * @param[in] cipher    cipher suite
41  *                             0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA_256
42  *                             0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
43  *                             0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
44  *
45  * @retval  ::CA_STATUS_OK for success, otherwise some error value
46  */
47 CAResult_t CAsetTlsCipherSuite(const uint32_t cipher);
48
49 /**
50  * Used set send and recv callbacks for different adapters(WIFI,EtherNet).
51  *
52  * @param[in]  recvCallback    packet received callback.
53  * @param[in]  sendCallback    packet sent callback.
54  * @param[in]  type  type of adapter.
55  *
56  */
57 void CAsetTlsAdapterCallbacks(CAPacketReceivedCallback recvCallback,
58                               CAPacketSendCallback sendCallback,
59                               CATransportAdapter_t type);
60
61 /**
62  * Register callback to get credentials types.
63  * @param[in]   credTypesCallback    callback to get credential types.
64  */
65 void CAsetCredentialTypesCallback(CAgetCredentialTypesHandler credTypesCallback);
66 /**
67  * Register callback to get credential types.
68  * @param[in]  typesCallback    callback to get credential types.
69  */
70 void CAsetTlsCredentialsCallback(CAGetDTLSPskCredentialsHandler credCallback);
71
72 /**
73  * Close the TLS session
74  *
75  * @param[in] endpoint  information of network address
76  *
77  * @retval  ::CA_STATUS_OK for success, otherwise some error value
78  */
79 CAResult_t CAcloseTlsConnection(const CAEndpoint_t *endpoint);
80
81 /**
82  * initialize mbedTLS library and other necessary initialization.
83  *
84  * @return  0 on success otherwise a positive error value.
85  * @retval  ::CA_STATUS_OK  Successful.
86  * @retval  ::CA_MEMORY_ALLOC_FAILED  Memory allocation failed.
87  * @retval  ::CA_STATUS_FAILED Operation failed.
88  *
89  */
90 CAResult_t CAinitTlsAdapter();
91
92 /**
93  * de-inits mbedTLS library and free the allocated memory.
94  */
95 void CAdeinitTlsAdapter();
96
97 /**
98  * Performs TLS encryption of the CoAP PDU.
99  *
100  * If a DTLS session does not exist yet with the @dst,
101  * a TLS handshake will be started. In case where a new TLS handshake
102  * is started, pdu info is cached to be send when session setup is finished.
103  *
104  * @param[in]  endpoint  address to which data will be sent.
105  * @param[in]  data  length of data.
106  * @param[in]  dataLen  length of given data
107  *
108  * @return  0 on success otherwise a positive error value.
109  * @retval  ::CA_STATUS_OK  Successful.
110  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
111  * @retval  ::CA_STATUS_FAILED Operation failed.
112  *
113  */
114
115 CAResult_t CAencryptTls(const CAEndpoint_t *endpoint, void *data, uint32_t dataLen);
116
117 /**
118  * Performs TLS decryption of the data.
119  *
120  * @param[in]  sep  address and flags for which data will be decrypted.
121  * @param[in]  data  length of data.
122  * @param[in]  dataLen  length of given data
123  *
124  * @return  0 on success otherwise a positive error value.
125  * @retval  ::CA_STATUS_OK  Successful.
126  * @retval  ::CA_STATUS_INVALID_PARAM  Invalid input arguments.
127  * @retval  ::CA_STATUS_FAILED Operation failed.
128  *
129  */
130 CAResult_t CAdecryptTls(const CASecureEndpoint_t *sep, uint8_t *data, uint32_t dataLen);
131
132 /**
133  * Initiate TLS handshake with selected cipher suite.
134  *
135  * @param[in] endpoint  information of network address
136  *
137  * @retval  ::CA_STATUS_OK for success, otherwise some error value
138  */
139 CAResult_t CAinitiateTlsHandshake(const CAEndpoint_t *endpoint);
140
141 /**
142  * Register callback to deliver the result of TLS handshake
143  * @param[in] tlsHandshakeCallback Callback to receive the result of TLS handshake.
144  */
145 void CAsetTlsHandshakeCallback(CAErrorCallback tlsHandshakeCallback);
146
147 /**
148  * Generate ownerPSK using the PKCS#12 derivation function
149  *
150  * @param[in,out] ownerPSK  Output buffer for owner PSK
151  * @param[in] ownerPSKSize  Byte length of the ownerPSK to be generated
152  * @param[in] deviceID  ID of new device(Resource Server)
153  * @param[in] deviceIDLen  Byte length of deviceID
154  *
155  * @retval  ::CA_STATUS_OK for success, otherwise some error value
156  */
157 CAResult_t CAtlsGenerateOwnerPSK(const CAEndpoint_t *endpoint,
158                                  uint8_t* ownerPSK, const size_t ownerPSKSize,
159                                  const uint8_t* deviceID, const size_t deviceIDLen);
160
161 #endif /* CA_ADAPTER_NET_TLS_H_ */
162
163