Commit 1b9abc4b authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Replace hmac-verify with accept-bad-signatures.

Its polarity is changed, and it also controls incorrectly signed packets.
parent 3777eb4a
...@@ -469,10 +469,9 @@ otherwise. ...@@ -469,10 +469,9 @@ otherwise.
Enable HMAC security on this interface, and use the key Enable HMAC security on this interface, and use the key
.IR id . .IR id .
.TP .TP
.BR hmac-verify " {" true | false } .BR accept\-bad\-signatures " {" true | false }
Check packet signatures, reject unsigned or incorrectly signed Accept packets with no signature or an incorrect signature. This only has
packets. The default is an effect if a key was configured on an interface. The default is false.
.BR true .
.TP .TP
.SS Filtering rules .SS Filtering rules
A filtering rule is defined by a single line with the following format: A filtering rule is defined by a single line with the following format:
......
...@@ -694,12 +694,12 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure, ...@@ -694,12 +694,12 @@ parse_anonymous_ifconf(int c, gnc_t gnc, void *closure,
} }
if_conf->key = key; if_conf->key = key;
free(key_id); free(key_id);
} else if(strcmp(token, "hmac-verify") == 0) { } else if(strcmp(token, "accept-bad-signatures") == 0) {
int v; int v;
c = getbool(c, &v, gnc, closure); c = getbool(c, &v, gnc, closure);
if(c < -1) if(c < -1)
goto error; goto error;
if_conf->hmac_verify = v; if_conf->accept_bad_signatures = v;
} else { } else {
goto error; goto error;
} }
...@@ -891,7 +891,7 @@ merge_ifconf(struct interface_conf *dest, ...@@ -891,7 +891,7 @@ merge_ifconf(struct interface_conf *dest,
MERGE(lq); MERGE(lq);
MERGE(faraway); MERGE(faraway);
MERGE(unicast); MERGE(unicast);
MERGE(hmac_verify); MERGE(accept_bad_signatures);
MERGE(channel); MERGE(channel);
MERGE(enable_timestamps); MERGE(enable_timestamps);
MERGE(rfc6126); MERGE(rfc6126);
......
...@@ -398,11 +398,10 @@ interface_updown(struct interface *ifp, int up) ...@@ -398,11 +398,10 @@ interface_updown(struct interface *ifp, int up)
if(IF_CONF(ifp, unicast) == CONFIG_YES) if(IF_CONF(ifp, unicast) == CONFIG_YES)
ifp->flags |= IF_UNICAST; ifp->flags |= IF_UNICAST;
if(IF_CONF(ifp, hmac_verify) == CONFIG_YES || if(IF_CONF(ifp, accept_bad_signatures) == CONFIG_YES)
IF_CONF(ifp, hmac_verify) == CONFIG_DEFAULT) ifp->flags |= IF_ACCEPT_BAD_SIGNATURES;
ifp->flags |= IF_HMAC_VERIFY; else
else if(IF_CONF(ifp, hmac_verify) == CONFIG_NO) ifp->flags &= ~IF_ACCEPT_BAD_SIGNATURES;
ifp->flags &= ~IF_HMAC_VERIFY;
if(IF_CONF(ifp, hello_interval) > 0) if(IF_CONF(ifp, hello_interval) > 0)
ifp->hello_interval = IF_CONF(ifp, hello_interval); ifp->hello_interval = IF_CONF(ifp, hello_interval);
else if(type == IF_TYPE_WIRELESS) else if(type == IF_TYPE_WIRELESS)
......
...@@ -55,7 +55,7 @@ struct interface_conf { ...@@ -55,7 +55,7 @@ struct interface_conf {
char unicast; char unicast;
char enable_timestamps; char enable_timestamps;
char rfc6126; char rfc6126;
char hmac_verify; char accept_bad_signatures;
int channel; int channel;
unsigned int rtt_decay; unsigned int rtt_decay;
unsigned int rtt_min; unsigned int rtt_min;
...@@ -85,8 +85,8 @@ struct interface_conf { ...@@ -85,8 +85,8 @@ struct interface_conf {
#define IF_TIMESTAMPS (1 << 6) #define IF_TIMESTAMPS (1 << 6)
/* Remain compatible with RFC 6126. */ /* Remain compatible with RFC 6126. */
#define IF_RFC6126 (1 << 7) #define IF_RFC6126 (1 << 7)
/* Incoming packets are required to have a valid MAC hash. */ /* Accept packets even if incorrectly signed. */
#define IF_HMAC_VERIFY (1 << 8) #define IF_ACCEPT_BAD_SIGNATURES (1 << 8)
/* Use Babel over DTLS on this interface. */ /* Use Babel over DTLS on this interface. */
#define IF_DTLS (1 << 9) #define IF_DTLS (1 << 9)
......
...@@ -631,26 +631,27 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -631,26 +631,27 @@ parse_packet(const unsigned char *from, struct interface *ifp,
} }
if(ifp->key != NULL) { if(ifp->key != NULL) {
switch(check_hmac(packet, packetlen, bodylen, from, to, ifp)) { int rc = check_hmac(packet, packetlen, bodylen, from, to, ifp);
case -1: /* no mac trailer */ if(rc <= 0) {
if(!(ifp->flags & IF_HMAC_VERIFY)) if(rc < 0)
break; debugf("Received unsigned packet.\n");
/* fallthrough */ else
case 0: debugf("Received packet with bad signature.\n");
fputs("Received wrong hmac.\n", stderr); if(!(ifp->flags & IF_ACCEPT_BAD_SIGNATURES))
return; return;
case 1: } else {
neigh = preparse_packet(from, ifp, packet, bodylen, to); neigh = preparse_packet(from, ifp, packet, bodylen, to);
if(neigh == NULL) { if(neigh == NULL) {
fputs("Received wrong PC or failed the challenge.\n", stderr); debugf("Received packet with wrong PC.\n");
return; return;
} }
} }
} }
neigh = neigh != NULL ? neigh : find_neighbour(from, ifp); if(neigh == NULL)
neigh = find_neighbour(from, ifp);
if(neigh == NULL) { if(neigh == NULL) {
fputs("Couldn't allocate neighbour.\n", stderr); fprintf(stderr, "Couldn't allocate neighbour.\n");
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment