Skip to content

Conversation

ubruhin
Copy link
Contributor

@ubruhin ubruhin commented Jul 20, 2024

Hi,

In the AuthKey raw-to-hex conversion loop, the loop variable was incremented by 2 (i += 2) which skipped every second byte in auth_key_factory. In addition, the snprintf(auth_key_hex + 2 * i, ...) wrote to index 4 in the second loop execution, while the first loop execution wrote a \0 to index 2, thus the variable auth_key_hex always contained only 2 characters (plus zero-termination). So in the end, only the first byte of auth_key_factory was stored, the rest was completely lost.

I found this because the authentication didn't work for me. Changing i += 2 to i++ fixed the problem. The same problem existed in setAuthKey(). Note that there was already a place where the conversion was correct:

#if MO_DBG_LEVEL >= MO_DL_DEBUG
{
char auth_key_hex [2 * MO_AUTHKEY_LEN_MAX + 1];
auth_key_hex[0] = '\0';
for (size_t i = 0; i < auth_key_len; i++) {
snprintf(auth_key_hex + 2 * i, 3, "%02X", auth_key[i]);
}
MO_DBG_DEBUG("auth Token=%s:%s (key will be converted to non-hex)", cb_id.c_str(), auth_key_hex);
}
#endif //MO_DBG_LEVEL >= MO_DL_DEBUG

Just let me know if I need to adjust anything.

@matth-x matth-x merged commit b29f582 into matth-x:main Jul 23, 2024
@matth-x
Copy link
Owner

matth-x commented Jul 23, 2024

Hi @ubruhin, thank you very much for this contribution and the great explanation!

@ubruhin ubruhin deleted the fix-auth-key-conversion branch July 23, 2024 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants