Commit 21429fdf authored by Killian Lufau's avatar Killian Lufau

New ignore_no_hmac option for HMAC

The possibility to accept packets without HMAC on interfaces
configured for HMAC is added to do non-blocking steps when
initializing HMAC on a network.
TODO: push upstream
parent 42b1604b
...@@ -1227,6 +1227,8 @@ parse_config_line(int c, gnc_t gnc, void *closure, ...@@ -1227,6 +1227,8 @@ parse_config_line(int c, gnc_t gnc, void *closure,
} }
add_key(key->id, key->type, key->len, key->value); add_key(key->id, key->type, key->len, key->value);
free(key); free(key);
} else if(strcmp(token, "ignore_no_hmac") == 0) {
ignore_no_hmac = 1;
} else { } else {
c = parse_option(c, gnc, closure, token); c = parse_option(c, gnc, closure, token);
if(c < -1) if(c < -1)
......
...@@ -39,6 +39,7 @@ THE SOFTWARE. ...@@ -39,6 +39,7 @@ THE SOFTWARE.
struct key **keys = NULL; struct key **keys = NULL;
int numkeys = 0, maxkeys = 0; int numkeys = 0, maxkeys = 0;
int ignore_no_hmac = 0;
struct key * struct key *
find_key(const char *id) find_key(const char *id)
...@@ -276,6 +277,7 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen, ...@@ -276,6 +277,7 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
{ {
int i = bodylen + 4; int i = bodylen + 4;
int len; int len;
int rc = ignore_no_hmac ? 2 : 0;
debugf("check_hmac %s -> %s\n", debugf("check_hmac %s -> %s\n",
format_address(src), format_address(dst)); format_address(src), format_address(dst));
...@@ -294,8 +296,9 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen, ...@@ -294,8 +296,9 @@ check_hmac(const unsigned char *packet, int packetlen, int bodylen,
packet + i + 2 , len) == 1) { packet + i + 2 , len) == 1) {
return 1; return 1;
} }
rc = 0;
} }
i += len + 2; i += len + 2;
} }
return 0; return rc;
} }
...@@ -28,6 +28,7 @@ struct key *find_key(const char *id); ...@@ -28,6 +28,7 @@ struct key *find_key(const char *id);
struct key *retain_key(struct key *key); struct key *retain_key(struct key *key);
void release_key(struct key *key); void release_key(struct key *key);
struct key *add_key(char *id, int type, int len, unsigned char *value); struct key *add_key(char *id, int type, int len, unsigned char *value);
extern int ignore_no_hmac;
int add_hmac(struct buffered *buf, struct interface *ifp, int add_hmac(struct buffered *buf, struct interface *ifp,
unsigned char *packet_header); unsigned char *packet_header);
int check_hmac(const unsigned char *packet, int packetlen, int bodylen, int check_hmac(const unsigned char *packet, int packetlen, int bodylen,
......
...@@ -575,15 +575,18 @@ parse_packet(const unsigned char *from, struct interface *ifp, ...@@ -575,15 +575,18 @@ parse_packet(const unsigned char *from, struct interface *ifp,
} }
if(ifp->key != NULL) { if(ifp->key != NULL) {
if(check_hmac(packet, packetlen, bodylen, neigh->address, switch(check_hmac(packet, packetlen, bodylen, neigh->address, to)) {
to) != 1) { case 0:
fprintf(stderr, "Received wrong hmac.\n"); fprintf(stderr, "Received wrong hmac.\n");
return; return;
} case 1:
if(preparse_packet(packet, bodylen, neigh, ifp) == 0) {
if(preparse_packet(packet, bodylen, neigh, ifp) == 0) { fprintf(stderr, "Received wrong PC or failed the challenge.\n");
fprintf(stderr, "Received wrong PC or failed the challenge.\n"); return;
return; }
break;
case 2: /* missing key ignored */
;
} }
} }
......
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