X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=src%2Fprotocol_auth.c;h=d69c8ab722913732c2521ec94356df5ec9e35106;hb=9699f08afc6420d2bdac1063ea6789b585aaf42e;hp=1623e75e4992307f0b460e78f66a8f870301c689;hpb=5dec1c25713a19c49fcbb885200184a9682ef175;p=meshlink diff --git a/src/protocol_auth.c b/src/protocol_auth.c index 1623e75e..d69c8ab7 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -190,8 +190,19 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const char *dat if(type != 0 || len != 18 || c->status.invitation_used) return false; + // Recover the filename from the cookie and the key + digest_t *digest = digest_open_by_name("sha256", 18); + if(!digest) + abort(); + char *fingerprint = ecdsa_get_base64_public_key(invitation_key); + char hashbuf[18 + strlen(fingerprint)]; char cookie[25]; - b64encode_urlsafe(data, cookie, 18); + memcpy(hashbuf, data, 18); + memcpy(hashbuf + 18, fingerprint, sizeof hashbuf - 18); + digest_create(digest, hashbuf, sizeof hashbuf, cookie); + b64encode_urlsafe(cookie, cookie, 18); + digest_close(digest); + free(fingerprint); char filename[PATH_MAX], usedname[PATH_MAX]; snprintf(filename, sizeof filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookie);