libcoap 4.3.1
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 "str.h"
23
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
43typedef enum coap_dtls_role_t {
47
48#define COAP_DTLS_RPK_CERT_CN "RPK"
49
56
62int coap_tls_is_supported(void);
63
64typedef enum coap_tls_library_t {
71
76typedef struct coap_tls_version_t {
77 uint64_t version;
79 uint64_t built_version;
81
88
104typedef int (*coap_dtls_security_setup_t)(void* tls_session,
105 coap_dtls_pki_t *setup_data);
106
127typedef int (*coap_dtls_cn_callback_t)(const char *cn,
128 const uint8_t *asn1_public_cert,
129 size_t asn1_length,
130 coap_session_t *coap_session,
131 unsigned int depth,
132 int validated,
133 void *arg);
134
156
160typedef enum coap_pki_key_t {
166
170typedef struct coap_pki_key_pem_t {
171 const char *ca_file;
172 const char *public_cert;
173 const char *private_key;
175
186 const uint8_t *ca_cert;
187 const uint8_t *public_cert;
188 const uint8_t *private_key;
191 size_t ca_cert_len;
195
199typedef struct coap_pki_key_asn1_t {
200 const uint8_t *ca_cert;
201 const uint8_t *public_cert;
202 const uint8_t *private_key;
203 size_t ca_cert_len;
208
212typedef struct coap_pki_key_pkcs11_t {
213 const char *ca;
214 const char *public_cert;
215 const char *private_key;
216 const char *user_pin;
220
224typedef struct coap_dtls_key_t {
226 union {
233
247typedef coap_dtls_key_t *(*coap_dtls_pki_sni_callback_t)(const char *sni,
248 void* arg);
249
250
251#define COAP_DTLS_PKI_SETUP_VERSION 1
257 uint8_t version;
260 /* Options to enable different TLS functionality in libcoap */
270 uint8_t allow_no_crl;
277 uint8_t reserved[3];
279 /* Size of 3 chosen to align to next
280 * parameter, so if newly defined option
281 * it can use one of the reserverd slot so
282 * no need to change
283 * COAP_DTLS_PKI_SETUP_VERSION and just
284 * decrement the reserved[] count.
285 */
286
308
314};
315
319typedef struct coap_dtls_cpsk_info_t {
323
340typedef const coap_dtls_cpsk_info_t *(*coap_dtls_ih_callback_t)(
341 coap_str_const_t *hint,
342 coap_session_t *coap_session,
343 void *arg);
344
345#define COAP_DTLS_CPSK_SETUP_VERSION 1
350typedef struct coap_dtls_cpsk_t {
351 uint8_t version;
354 /* Options to enable different TLS functionality in libcoap */
355 uint8_t reserved[7];
357 /* Size of 7 chosen to align to next
358 * parameter, so if newly defined option
359 * it can use one of the reserverd slot so
360 * no need to change
361 * COAP_DTLS_CPSK_SETUP_VERSION and just
362 * decrement the reserved[] count.
363 */
364
381
386typedef struct coap_dtls_spsk_info_t {
390
391
409typedef const coap_bin_const_t *(*coap_dtls_id_callback_t)(
410 coap_bin_const_t *identity,
411 coap_session_t *coap_session,
412 void *arg);
427typedef const coap_dtls_spsk_info_t *(*coap_dtls_psk_sni_callback_t)(
428 const char *sni,
429 coap_session_t *coap_session,
430 void *arg);
431
432#define COAP_DTLS_SPSK_SETUP_VERSION 1
437typedef struct coap_dtls_spsk_t {
438 uint8_t version;
441 /* Options to enable different TLS functionality in libcoap */
442 uint8_t reserved[7];
444 /* Size of 7 chosen to align to next
445 * parameter, so if newly defined option
446 * it can use one of the reserverd slot so
447 * no need to change
448 * COAP_DTLS_SPSK_SETUP_VERSION and just
449 * decrement the reserved[] count.
450 */
451
469
470
480void coap_dtls_set_log_level(int level);
481
489
490
491#endif /* COAP_DTLS_H */
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:409
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:33
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:43
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:160
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:340
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:139
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:427
coap_tls_library_t
Definition: coap_dtls.h:64
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:127
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:247
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:104
@ COAP_DTLS_ROLE_SERVER
Internal function invoked for server.
Definition: coap_dtls.h:45
@ COAP_DTLS_ROLE_CLIENT
Internal function invoked for client.
Definition: coap_dtls.h:44
@ COAP_PKI_KEY_PKCS11
The PKI key type is PKCS11 (DER)
Definition: coap_dtls.h:164
@ COAP_PKI_KEY_PEM_BUF
The PKI key type is PEM buffer.
Definition: coap_dtls.h:163
@ COAP_PKI_KEY_PEM
The PKI key type is PEM file.
Definition: coap_dtls.h:161
@ COAP_PKI_KEY_ASN1
The PKI key type is ASN.1 (DER) buffer.
Definition: coap_dtls.h:162
@ COAP_ASN1_PKEY_DH
DH type.
Definition: coap_dtls.h:148
@ COAP_ASN1_PKEY_NONE
NONE.
Definition: coap_dtls.h:140
@ COAP_ASN1_PKEY_TLS1_PRF
TLS1_PRF type.
Definition: coap_dtls.h:153
@ COAP_ASN1_PKEY_RSA2
RSA2 type.
Definition: coap_dtls.h:142
@ COAP_ASN1_PKEY_DSA
DSA type.
Definition: coap_dtls.h:143
@ COAP_ASN1_PKEY_DHX
DHX type.
Definition: coap_dtls.h:149
@ COAP_ASN1_PKEY_DSA4
DSA4 type.
Definition: coap_dtls.h:147
@ COAP_ASN1_PKEY_DSA2
DSA2 type.
Definition: coap_dtls.h:145
@ COAP_ASN1_PKEY_RSA
RSA type.
Definition: coap_dtls.h:141
@ COAP_ASN1_PKEY_DSA1
DSA1 type.
Definition: coap_dtls.h:144
@ COAP_ASN1_PKEY_HKDF
HKDF type.
Definition: coap_dtls.h:154
@ COAP_ASN1_PKEY_EC
EC type.
Definition: coap_dtls.h:150
@ COAP_ASN1_PKEY_DSA3
DSA3 type.
Definition: coap_dtls.h:146
@ COAP_ASN1_PKEY_HMAC
HMAC type.
Definition: coap_dtls.h:151
@ COAP_ASN1_PKEY_CMAC
CMAC type.
Definition: coap_dtls.h:152
@ COAP_TLS_LIBRARY_GNUTLS
Using GnuTLS library.
Definition: coap_dtls.h:68
@ COAP_TLS_LIBRARY_TINYDTLS
Using TinyDTLS library.
Definition: coap_dtls.h:66
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition: coap_dtls.h:65
@ COAP_TLS_LIBRARY_OPENSSL
Using OpenSSL library.
Definition: coap_dtls.h:67
@ COAP_TLS_LIBRARY_MBEDTLS
Using Mbed TLS library.
Definition: coap_dtls.h:69
void coap_dtls_set_log_level(int level)
Sets the (D)TLS logging level to the specified level.
Definition: coap_notls.c:97
int coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition: coap_notls.c:102
Strings to be used in the CoAP library.
CoAP binary data definition with const data.
Definition: str.h:64
The structure that holds the Client PSK information.
Definition: coap_dtls.h:319
coap_bin_const_t key
Definition: coap_dtls.h:321
coap_bin_const_t identity
Definition: coap_dtls.h:320
The structure used for defining the Client PSK setup data to be used.
Definition: coap_dtls.h:350
uint8_t version
Definition: coap_dtls.h:351
void * ih_call_back_arg
Passed in to the Identity Hint callback function.
Definition: coap_dtls.h:371
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition: coap_dtls.h:374
coap_dtls_ih_callback_t validate_ih_call_back
Identity Hint check callback function.
Definition: coap_dtls.h:370
coap_dtls_cpsk_info_t psk_info
Client PSK definition.
Definition: coap_dtls.h:379
uint8_t reserved[7]
Set to COAP_DTLS_CPSK_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:355
The structure that holds the PKI key information.
Definition: coap_dtls.h:224
coap_pki_key_pem_t pem
for PEM file keys
Definition: coap_dtls.h:227
coap_pki_key_pkcs11_t pkcs11
for PKCS11 keys
Definition: coap_dtls.h:230
union coap_dtls_key_t::@2 key
coap_pki_key_pem_buf_t pem_buf
for PEM memory keys
Definition: coap_dtls.h:228
coap_pki_key_t key_type
key format type
Definition: coap_dtls.h:225
coap_pki_key_asn1_t asn1
for ASN.1 (DER) memory keys
Definition: coap_dtls.h:229
The structure used for defining the PKI setup data to be used.
Definition: coap_dtls.h:256
uint8_t allow_no_crl
1 ignore if CRL not there
Definition: coap_dtls.h:270
void * cn_call_back_arg
Passed in to the CN callback function.
Definition: coap_dtls.h:292
uint8_t allow_short_rsa_length
1 if small RSA keysizes are allowed
Definition: coap_dtls.h:273
uint8_t cert_chain_validation
1 if to check cert_chain_verify_depth
Definition: coap_dtls.h:267
uint8_t allow_bad_md_hash
1 if unsupported MD hashes are allowed
Definition: coap_dtls.h:272
uint8_t version
Definition: coap_dtls.h:257
uint8_t check_cert_revocation
1 if revocation checks wanted
Definition: coap_dtls.h:269
coap_dtls_pki_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition: coap_dtls.h:299
uint8_t cert_chain_verify_depth
recommended depth is 3
Definition: coap_dtls.h:268
uint8_t reserved[3]
Reserved - must be set to 0 for future compatibility.
Definition: coap_dtls.h:277
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:307
uint8_t allow_expired_certs
1 if expired certs are allowed
Definition: coap_dtls.h:266
uint8_t verify_peer_cert
Set to COAP_DTLS_PKI_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:261
char * client_sni
If not NULL, SNI to use in client TLS setup.
Definition: coap_dtls.h:309
uint8_t allow_self_signed
1 if self-signed certs are allowed.
Definition: coap_dtls.h:264
void * sni_call_back_arg
Passed in to the sni callback function.
Definition: coap_dtls.h:300
coap_dtls_cn_callback_t validate_cn_call_back
CN check callback function.
Definition: coap_dtls.h:291
uint8_t allow_expired_crl
1 if expired crl is allowed
Definition: coap_dtls.h:271
uint8_t is_rpk_not_cert
1 is RPK instead of Public Certificate.
Definition: coap_dtls.h:274
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:262
coap_dtls_key_t pki_key
PKI key definition.
Definition: coap_dtls.h:313
The structure that holds the Server Pre-Shared Key and Identity Hint information.
Definition: coap_dtls.h:386
coap_bin_const_t hint
Definition: coap_dtls.h:387
coap_bin_const_t key
Definition: coap_dtls.h:388
The structure used for defining the Server PSK setup data to be used.
Definition: coap_dtls.h:437
coap_dtls_psk_sni_callback_t validate_sni_call_back
SNI check callback function.
Definition: coap_dtls.h:464
coap_dtls_id_callback_t validate_id_call_back
Identity check callback function.
Definition: coap_dtls.h:456
uint8_t version
Definition: coap_dtls.h:438
uint8_t reserved[7]
Set to COAP_DTLS_SPSK_SETUP_VERSION to support this version of the struct.
Definition: coap_dtls.h:442
void * id_call_back_arg
Passed in to the Identity callback function.
Definition: coap_dtls.h:457
void * sni_call_back_arg
Passed in to the SNI callback function.
Definition: coap_dtls.h:465
coap_dtls_spsk_info_t psk_info
Server PSK definition.
Definition: coap_dtls.h:467
The structure that holds the PKI ASN.1 (DER) definitions.
Definition: coap_dtls.h:199
const uint8_t * private_key
ASN1 (DER) Private Key.
Definition: coap_dtls.h:202
coap_asn1_privatekey_type_t private_key_type
Private Key Type.
Definition: coap_dtls.h:206
size_t public_cert_len
ASN1 Public Cert length.
Definition: coap_dtls.h:204
size_t private_key_len
ASN1 Private Key length.
Definition: coap_dtls.h:205
const uint8_t * ca_cert
ASN1 (DER) Common CA Cert.
Definition: coap_dtls.h:200
size_t ca_cert_len
ASN1 CA Cert length.
Definition: coap_dtls.h:203
const uint8_t * public_cert
ASN1 (DER) Public Cert, or Public Key if RPK.
Definition: coap_dtls.h:201
The structure that holds the PKI PEM buffer definitions.
Definition: coap_dtls.h:185
size_t ca_cert_len
PEM buffer CA Cert length.
Definition: coap_dtls.h:191
const uint8_t * ca_cert
PEM buffer Common CA Cert.
Definition: coap_dtls.h:186
size_t private_key_len
PEM buffer Private Key length.
Definition: coap_dtls.h:193
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:188
size_t public_cert_len
PEM buffer Public Cert length.
Definition: coap_dtls.h:192
const uint8_t * public_cert
PEM buffer Public Cert, or Public Key if RPK.
Definition: coap_dtls.h:187
The structure that holds the PKI PEM definitions.
Definition: coap_dtls.h:170
const char * ca_file
File location of Common CA in PEM format.
Definition: coap_dtls.h:171
const char * public_cert
File location of Public Cert.
Definition: coap_dtls.h:172
const char * private_key
File location of Private Key in PEM format.
Definition: coap_dtls.h:173
The structure that holds the PKI PKCS11 definitions.
Definition: coap_dtls.h:212
const char * private_key
pkcs11: URI for Private Key
Definition: coap_dtls.h:215
const char * ca
pkcs11: URI for Common CA Certificate
Definition: coap_dtls.h:213
const char * user_pin
User pin to access PKCS11.
Definition: coap_dtls.h:216
const char * public_cert
pkcs11: URI for Public Cert
Definition: coap_dtls.h:214
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: str.h:46
The structure used for returning the underlying (D)TLS library information.
Definition: coap_dtls.h:76
uint64_t built_version
(D)TLS Built against Library Version
Definition: coap_dtls.h:79
coap_tls_library_t type
Library type.
Definition: coap_dtls.h:78
uint64_t version
(D)TLS runtime Library Version
Definition: coap_dtls.h:77