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 #endif //__WITH_X509__
43 * @enum CADtlsPskCredType_t
44 * Type of PSK credential required during DTLS handshake
45 * It does not make much sense in bringing in all definitions from dtls.h into here.
46 * Therefore, redefining them here.
53 } CADtlsPskCredType_t;
56 * This internal callback is used by CA layer to
57 * retrieve PSK credentials from SRM.
59 * @param[in] type type of PSK data required by CA layer during DTLS handshake set.
60 * @param[in] desc Additional request information.
61 * @param[in] desc_len The actual length of desc.
62 * @param[out] result Must be filled with the requested information.
63 * @param[in] result_length Maximum size of @p result.
65 * @return The number of bytes written to @p result or a value
66 * less than zero on error.
68 typedef int (*CAGetDTLSPskCredentialsHandler)( CADtlsPskCredType_t type,
69 const unsigned char *desc, size_t desc_len,
70 unsigned char *result, size_t result_length);
73 * Register callback to get DTLS PSK credentials.
74 * @param[in] GetDTLSCredentials GetDTLS Credetials callback.
75 * @return ::CA_STATUS_OK
77 CAResult_t CARegisterDTLSCredentialsHandler(CAGetDTLSPskCredentialsHandler GetDTLSCredentials);
79 #endif //__WITH_DTLS__
83 * Binary structure containing certificate chain and certificate credentials
88 // certificate message for DTLS
89 unsigned char certificateChain[MAX_CERT_MESSAGE_LEN];
90 // length of the certificate message
91 uint32_t certificateChainLen;
92 // number of certificates in certificate message
94 // x component of EC public key
95 uint8_t rootPublicKeyX[PUBLIC_KEY_SIZE / 2];
96 // y component of EC public key
97 uint8_t rootPublicKeyY[PUBLIC_KEY_SIZE / 2];
99 uint8_t devicePrivateKey[PRIVATE_KEY_SIZE];
104 * @brief Callback function type for getting certificate credentials.
105 * @param credInfo [OUT] Certificate credentials info. Handler has to allocate new memory for
106 * credInfo which is then freed by CA
109 typedef int (*CAGetDTLSX509CredentialsHandler)(CADtlsX509Creds_t *credInfo);
111 * @brief Callback function type for getting CRL.
112 * @param crlInfo [OUT] Certificate credentials info. Handler has to allocate new memory for
113 * credInfo which is then freed by CA
116 typedef void (*CAGetDTLSCrlHandler)(ByteArray crlInfo);
119 * @brief Register callback to get DTLS Cert credentials.
120 * @param GetCertCredentials [IN] GetCert Credetials callback
121 * @return #CA_STATUS_OK
123 CAResult_t CARegisterDTLSX509CredentialsHandler(CAGetDTLSX509CredentialsHandler GetX509Credentials);
125 * @brief Register callback to get CRL.
126 * @param GetCrl [IN] GetCrl callback
127 * @return #CA_STATUS_OK
129 CAResult_t CARegisterDTLSCrlHandler(CAGetDTLSCrlHandler GetCrl);
130 #endif //__WITH_X509__
136 * Select the cipher suite for dtls handshake.
138 * @param[in] cipher cipher suite (Note : Make sure endianness).
139 * 0xC018 : TLS_ECDH_anon_WITH_AES_128_CBC_SHA
140 * 0xC0A8 : TLS_PSK_WITH_AES_128_CCM_8
141 * 0xC0AE : TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8
143 * @retval ::CA_STATUS_OK Successful.
144 * @retval ::CA_STATUS_INVALID_PARAM Invalid input arguments.
145 * @retval ::CA_STATUS_FAILED Operation failed.
147 CAResult_t CASelectCipherSuite(const uint16_t cipher);
150 * Enable TLS_ECDH_anon_WITH_AES_128_CBC_SHA cipher suite in dtls.
152 * @param[in] enable TRUE/FALSE enables/disables anonymous cipher suite.
154 * @retval ::CA_STATUS_OK Successful.
155 * @retval ::CA_STATUS_FAILED Operation failed.
157 * @note anonymous cipher suite should only be enabled for 'JustWorks' provisioning.
159 CAResult_t CAEnableAnonECDHCipherSuite(const bool enable);
163 * Generate ownerPSK using PRF.
164 * OwnerPSK = TLS-PRF('master key' , 'oic.sec.doxm.jw',
165 * 'ID of new device(Resource Server)',
166 * 'ID of owner smart-phone(Provisioning Server)')
168 * @param[in] endpoint information of network address.
169 * @param[in] label Ownership transfer method e.g)"oic.sec.doxm.jw".
170 * @param[in] labelLen Byte length of label.
171 * @param[in] rsrcServerDeviceID ID of new device(Resource Server).
172 * @param[in] rsrcServerDeviceIDLen Byte length of rsrcServerDeviceID.
173 * @param[in] provServerDeviceID label of previous owner.
174 * @param[in] provServerDeviceIDLen byte length of provServerDeviceID.
175 * @param[in,out] ownerPSK Output buffer for owner PSK.
176 * @param[in] ownerPSKSize Byte length of the ownerPSK to be generated.
178 * @retval ::CA_STATUS_OK Successful.
179 * @retval ::CA_STATUS_FAILED Operation failed.
181 CAResult_t CAGenerateOwnerPSK(const CAEndpoint_t *endpoint,
182 const uint8_t* label, const size_t labelLen,
183 const uint8_t* rsrcServerDeviceID,
184 const size_t rsrcServerDeviceIDLen,
185 const uint8_t* provServerDeviceID,
186 const size_t provServerDeviceIDLen,
187 uint8_t* ownerPSK, const size_t ownerPSKSize);
190 * Initiate DTLS handshake with selected cipher suite.
192 * @param[in] endpoint information of network address.
194 * @retval ::CA_STATUS_OK Successful.
195 * @retval ::CA_STATUS_FAILED Operation failed.
197 CAResult_t CAInitiateHandshake(const CAEndpoint_t *endpoint);
200 * Close the DTLS session.
202 * @param[in] endpoint information of network address.
204 * @retval ::CA_STATUS_OK Successful.
205 * @retval ::CA_STATUS_FAILED Operation failed.
207 CAResult_t CACloseDtlsSession(const CAEndpoint_t *endpoint);
209 #endif /* __WITH_DTLS__ */
217 #endif /* CA_SECURITY_INTERFACE_H_ */