struct nhrp_extension_header *ext;
struct zbuf *extensions, pl;
int cmp = 1;
+ int pl_pass_length, auth_pass_length;
+ size_t auth_size, pl_size;
extensions = zbuf_alloc(zbuf_used(&pp->extensions));
zbuf_copy_peek(extensions, &pp->extensions, zbuf_used(&pp->extensions));
while ((ext = nhrp_ext_pull(extensions, &pl)) != NULL) {
switch (htons(ext->type) & ~NHRP_EXTENSION_FLAG_COMPULSORY) {
case NHRP_EXTENSION_AUTHENTICATION:
- cmp = memcmp(auth->buf, pl.buf, zbuf_size(auth));
+ /* Size of authentication extensions
+ * (varies based on password length)
+ */
+ auth_size = zbuf_size(auth);
+ pl_size = zbuf_size(&pl);
auth_ext = (struct nhrp_cisco_authentication_extension *)
auth->buf;
- debugf(NHRP_DEBUG_COMMON,
- "Processing Authentication Extension for (%s:%s|%d)",
- auth_ext->secret,
- ((struct nhrp_cisco_authentication_extension *)
- pl.buf)
- ->secret,
- cmp);
+
+ if (auth_size == pl_size)
+ cmp = memcmp(auth_ext, pl.buf, auth_size);
+ else
+ cmp = 1;
+
+ if (unlikely(debug_flags & NHRP_DEBUG_COMMON)) {
+ /* 4 bytes in nhrp_cisco_authentication_extension are allocated
+ * toward the authentication type. The remaining bytes are used for the
+ * password - so the password length is just the length of the extension - 4
+ */
+ auth_pass_length = (auth_size - 4);
+ pl_pass_length = (pl_size - 4);
+ /* Because characters are to be printed in HEX, (2* the max pass length) + 1
+ * is needed for the string representation
+ */
+ char auth_pass[(2 * NHRP_CISCO_PASS_LEN) + 1] = { 0 },
+ pl_pass[(2 * NHRP_CISCO_PASS_LEN) + 1] = { 0 };
+ /* Converting bytes in buffer to HEX and saving output as a string -
+ * Passphrase is converted to HEX in order to avoid printing
+ * non ACII-compliant characters
+ */
+ for (int i = 0; i < (auth_pass_length); i++)
+ snprintf(auth_pass + (i * 2), 3, "%02X",
+ auth_ext->secret[i]);
+ for (int i = 0; i < (pl_pass_length); i++)
+ snprintf(pl_pass + (i * 2), 3, "%02X",
+ ((struct nhrp_cisco_authentication_extension *)pl.buf)
+ ->secret[i]);
+
+ debugf(NHRP_DEBUG_COMMON,
+ "Processing Authentication Extension for (%s:%s|%d)",
+ auth_pass, pl_pass, cmp);
+ }
break;
default:
/* Ignoring all received extensions except Authentication*/