libcoap 4.3.5-develop-e2463f0
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 * Copyright (C) 2023-2026 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
18
19#ifndef COAP_DTLS_H_
20#define COAP_DTLS_H_
21
22#include "coap_time.h"
23#include "coap_str.h"
24
25#ifdef __cplusplus
26extern "C" {
27#endif
28
35
37
38#ifndef COAP_DTLS_HINT_LENGTH
39#define COAP_DTLS_HINT_LENGTH 128
40#endif
41#ifndef COAP_DTLS_MAX_PSK_IDENTITY
42#define COAP_DTLS_MAX_PSK_IDENTITY 64
43#endif
44#ifndef COAP_DTLS_MAX_PSK
45#define COAP_DTLS_MAX_PSK 64
46#endif
47
52
53#define COAP_DTLS_RPK_CERT_CN "RPK"
54
64
73
83
93
100
116typedef int (*coap_dtls_security_setup_t)(void *tls_session,
117 coap_dtls_pki_t *setup_data);
118
139typedef int (*coap_dtls_cn_callback_t)(const char *cn,
140 const uint8_t *asn1_public_cert,
141 size_t asn1_length,
142 coap_session_t *coap_session,
143 unsigned int depth,
144 int validated,
145 void *arg);
146
168
179
183typedef struct coap_pki_key_pem_t {
184 const char *ca_file;
186 const char *public_cert;
187 const char *private_key;
189
200 const uint8_t *ca_cert;
201 const uint8_t *public_cert;
202 const uint8_t *private_key;
205 size_t ca_cert_len;
209
222
226typedef struct coap_pki_key_pkcs11_t {
227 const char *ca;
228 const char *public_cert;
229 const char *private_key;
230 const char *user_pin;
234
260
280
294
308typedef coap_dtls_key_t *(*coap_dtls_pki_sni_callback_t)(const char *sni,
309 void *arg);
310
311
312#define COAP_DTLS_PKI_SETUP_VERSION 1
313
318 uint8_t version;
320
321 /* Options to enable different TLS functionality in libcoap */
331 uint8_t allow_no_crl;
338 uint8_t use_cid;
343 uint8_t reserved[1];
345 /* Size of 1 chosen to align to next
346 * parameter, so if newly defined option
347 * it can use one of the reserved slots so
348 * no need to change
349 * COAP_DTLS_PKI_SETUP_VERSION and just
350 * decrement the reserved[] count.
351 * [Now just adding 1 bit at a time].
352 */
353
360
368
375
380
382};
383
391
408typedef const coap_dtls_cpsk_info_t *(*coap_dtls_ih_callback_t)(
409 coap_str_const_t *hint,
410 coap_session_t *coap_session,
411 void *arg);
412
413#define COAP_DTLS_CPSK_SETUP_VERSION 1
414
418typedef struct coap_dtls_cpsk_t {
419 uint8_t version;
421
422 /* Options to enable different TLS functionality in libcoap */
423 uint8_t ec_jpake;
425 uint8_t use_cid;
426 uint8_t reserved[5];
428 /* Size of 5 chosen to align to next
429 * parameter, so if newly defined option
430 * it can use one of the reserverd slot so
431 * no need to change
432 * COAP_DTLS_CPSK_SETUP_VERSION and just
433 * decrement the reserved[] count.
434 */
435
444
450
453
462
463
481typedef const coap_bin_const_t *(*coap_dtls_id_callback_t)(
482 coap_bin_const_t *identity,
483 coap_session_t *coap_session,
484 void *arg);
499typedef const coap_dtls_spsk_info_t *(*coap_dtls_psk_sni_callback_t)(
500 const char *sni,
501 coap_session_t *coap_session,
502 void *arg);
503
504#define COAP_DTLS_SPSK_SETUP_VERSION 1
505
509typedef struct coap_dtls_spsk_t {
510 uint8_t version;
512
513 /* Options to enable different TLS functionality in libcoap */
514 uint8_t ec_jpake;
516 uint8_t reserved[6];
518 /* Size of 6 chosen to align to next
519 * parameter, so if newly defined option
520 * it can use one of the reserverd slot so
521 * no need to change
522 * COAP_DTLS_SPSK_SETUP_VERSION and just
523 * decrement the reserved[] count.
524 */
525
532
540
543
545
546#ifdef __cplusplus
547}
548#endif
549
550#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:481
coap_pki_define_t
The enum to define the format of the key parameter definition.
Definition coap_dtls.h:238
int coap_tls_engine_configure(coap_str_const_t *conf_mem)
Configure an ENGINE for a TLS library.
Definition coap_notls.c:22
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:101
coap_dtls_role_t
Definition coap_dtls.h:48
int coap_tls_engine_remove(void)
Remove a previously configured ENGINE from a TLS library.
Definition coap_notls.c:28
coap_pki_key_t
The enum used for determining the PKI key formats.
Definition coap_dtls.h:172
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:408
coap_asn1_privatekey_type_t
The enum used for determining the provided PKI ASN.1 (DER) Private Key formats.
Definition coap_dtls.h:151
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:499
coap_tls_library_t
Definition coap_dtls.h:74
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:139
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:308
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:116
@ COAP_PKI_KEY_DEF_PKCS11
The PKI key type is PKCS11 (pkcs11:...).
Definition coap_dtls.h:250
@ COAP_PKI_KEY_DEF_DER_BUF
The PKI key type is DER buffer (ASN.1).
Definition coap_dtls.h:247
@ COAP_PKI_KEY_DEF_PEM_BUF
The PKI key type is PEM buffer.
Definition coap_dtls.h:241
@ COAP_PKI_KEY_DEF_PEM
The PKI key type is PEM file.
Definition coap_dtls.h:239
@ COAP_PKI_KEY_DEF_ENGINE
The PKI key type is to be passed to ENGINE.
Definition coap_dtls.h:256
@ COAP_PKI_KEY_DEF_RPK_BUF
The PKI key type is RPK in buffer.
Definition coap_dtls.h:243
@ COAP_PKI_KEY_DEF_DER
The PKI key type is DER file.
Definition coap_dtls.h:245
@ COAP_PKI_KEY_DEF_PKCS11_RPK
The PKI key type is PKCS11 w/ RPK (pkcs11:...).
Definition coap_dtls.h:253
@ COAP_DTLS_ROLE_SERVER
Internal function invoked for server.
Definition coap_dtls.h:50
@ COAP_DTLS_ROLE_CLIENT
Internal function invoked for client.
Definition coap_dtls.h:49
@ COAP_PKI_KEY_PKCS11
The PKI key type is PKCS11 (DER).
Definition coap_dtls.h:176
@ COAP_PKI_KEY_PEM_BUF
The PKI key type is PEM buffer.
Definition coap_dtls.h:175
@ COAP_PKI_KEY_DEFINE
The individual PKI key types are Definable.
Definition coap_dtls.h:177
@ COAP_PKI_KEY_PEM
The PKI key type is PEM file.
Definition coap_dtls.h:173
@ COAP_PKI_KEY_ASN1
The PKI key type is ASN.1 (DER) buffer.
Definition coap_dtls.h:174
@ COAP_ASN1_PKEY_DH
DH type.
Definition coap_dtls.h:160
@ COAP_ASN1_PKEY_NONE
NONE.
Definition coap_dtls.h:152
@ COAP_ASN1_PKEY_TLS1_PRF
TLS1_PRF type.
Definition coap_dtls.h:165
@ COAP_ASN1_PKEY_RSA2
RSA2 type.
Definition coap_dtls.h:154
@ COAP_ASN1_PKEY_DSA
DSA type.
Definition coap_dtls.h:155
@ COAP_ASN1_PKEY_DHX
DHX type.
Definition coap_dtls.h:161
@ COAP_ASN1_PKEY_DSA4
DSA4 type.
Definition coap_dtls.h:159
@ COAP_ASN1_PKEY_DSA2
DSA2 type.
Definition coap_dtls.h:157
@ COAP_ASN1_PKEY_RSA
RSA type.
Definition coap_dtls.h:153
@ COAP_ASN1_PKEY_DSA1
DSA1 type.
Definition coap_dtls.h:156
@ COAP_ASN1_PKEY_HKDF
HKDF type.
Definition coap_dtls.h:166
@ COAP_ASN1_PKEY_EC
EC type.
Definition coap_dtls.h:162
@ COAP_ASN1_PKEY_DSA3
DSA3 type.
Definition coap_dtls.h:158
@ COAP_ASN1_PKEY_HMAC
HMAC type.
Definition coap_dtls.h:163
@ COAP_ASN1_PKEY_CMAC
CMAC type.
Definition coap_dtls.h:164
@ COAP_TLS_LIBRARY_OPENHITLS
Using openHiTLS library.
Definition coap_dtls.h:81
@ COAP_TLS_LIBRARY_WOLFSSL
Using wolfSSL library.
Definition coap_dtls.h:80
@ COAP_TLS_LIBRARY_GNUTLS
Using GnuTLS library.
Definition coap_dtls.h:78
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
Definition coap_dtls.h:76
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition coap_dtls.h:75
@ COAP_TLS_LIBRARY_OPENSSL
Using OpenSSL library.
Definition coap_dtls.h:77
@ COAP_TLS_LIBRARY_MBEDTLS
Using Mbed TLS library.
Definition coap_dtls.h:79
CoAP binary data definition with const data.
Definition coap_str.h:65
The structure that holds the Client PSK information.
Definition coap_dtls.h:387
coap_bin_const_t key
Definition coap_dtls.h:389
coap_bin_const_t identity
Definition coap_dtls.h:388
The structure used for defining the Client PSK setup data to be used.
Definition coap_dtls.h:418
uint8_t use_cid
Set to 1 if DTLS Connection ID is to be used.
Definition coap_dtls.h:425
void * ih_call_back_arg
Passed in to the Identity Hint callback function.
Definition coap_dtls.h:442
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:445
uint8_t reserved[5]
Reserved - must be set to 0 for future compatibility.
Definition coap_dtls.h:426
coap_dtls_ih_callback_t validate_ih_call_back
Identity Hint check callback function.
Definition coap_dtls.h:441
uint8_t ec_jpake
Set to COAP_DTLS_CPSK_SETUP_VERSION to support this version of the struct.
Definition coap_dtls.h:423
coap_dtls_cpsk_info_t psk_info
Client PSK definition.
Definition coap_dtls.h:451
The structure that holds the PKI key information.
Definition coap_dtls.h:284
coap_pki_key_define_t define
for definable type keys
Definition coap_dtls.h:291
coap_pki_key_pem_t pem
for PEM file keys
Definition coap_dtls.h:287
coap_pki_key_pkcs11_t pkcs11
for PKCS11 keys
Definition coap_dtls.h:290
coap_pki_key_pem_buf_t pem_buf
for PEM memory keys
Definition coap_dtls.h:288
coap_pki_key_t key_type
key format type
Definition coap_dtls.h:285
coap_pki_key_asn1_t asn1
for ASN.1 (DER) memory keys
Definition coap_dtls.h:289
union coap_dtls_key_t::@003017313271040156213200302176016051164315363211 key
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:317
uint8_t allow_no_crl
1 ignore if CRL not there
Definition coap_dtls.h:331
void * cn_call_back_arg
Passed in to the CN callback function.
Definition coap_dtls.h:359
uint8_t allow_short_rsa_length
1 if small RSA keysizes are allowed
Definition coap_dtls.h:334
uint8_t allow_sni_cn_mismatch
1 if SNI and returnd CN allowed to mismatch (Client only).
Definition coap_dtls.h:341
uint8_t cert_chain_validation
1 if to check cert_chain_verify_depth
Definition coap_dtls.h:328
uint8_t allow_bad_md_hash
1 if unsupported MD hashes are allowed
Definition coap_dtls.h:333
uint8_t use_cid
1 if DTLS Connection ID is to be used (Client only, server always enabled) if supported
Definition coap_dtls.h:338
uint8_t reserved[1]
Reserved - must be set to 0 for future compatibility.
Definition coap_dtls.h:343
uint8_t version
Definition coap_dtls.h:318
uint8_t check_cert_revocation
1 if revocation checks wanted
Definition coap_dtls.h:330
coap_dtls_pki_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition coap_dtls.h:366
uint8_t cert_chain_verify_depth
recommended depth is 3
Definition coap_dtls.h:329
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:374
uint8_t allow_expired_certs
1 if expired certs are allowed
Definition coap_dtls.h:327
uint8_t verify_peer_cert
Set to COAP_DTLS_PKI_SETUP_VERSION to support this version of the struct.
Definition coap_dtls.h:322
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition coap_dtls.h:376
uint8_t allow_self_signed
1 if self-signed certs are allowed.
Definition coap_dtls.h:325
void * sni_call_back_arg
Passed in to the sni callback function.
Definition coap_dtls.h:367
coap_dtls_cn_callback_t validate_cn_call_back
CN check callback function.
Definition coap_dtls.h:358
uint8_t allow_expired_crl
1 if expired crl is allowed
Definition coap_dtls.h:332
uint8_t is_rpk_not_cert
1 is RPK instead of Public Certificate.
Definition coap_dtls.h:335
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:323
coap_dtls_key_t pki_key
PKI key definition.
Definition coap_dtls.h:381
The structure that holds the Server Pre-Shared Key and Identity Hint information.
Definition coap_dtls.h:458
coap_bin_const_t hint
Definition coap_dtls.h:459
coap_bin_const_t key
Definition coap_dtls.h:460
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:509
coap_dtls_psk_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition coap_dtls.h:538
uint8_t reserved[6]
Reserved - must be set to 0 for future compatibility.
Definition coap_dtls.h:516
coap_dtls_id_callback_t validate_id_call_back
Identity check callback function.
Definition coap_dtls.h:530
void * id_call_back_arg
Passed in to the Identity callback function.
Definition coap_dtls.h:531
uint8_t ec_jpake
Set to COAP_DTLS_SPSK_SETUP_VERSION to support this version of the struct.
Definition coap_dtls.h:514
void * sni_call_back_arg
Passed in to the SNI callback function.
Definition coap_dtls.h:539
coap_dtls_spsk_info_t psk_info
Server PSK definition.
Definition coap_dtls.h:541
The structure that holds the PKI ASN.1 (DER) definitions.
Definition coap_dtls.h:213
const uint8_t * private_key
ASN1 (DER) Private Key.
Definition coap_dtls.h:216
coap_asn1_privatekey_type_t private_key_type
Private Key Type.
Definition coap_dtls.h:220
size_t public_cert_len
ASN1 Public Cert length.
Definition coap_dtls.h:218
size_t private_key_len
ASN1 Private Key length.
Definition coap_dtls.h:219
const uint8_t * ca_cert
ASN1 (DER) Common CA Cert.
Definition coap_dtls.h:214
size_t ca_cert_len
ASN1 CA Cert length.
Definition coap_dtls.h:217
const uint8_t * public_cert
ASN1 (DER) Public Cert, or Public Key if RPK.
Definition coap_dtls.h:215
The structure that holds the PKI Definable key type definitions.
Definition coap_dtls.h:264
coap_const_char_ptr_t public_cert
define: Public Cert
Definition coap_dtls.h:266
coap_asn1_privatekey_type_t private_key_type
define: ASN1 Private Key Type (if needed)
Definition coap_dtls.h:274
const char * user_pin
define: User pin to access type PKCS11.
Definition coap_dtls.h:276
coap_const_char_ptr_t private_key
define: Private Key
Definition coap_dtls.h:267
coap_const_char_ptr_t ca
define: Common CA Certificate
Definition coap_dtls.h:265
size_t public_cert_len
define Public Cert length (if needed)
Definition coap_dtls.h:269
size_t ca_len
define CA Cert length (if needed)
Definition coap_dtls.h:268
coap_pki_define_t private_key_def
define: Private Key type definition
Definition coap_dtls.h:273
size_t private_key_len
define Private Key length (if needed)
Definition coap_dtls.h:270
coap_pki_define_t ca_def
define: Common CA type definition
Definition coap_dtls.h:271
coap_pki_define_t public_cert_def
define: Public Cert type definition
Definition coap_dtls.h:272
The structure that holds the PKI PEM buffer definitions.
Definition coap_dtls.h:199
size_t ca_cert_len
PEM buffer CA Cert length.
Definition coap_dtls.h:205
const uint8_t * ca_cert
PEM buffer Common CA Cert.
Definition coap_dtls.h:200
size_t private_key_len
PEM buffer Private Key length.
Definition coap_dtls.h:207
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:202
size_t public_cert_len
PEM buffer Public Cert length.
Definition coap_dtls.h:206
const uint8_t * public_cert
PEM buffer Public Cert, or Public Key if RPK.
Definition coap_dtls.h:201
The structure that holds the PKI PEM definitions.
Definition coap_dtls.h:183
const char * ca_file
File location of Common CA (and any intermediates) in PEM format.
Definition coap_dtls.h:184
const char * public_cert
File location of Public Cert.
Definition coap_dtls.h:186
const char * private_key
File location of Private Key in PEM format.
Definition coap_dtls.h:187
The structure that holds the PKI PKCS11 definitions.
Definition coap_dtls.h:226
const char * private_key
pkcs11: URI for Private Key
Definition coap_dtls.h:229
const char * ca
pkcs11: URI for Common CA Certificate
Definition coap_dtls.h:227
const char * user_pin
User pin to access PKCS11.
Definition coap_dtls.h:230
const char * public_cert
pkcs11: URI for Public Cert
Definition coap_dtls.h:228
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:47
The structure used for returning the underlying (D)TLS library information.
Definition coap_dtls.h:88
uint64_t built_version
(D)TLS Built against Library Version
Definition coap_dtls.h:91
coap_tls_library_t type
Library type.
Definition coap_dtls.h:90
uint64_t version
(D)TLS runtime Library Version
Definition coap_dtls.h:89
CoAP union for handling signed / unsigned chars.
Definition coap_str.h:83