From 4a543d1198b7858ada50a97c4e2234a807b5e13f Mon Sep 17 00:00:00 2001 From: Jon Shallow Date: Sat, 24 Nov 2018 21:07:58 +0000 Subject: [PATCH] Extend coap_tls_version_t to include both built and runtime TLS versions This allows an application to determine what the built version is as well as what the runtime version of a TLS library is. include/coap2/coap_dtls.h Add built_version to coap_tls_version_t src/coap_openssl.c src/coap_tinydtls.c Additionally populate coap_tls_version_t with build_version when coap_get_tls_library_version() is called. src/coap_tinydtls.c Correct the version returned as actual TinyDTLS version instead the binary value of a DTLS packet type. --- include/coap2/coap_dtls.h | 3 ++- src/coap_openssl.c | 1 + src/coap_tinydtls.c | 18 +++++++++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/include/coap2/coap_dtls.h b/include/coap2/coap_dtls.h index 1c1a10ed..2f61e032 100644 --- a/include/coap2/coap_dtls.h +++ b/include/coap2/coap_dtls.h @@ -45,8 +45,9 @@ int coap_tls_is_supported(void); * information. */ typedef struct coap_tls_version_t { - uint64_t version; /**< (D)TLS Library Version */ + uint64_t version; /**< (D)TLS runtime Library Version */ int type; /**< Library type. One of COAP_TLS_LIBRARY_* */ + uint64_t built_version; /**< (D)TLS Built against Library Version */ } coap_tls_version_t; /** diff --git a/src/coap_openssl.c b/src/coap_openssl.c index cf301281..0547a233 100644 --- a/src/coap_openssl.c +++ b/src/coap_openssl.c @@ -142,6 +142,7 @@ coap_tls_version_t * coap_get_tls_library_version(void) { static coap_tls_version_t version; version.version = SSLeay(); + version.built_version = OPENSSL_VERSION_NUMBER; version.type = COAP_TLS_LIBRARY_OPENSSL; return &version; } diff --git a/src/coap_tinydtls.c b/src/coap_tinydtls.c index 55947e8d..2ec5351a 100644 --- a/src/coap_tinydtls.c +++ b/src/coap_tinydtls.c @@ -453,7 +453,23 @@ int coap_tls_is_supported(void) { coap_tls_version_t * coap_get_tls_library_version(void) { static coap_tls_version_t version; - version.version = DTLS_VERSION; + const char *vers = dtls_package_version(); + + version.version = 0; + if (vers) { + long int p1, p2 = 0, p3 = 0; + char* endptr; + + p1 = strtol(vers, &endptr, 10); + if (*endptr == '.') { + p2 = strtol(endptr+1, &endptr, 10); + if (*endptr == '.') { + p3 = strtol(endptr+1, &endptr, 10); + } + } + version.version = (p1 << 16) | (p2 << 8) | p3; + } + version.built_version = version.version; version.type = COAP_TLS_LIBRARY_TINYDTLS; return &version; }