X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;ds=sidebyside;f=src%2Finvitation.c;h=5175ba92003c07be3c2a6a37833bc9d786db2126;hb=9699f08afc6420d2bdac1063ea6789b585aaf42e;hp=6ed17ca16c655f24c5751eceb24becf17a1667cd;hpb=c798f7309337fc4c6dec7fd99d45cd76f809ab02;p=tinc diff --git a/src/invitation.c b/src/invitation.c index 6ed17ca1..5175ba92 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -349,10 +349,19 @@ int cmd_invite(int argc, char *argv[]) { // Create a random cookie for this invitation. char cookie[25]; randomize(cookie, 18); + + // Create a filename that doesn't reveal the cookie itself + char buf[18 + strlen(fingerprint)]; + char cookiehash[25]; + memcpy(buf, cookie, 18); + memcpy(buf + 18, fingerprint, sizeof buf - 18); + digest_create(digest, buf, sizeof buf, cookiehash); + b64encode_urlsafe(cookiehash, cookiehash, 18); + b64encode_urlsafe(cookie, cookie, 18); // Create a file containing the details of the invitation. - xasprintf(&filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookie); + xasprintf(&filename, "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash); int ifd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600); if(!ifd) { fprintf(stderr, "Could not create invitation file %s: %s\n", filename, strerror(errno)); @@ -688,10 +697,6 @@ make_names: check_port(name); - fprintf(stderr, "Invitation succesfully accepted.\n"); - shutdown(sock, SHUT_RDWR); - success = true; - ask_netname: if(ask_netname) { fprintf(stderr, "Enter a new netname: "); @@ -720,6 +725,7 @@ ask_netname: return true; } + static bool invitation_send(void *handle, uint8_t type, const char *data, size_t len) { while(len) { int result = send(sock, data, len, 0); @@ -748,6 +754,12 @@ static bool invitation_receive(void *handle, uint8_t type, const char *msg, uint case 1: return finalize_join(); + case 2: + fprintf(stderr, "Invitation succesfully accepted.\n"); + shutdown(sock, SHUT_RDWR); + success = true; + break; + default: return false; }