From e1fa280d887e3ccc357239f6d4e1cf20ba9c5375 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 18:34:42 +0000 Subject: [PATCH 1/5] coap_dtls.h: Add in TLS library determination support A new function coap_get_tls_library_version() that returns a pointer to a coap_tls_version_t structure that contains both the TLS library type libcoap was compiled against as well as the current TLS library version. --- include/coap/coap_dtls.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/include/coap/coap_dtls.h b/include/coap/coap_dtls.h index 3e640eff..e6235a8a 100644 --- a/include/coap/coap_dtls.h +++ b/include/coap/coap_dtls.h @@ -27,6 +27,21 @@ int coap_dtls_is_supported(void); /** Returns 1 if support for TLS is enabled, or 0 otherwise. */ int coap_tls_is_supported( void ); +#define COAP_TLS_LIBRARY_NOTLS 0 +#define COAP_TLS_LIBRARY_TINYDTLS 1 +#define COAP_TLS_LIBRARY_OPENSSL 2 +#define COAP_TLS_LIBRARY_GNUTLS 3 + +typedef struct coap_tls_version_t { + uint64_t version; /* Library Version */ + int type; /* One of COAP_TLS_LIBRARY_* */ +} coap_tls_version_t; + +/** + * Returns the version and type of library libcoap was compiled against + */ +coap_tls_version_t *coap_get_tls_library_version(void); + /** Sets the log level to the specified value. */ void coap_dtls_set_log_level(int level); From 7d14b745c9e355f61ae4c8a5cb41c7f1301cd838 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 19:35:28 +0000 Subject: [PATCH 2/5] coap_notls.c: Add in coap_get_tls_library_version() function Add in coap_get_tls_library_version() for determining TLS build base + version --- src/coap_notls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coap_notls.c b/src/coap_notls.c index 41d810fa..fb06c8a8 100644 --- a/src/coap_notls.c +++ b/src/coap_notls.c @@ -29,6 +29,14 @@ coap_tls_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; +} + static int dtls_log_level = 0; void coap_dtls_startup(void) { From 30794440af5fbccb39d55d445a971b63b55333b6 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 19:38:08 +0000 Subject: [PATCH 3/5] coap_tinydtls.c: Add in coap_get_tls_library_version() function Add in coap_get_tls_library_version() for determining TLS build base + version --- src/coap_tinydtls.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/coap_tinydtls.c b/src/coap_tinydtls.c index 825f68e4..07064a4c 100644 --- a/src/coap_tinydtls.c +++ b/src/coap_tinydtls.c @@ -444,6 +444,14 @@ int coap_tls_is_supported(void) { return 0; } +coap_tls_version_t * +coap_get_tls_library_version(void) { + static coap_tls_version_t version; + version.version = DTLS_VERSION; + version.type = COAP_TLS_LIBRARY_TINYDTLS; + return &version; +} + void *coap_tls_new_client_session(coap_session_t *session UNUSED, int *connected UNUSED) { return NULL; } From 47205bd56cab0caffe465e4f6f1f019766fdafe8 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 10 Feb 2018 19:39:27 +0000 Subject: [PATCH 4/5] coap_openssl.c: Add in coap_get_tls_library_version() function Add in coap_get_tls_library_version() for determining TLS build base + version Do not allow a dynamic openssl library to be loaded and used at application runtime that is less than OpenSSL version 1.1.0. --- src/coap_openssl.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/coap_openssl.c b/src/coap_openssl.c index 998ac7c1..178de60b 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -40,13 +40,29 @@ typedef struct coap_openssl_context_t { } coap_openssl_context_t; int coap_dtls_is_supported(void) { + if (SSLeay() < 0x10100000L) { + coap_log(LOG_WARNING, "OpenSSL version 1.1.0 or later is required\n"); + return 0; + } return 1; } int coap_tls_is_supported(void) { + if (SSLeay() < 0x10100000L) { + coap_log(LOG_WARNING, "OpenSSL version 1.1.0 or later is required\n"); + return 0; + } return 1; } +coap_tls_version_t * +coap_get_tls_library_version(void) { + static coap_tls_version_t version; + version.version = SSLeay(); + version.type = COAP_TLS_LIBRARY_OPENSSL; + return &version; +} + void coap_dtls_startup(void) { SSL_load_error_strings(); SSL_library_init(); From c4729fa80126ce0e9d662a519efe7dc11228c7c5 Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Wed, 14 Feb 2018 09:55:53 +0000 Subject: [PATCH 5/5] libcoap-1.map, libcoap-1.sym: Expose coap_get_tls_library_version() --- libcoap-1.map | 1 + libcoap-1.sym | 1 + 2 files changed, 2 insertions(+) diff --git a/libcoap-1.map b/libcoap-1.map index 18eee976..9e4f6617 100644 --- a/libcoap-1.map +++ b/libcoap-1.map @@ -73,6 +73,7 @@ global: coap_get_log_level; coap_get_query; coap_get_resource_from_key; + coap_get_tls_library_version; coap_handle_dgram; coap_handle_event; coap_handle_failed_notify; diff --git a/libcoap-1.sym b/libcoap-1.sym index 1ad76f30..fb8aafcd 100644 --- a/libcoap-1.sym +++ b/libcoap-1.sym @@ -71,6 +71,7 @@ coap_get_data coap_get_log_level coap_get_query coap_get_resource_from_key +coap_get_tls_library_version coap_handle_dgram coap_handle_event coap_handle_failed_notify