2 invitation.c -- Create and accept invitations
3 Copyright (C) 2013-2017 Guus Sliepen <guus@tinc-vpn.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include "control_common.h"
27 #include "invitation.h"
38 #include "ed25519/sha512.h"
40 int addressfamily = AF_UNSPEC;
42 static void scan_for_hostname(const char *filename, char **hostname, char **port) {
43 if(!filename || (*hostname && *port)) {
47 FILE *f = fopen(filename, "r");
53 while(fgets(line, sizeof(line), f)) {
59 p += strcspn(p, "\t =");
65 q = p + strspn(p, "\t ");
68 q += 1 + strspn(q + 1, "\t ");
72 p = q + strcspn(q, "\t ");
78 p += strspn(p, "\t ");
79 p[strcspn(p, "\t ")] = 0;
81 if(!*port && !strcasecmp(line, "Port")) {
83 } else if(!*hostname && !strcasecmp(line, "Address")) {
84 *hostname = xstrdup(q);
92 if(*hostname && *port) {
100 char *get_my_hostname() {
101 char *hostname = NULL;
103 char *hostport = NULL;
104 char *name = get_my_name(false);
105 char filename[PATH_MAX] = {0};
107 // Use first Address statement in own host config file
109 snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, name);
110 scan_for_hostname(filename, &hostname, &port);
111 scan_for_hostname(tinc_conf, &hostname, &port);
118 // If that doesn't work, guess externally visible hostname
119 fprintf(stderr, "Trying to discover externally visible hostname...\n");
120 struct addrinfo *ai = str2addrinfo("tinc-vpn.org", "80", SOCK_STREAM);
121 struct addrinfo *aip = ai;
122 static const char request[] = "GET http://tinc-vpn.org/host.cgi HTTP/1.0\r\n\r\n";
125 int s = socket(aip->ai_family, aip->ai_socktype, aip->ai_protocol);
128 if(connect(s, aip->ai_addr, aip->ai_addrlen)) {
135 send(s, request, sizeof(request) - 1, 0);
136 int len = recv(s, line, sizeof(line) - 1, MSG_WAITALL);
141 if(line[len - 1] == '\n') {
145 char *p = strrchr(line, '\n');
148 hostname = xstrdup(p + 1);
167 // Check that the hostname is reasonable
169 for(char *p = hostname; *p; p++) {
170 if(isalnum(*p) || *p == '-' || *p == '.' || *p == ':') {
174 // If not, forget it.
183 fprintf(stderr, "Could not determine the external address or hostname. Please set Address manually.\n");
191 fprintf(stderr, "Please enter your host's external address or hostname");
194 fprintf(stderr, " [%s]", hostname);
197 fprintf(stderr, ": ");
199 if(!fgets(line, sizeof(line), stdin)) {
200 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
213 for(char *p = line; *p; p++) {
214 if(isalnum(*p) || *p == '-' || *p == '.') {
218 fprintf(stderr, "Invalid address or hostname.\n");
223 hostname = xstrdup(line);
228 FILE *f = fopen(filename, "a");
231 fprintf(f, "\nAddress = %s\n", hostname);
234 fprintf(stderr, "Could not append Address to %s: %s\n", filename, strerror(errno));
241 if(strchr(hostname, ':')) {
242 xasprintf(&hostport, "[%s]:%s", hostname, port);
244 xasprintf(&hostport, "%s:%s", hostname, port);
247 if(strchr(hostname, ':')) {
248 xasprintf(&hostport, "[%s]", hostname);
250 hostport = xstrdup(hostname);
259 static bool fcopy(FILE *out, const char *filename) {
260 FILE *in = fopen(filename, "r");
263 fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno));
270 while((len = fread(buf, 1, sizeof(buf), in))) {
271 fwrite(buf, len, 1, out);
278 int cmd_invite(int argc, char *argv[]) {
280 fprintf(stderr, "Not enough arguments!\n");
284 // Check validity of the new node's name
285 if(!check_id(argv[1])) {
286 fprintf(stderr, "Invalid name for node.\n");
290 myname = get_my_name(true);
296 // Ensure no host configuration file with that name exists
297 char filename[PATH_MAX];
298 snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]);
300 if(!access(filename, F_OK)) {
301 fprintf(stderr, "A host config file for %s already exists!\n", argv[1]);
305 // If a daemon is running, ensure no other nodes know about this name
306 if(connect_tincd(false)) {
308 sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
310 while(recvline(fd, line, sizeof(line))) {
314 if(sscanf(line, "%d %d %4095s", &code, &req, node) != 3) {
318 if(!strcmp(node, argv[1])) {
324 fprintf(stderr, "A node with name %s is already known!\n", argv[1]);
329 snprintf(filename, sizeof(filename), "%s" SLASH "invitations", confbase);
331 if(mkdir(filename, 0700) && errno != EEXIST) {
332 fprintf(stderr, "Could not create directory %s: %s\n", filename, strerror(errno));
336 // Count the number of valid invitations, clean up old ones
337 DIR *dir = opendir(filename);
340 fprintf(stderr, "Could not read directory %s: %s\n", filename, strerror(errno));
347 time_t deadline = time(NULL) - 604800; // 1 week in the past
349 while((ent = readdir(dir))) {
350 if(strlen(ent->d_name) != 24) {
354 char invname[PATH_MAX];
356 snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name);
358 if(!stat(invname, &st)) {
359 if(deadline < st.st_mtime) {
365 fprintf(stderr, "Could not stat %s: %s\n", invname, strerror(errno));
373 fprintf(stderr, "Error while reading directory %s: %s\n", filename, strerror(errno));
378 snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
380 // Remove the key if there are no outstanding invitations.
385 // Create a new key if necessary.
386 FILE *f = fopen(filename, "r");
389 if(errno != ENOENT) {
390 fprintf(stderr, "Could not read %s: %s\n", filename, strerror(errno));
394 key = ecdsa_generate();
400 f = fopen(filename, "w");
403 fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno));
407 chmod(filename, 0600);
409 if(!ecdsa_write_pem_private_key(key, f)) {
410 fprintf(stderr, "Could not write ECDSA private key\n");
417 if(connect_tincd(false)) {
418 sendline(fd, "%d %d", CONTROL, REQ_RELOAD);
421 key = ecdsa_read_pem_private_key(f);
425 fprintf(stderr, "Could not read private key from %s\n", filename);
433 // Create a hash of the key.
435 char *fingerprint = ecdsa_get_base64_public_key(key);
436 sha512(fingerprint, strlen(fingerprint), hash);
437 b64encode_urlsafe(hash, hash, 18);
439 // Create a random cookie for this invitation.
441 randomize(cookie, 18);
443 // Create a filename that doesn't reveal the cookie itself
444 char buf[18 + strlen(fingerprint)];
446 memcpy(buf, cookie, 18);
447 memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
448 sha512(buf, sizeof(buf), cookiehash);
449 b64encode_urlsafe(cookiehash, cookiehash, 18);
451 b64encode_urlsafe(cookie, cookie, 18);
453 // Create a file containing the details of the invitation.
454 snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
455 int ifd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
458 fprintf(stderr, "Could not create invitation file %s: %s\n", filename, strerror(errno));
462 f = fdopen(ifd, "w");
468 // Get the local address
469 char *address = get_my_hostname();
471 // Fill in the details.
472 fprintf(f, "Name = %s\n", argv[1]);
474 if(check_netname(netname, true)) {
475 fprintf(f, "NetName = %s\n", netname);
478 fprintf(f, "ConnectTo = %s\n", myname);
480 // Copy Broadcast and Mode
481 FILE *tc = fopen(tinc_conf, "r");
486 while(fgets(buf, sizeof(buf), tc)) {
487 if((!strncasecmp(buf, "Mode", 4) && strchr(" \t=", buf[4]))
488 || (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) {
491 // Make sure there is a newline character.
492 if(!strchr(buf, '\n')) {
501 fprintf(f, "#---------------------------------------------------------------#\n");
502 fprintf(f, "Name = %s\n", myname);
504 char filename2[PATH_MAX];
505 snprintf(filename2, sizeof(filename2), "%s" SLASH "hosts" SLASH "%s", confbase, myname);
509 // Create an URL from the local address, key hash and cookie
511 xasprintf(&url, "%s/%s%s", address, hash, cookie);
513 // Call the inviation-created script
515 environment_init(&env);
516 environment_add(&env, "NODE=%s", argv[1]);
517 environment_add(&env, "INVITATION_FILE=%s", filename);
518 environment_add(&env, "INVITATION_URL=%s", url);
519 execute_script("invitation-created", &env);
520 environment_exit(&env);
530 static char cookie[18];
531 static sptps_t sptps;
533 static size_t datalen;
534 static bool success = false;
536 static char cookie[18], hash[18];
538 static char *get_line(const char **data) {
539 if(!data || !*data) {
548 static char line[1024];
549 const char *end = strchr(*data, '\n');
550 size_t len = end ? end - *data : strlen(*data);
552 if(len >= sizeof(line)) {
553 fprintf(stderr, "Maximum line length exceeded!\n");
557 if(len && !isprint(**data)) {
561 memcpy(line, *data, len);
573 static char *get_value(const char *data, const char *var) {
574 char *line = get_line(&data);
580 char *sep = line + strcspn(line, " \t=");
581 char *val = sep + strspn(sep, " \t");
584 val += 1 + strspn(val + 1, " \t");
589 if(strcasecmp(line, var)) {
596 static char *grep(const char *data, const char *var) {
597 static char value[1024];
599 const char *p = data;
600 int varlen = strlen(var);
602 // Skip all lines not starting with var
603 while(strncasecmp(p, var, varlen) || !strchr(" \t=", p[varlen])) {
618 p += strspn(p, " \t");
621 p += 1 + strspn(p + 1, " \t");
624 const char *e = strchr(p, '\n');
630 if(e - p >= sizeof(value)) {
631 fprintf(stderr, "Maximum line length exceeded!\n");
635 memcpy(value, p, e - p);
640 static bool finalize_join(void) {
641 char *name = xstrdup(get_value(data, "Name"));
644 fprintf(stderr, "No Name found in invitation!\n");
648 if(!check_id(name)) {
649 fprintf(stderr, "Invalid Name found in invitation!\n");
654 netname = grep(data, "NetName");
656 if(netname && !check_netname(netname, true)) {
657 fprintf(stderr, "Unsafe NetName found in invitation!\n");
662 bool ask_netname = false;
663 char temp_netname[32];
677 xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
678 xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
680 if(!access(tinc_conf, F_OK)) {
681 fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
687 // Generate a random netname, ask for a better one later.
689 snprintf(temp_netname, sizeof(temp_netname), "join_%x", rand());
690 netname = temp_netname;
694 if(mkdir(confbase, 0777) && errno != EEXIST) {
695 fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
699 if(mkdir(hosts_dir, 0777) && errno != EEXIST) {
700 fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno));
704 FILE *f = fopen(tinc_conf, "w");
707 fprintf(stderr, "Could not create file %s: %s\n", tinc_conf, strerror(errno));
711 fprintf(f, "Name = %s\n", name);
713 char filename[PATH_MAX];
714 snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
715 FILE *fh = fopen(filename, "w");
718 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
723 snprintf(filename, sizeof(filename), "%s" SLASH "invitation-data", confbase);
724 FILE *finv = fopen(filename, "w");
726 if(!finv || fwrite(data, datalen, 1, finv) != 1) {
727 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
736 snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
737 FILE *fup = fopen(filename, "w");
740 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
746 ifconfig_header(fup);
748 // Filter first chunk on approved keywords, split between tinc.conf and hosts/Name
749 // Generate a tinc-up script from Ifconfig and Route keywords.
750 // Other chunks go unfiltered to their respective host config files
751 const char *p = data;
754 while((l = get_line(&p))) {
760 // Split line into variable and value
761 int len = strcspn(l, "\t =");
763 value += strspn(value, "\t ");
767 value += strspn(value, "\t ");
772 // Ignore lines with empty variable names
778 if(!strcasecmp(l, "Name")) {
779 if(strcmp(value, name)) {
784 } else if(!strcasecmp(l, "NetName")) {
788 // Check the list of known variables
792 for(i = 0; variables[i].name; i++) {
793 if(strcasecmp(l, variables[i].name)) {
801 // Handle Ifconfig and Route statements
803 if(!strcasecmp(l, "Ifconfig")) {
804 if(!strcasecmp(value, "dhcp")) {
806 } else if(!strcasecmp(value, "dhcp6")) {
808 } else if(!strcasecmp(value, "slaac")) {
811 ifconfig_address(fup, value);
815 } else if(!strcasecmp(l, "Route")) {
816 ifconfig_route(fup, value);
821 // Ignore unknown and unsafe variables
823 fprintf(stderr, "Ignoring unknown variable '%s' in invitation.\n", l);
825 } else if(!(variables[i].type & VAR_SAFE)) {
826 fprintf(stderr, "Ignoring unsafe variable '%s' in invitation.\n", l);
830 // Copy the safe variable to the right config file
831 fprintf((variables[i].type & VAR_HOST) ? fh : f, "%s = %s\n", l, value);
835 bool valid_tinc_up = ifconfig_footer(fup);
838 while(l && !strcasecmp(l, "Name")) {
839 if(!check_id(value)) {
840 fprintf(stderr, "Invalid Name found in invitation.\n");
844 if(!strcmp(value, name)) {
845 fprintf(stderr, "Secondary chunk would overwrite our own host config file.\n");
849 snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, value);
850 f = fopen(filename, "w");
853 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
857 while((l = get_line(&p))) {
858 if(!strcmp(l, "#---------------------------------------------------------------#")) {
862 int len = strcspn(l, "\t =");
864 if(len == 4 && !strncasecmp(l, "Name", 4)) {
866 value += strspn(value, "\t ");
870 value += strspn(value, "\t ");
884 // Generate our key and send a copy to the server
885 ecdsa_t *key = ecdsa_generate();
891 char *b64key = ecdsa_get_base64_public_key(key);
897 snprintf(filename, sizeof(filename), "%s" SLASH "ed25519_key.priv", confbase);
898 f = fopenmask(filename, "w", 0600);
904 if(!ecdsa_write_pem_private_key(key, f)) {
905 fprintf(stderr, "Error writing private key!\n");
913 fprintf(fh, "Ed25519PublicKey = %s\n", b64key);
915 sptps_send_record(&sptps, 1, b64key, strlen(b64key));
919 #ifndef DISABLE_LEGACY
920 rsa_t *rsa = rsa_generate(2048, 0x1001);
921 snprintf(filename, sizeof(filename), "%s" SLASH "rsa_key.priv", confbase);
922 f = fopenmask(filename, "w", 0600);
924 if(!f || !rsa_write_pem_private_key(rsa, f)) {
925 fprintf(stderr, "Could not write private RSA key\n");
926 } else if(!rsa_write_pem_public_key(rsa, fh)) {
927 fprintf(stderr, "Could not write public RSA key\n");
941 if(ask_netname && tty) {
942 fprintf(stderr, "Enter a new netname: ");
944 if(!fgets(line, sizeof(line), stdin)) {
945 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
949 if(!*line || *line == '\n') {
953 line[strlen(line) - 1] = 0;
955 char newbase[PATH_MAX];
956 snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line);
958 if(rename(confbase, newbase)) {
959 fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
967 char filename2[PATH_MAX];
968 snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
969 snprintf(filename2, sizeof(filename2), "%s" SLASH "tinc-up", confbase);
973 FILE *fup = fopen(filename, "r");
976 fprintf(stderr, "\nPlease review the following tinc-up script:\n\n");
980 while(fgets(buf, sizeof(buf), fup)) {
989 fprintf(stderr, "\nDo you want to use this script [y]es/[n]o/[e]dit? ");
990 response = tolower(getchar());
991 } while(!strchr("yne", response));
993 fprintf(stderr, "\n");
995 if(response == 'e') {
998 xasprintf(&command, "\"%s\" \"%s\"", getenv("VISUAL") ? : getenv("EDITOR") ? : "vi", filename);
1000 xasprintf(&command, "edit \"%s\"", filename);
1003 if(system(command)) {
1012 if(response == 'y') {
1013 rename(filename, filename2);
1014 chmod(filename2, 0755);
1015 fprintf(stderr, "tinc-up enabled.\n");
1017 fprintf(stderr, "tinc-up has been left disabled.\n");
1021 fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n");
1024 // A placeholder was generated.
1025 rename(filename, filename2);
1026 chmod(filename2, 0755);
1029 fprintf(stderr, "Configuration stored in: %s\n", confbase);
1035 static bool invitation_send(void *handle, uint8_t type, const void *data, size_t len) {
1037 int result = send(sock, data, len, 0);
1039 if(result == -1 && errno == EINTR) {
1041 } else if(result <= 0) {
1052 static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) {
1054 case SPTPS_HANDSHAKE:
1055 return sptps_send_record(&sptps, 0, cookie, sizeof(cookie));
1058 data = xrealloc(data, datalen + len + 1);
1059 memcpy(data + datalen, msg, len);
1065 return finalize_join();
1068 fprintf(stderr, "Invitation successfully accepted.\n");
1069 shutdown(sock, SHUT_RDWR);
1080 int cmd_join(int argc, char *argv[]) {
1086 fprintf(stderr, "Too many arguments!\n");
1090 // Make sure confbase exists and is accessible.
1091 if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
1092 fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
1096 if(mkdir(confbase, 0777) && errno != EEXIST) {
1097 fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
1101 if(access(confbase, R_OK | W_OK | X_OK)) {
1102 fprintf(stderr, "No permission to write in directory %s: %s\n", confbase, strerror(errno));
1106 // If a netname or explicit configuration directory is specified, check for an existing tinc.conf.
1107 if((netname || confbasegiven) && !access(tinc_conf, F_OK)) {
1108 fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
1112 // Either read the invitation from the command line or from stdin.
1116 invitation = argv[1];
1119 fprintf(stderr, "Enter invitation URL: ");
1124 if(!fgets(line, sizeof(line), stdin)) {
1125 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
1132 // Parse the invitation URL.
1135 char *slash = strchr(invitation, '/');
1143 if(strlen(slash) != 48) {
1147 char *address = invitation;
1150 if(*address == '[') {
1152 char *bracket = strchr(address, ']');
1160 if(bracket[1] == ':') {
1164 port = strchr(address, ':');
1171 if(!port || !*port) {
1175 if(!b64decode(slash, hash, 24) || !b64decode(slash + 24, cookie, 24)) {
1179 // Generate a throw-away key for the invitation.
1180 ecdsa_t *key = ecdsa_generate();
1186 char *b64key = ecdsa_get_base64_public_key(key);
1188 // Connect to the tinc daemon mentioned in the URL.
1189 struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
1195 struct addrinfo *aip = NULL;
1209 sock = socket(aip->ai_family, aip->ai_socktype, aip->ai_protocol);
1212 fprintf(stderr, "Could not open socket: %s\n", strerror(errno));
1216 if(connect(sock, aip->ai_addr, aip->ai_addrlen)) {
1217 char *addrstr, *portstr;
1218 sockaddr2str((sockaddr_t *)aip->ai_addr, &addrstr, &portstr);
1219 fprintf(stderr, "Could not connect to %s port %s: %s\n", addrstr, portstr, strerror(errno));
1226 fprintf(stderr, "Connected to %s port %s...\n", address, port);
1228 // Tell him we have an invitation, and give him our throw-away key.
1229 int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
1231 if(len <= 0 || len >= sizeof(line)) {
1235 if(!sendline(sock, "0 ?%s %d.%d", b64key, PROT_MAJOR, 1)) {
1236 fprintf(stderr, "Error sending request to %s port %s: %s\n", address, port, strerror(errno));
1241 char hisname[4096] = "";
1242 int code, hismajor, hisminor = 0;
1244 if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof(line)) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) {
1245 fprintf(stderr, "Cannot read greeting from peer\n");
1252 // Check if the hash of the key he gave us matches the hash in the URL.
1253 char *fingerprint = line + 2;
1256 if(sha512(fingerprint, strlen(fingerprint), hishash)) {
1257 fprintf(stderr, "Could not create digest\n%s\n", line + 2);
1261 if(memcmp(hishash, hash, 18)) {
1262 fprintf(stderr, "Peer has an invalid key!\n%s\n", line + 2);
1267 ecdsa_t *hiskey = ecdsa_set_base64_public_key(fingerprint);
1273 // Start an SPTPS session
1274 if(!sptps_start(&sptps, NULL, true, false, key, hiskey, "tinc invitation", 15, invitation_send, invitation_receive)) {
1278 // Feed rest of input buffer to SPTPS
1279 if(!sptps_receive_data(&sptps, buffer, blen)) {
1283 while((len = recv(sock, line, sizeof(line), 0))) {
1285 if(errno == EINTR) {
1289 fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, strerror(errno));
1296 int done = sptps_receive_data(&sptps, p, len);
1313 fprintf(stderr, "Connection closed by peer, invitation cancelled.\n");
1320 fprintf(stderr, "Invalid invitation URL.\n");