Loading...
Searching...
No Matches
coap_notls.c
Go to the documentation of this file.
/*
* coap_notls.c -- Stub Datagram Transport Layer Support for libcoap
*
* Copyright (C) 2016 Olaf Bergmann <bergmann@tzi.org>
* Copyright (C) 2021-2023 Jon Shallow <supjps-libcoap@jpshallow.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#include "coap3/coap_internal.h"
#if !defined(COAP_WITH_LIBTINYDTLS) && !defined(COAP_WITH_LIBOPENSSL) && !defined(COAP_WITH_LIBGNUTLS) && !defined(COAP_WITH_LIBMBEDTLS)
int
coap_dtls_is_supported(void) {
return 0;
}
int
coap_tls_is_supported(void) {
return 0;
}
/*
* return 0 failed
* 1 passed
*/
int
coap_dtls_psk_is_supported(void) {
return 0;
}
/*
* return 0 failed
* 1 passed
*/
int
coap_dtls_pki_is_supported(void) {
return 0;
}
/*
* return 0 failed
* 1 passed
*/
int
coap_dtls_pkcs11_is_supported(void) {
return 0;
}
/*
* return 0 failed
* 1 passed
*/
int
coap_dtls_rpk_is_supported(void) {
return 0;
}
coap_tls_version_t *
coap_get_tls_library_version(void) {
static coap_tls_version_t version;
version.version = 0;
version.type = COAP_TLS_LIBRARY_NOTLS;
return &version;
}
int
coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED,
const coap_dtls_pki_t *setup_data COAP_UNUSED,
const coap_dtls_role_t role COAP_UNUSED
) {
return 0;
}
int
coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED,
const char *ca_file COAP_UNUSED,
const char *ca_path COAP_UNUSED
) {
return 0;
}
#if COAP_CLIENT_SUPPORT
int
coap_dtls_context_set_cpsk(coap_context_t *ctx COAP_UNUSED,
coap_dtls_cpsk_t *setup_data COAP_UNUSED
) {
return 0;
}
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
int
coap_dtls_context_set_spsk(coap_context_t *ctx COAP_UNUSED,
coap_dtls_spsk_t *setup_data COAP_UNUSED
) {
return 0;
}
#endif /* COAP_SERVER_SUPPORT */
int
coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED) {
return 0;
}
static coap_log_t dtls_log_level = COAP_LOG_EMERG;
void
coap_dtls_startup(void) {
}
void *
coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED,
coap_tls_library_t *tls_lib) {
if (tls_lib)
*tls_lib = COAP_TLS_LIBRARY_NOTLS;
return NULL;
}
void
coap_dtls_shutdown(void) {
coap_dtls_set_log_level(COAP_LOG_EMERG);
}
void
coap_dtls_set_log_level(coap_log_t level) {
dtls_log_level = level;
}
coap_log_t
coap_dtls_get_log_level(void) {
return dtls_log_level;
}
void *
coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED) {
return NULL;
}
void
coap_dtls_free_context(void *handle COAP_UNUSED) {
}
#if COAP_SERVER_SUPPORT
void *
coap_dtls_new_server_session(coap_session_t *session COAP_UNUSED) {
return NULL;
}
#endif /* COAP_SERVER_SUPPORT */
#if COAP_CLIENT_SUPPORT
void *
coap_dtls_new_client_session(coap_session_t *session COAP_UNUSED) {
return NULL;
}
#endif /* COAP_CLIENT_SUPPORT */
void
coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED) {
}
void
coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED) {
}
ssize_t
coap_dtls_send(coap_session_t *session COAP_UNUSED,
const uint8_t *data COAP_UNUSED,
size_t data_len COAP_UNUSED) {
return -1;
}
int
coap_dtls_is_context_timeout(void) {
return 1;
}
coap_tick_t
coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED) {
return 0;
}
coap_tick_t
coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED) {
return 0;
}
/*
* return 1 timed out
* 0 still timing out
*/
int
coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED) {
return 0;
}
int
coap_dtls_receive(coap_session_t *session COAP_UNUSED,
const uint8_t *data COAP_UNUSED,
size_t data_len COAP_UNUSED
) {
return -1;
}
#if COAP_SERVER_SUPPORT
int
coap_dtls_hello(coap_session_t *session COAP_UNUSED,
const uint8_t *data COAP_UNUSED,
size_t data_len COAP_UNUSED
) {
return 0;
}
#endif /* COAP_SERVER_SUPPORT */
unsigned int
coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED) {
return 0;
}
#if COAP_CLIENT_SUPPORT
void *
coap_tls_new_client_session(coap_session_t *session COAP_UNUSED) {
return NULL;
}
#endif /* COAP_CLIENT_SUPPORT */
#if COAP_SERVER_SUPPORT
void *
coap_tls_new_server_session(coap_session_t *session COAP_UNUSED) {
return NULL;
}
#endif /* COAP_SERVER_SUPPORT */
void
coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED) {
}
/*
* strm
* return +ve Number of bytes written.
* -1 Error (error in errno).
*/
ssize_t
coap_tls_write(coap_session_t *session COAP_UNUSED,
const uint8_t *data COAP_UNUSED,
size_t data_len COAP_UNUSED) {
return -1;
}
/*
* strm
* return >=0 Number of bytes read.
* -1 Error (error in errno).
*/
ssize_t
coap_tls_read(coap_session_t *session COAP_UNUSED,
uint8_t *data COAP_UNUSED,
size_t data_len COAP_UNUSED) {
return -1;
}
#if COAP_SERVER_SUPPORT
typedef struct coap_local_hash_t {
size_t ofs;
coap_key_t key[8]; /* 32 bytes in total */
} coap_local_hash_t;
coap_digest_ctx_t *
coap_digest_setup(void) {
coap_key_t *digest_ctx = coap_malloc_type(COAP_DIGEST_CTX, sizeof(coap_local_hash_t));
if (digest_ctx) {
memset(digest_ctx, 0, sizeof(coap_local_hash_t));
}
return digest_ctx;
}
void
coap_digest_free(coap_digest_ctx_t *digest_ctx) {
coap_free_type(COAP_DIGEST_CTX, digest_ctx);
}
int
coap_digest_update(coap_digest_ctx_t *digest_ctx,
const uint8_t *data,
size_t data_len) {
coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
coap_hash(data, data_len, local->key[local->ofs]);
local->ofs = (local->ofs + 1) % 7;
return 1;
}
int
coap_digest_final(coap_digest_ctx_t *digest_ctx,
coap_digest_t *digest_buffer) {
coap_local_hash_t *local = (coap_local_hash_t *)digest_ctx;
memcpy(digest_buffer, local->key, sizeof(coap_digest_t));
coap_digest_free(digest_ctx);
return 1;
}
#endif /* COAP_SERVER_SUPPORT */
#if COAP_WS_SUPPORT
int
coap_crypto_hash(cose_alg_t alg,
const coap_bin_const_t *data,
coap_bin_const_t **hash) {
(void)alg;
(void)data;
(void)hash;
return 0;
}
#endif /* COAP_WS_SUPPORT */
#if COAP_OSCORE_SUPPORT
int
coap_oscore_is_supported(void) {
return 0;
}
int
coap_crypto_check_cipher_alg(cose_alg_t alg) {
(void)alg;
return 0;
}
int
coap_crypto_check_hkdf_alg(cose_hkdf_alg_t hkdf_alg) {
(void)hkdf_alg;
return 0;
}
int
coap_crypto_aead_encrypt(const coap_crypto_param_t *params,
coap_bin_const_t *data,
coap_bin_const_t *aad,
uint8_t *result,
size_t *max_result_len) {
(void)params;
(void)data;
(void)aad;
(void)result;
*max_result_len = 0;
return 0;
}
int
coap_crypto_aead_decrypt(const coap_crypto_param_t *params,
coap_bin_const_t *data,
coap_bin_const_t *aad,
uint8_t *result,
size_t *max_result_len) {
(void)params;
(void)data;
(void)aad;
(void)result;
*max_result_len = 0;
return 0;
}
int
coap_crypto_hmac(cose_hmac_alg_t hmac_alg,
coap_bin_const_t *key,
coap_bin_const_t *data,
coap_bin_const_t **hmac) {
(void)hmac_alg;
(void)key;
(void)data;
(void)hmac;
return 0;
}
#endif /* COAP_OSCORE_SUPPORT */
#else /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBGNUTLS */
#ifdef __clang__
/* Make compilers happy that do not like empty modules. As this function is
* never used, we ignore -Wunused-function at the end of compiling this file
*/
#pragma GCC diagnostic ignored "-Wunused-function"
#endif
static inline void
dummy(void) {
}
#endif /* !COAP_WITH_LIBTINYDTLS && !COAP_WITH_LIBOPENSSL && !COAP_WITH_LIBGNUTLS && !COAP_WITH_LIBMBEDTLS */
dummy
static void dummy(void)
Definition coap_gnutls.c:3246
coap_key_t
unsigned char coap_key_t[4]
Definition coap_hashkey_internal.h:24
coap_hash
#define coap_hash(String, Length, Result)
Definition coap_hashkey_internal.h:38
coap_internal.h
Pulls together all the internal only header files.
COAP_DIGEST_CTX
@ COAP_DIGEST_CTX
Definition coap_mem.h:57
coap_malloc_type
void * coap_malloc_type(coap_memory_tag_t type, size_t size)
Allocates a chunk of size bytes and returns a pointer to the newly allocated memory.
coap_free_type
void coap_free_type(coap_memory_tag_t type, void *p)
Releases the memory that was allocated by coap_malloc_type().
coap_dtls_context_set_pki
int coap_dtls_context_set_pki(coap_context_t *ctx COAP_UNUSED, const coap_dtls_pki_t *setup_data COAP_UNUSED, const coap_dtls_role_t role COAP_UNUSED)
Definition coap_notls.c:77
coap_dtls_get_timeout
coap_tick_t coap_dtls_get_timeout(coap_session_t *session COAP_UNUSED, coap_tick_t now COAP_UNUSED)
Definition coap_notls.c:193
coap_tls_read
ssize_t coap_tls_read(coap_session_t *session COAP_UNUSED, uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:265
coap_dtls_get_context_timeout
coap_tick_t coap_dtls_get_context_timeout(void *dtls_context COAP_UNUSED)
Definition coap_notls.c:188
coap_dtls_receive
int coap_dtls_receive(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:207
coap_dtls_get_tls
void * coap_dtls_get_tls(const coap_session_t *c_session COAP_UNUSED, coap_tls_library_t *tls_lib)
Definition coap_notls.c:122
coap_dtls_get_overhead
unsigned int coap_dtls_get_overhead(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:225
dtls_log_level
static coap_log_t dtls_log_level
Definition coap_notls.c:115
coap_dtls_context_check_keys_enabled
int coap_dtls_context_check_keys_enabled(coap_context_t *ctx COAP_UNUSED)
Definition coap_notls.c:111
coap_dtls_send
ssize_t coap_dtls_send(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:176
coap_tls_write
ssize_t coap_tls_write(coap_session_t *session COAP_UNUSED, const uint8_t *data COAP_UNUSED, size_t data_len COAP_UNUSED)
Definition coap_notls.c:253
coap_dtls_session_update_mtu
void coap_dtls_session_update_mtu(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:172
coap_dtls_context_set_pki_root_cas
int coap_dtls_context_set_pki_root_cas(coap_context_t *ctx COAP_UNUSED, const char *ca_file COAP_UNUSED, const char *ca_path COAP_UNUSED)
Definition coap_notls.c:85
coap_dtls_handle_timeout
int coap_dtls_handle_timeout(coap_session_t *session COAP_UNUSED)
Definition coap_notls.c:202
coap_dtls_free_context
void coap_dtls_free_context(void *handle COAP_UNUSED)
Definition coap_notls.c:150
coap_dtls_free_session
void coap_dtls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:168
coap_dtls_new_context
void * coap_dtls_new_context(coap_context_t *coap_context COAP_UNUSED)
Definition coap_notls.c:145
coap_tls_free_session
void coap_tls_free_session(coap_session_t *coap_session COAP_UNUSED)
Definition coap_notls.c:244
coap_digest_free
void coap_digest_free(coap_digest_ctx_t *digest_ctx)
Free off coap_digest_ctx_t.
coap_digest_final
int coap_digest_final(coap_digest_ctx_t *digest_ctx, coap_digest_t *digest_buffer)
Finalize the coap_digest information into the provided digest_buffer.
coap_digest_update
int coap_digest_update(coap_digest_ctx_t *digest_ctx, const uint8_t *data, size_t data_len)
Update the coap_digest information with the next chunk of data.
coap_digest_ctx_t
void coap_digest_ctx_t
Definition coap_cache_internal.h:61
coap_digest_setup
coap_digest_ctx_t * coap_digest_setup(void)
Initialize a coap_digest.
coap_tick_t
uint64_t coap_tick_t
This data type represents internal timer ticks with COAP_TICKS_PER_SECOND resolution.
Definition coap_time.h:144
coap_crypto_hmac
int coap_crypto_hmac(cose_hmac_alg_t hmac_alg, coap_bin_const_t *key, coap_bin_const_t *data, coap_bin_const_t **hmac)
Create a HMAC hash of the provided data.
coap_crypto_aead_decrypt
int coap_crypto_aead_decrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Decrypt the provided encrypted data into plaintext.
coap_crypto_aead_encrypt
int coap_crypto_aead_encrypt(const coap_crypto_param_t *params, coap_bin_const_t *data, coap_bin_const_t *aad, uint8_t *result, size_t *max_result_len)
Encrypt the provided plaintext data.
coap_crypto_hash
int coap_crypto_hash(cose_alg_t alg, const coap_bin_const_t *data, coap_bin_const_t **hash)
Create a hash of the provided data.
coap_crypto_check_hkdf_alg
int coap_crypto_check_hkdf_alg(cose_hkdf_alg_t hkdf_alg)
Check whether the defined hkdf algorithm is supported by the underlying crypto library.
coap_crypto_check_cipher_alg
int coap_crypto_check_cipher_alg(cose_alg_t alg)
Check whether the defined cipher algorithm is supported by the underlying crypto library.
coap_tls_new_server_session
void * coap_tls_new_server_session(coap_session_t *coap_session)
Create a TLS new server-side session.
coap_dtls_startup
void coap_dtls_startup(void)
Initialize the underlying (D)TLS Library layer.
Definition coap_notls.c:118
coap_dtls_new_client_session
void * coap_dtls_new_client_session(coap_session_t *coap_session)
Create a new client-side session.
coap_dtls_new_server_session
void * coap_dtls_new_server_session(coap_session_t *coap_session)
Create a new DTLS server-side session.
coap_dtls_hello
int coap_dtls_hello(coap_session_t *coap_session, const uint8_t *data, size_t data_len)
Handling client HELLO messages from a new candiate peer.
coap_dtls_is_context_timeout
int coap_dtls_is_context_timeout(void)
Check if timeout is handled per CoAP session or per CoAP context.
Definition coap_notls.c:183
coap_dtls_context_set_cpsk
int coap_dtls_context_set_cpsk(coap_context_t *coap_context, coap_dtls_cpsk_t *setup_data)
Set the DTLS context's default client PSK information.
coap_dtls_context_set_spsk
int coap_dtls_context_set_spsk(coap_context_t *coap_context, coap_dtls_spsk_t *setup_data)
Set the DTLS context's default server PSK information.
coap_dtls_shutdown
void coap_dtls_shutdown(void)
Close down the underlying (D)TLS Library layer.
Definition coap_notls.c:130
coap_tls_new_client_session
void * coap_tls_new_client_session(coap_session_t *coap_session)
Create a new TLS client-side session.
coap_get_tls_library_version
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
coap_dtls_psk_is_supported
int coap_dtls_psk_is_supported(void)
Check whether (D)TLS PSK is available.
Definition coap_notls.c:37
coap_dtls_role_t
coap_dtls_role_t
Definition coap_dtls.h:43
coap_tls_is_supported
int coap_tls_is_supported(void)
Check whether TLS is available.
Definition coap_notls.c:28
coap_dtls_is_supported
int coap_dtls_is_supported(void)
Check whether DTLS is available.
Definition coap_notls.c:23
coap_dtls_pki_is_supported
int coap_dtls_pki_is_supported(void)
Check whether (D)TLS PKI is available.
Definition coap_notls.c:46
coap_dtls_rpk_is_supported
int coap_dtls_rpk_is_supported(void)
Check whether (D)TLS RPK is available.
Definition coap_notls.c:64
coap_tls_library_t
coap_tls_library_t
Definition coap_dtls.h:92
coap_dtls_pkcs11_is_supported
int coap_dtls_pkcs11_is_supported(void)
Check whether (D)TLS PKCS11 is available.
Definition coap_notls.c:55
COAP_TLS_LIBRARY_NOTLS
@ COAP_TLS_LIBRARY_NOTLS
No DTLS library.
Definition coap_dtls.h:93
coap_log_t
coap_log_t
Logging type.
Definition coap_debug.h:50
coap_dtls_get_log_level
coap_log_t coap_dtls_get_log_level(void)
Get the current (D)TLS logging.
Definition coap_notls.c:140
coap_dtls_set_log_level
void coap_dtls_set_log_level(coap_log_t level)
Sets the (D)TLS logging level to the specified level.
Definition coap_notls.c:135
COAP_LOG_EMERG
@ COAP_LOG_EMERG
Definition coap_debug.h:51
cose_hkdf_alg_t
cose_hkdf_alg_t
Definition oscore_cose.h:165
cose_hmac_alg_t
cose_hmac_alg_t
Definition oscore_cose.h:157
cose_alg_t
cose_alg_t
Definition oscore_cose.h:126
coap_oscore_is_supported
int coap_oscore_is_supported(void)
Check whether OSCORE is available.
Definition coap_oscore.c:2104
COAP_UNUSED
#define COAP_UNUSED
Definition libcoap.h:68
coap_bin_const_t
CoAP binary data definition with const data.
Definition coap_str.h:64
coap_context_t
The CoAP stack's global state is stored in a coap_context_t object.
Definition coap_net_internal.h:49
coap_crypto_param_t
The common structure that holds the Crypto information.
Definition coap_crypto_internal.h:59
coap_digest_t
Definition coap_cache_internal.h:33
coap_dtls_cpsk_t
The structure used for defining the Client PSK setup data to be used.
Definition coap_dtls.h:378
coap_dtls_pki_t
The structure used for defining the PKI setup data to be used.
Definition coap_dtls.h:284
coap_dtls_spsk_t
The structure used for defining the Server PSK setup data to be used.
Definition coap_dtls.h:465
coap_session_t
Abstraction of virtual session that can be attached to coap_context_t (client) or coap_endpoint_t (se...
Definition coap_session_internal.h:68
coap_tls_version_t
The structure used for returning the underlying (D)TLS library information.
Definition coap_dtls.h:104
coap_tls_version_t::type
coap_tls_library_t type
Library type.
Definition coap_dtls.h:106
coap_tls_version_t::version
uint64_t version
(D)TLS runtime Library Version
Definition coap_dtls.h:105