diff --git a/plugins/mqtt/mqtt_util.c b/plugins/mqtt/mqtt_util.c index cf9ceb04..165eb997 100644 --- a/plugins/mqtt/mqtt_util.c +++ b/plugins/mqtt/mqtt_util.c @@ -30,30 +30,11 @@ #include "mqtt_plugin.h" #include "mqtt_util.h" -int uuid_v4(char *buffer) +int client_id_generate(char *buff) { - union { - struct { - uint32_t time_low; - uint16_t time_mid; - uint16_t time_hi_and_version; - uint8_t clk_seq_hi_res; - uint8_t clk_seq_low; - uint8_t node[6]; - }; - uint8_t __rnd[16]; - } uuid; - - int rc = RAND_bytes(uuid.__rnd, sizeof(uuid)); - uuid.clk_seq_hi_res = (uint8_t)((uuid.clk_seq_hi_res & 0x3F) | 0x80); - uuid.time_hi_and_version = - (uint16_t)((uuid.time_hi_and_version & 0x0FFF) | 0x4000); - - snprintf(buffer, 38, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid.time_low, uuid.time_mid, uuid.time_hi_and_version, - uuid.clk_seq_hi_res, uuid.clk_seq_low, uuid.node[0], uuid.node[1], - uuid.node[2], uuid.node[3], uuid.node[4], uuid.node[5]); - + unsigned char nonce[4] = { 0 }; + int rc = RAND_bytes(nonce, sizeof(nonce)); + snprintf(buff, 15, "%s%08x", "neuron", *((uint32_t *) nonce)); return rc; } @@ -147,8 +128,8 @@ int mqtt_option_init(neu_plugin_t *plugin, char *config, neu_json_elem_t keypass = { .name = "keypass", .t = NEU_JSON_STR }; // client-id, required - char uuid[38] = { 0 }; - int rc = uuid_v4(uuid); + char uuid[15] = { 0 }; + int rc = client_id_generate(uuid); if (1 != rc) { return 2; }