mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-12 19:40:39 +03:00
New coap_show_tls_version() and coap_string_tls_version() functions
These new functions can be used to either update a buffer with, or coap_log() out the current runtime TLS library along with the version of the library that libcoap was built against. include/coap2/debug.h src/debug.c libcoap-2.map libcoap-2.sym Support for the new functions coap_show_tls_version() and coap_string_tls_version().
This commit is contained in:
1 parent
8a3b46eee4
commit
d8b399cfc9
4 files changed
+110
No files matched your search
@@ -145,6 +145,24 @@ void coap_set_show_pdu_output(int use_fprintf);
|
||||
*/
|
||||
void coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu);
|
||||
|
||||
/**
|
||||
* Display the current (D)TLS library linked with and built for version.
|
||||
*
|
||||
* @param level The required minimum logging level.
|
||||
*/
|
||||
void coap_show_tls_version(coap_log_t level);
|
||||
|
||||
/**
|
||||
* Build a string containing the current (D)TLS library linked with and
|
||||
* built for version.
|
||||
*
|
||||
* @param buffer The buffer to put the string into.
|
||||
* @param bufsize The size of the buffer to put the string into.
|
||||
*
|
||||
* @return A pointer to the provided buffer.
|
||||
*/
|
||||
char *coap_string_tls_version(char *buffer, size_t bufsize);
|
||||
|
||||
struct coap_address_t;
|
||||
|
||||
/**
|
||||
|
||||
@@ -173,11 +173,13 @@ global:
|
||||
coap_set_log_level;
|
||||
coap_set_show_pdu_output;
|
||||
coap_show_pdu;
|
||||
coap_show_tls_version;
|
||||
coap_socket_strerror;
|
||||
coap_split_path;
|
||||
coap_split_query;
|
||||
coap_split_uri;
|
||||
coap_startup;
|
||||
coap_string_tls_version;
|
||||
coap_subscription_init;
|
||||
coap_ticks;
|
||||
coap_ticks_from_rt_us;
|
||||
|
||||
@@ -171,11 +171,13 @@ coap_set_log_handler
|
||||
coap_set_log_level
|
||||
coap_set_show_pdu_output
|
||||
coap_show_pdu
|
||||
coap_show_tls_version
|
||||
coap_socket_strerror
|
||||
coap_split_path
|
||||
coap_split_query
|
||||
coap_split_uri
|
||||
coap_startup
|
||||
coap_string_tls_version
|
||||
coap_subscription_init
|
||||
coap_ticks
|
||||
coap_ticks_from_rt_us
|
||||
|
||||
+88
@@ -648,6 +648,94 @@ coap_show_pdu(coap_log_t level, const coap_pdu_t *pdu) {
|
||||
COAP_DO_SHOW_OUTPUT_LINE;
|
||||
}
|
||||
|
||||
void coap_show_tls_version(coap_log_t level)
|
||||
{
|
||||
char buffer[64];
|
||||
coap_string_tls_version(buffer, sizeof(buffer));
|
||||
coap_log(level, "%s\n", buffer);
|
||||
}
|
||||
|
||||
char *coap_string_tls_version(char *buffer, size_t bufsize)
|
||||
{
|
||||
coap_tls_version_t *tls_version = coap_get_tls_library_version();
|
||||
char beta[8];
|
||||
char sub[2];
|
||||
char b_beta[8];
|
||||
char b_sub[2];
|
||||
|
||||
switch (tls_version->type) {
|
||||
case COAP_TLS_LIBRARY_NOTLS:
|
||||
snprintf(buffer, bufsize, "TLS Library: None");
|
||||
break;
|
||||
case COAP_TLS_LIBRARY_TINYDTLS:
|
||||
snprintf(buffer, bufsize, "TLS Library: TinyDTLS - runtime %ld.%ld.%ld, "
|
||||
"libcoap built for %ld.%ld.%ld",
|
||||
tls_version->version >> 16,
|
||||
(tls_version->version >> 8) & 0xff,
|
||||
tls_version->version & 0xff,
|
||||
tls_version->built_version >> 16,
|
||||
(tls_version->built_version >> 8) & 0xff,
|
||||
tls_version->built_version & 0xff);
|
||||
break;
|
||||
case COAP_TLS_LIBRARY_OPENSSL:
|
||||
switch (tls_version->version &0xf) {
|
||||
case 0:
|
||||
strcpy(beta, "-dev");
|
||||
break;
|
||||
case 0xf:
|
||||
strcpy(beta, "");
|
||||
break;
|
||||
default:
|
||||
strcpy(beta, "-beta");
|
||||
beta[5] = (tls_version->version &0xf) + '0';
|
||||
beta[6] = '\000';
|
||||
break;
|
||||
}
|
||||
sub[0] = ((tls_version->version >> 4) & 0xff) ?
|
||||
((tls_version->version >> 4) & 0xff) + 'a' -1 : '\000';
|
||||
sub[1] = '\000';
|
||||
switch (tls_version->built_version &0xf) {
|
||||
case 0:
|
||||
strcpy(b_beta, "-dev");
|
||||
break;
|
||||
case 0xf:
|
||||
strcpy(b_beta, "");
|
||||
break;
|
||||
default:
|
||||
strcpy(b_beta, "-beta");
|
||||
b_beta[5] = (tls_version->built_version &0xf) + '0';
|
||||
b_beta[6] = '\000';
|
||||
break;
|
||||
}
|
||||
b_sub[0] = ((tls_version->built_version >> 4) & 0xff) ?
|
||||
((tls_version->built_version >> 4) & 0xff) + 'a' -1 : '\000';
|
||||
b_sub[1] = '\000';
|
||||
snprintf(buffer, bufsize, "TLS Library: OpenSSL - runtime "
|
||||
"%ld.%ld.%ld%s%s, libcoap built for %ld.%ld.%ld%s%s",
|
||||
tls_version->version >> 28,
|
||||
(tls_version->version >> 20) & 0xff,
|
||||
(tls_version->version >> 12) & 0xff, sub, beta,
|
||||
tls_version->built_version >> 28,
|
||||
(tls_version->built_version >> 20) & 0xff,
|
||||
(tls_version->built_version >> 12) & 0xff, b_sub, b_beta);
|
||||
break;
|
||||
case COAP_TLS_LIBRARY_GNUTLS:
|
||||
snprintf(buffer, bufsize, "TLS Library: GnuTLS - runtime %ld.%ld.%ld, "
|
||||
"libcoap built for %ld.%ld.%ld",
|
||||
tls_version->version >> 16,
|
||||
(tls_version->version >> 8) & 0xff,
|
||||
tls_version->version & 0xff,
|
||||
tls_version->built_version >> 16,
|
||||
(tls_version->built_version >> 8) & 0xff,
|
||||
tls_version->built_version & 0xff);
|
||||
break;
|
||||
default:
|
||||
snprintf(buffer, bufsize, "Library type %d unknown", tls_version->type);
|
||||
break;
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
||||
static coap_log_handler_t log_handler = NULL;
|
||||
|
||||
void coap_set_log_handler(coap_log_handler_t handler) {
|
||||
|
||||
Reference in new issue
Block a user