1 /* *****************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
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 ******************************************************************/
24 * This file contains the Security APIs for Resource Model to use.
27 #ifndef CA_SECURITY_INTERFACE_H_
28 #define CA_SECURITY_INTERFACE_H_
32 #include "byte_array.h"
40 * @enum CADtlsPskCredType_t
41 * Type of PSK credential required during DTLS handshake
42 * It does not make much sense in bringing in all definitions from dtls.h into here.
43 * Therefore, redefining them here.
50 } CADtlsPskCredType_t;
53 * This internal callback is used by CA layer to
54 * retrieve PSK credentials from SRM.
56 * @param[in] type type of PSK data required by CA layer during DTLS handshake set.
57 * @param[in] desc Additional request information.
58 * @param[in] desc_len The actual length of desc.
59 * @param[out] result Must be filled with the requested information.
60 * @param[in] result_length Maximum size of @p result.
62 * @return The number of bytes written to @p result or a value
63 * less than zero on error.
65 typedef int (*CAgetPskCredentialsHandler)(CADtlsPskCredType_t type,
66 const uint8_t *desc, size_t desc_len,
67 uint8_t *result, size_t result_length);
69 #if defined(__WITH_DTLS__) || defined(__WITH_TLS__)
70 #ifdef _ENABLE_MULTIPLE_OWNER_
72 * API to get a secure connected peer information
74 * @param[in] peer peer information includs IP address and port.
76 * @return secure connected peer information on success, otherwise NULL
78 const CASecureEndpoint_t *CAGetSecureEndpointData(const CAEndpoint_t *peer);
79 #endif //_ENABLE_MULTIPLE_OWNER_
83 * This internal callback is used by CA layer to
84 * retrieve all credential types from SRM
86 * @param[out] list of enabled credential types for CA handshake
89 typedef void (*CAgetCredentialTypesHandler)(bool * list);
91 * Binary structure containing PKIX related info
92 * own certificate chain, public key, CA's and CRL's
96 // own certificate chain
107 * Register callback to get types of TLS suites.
108 * @param[in] getCredTypesHandler Get types of TLS suites callback.
109 * @return ::CA_STATUS_OK or appropriate error code.
111 CAResult_t CAregisterGetCredentialTypesHandler(CAgetCredentialTypesHandler getCredTypesHandler);
114 * Register callback to receive the result of TLS handshake.
115 * @param[in] tlsHandshakeCallback callback for get tls handshake result
116 * @return ::CA_STATUS_OK
118 CAResult_t CAregisterSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback);
121 * Register callback to get TLS PSK credentials.
122 * @param[in] getTLSCredentials GetDTLS Credetials callback.
123 * @return ::CA_STATUS_OK
125 CAResult_t CAregisterPskCredentialsHandler(CAgetPskCredentialsHandler getTlsCredentials);
128 * @brief Callback function type for getting PKIX info
130 * @param inf[out] PKIX related info
134 typedef void (*CAgetPkixInfoHandler)(PkiInfo_t * inf);
137 * Register callback to get PKIX related info.
138 * @param[in] getPkixInfoHandler Get PKIX related info callback.
139 * @return ::CA_STATUS_OK or appropriate error code.
141 CAResult_t CAregisterPkixInfoHandler(CAgetPkixInfoHandler getPkixInfoHandler);
144 * Select the cipher suite for dtls handshake.
146 * @param[in] cipher cipher suite (Note : Make sure endianness).
147 * 0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA
148 * 0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
149 * 0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
151 * @retval ::CA_STATUS_OK Successful.
152 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
153 * @retval ::CA_STATUS_FAILED Operation failed.
155 CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter);
158 * Enable TLS_ECDH_anon_WITH_AES_128_CBC_SHA cipher suite in dtls.
160 * @param[in] enable TRUE/FALSE enables/disables anonymous cipher suite.
162 * @retval ::CA_STATUS_OK Successful.
163 * @retval ::CA_STATUS_FAILED Operation failed.
165 * @note anonymous cipher suite should only be enabled for 'JustWorks' provisioning.
167 CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
171 * Generate ownerPSK using PRF.
172 * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
173 * 'ID of new device(Resource Server)',
174 * 'ID of owner smart-phone(Provisioning Server)')
176 * @param[in] endpoint information of network address.
177 * @param[in] label Ownership transfer method e.g)"oic.sec.doxm.jw".
178 * @param[in] labelLen Byte length of label.
179 * @param[in] rsrcServerDeviceID ID of new device(Resource Server).
180 * @param[in] rsrcServerDeviceIDLen Byte length of rsrcServerDeviceID.
181 * @param[in] provServerDeviceID label of previous owner.
182 * @param[in] provServerDeviceIDLen byte length of provServerDeviceID.
183 * @param[in,out] ownerPSK Output buffer for owner PSK.
184 * @param[in] ownerPskSize Byte length of the ownerPSK to be generated.
186 * @retval ::CA_STATUS_OK Successful.
187 * @retval ::CA_STATUS_FAILED Operation failed.
189 CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t *endpoint,
190 const uint8_t* label, const size_t labelLen,
191 const uint8_t* rsrcServerDeviceID,
192 const size_t rsrcServerDeviceIDLen,
193 const uint8_t* provServerDeviceID,
194 const size_t provServerDeviceIDLen,
195 uint8_t* ownerPSK, const size_t ownerPskSize);
198 * Initiate DTLS handshake with selected cipher suite.
200 * @param[in] endpoint information of network address.
202 * @retval ::CA_STATUS_OK Successful.
203 * @retval ::CA_STATUS_FAILED Operation failed.
205 CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint);
208 * Close the DTLS session.
210 * @param[in] endpoint information of network address.
212 * @retval ::CA_STATUS_OK Successful.
213 * @retval ::CA_STATUS_FAILED Operation failed.
215 CAResult_t CAcloseSslSession(const CAEndpoint_t *endpoint);
218 * Initiate TLS handshake with selected cipher suite.
220 * @param[in] endpoint information of network address.
222 * @retval ::CA_STATUS_OK Successful.
223 * @retval ::CA_STATUS_FAILED Operation failed.
225 CAResult_t CAinitiateSslHandshake(const CAEndpoint_t *endpoint);
228 * Close the DTLS session.
230 * @param[in] endpoint information of network address.
232 * @retval ::CA_STATUS_OK Successful.
233 * @retval ::CA_STATUS_FAILED Operation failed.
235 CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
239 * Close All of DTLS sessions.
241 void CAcloseSslConnectionAll();
248 #endif /* CA_SECURITY_INTERFACE_H_ */