libcoap
4.3.4
Loading...
Searching...
No Matches
coap_dtls.h
Go to the documentation of this file.
1
/*
2
* coap_dtls.h -- (Datagram) Transport Layer Support for libcoap
3
*
4
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
5
* Copyright (C) 2017 Jean-Claude Michelou <jcm@spinetix.com>
6
*
7
* SPDX-License-Identifier: BSD-2-Clause
8
*
9
* This file is part of the CoAP library libcoap. Please see README for terms
10
* of use.
11
*/
12
18
#ifndef COAP_DTLS_H_
19
#define COAP_DTLS_H_
20
21
#include "
coap_time.h
"
22
#include "
coap_str.h
"
23
31
typedef
struct
coap_dtls_pki_t
coap_dtls_pki_t
;
32
33
#ifndef COAP_DTLS_HINT_LENGTH
34
#define COAP_DTLS_HINT_LENGTH 128
35
#endif
36
#ifndef COAP_DTLS_MAX_PSK_IDENTITY
37
#define COAP_DTLS_MAX_PSK_IDENTITY 64
38
#endif
39
#ifndef COAP_DTLS_MAX_PSK
40
#define COAP_DTLS_MAX_PSK 64
41
#endif
42
43
typedef
enum
coap_dtls_role_t
{
44
COAP_DTLS_ROLE_CLIENT
,
45
COAP_DTLS_ROLE_SERVER
46
}
coap_dtls_role_t
;
47
48
#define COAP_DTLS_RPK_CERT_CN "RPK"
49
55
int
coap_dtls_is_supported
(
void
);
56
62
int
coap_tls_is_supported
(
void
);
63
69
int
coap_dtls_psk_is_supported
(
void
);
70
76
int
coap_dtls_pki_is_supported
(
void
);
77
83
int
coap_dtls_pkcs11_is_supported
(
void
);
84
90
int
coap_dtls_rpk_is_supported
(
void
);
91
92
typedef
enum
coap_tls_library_t
{
93
COAP_TLS_LIBRARY_NOTLS
= 0,
94
COAP_TLS_LIBRARY_TINYDTLS
,
95
COAP_TLS_LIBRARY_OPENSSL
,
96
COAP_TLS_LIBRARY_GNUTLS
,
97
COAP_TLS_LIBRARY_MBEDTLS
,
98
}
coap_tls_library_t
;
99
104
typedef
struct
coap_tls_version_t
{
105
uint64_t
version
;
106
coap_tls_library_t
type
;
107
uint64_t
built_version
;
108
}
coap_tls_version_t
;
109
115
coap_tls_version_t
*
coap_get_tls_library_version
(
void
);
116
132
typedef
int (*
coap_dtls_security_setup_t
)(
void
*tls_session,
133
coap_dtls_pki_t
*setup_data);
134
155
typedef
int (*
coap_dtls_cn_callback_t
)(
const
char
*cn,
156
const
uint8_t *asn1_public_cert,
157
size_t
asn1_length,
158
coap_session_t
*coap_session,
159
unsigned
int
depth,
160
int
validated,
161
void
*arg);
162
167
typedef
enum
coap_asn1_privatekey_type_t
{
168
COAP_ASN1_PKEY_NONE
,
169
COAP_ASN1_PKEY_RSA
,
170
COAP_ASN1_PKEY_RSA2
,
171
COAP_ASN1_PKEY_DSA
,
172
COAP_ASN1_PKEY_DSA1
,
173
COAP_ASN1_PKEY_DSA2
,
174
COAP_ASN1_PKEY_DSA3
,
175
COAP_ASN1_PKEY_DSA4
,
176
COAP_ASN1_PKEY_DH
,
177
COAP_ASN1_PKEY_DHX
,
178
COAP_ASN1_PKEY_EC
,
179
COAP_ASN1_PKEY_HMAC
,
180
COAP_ASN1_PKEY_CMAC
,
181
COAP_ASN1_PKEY_TLS1_PRF
,
182
COAP_ASN1_PKEY_HKDF
183
}
coap_asn1_privatekey_type_t
;
184
188
typedef
enum
coap_pki_key_t
{
189
COAP_PKI_KEY_PEM
= 0,
190
COAP_PKI_KEY_ASN1
,
191
COAP_PKI_KEY_PEM_BUF
,
192
COAP_PKI_KEY_PKCS11
,
193
}
coap_pki_key_t
;
194
198
typedef
struct
coap_pki_key_pem_t
{
199
const
char
*
ca_file
;
200
const
char
*
public_cert
;
201
const
char
*
private_key
;
202
}
coap_pki_key_pem_t
;
203
213
typedef
struct
coap_pki_key_pem_buf_t
{
214
const
uint8_t *
ca_cert
;
215
const
uint8_t *
public_cert
;
216
const
uint8_t *
private_key
;
219
size_t
ca_cert_len
;
220
size_t
public_cert_len
;
221
size_t
private_key_len
;
222
}
coap_pki_key_pem_buf_t
;
223
227
typedef
struct
coap_pki_key_asn1_t
{
228
const
uint8_t *
ca_cert
;
229
const
uint8_t *
public_cert
;
230
const
uint8_t *
private_key
;
231
size_t
ca_cert_len
;
232
size_t
public_cert_len
;
233
size_t
private_key_len
;
234
coap_asn1_privatekey_type_t
private_key_type
;
235
}
coap_pki_key_asn1_t
;
236
240
typedef
struct
coap_pki_key_pkcs11_t
{
241
const
char
*
ca
;
242
const
char
*
public_cert
;
243
const
char
*
private_key
;
244
const
char
*
user_pin
;
247
}
coap_pki_key_pkcs11_t
;
248
252
typedef
struct
coap_dtls_key_t
{
253
coap_pki_key_t
key_type
;
254
union
{
255
coap_pki_key_pem_t
pem
;
256
coap_pki_key_pem_buf_t
pem_buf
;
257
coap_pki_key_asn1_t
asn1
;
258
coap_pki_key_pkcs11_t
pkcs11
;
259
}
key
;
260
}
coap_dtls_key_t
;
261
275
typedef
coap_dtls_key_t
*(*coap_dtls_pki_sni_callback_t)(
const
char
*sni,
276
void
*arg);
277
278
279
#define COAP_DTLS_PKI_SETUP_VERSION 1
284
struct
coap_dtls_pki_t
{
285
uint8_t
version
;
288
/* Options to enable different TLS functionality in libcoap */
289
uint8_t
verify_peer_cert
;
290
uint8_t
check_common_ca
;
292
uint8_t
allow_self_signed
;
294
uint8_t
allow_expired_certs
;
295
uint8_t
cert_chain_validation
;
296
uint8_t
cert_chain_verify_depth
;
297
uint8_t
check_cert_revocation
;
298
uint8_t
allow_no_crl
;
299
uint8_t
allow_expired_crl
;
300
uint8_t
allow_bad_md_hash
;
301
uint8_t
allow_short_rsa_length
;
302
uint8_t
is_rpk_not_cert
;