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 receive credential types.
108 * @param[in] credTypesCallback callback to get cerdential types
109 * @return ::CA_STATUS_OK
111 CAResult_t CAregisterGetCredentialTypesCallback(CAgetCredentialTypesHandler credTypesCallback);
113 * Register callback to receive the result of TLS handshake.
114 * @param[in] tlsHandshakeCallback callback for get tls handshake result
115 * @return ::CA_STATUS_OK
117 CAResult_t CAregisterSslHandshakeCallback(CAErrorCallback tlsHandshakeCallback);
120 * Register callback to get TLS PSK credentials.
121 * @param[in] getTLSCredentials GetDTLS Credetials callback.
122 * @return ::CA_STATUS_OK
124 CAResult_t CAregisterPskCredentialsHandler(CAgetPskCredentialsHandler getTlsCredentials);
127 * @brief Callback function type for getting PKIX info
129 * @param inf[out] PKIX related info
133 typedef void (*CAgetPkixInfoHandler)(PkiInfo_t * inf);
136 * Register callback to get PKIX related info.
137 * @param[in] getPkixInfoHandler Get PKIX related info callback.
138 * @return ::CA_STATUS_OK or appropriate error code.
140 CAResult_t CAregisterPkixInfoHandler(CAgetPkixInfoHandler getPkixInfoHandler);
142 * Register callback to get types of TLS suites.
143 * @param[in] getCredTypesHandler Get types of TLS suites callback.
144 * @return ::CA_STATUS_OK or appropriate error code.
146 CAResult_t CAregisterGetCredentialTypesHandler(CAgetCredentialTypesHandler getCredTypesHandler);
149 * Select the cipher suite for dtls handshake.
151 * @param[in] cipher cipher suite (Note : Make sure endianness).
152 * 0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA
153 * 0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
154 * 0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
156 * @retval ::CA_STATUS_OK Successful.
157 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
158 * @retval ::CA_STATUS_FAILED Operation failed.
160 CAResult_t CASelectCipherSuite(const uint16_t cipher, CATransportAdapter_t adapter);
163 * Enable TLS_ECDH_anon_WITH_AES_128_CBC_SHA cipher suite in dtls.
165 * @param[in] enable TRUE/FALSE enables/disables anonymous cipher suite.
167 * @retval ::CA_STATUS_OK Successful.
168 * @retval ::CA_STATUS_FAILED Operation failed.
170 * @note anonymous cipher suite should only be enabled for 'JustWorks' provisioning.
172 CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
176 * Generate ownerPSK using PRF.
177 * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
178 * 'ID of new device(Resource Server)',
179 * 'ID of owner smart-phone(Provisioning Server)')
181 * @param[in] endpoint information of network address.
182 * @param[in] label Ownership transfer method e.g)"oic.sec.doxm.jw".
183 * @param[in] labelLen Byte length of label.
184 * @param[in] rsrcServerDeviceID ID of new device(Resource Server).
185 * @param[in] rsrcServerDeviceIDLen Byte length of rsrcServerDeviceID.
186 * @param[in] provServerDeviceID label of previous owner.
187 * @param[in] provServerDeviceIDLen byte length of provServerDeviceID.
188 * @param[in,out] ownerPSK Output buffer for owner PSK.
189 * @param[in] ownerPskSize Byte length of the ownerPSK to be generated.
191 * @retval ::CA_STATUS_OK Successful.
192 * @retval ::CA_STATUS_FAILED Operation failed.
194 CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t *endpoint,
195 const uint8_t* label, const size_t labelLen,
196 const uint8_t* rsrcServerDeviceID,
197 const size_t rsrcServerDeviceIDLen,
198 const uint8_t* provServerDeviceID,
199 const size_t provServerDeviceIDLen,
200 uint8_t* ownerPSK, const size_t ownerPskSize);
203 * Initiate DTLS handshake with selected cipher suite.
205 * @param[in] endpoint information of network address.
207 * @retval ::CA_STATUS_OK Successful.
208 * @retval ::CA_STATUS_FAILED Operation failed.
210 CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint);
213 * Close the DTLS session.
215 * @param[in] endpoint information of network address.
217 * @retval ::CA_STATUS_OK Successful.
218 * @retval ::CA_STATUS_FAILED Operation failed.
220 CAResult_t CAcloseSslSession(const CAEndpoint_t *endpoint);
223 * Initiate TLS handshake with selected cipher suite.
225 * @param[in] endpoint information of network address.
227 * @retval ::CA_STATUS_OK Successful.
228 * @retval ::CA_STATUS_FAILED Operation failed.
230 CAResult_t CAinitiateSslHandshake(const CAEndpoint_t *endpoint);
233 * Close the DTLS session.
235 * @param[in] endpoint information of network address.
237 * @retval ::CA_STATUS_OK Successful.
238 * @retval ::CA_STATUS_FAILED Operation failed.
240 CAResult_t CAcloseSslConnection(const CAEndpoint_t *endpoint);
244 * Close All of DTLS sessions.
246 void CAcloseSslConnectionAll();
253 #endif /* CA_SECURITY_INTERFACE_H_ */