libcoap 4.3.4-develop-749e16f
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 * Copyright (C) 2023-2024 Jon Shallow <supjps-libcoap@jpshallow.com>
7 *
8 * SPDX-License-Identifier: BSD-2-Clause
9 *
10 * This file is part of the CoAP library libcoap. Please see README for terms
11 * of use.
12 */
13
19#ifndef COAP_DTLS_H_
20#define COAP_DTLS_H_
21
22#include "coap_time.h"
23#include "coap_str.h"
24
33
34#ifndef COAP_DTLS_HINT_LENGTH
35#define COAP_DTLS_HINT_LENGTH 128
36#endif
37#ifndef COAP_DTLS_MAX_PSK_IDENTITY
38#define COAP_DTLS_MAX_PSK_IDENTITY 64
39#endif
40#ifndef COAP_DTLS_MAX_PSK
41#define COAP_DTLS_MAX_PSK 64
42#endif
43
44typedef enum coap_dtls_role_t {
48
49#define COAP_DTLS_RPK_CERT_CN "RPK"
50
57
63int coap_tls_is_supported(void);
64
71
78
85
92
93typedef enum coap_tls_library_t {
101
106typedef struct coap_tls_version_t {
107 uint64_t version;
109 uint64_t built_version;
111
118
134typedef int (*coap_dtls_security_setup_t)(void *tls_session,
135 coap_dtls_pki_t *setup_data);
136
157typedef int (*coap_dtls_cn_callback_t)(const char *cn,
158 const uint8_t *asn1_public_cert,
159 size_t asn1_length,
160 coap_session_t *coap_session,
161 unsigned int depth,
162 int validated,
163 void *arg);
164
186
190typedef enum coap_pki_key_t {
196
200typedef struct coap_pki_key_pem_t {
201 const char *ca_file;
203 const char *public_cert;
204 const char *private_key;
206
217 const uint8_t *ca_cert;
218 const uint8_t *public_cert;
219 const uint8_t *private_key;
222 size_t ca_cert_len;
226
230typedef struct coap_pki_key_asn1_t {
231 const uint8_t *ca_cert;
232 const uint8_t *public_cert;
233 const uint8_t *private_key;
234 size_t ca_cert_len;
239
243typedef struct coap_pki_key_pkcs11_t {
244 const char *ca;
245 const char *public_cert;
246 const char *private_key;
247 const char *user_pin;
251
255typedef struct coap_dtls_key_t {
257 union {
264
278typedef coap_dtls_key_t *(*coap_dtls_pki_sni_callback_t)(const char *sni,
279 void *arg);
280
281
282#define COAP_DTLS_PKI_SETUP_VERSION 1
288 uint8_t version;
291 /* Options to enable different TLS functionality in libcoap */
301 uint8_t allow_no_crl;
308 uint8_t reserved[3];
310 /* Size of 3 chosen to align to next
311 * parameter, so if newly defined option
312 * it can use one of the reserved slots so
313 * no need to change
314 * COAP_DTLS_PKI_SETUP_VERSION and just
315 * decrement the reserved[] count.
316 */
317
339
345};
346
350typedef struct coap_dtls_cpsk_info_t {
354
371typedef const coap_dtls_cpsk_info_t *(*coap_dtls_ih_callback_t)(
372 coap_str_const_t *hint,
373 coap_session_t *coap_session,
374 void *arg);
375
376#define COAP_DTLS_CPSK_SETUP_VERSION 1
381typedef struct coap_dtls_cpsk_t {
382 uint8_t version;
385 /* Options to enable different TLS functionality in libcoap */
386 uint8_t reserved[7];
388 /* Size of 7 chosen to align to next
389 * parameter, so if newly defined option
390 * it can use one of the reserverd slot so
391 * no need to change
392 * COAP_DTLS_CPSK_SETUP_VERSION and just
393 * decrement the reserved[] count.
394 */
395
412
417typedef struct coap_dtls_spsk_info_t {
421
422
440typedef const coap_bin_const_t *(*coap_dtls_id_callback_t)(
441 coap_bin_const_t *identity,
442 coap_session_t *coap_session,
443 void *arg);
458typedef const coap_dtls_spsk_info_t *(*coap_dtls_psk_sni_callback_t)(
459 const char *sni,
460 coap_session_t *coap_session,
461 void *arg);
462
463#define COAP_DTLS_SPSK_SETUP_VERSION 1
468typedef struct coap_dtls_spsk_t {
469 uint8_t version;
472 /* Options to enable different TLS functionality in libcoap */
473 uint8_t reserved[7];
475 /* Size of 7 chosen to align to next
476 * parameter, so if newly defined option
477 * it can use one of the reserverd slot so
478 * no need to change
479 * COAP_DTLS_SPSK_SETUP_VERSION and just
480 * decrement the reserved[] count.
481 */
482
500
501
504#endif /* COAP_DTLS_H */
Strings to be used in the CoAP library.
Clock Handling.
const coap_bin_const_t *(* coap_dtls_id_callback_t)(coap_bin_const_t *identity, coap_session_t *coap_session, void *arg)
Identity Validation callback that can be set up by coap_context_set_psk2().
Definition: coap_dtls.h:440
struct coap_dtls_cpsk_info_t coap_dtls_cpsk_info_t
The structure that holds the Client PSK information.
coap_tls_version_t * coap_get_tls_library_version(void)
Determine the type and version of the underlying (D)TLS library.
Definition: coap_notls.c:69
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
Definition: coap_notls.c:37
struct coap_dtls_key_t coap_dtls_key_t
The structure that holds the PKI key information.
struct coap_dtls_spsk_t coap_dtls_spsk_t
The structure used for defining the Server PSK setup data to be used.
struct coap_dtls_cpsk_t coap_dtls_cpsk_t
The structure used for defining the Client PSK setup data to be used.
struct coap_pki_key_pkcs11_t coap_pki_key_pkcs11_t
The structure that holds the PKI PKCS11 definitions.
coap_dtls_role_t
Definition: coap_dtls.h:44
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition: coap_notls.c:28
struct coap_tls_version_t coap_tls_version_t
The structure used for returning the underlying (D)TLS library information.
struct coap_pki_key_pem_t coap_pki_key_pem_t
The structure that holds the PKI PEM definitions.
coap_pki_key_t
The enum used for determining the PKI key formats.
Definition: coap_dtls.h:190
const coap_dtls_cpsk_info_t *(* coap_dtls_ih_callback_t)(coap_str_const_t *hint, coap_session_t *coap_session, void *arg)
Identity Hint Validation callback that can be set up by coap_new_client_session_psk2().
Definition: coap_dtls.h:371
struct coap_dtls_spsk_info_t coap_dtls_spsk_info_t
The structure that holds the Server Pre-Shared Key and Identity Hint information.
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition: coap_notls.c:23
struct coap_pki_key_asn1_t coap_pki_key_asn1_t
The structure that holds the PKI ASN.1 (DER) definitions.
struct coap_pki_key_pem_buf_t coap_pki_key_pem_buf_t
The structure that holds the PKI PEM buffer definitions.
coap_asn1_privatekey_type_t
The enum used for determining the provided PKI ASN.1 (DER) Private Key formats.
Definition: coap_dtls.h:169
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
Definition: coap_notls.c:46
const coap_dtls_spsk_info_t *(* coap_dtls_psk_sni_callback_t)(const char *sni, coap_session_t *coap_session, void *arg)
PSK SNI callback that can be set up by coap_context_set_psk2().
Definition: coap_dtls.h:458
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
Definition: coap_notls.c:64
coap_tls_library_t
Definition: coap_dtls.h:93
int(* coap_dtls_cn_callback_t)(const char *cn, const uint8_t *asn1_public_cert, size_t asn1_length, coap_session_t *coap_session, unsigned int depth, int validated, void *arg)
CN Validation callback that can be set up by coap_context_set_pki().
Definition: coap_dtls.h:157
coap_dtls_key_t *(* coap_dtls_pki_sni_callback_t)(const char *sni, void *arg)
Server Name Indication (SNI) Validation callback that can be set up by coap_context_set_pki().
Definition: coap_dtls.h:278
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
Definition: coap_notls.c:55
int(* coap_dtls_security_setup_t)(void *tls_session, coap_dtls_pki_t *setup_data)
Additional Security setup handler that can be set up by coap_context_set_pki().
Definition: coap_dtls.h:134
@ COAP_DTLS_ROLE_SERVER
Internal function invoked for server.
Definition: coap_dtls.h:46
@ COAP_DTLS_ROLE_CLIENT
Internal function invoked for client.
Definition: coap_dtls.h:45
@ COAP_PKI_KEY_PKCS11
The PKI key type is PKCS11 (DER)
Definition: coap_dtls.h:194
@ COAP_PKI_KEY_PEM_BUF
The PKI key type is PEM buffer.
Definition: coap_dtls.h:193
@ COAP_PKI_KEY_PEM
The PKI key type is PEM file.
Definition: coap_dtls.h:191
@ COAP_PKI_KEY_ASN1
The PKI key type is ASN.1 (DER) buffer.
Definition: coap_dtls.h:192
@ COAP_ASN1_PKEY_DH
DH type.
Definition: coap_dtls.h:178
@ COAP_ASN1_PKEY_NONE
NONE.
Definition: coap_dtls.h:170
@ COAP_ASN1_PKEY_TLS1_PRF
TLS1_PRF type.
Definition: coap_dtls.h:183
@ COAP_ASN1_PKEY_RSA2
RSA2 type.
Definition: coap_dtls.h:172
@ COAP_ASN1_PKEY_DSA
DSA type.
Definition: coap_dtls.h:173
@ COAP_ASN1_PKEY_DHX
DHX type.
Definition: coap_dtls.h:179
@ COAP_ASN1_PKEY_DSA4
DSA4 type.
Definition: coap_dtls.h:177
@ COAP_ASN1_PKEY_DSA2
DSA2 type.
Definition: coap_dtls.h:175
@ COAP_ASN1_PKEY_RSA
RSA type.
Definition: coap_dtls.h:171
@ COAP_ASN1_PKEY_DSA1
DSA1 type.
Definition: coap_dtls.h:174
@ COAP_ASN1_PKEY_HKDF
HKDF type.
Definition: coap_dtls.h:184
@ COAP_ASN1_PKEY_EC
EC type.
Definition: coap_dtls.h:180
@ COAP_ASN1_PKEY_DSA3
DSA3 type.
Definition: coap_dtls.h:176
@ COAP_ASN1_PKEY_HMAC
HMAC type.
Definition: coap_dtls.h:181
@ COAP_ASN1_PKEY_CMAC
CMAC type.
Definition: coap_dtls.h:182
@ COAP_TLS_LIBRARY_WOLFSSL
Using wolfSSL library.
Definition: coap_dtls.h:99
@ COAP_TLS_LIBRARY_GNUTLS
Using GnuTLS library.
Definition: coap_dtls.h:97
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
Definition: coap_dtls.h:95
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:94
@ COAP_TLS_LIBRARY_OPENSSL
Using OpenSSL library.
Definition: coap_dtls.h:96
@ COAP_TLS_LIBRARY_MBEDTLS
Using Mbed TLS library.
Definition: coap_dtls.h:98
CoAP binary data definition with const data.
Definition: coap_str.h:64
The structure that holds the Client PSK information.
Definition: coap_dtls.h:350
coap_bin_const_t key
Definition: coap_dtls.h:352
coap_bin_const_t identity
Definition: coap_dtls.h:351
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:381
uint8_t version
Definition: coap_dtls.h:382
void * ih_call_back_arg
Passed in to the Identity Hint callback function.
Definition: coap_dtls.h:402
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition: coap_dtls.h:405
coap_dtls_ih_callback_t validate_ih_call_back
Identity Hint check callback function.
Definition: coap_dtls.h:401
coap_dtls_cpsk_info_t psk_info
Client PSK definition.
Definition: coap_dtls.h:410
uint8_t reserved[7]
Set to COAP_DTLS_CPSK_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:386
The structure that holds the PKI key information.
Definition: coap_dtls.h:255
coap_pki_key_pem_t pem
for PEM file keys
Definition: coap_dtls.h:258
coap_pki_key_pkcs11_t pkcs11
for PKCS11 keys
Definition: coap_dtls.h:261
union coap_dtls_key_t::@3 key
coap_pki_key_pem_buf_t pem_buf
for PEM memory keys
Definition: coap_dtls.h:259
coap_pki_key_t key_type
key format type
Definition: coap_dtls.h:256
coap_pki_key_asn1_t asn1
for ASN.1 (DER) memory keys
Definition: coap_dtls.h:260
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:287
uint8_t allow_no_crl
1 ignore if CRL not there
Definition: coap_dtls.h:301
void * cn_call_back_arg
Passed in to the CN callback function.
Definition: coap_dtls.h:323
uint8_t allow_short_rsa_length
1 if small RSA keysizes are allowed
Definition: coap_dtls.h:304
uint8_t cert_chain_validation
1 if to check cert_chain_verify_depth
Definition: coap_dtls.h:298
uint8_t allow_bad_md_hash
1 if unsupported MD hashes are allowed
Definition: coap_dtls.h:303
uint8_t version
Definition: coap_dtls.h:288
uint8_t check_cert_revocation
1 if revocation checks wanted
Definition: coap_dtls.h:300
coap_dtls_pki_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition: coap_dtls.h:330
uint8_t cert_chain_verify_depth
recommended depth is 3
Definition: coap_dtls.h:299
uint8_t reserved[3]
Reserved - must be set to 0 for future compatibility.
Definition: coap_dtls.h:308
coap_dtls_security_setup_t additional_tls_setup_call_back
Additional Security callback handler that is invoked when libcoap has done the standard,...
Definition: coap_dtls.h:338
uint8_t allow_expired_certs
1 if expired certs are allowed
Definition: coap_dtls.h:297
uint8_t verify_peer_cert
Set to COAP_DTLS_PKI_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:292
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition: coap_dtls.h:340
uint8_t allow_self_signed
1 if self-signed certs are allowed.
Definition: coap_dtls.h:295
void * sni_call_back_arg
Passed in to the sni callback function.
Definition: coap_dtls.h:331
coap_dtls_cn_callback_t validate_cn_call_back
CN check callback function.
Definition: coap_dtls.h:322
uint8_t allow_expired_crl
1 if expired crl is allowed
Definition: coap_dtls.h:302
uint8_t is_rpk_not_cert
1 is RPK instead of Public Certificate.
Definition: coap_dtls.h:305
uint8_t check_common_ca
1 if peer cert is to be signed by the same CA as the local cert
Definition: coap_dtls.h:293
coap_dtls_key_t pki_key
PKI key definition.
Definition: coap_dtls.h:344
The structure that holds the Server Pre-Shared Key and Identity Hint information.
Definition: coap_dtls.h:417
coap_bin_const_t hint
Definition: coap_dtls.h:418
coap_bin_const_t key
Definition: coap_dtls.h:419
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:468
coap_dtls_psk_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition: coap_dtls.h:495
coap_dtls_id_callback_t validate_id_call_back
Identity check callback function.
Definition: coap_dtls.h:487
uint8_t version
Definition: coap_dtls.h:469
uint8_t reserved[7]
Set to COAP_DTLS_SPSK_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:473
void * id_call_back_arg
Passed in to the Identity callback function.
Definition: coap_dtls.h:488
void * sni_call_back_arg
Passed in to the SNI callback function.
Definition: coap_dtls.h:496
coap_dtls_spsk_info_t psk_info
Server PSK definition.
Definition: coap_dtls.h:498
The structure that holds the PKI ASN.1 (DER) definitions.
Definition: coap_dtls.h:230
const uint8_t * private_key
ASN1 (DER) Private Key.
Definition: coap_dtls.h:233
coap_asn1_privatekey_type_t private_key_type
Private Key Type.
Definition: coap_dtls.h:237
size_t public_cert_len
ASN1 Public Cert length.
Definition: coap_dtls.h:235
size_t private_key_len
ASN1 Private Key length.
Definition: coap_dtls.h:236
const uint8_t * ca_cert
ASN1 (DER) Common CA Cert.
Definition: coap_dtls.h:231
size_t ca_cert_len
ASN1 CA Cert length.
Definition: coap_dtls.h:234
const uint8_t * public_cert
ASN1 (DER) Public Cert, or Public Key if RPK.
Definition: coap_dtls.h:232
The structure that holds the PKI PEM buffer definitions.
Definition: coap_dtls.h:216
size_t ca_cert_len
PEM buffer CA Cert length.
Definition: coap_dtls.h:222
const uint8_t * ca_cert
PEM buffer Common CA Cert.
Definition: coap_dtls.h:217
size_t private_key_len
PEM buffer Private Key length.
Definition: coap_dtls.h:224
const uint8_t * private_key
PEM buffer Private Key If RPK and 'EC PRIVATE KEY' this can be used for both the public_cert and priv...
Definition: coap_dtls.h:219
size_t public_cert_len
PEM buffer Public Cert length.
Definition: coap_dtls.h:223
const uint8_t * public_cert
PEM buffer Public Cert, or Public Key if RPK.
Definition: coap_dtls.h:218
The structure that holds the PKI PEM definitions.
Definition: coap_dtls.h:200
const char * ca_file
File location of Common CA (and any intermediates) in PEM format.
Definition: coap_dtls.h:201
const char * public_cert
File location of Public Cert.
Definition: coap_dtls.h:203
const char * private_key
File location of Private Key in PEM format.
Definition: coap_dtls.h:204
The structure that holds the PKI PKCS11 definitions.
Definition: coap_dtls.h:243
const char * private_key
pkcs11: URI for Private Key
Definition: coap_dtls.h:246
const char * ca
pkcs11: URI for Common CA Certificate
Definition: coap_dtls.h:244
const char * user_pin
User pin to access PKCS11.
Definition: coap_dtls.h:247
const char * public_cert
pkcs11: URI for Public Cert
Definition: coap_dtls.h:245
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
CoAP string data definition with const data.
Definition: coap_str.h:46
The structure used for returning the underlying (D)TLS library information.
Definition: coap_dtls.h:106
uint64_t built_version
(D)TLS Built against Library Version
Definition: coap_dtls.h:109
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:108
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:107