From e001e8c056deecfdd295638262a9d61ca9995e23 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 21 Apr 2014 22:31:55 +0100 Subject: [PATCH] site: Remove clone-and-hack of signature verification process_msg3 and process_msg4 shared some signature checking etc. code. Move it into a common function. No functional change other than to error messages. Signed-off-by: Ian Jackson --- site.c | 52 ++++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/site.c b/site.c index 00a3a4c..e6c34c8 100644 --- a/site.c +++ b/site.c @@ -703,12 +703,32 @@ static bool_t generate_msg3(struct site *st) "site:MSG3"); } +static bool_t process_msg3_msg4(struct site *st, struct msg *m) +{ + uint8_t *hash; + void *hst; + + /* Check signature and store g^x mod m */ + hash=safe_malloc(st->hash->len, "process_msg3_msg4"); + hst=st->hash->init(); + st->hash->update(hst,m->hashstart,m->hashlen); + st->hash->final(hst,hash); + /* Terminate signature with a '0' - cheating, but should be ok */ + m->sig[m->siglen]=0; + if (!st->pubkey->check(st->pubkey->st,hash,st->hash->len,m->sig)) { + slog(st,LOG_SEC,"msg3/msg4 signature failed check!"); + free(hash); + return False; + } + free(hash); + + return True; +} + static bool_t process_msg3(struct site *st, struct buffer_if *msg3, const struct comm_addr *src, uint32_t msgtype) { struct msg m; - uint8_t *hash; - void *hst; cstring_t err; assert(msgtype==LABEL_MSG3 || msgtype==LABEL_MSG3BIS); @@ -741,19 +761,8 @@ static bool_t process_msg3(struct site *st, struct buffer_if *msg3, transform_found: st->chosen_transform=ti; - /* Check signature and store g^x mod m */ - hash=safe_malloc(st->hash->len, "process_msg3"); - hst=st->hash->init(); - st->hash->update(hst,m.hashstart,m.hashlen); - st->hash->final(hst,hash); - /* Terminate signature with a '0' - cheating, but should be ok */ - m.sig[m.siglen]=0; - if (!st->pubkey->check(st->pubkey->st,hash,st->hash->len,m.sig)) { - slog(st,LOG_SEC,"msg3 signature failed check!"); - free(hash); + if (!process_msg3_msg4(st,&m)) return False; - } - free(hash); /* Terminate their DH public key with a '0' */ m.pk[m.pklen]=0; @@ -777,8 +786,6 @@ static bool_t process_msg4(struct site *st, struct buffer_if *msg4, const struct comm_addr *src) { struct msg m; - uint8_t *hash; - void *hst; cstring_t err; if (!unpick_msg(st,LABEL_MSG4,msg4,&m)) return False; @@ -787,19 +794,8 @@ static bool_t process_msg4(struct site *st, struct buffer_if *msg4, return False; } - /* Check signature and store g^x mod m */ - hash=safe_malloc(st->hash->len, "process_msg4"); - hst=st->hash->init(); - st->hash->update(hst,m.hashstart,m.hashlen); - st->hash->final(hst,hash); - /* Terminate signature with a '0' - cheating, but should be ok */ - m.sig[m.siglen]=0; - if (!st->pubkey->check(st->pubkey->st,hash,st->hash->len,m.sig)) { - slog(st,LOG_SEC,"msg4 signature failed check!"); - free(hash); + if (!process_msg3_msg4(st,&m)) return False; - } - free(hash); /* Terminate their DH public key with a '0' */ m.pk[m.pklen]=0; -- 2.30.2