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");
192 fprintf(stderr, "Please enter your host's external address or hostname");
195 fprintf(stderr, " [%s]", hostname);
198 fprintf(stderr, ": ");
200 if(!fgets(line, sizeof(line), stdin)) {
201 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
215 for(char *p = line; *p; p++) {
216 if(isalnum(*p) || *p == '-' || *p == '.') {
220 fprintf(stderr, "Invalid address or hostname.\n");
225 hostname = xstrdup(line);
230 FILE *f = fopen(filename, "a");
233 fprintf(f, "\nAddress = %s\n", hostname);
236 fprintf(stderr, "Could not append Address to %s: %s\n", filename, strerror(errno));
243 if(strchr(hostname, ':')) {
244 xasprintf(&hostport, "[%s]:%s", hostname, port);
246 xasprintf(&hostport, "%s:%s", hostname, port);
249 if(strchr(hostname, ':')) {
250 xasprintf(&hostport, "[%s]", hostname);
252 hostport = xstrdup(hostname);
261 static bool fcopy(FILE *out, const char *filename) {
262 FILE *in = fopen(filename, "r");
265 fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno));
272 while((len = fread(buf, 1, sizeof(buf), in))) {
273 fwrite(buf, len, 1, out);
280 int cmd_invite(int argc, char *argv[]) {
282 fprintf(stderr, "Not enough arguments!\n");
286 // Check validity of the new node's name
287 if(!check_id(argv[1])) {
288 fprintf(stderr, "Invalid name for node.\n");
292 myname = get_my_name(true);
298 // Ensure no host configuration file with that name exists
299 char filename[PATH_MAX];
300 snprintf(filename, sizeof(filename), "%s" SLASH "hosts" SLASH "%s", confbase, argv[1]);
302 if(!access(filename, F_OK)) {
303 fprintf(stderr, "A host config file for %s already exists!\n", argv[1]);
307 // If a daemon is running, ensure no other nodes know about this name
308 if(connect_tincd(false)) {
310 sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
312 while(recvline(fd, line, sizeof(line))) {
316 if(sscanf(line, "%d %d %4095s", &code, &req, node) != 3) {
320 if(!strcmp(node, argv[1])) {
326 fprintf(stderr, "A node with name %s is already known!\n", argv[1]);
331 snprintf(filename, sizeof(filename), "%s" SLASH "invitations", confbase);
333 if(mkdir(filename, 0700) && errno != EEXIST) {
334 fprintf(stderr, "Could not create directory %s: %s\n", filename, strerror(errno));
338 // Count the number of valid invitations, clean up old ones
339 DIR *dir = opendir(filename);
342 fprintf(stderr, "Could not read directory %s: %s\n", filename, strerror(errno));
349 time_t deadline = time(NULL) - 604800; // 1 week in the past
351 while((ent = readdir(dir))) {
352 if(strlen(ent->d_name) != 24) {
356 char invname[PATH_MAX];
359 if((size_t)snprintf(invname, sizeof(invname), "%s" SLASH "%s", filename, ent->d_name) >= sizeof(invname)) {
360 fprintf(stderr, "Filename too long: %s" SLASH "%s\n", filename, ent->d_name);
364 if(!stat(invname, &st)) {
365 if(deadline < st.st_mtime) {
371 fprintf(stderr, "Could not stat %s: %s\n", invname, strerror(errno));
379 fprintf(stderr, "Error while reading directory %s: %s\n", filename, strerror(errno));
384 snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "ed25519_key.priv", confbase);
386 // Remove the key if there are no outstanding invitations.
391 // Create a new key if necessary.
392 FILE *f = fopen(filename, "r");
395 if(errno != ENOENT) {
396 fprintf(stderr, "Could not read %s: %s\n", filename, strerror(errno));
400 key = ecdsa_generate();
406 f = fopen(filename, "w");
409 fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno));
413 chmod(filename, 0600);
415 if(!ecdsa_write_pem_private_key(key, f)) {
416 fprintf(stderr, "Could not write ECDSA private key\n");
423 if(connect_tincd(true)) {
424 sendline(fd, "%d %d", CONTROL, REQ_RELOAD);
426 fprintf(stderr, "Could not signal the tinc daemon. Please restart or reload it manually.\n");
429 key = ecdsa_read_pem_private_key(f);
433 fprintf(stderr, "Could not read private key from %s\n", filename);
441 // Create a hash of the key.
443 char *fingerprint = ecdsa_get_base64_public_key(key);
444 sha512(fingerprint, strlen(fingerprint), hash);
445 b64encode_urlsafe(hash, hash, 18);
447 // Create a random cookie for this invitation.
449 randomize(cookie, 18);
451 // Create a filename that doesn't reveal the cookie itself
452 char buf[18 + strlen(fingerprint)];
454 memcpy(buf, cookie, 18);
455 memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
456 sha512(buf, sizeof(buf), cookiehash);
457 b64encode_urlsafe(cookiehash, cookiehash, 18);
459 b64encode_urlsafe(cookie, cookie, 18);
461 // Create a file containing the details of the invitation.
462 snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
463 int ifd = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600);
466 fprintf(stderr, "Could not create invitation file %s: %s\n", filename, strerror(errno));
470 f = fdopen(ifd, "w");
476 // Get the local address
477 char *address = get_my_hostname();
479 // Fill in the details.
480 fprintf(f, "Name = %s\n", argv[1]);
482 if(check_netname(netname, true)) {
483 fprintf(f, "NetName = %s\n", netname);
486 fprintf(f, "ConnectTo = %s\n", myname);
488 // Copy Broadcast and Mode
489 FILE *tc = fopen(tinc_conf, "r");
494 while(fgets(buf, sizeof(buf), tc)) {
495 if((!strncasecmp(buf, "Mode", 4) && strchr(" \t=", buf[4]))
496 || (!strncasecmp(buf, "Broadcast", 9) && strchr(" \t=", buf[9]))) {
499 // Make sure there is a newline character.
500 if(!strchr(buf, '\n')) {
509 fprintf(f, "#---------------------------------------------------------------#\n");
510 fprintf(f, "Name = %s\n", myname);
512 char filename2[PATH_MAX];
513 snprintf(filename2, sizeof(filename2), "%s" SLASH "hosts" SLASH "%s", confbase, myname);
517 // Create an URL from the local address, key hash and cookie
519 xasprintf(&url, "%s/%s%s", address, hash, cookie);
521 // Call the inviation-created script
523 environment_init(&env);
524 environment_add(&env, "NODE=%s", argv[1]);
525 environment_add(&env, "INVITATION_FILE=%s", filename);
526 environment_add(&env, "INVITATION_URL=%s", url);
527 execute_script("invitation-created", &env);
528 environment_exit(&env);
538 static char cookie[18];
539 static sptps_t sptps;
541 static size_t datalen;
542 static bool success = false;
544 static char cookie[18], hash[18];
546 static char *get_line(const char **data) {
547 if(!data || !*data) {
556 static char line[1024];
557 const char *end = strchr(*data, '\n');
558 size_t len = end ? (size_t)(end - *data) : strlen(*data);
560 if(len >= sizeof(line)) {
561 fprintf(stderr, "Maximum line length exceeded!\n");
565 if(len && !isprint(**data)) {
569 memcpy(line, *data, len);
581 static char *get_value(const char *data, const char *var) {
582 char *line = get_line(&data);
588 char *sep = line + strcspn(line, " \t=");
589 char *val = sep + strspn(sep, " \t");
592 val += 1 + strspn(val + 1, " \t");
597 if(strcasecmp(line, var)) {
604 static char *grep(const char *data, const char *var) {
605 static char value[1024];
607 const char *p = data;
608 int varlen = strlen(var);
610 // Skip all lines not starting with var
611 while(strncasecmp(p, var, varlen) || !strchr(" \t=", p[varlen])) {
626 p += strspn(p, " \t");
629 p += 1 + strspn(p + 1, " \t");
632 const char *e = strchr(p, '\n');
638 if((size_t)(e - p) >= sizeof(value)) {
639 fprintf(stderr, "Maximum line length exceeded!\n");
643 memcpy(value, p, e - p);
648 static bool finalize_join(void) {
649 const char *temp_name = get_value(data, "Name");
652 fprintf(stderr, "No Name found in invitation!\n");
656 size_t len = strlen(temp_name);
658 memcpy(name, temp_name, len);
661 if(!check_id(name)) {
662 fprintf(stderr, "Invalid Name found in invitation!\n");
667 netname = grep(data, "NetName");
669 if(netname && !check_netname(netname, true)) {
670 fprintf(stderr, "Unsafe NetName found in invitation!\n");
675 bool ask_netname = false;
676 char temp_netname[32];
690 xasprintf(&tinc_conf, "%s" SLASH "tinc.conf", confbase);
691 xasprintf(&hosts_dir, "%s" SLASH "hosts", confbase);
693 if(!access(tinc_conf, F_OK)) {
694 fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
700 // Generate a random netname, ask for a better one later.
702 snprintf(temp_netname, sizeof(temp_netname), "join_%x", rand());
703 netname = temp_netname;
707 if(mkdir(confbase, 0777) && errno != EEXIST) {
708 fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
712 if(mkdir(hosts_dir, 0777) && errno != EEXIST) {
713 fprintf(stderr, "Could not create directory %s: %s\n", hosts_dir, strerror(errno));
717 FILE *f = fopen(tinc_conf, "w");
720 fprintf(stderr, "Could not create file %s: %s\n", tinc_conf, strerror(errno));
724 fprintf(f, "Name = %s\n", name);
726 char filename[PATH_MAX];
727 snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, name);
728 FILE *fh = fopen(filename, "w");
731 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
736 snprintf(filename, sizeof(filename), "%s" SLASH "invitation-data", confbase);
737 FILE *finv = fopen(filename, "w");
739 if(!finv || fwrite(data, datalen, 1, finv) != 1) {
740 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
749 snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
750 FILE *fup = fopen(filename, "w");
753 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
759 ifconfig_header(fup);
761 // Filter first chunk on approved keywords, split between tinc.conf and hosts/Name
762 // Generate a tinc-up script from Ifconfig and Route keywords.
763 // Other chunks go unfiltered to their respective host config files
764 const char *p = data;
767 while((l = get_line(&p))) {
773 // Split line into variable and value
774 int len = strcspn(l, "\t =");
776 value += strspn(value, "\t ");
780 value += strspn(value, "\t ");
785 // Ignore lines with empty variable names
791 if(!strcasecmp(l, "Name")) {
792 if(strcmp(value, name)) {
797 } else if(!strcasecmp(l, "NetName")) {
801 // Check the list of known variables
805 for(i = 0; variables[i].name; i++) {
806 if(strcasecmp(l, variables[i].name)) {
814 // Handle Ifconfig and Route statements
816 if(!strcasecmp(l, "Ifconfig")) {
817 if(!strcasecmp(value, "dhcp")) {
819 } else if(!strcasecmp(value, "dhcp6")) {
821 } else if(!strcasecmp(value, "slaac")) {
824 ifconfig_address(fup, value);
828 } else if(!strcasecmp(l, "Route")) {
829 ifconfig_route(fup, value);
834 // Ignore unknown and unsafe variables
836 fprintf(stderr, "Ignoring unknown variable '%s' in invitation.\n", l);
838 } else if(!(variables[i].type & VAR_SAFE)) {
840 fprintf(stderr, "Warning: unsafe variable '%s' in invitation.\n", l);
842 fprintf(stderr, "Ignoring unsafe variable '%s' in invitation.\n", l);
847 // Copy the safe variable to the right config file
848 fprintf((variables[i].type & VAR_HOST) ? fh : f, "%s = %s\n", l, value);
852 bool valid_tinc_up = ifconfig_footer(fup);
855 while(l && !strcasecmp(l, "Name")) {
856 if(!check_id(value)) {
857 fprintf(stderr, "Invalid Name found in invitation.\n");
861 if(!strcmp(value, name)) {
862 fprintf(stderr, "Secondary chunk would overwrite our own host config file.\n");
866 snprintf(filename, sizeof(filename), "%s" SLASH "%s", hosts_dir, value);
867 f = fopen(filename, "w");
870 fprintf(stderr, "Could not create file %s: %s\n", filename, strerror(errno));
874 while((l = get_line(&p))) {
875 if(!strcmp(l, "#---------------------------------------------------------------#")) {
879 int len = strcspn(l, "\t =");
881 if(len == 4 && !strncasecmp(l, "Name", 4)) {
883 value += strspn(value, "\t ");
887 value += strspn(value, "\t ");
901 // Generate our key and send a copy to the server
902 ecdsa_t *key = ecdsa_generate();
908 char *b64key = ecdsa_get_base64_public_key(key);
914 snprintf(filename, sizeof(filename), "%s" SLASH "ed25519_key.priv", confbase);
915 f = fopenmask(filename, "w", 0600);
921 if(!ecdsa_write_pem_private_key(key, f)) {
922 fprintf(stderr, "Error writing private key!\n");
930 fprintf(fh, "Ed25519PublicKey = %s\n", b64key);
932 sptps_send_record(&sptps, 1, b64key, strlen(b64key));
936 #ifndef DISABLE_LEGACY
937 rsa_t *rsa = rsa_generate(2048, 0x1001);
938 snprintf(filename, sizeof(filename), "%s" SLASH "rsa_key.priv", confbase);
939 f = fopenmask(filename, "w", 0600);
941 if(!f || !rsa_write_pem_private_key(rsa, f)) {
942 fprintf(stderr, "Could not write private RSA key\n");
943 } else if(!rsa_write_pem_public_key(rsa, fh)) {
944 fprintf(stderr, "Could not write public RSA key\n");
958 if(ask_netname && tty) {
959 fprintf(stderr, "Enter a new netname: ");
961 if(!fgets(line, sizeof(line), stdin)) {
962 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
966 if(!*line || *line == '\n') {
970 line[strlen(line) - 1] = 0;
972 char newbase[PATH_MAX];
974 if((size_t)snprintf(newbase, sizeof(newbase), CONFDIR SLASH "tinc" SLASH "%s", line) >= sizeof(newbase)) {
975 fprintf(stderr, "Filename too long: " CONFDIR SLASH "tinc" SLASH "%s\n", line);
979 if(rename(confbase, newbase)) {
980 fprintf(stderr, "Error trying to rename %s to %s: %s\n", confbase, newbase, strerror(errno));
988 char filename2[PATH_MAX];
989 snprintf(filename, sizeof(filename), "%s" SLASH "tinc-up.invitation", confbase);
990 snprintf(filename2, sizeof(filename2), "%s" SLASH "tinc-up", confbase);
994 FILE *fup = fopen(filename, "r");
997 fprintf(stderr, "\nPlease review the following tinc-up script:\n\n");
1001 while(fgets(buf, sizeof(buf), fup)) {
1010 fprintf(stderr, "\nDo you want to use this script [y]es/[n]o/[e]dit? ");
1011 response = tolower(getchar());
1012 } while(!strchr("yne", response));
1014 fprintf(stderr, "\n");
1016 if(response == 'e') {
1019 const char *editor = getenv("VISUAL");
1022 editor = getenv("EDITOR");
1029 xasprintf(&command, "\"%s\" \"%s\"", editor, filename);
1031 xasprintf(&command, "edit \"%s\"", filename);
1034 if(system(command)) {
1043 if(response == 'y') {
1044 rename(filename, filename2);
1045 chmod(filename2, 0755);
1046 fprintf(stderr, "tinc-up enabled.\n");
1048 fprintf(stderr, "tinc-up has been left disabled.\n");
1052 fprintf(stderr, "A tinc-up script was generated, but has been left disabled.\n");
1055 // A placeholder was generated.
1056 rename(filename, filename2);
1057 chmod(filename2, 0755);
1060 fprintf(stderr, "Configuration stored in: %s\n", confbase);
1066 static bool invitation_send(void *handle, uint8_t type, const void *vdata, size_t len) {
1069 const char *data = vdata;
1072 int result = send(sock, data, len, 0);
1074 if(result == -1 && errno == EINTR) {
1076 } else if(result <= 0) {
1087 static bool invitation_receive(void *handle, uint8_t type, const void *msg, uint16_t len) {
1091 case SPTPS_HANDSHAKE:
1092 return sptps_send_record(&sptps, 0, cookie, sizeof(cookie));
1095 data = xrealloc(data, datalen + len + 1);
1096 memcpy(data + datalen, msg, len);
1102 return finalize_join();
1105 fprintf(stderr, "Invitation successfully accepted.\n");
1106 shutdown(sock, SHUT_RDWR);
1117 int cmd_join(int argc, char *argv[]) {
1123 fprintf(stderr, "Too many arguments!\n");
1127 // Make sure confbase exists and is accessible.
1128 if(!confbase_given && mkdir(confdir, 0755) && errno != EEXIST) {
1129 fprintf(stderr, "Could not create directory %s: %s\n", confdir, strerror(errno));
1133 if(mkdir(confbase, 0777) && errno != EEXIST) {
1134 fprintf(stderr, "Could not create directory %s: %s\n", confbase, strerror(errno));
1138 if(access(confbase, R_OK | W_OK | X_OK)) {
1139 fprintf(stderr, "No permission to write in directory %s: %s\n", confbase, strerror(errno));
1143 // If a netname or explicit configuration directory is specified, check for an existing tinc.conf.
1144 if((netname || confbasegiven) && !access(tinc_conf, F_OK)) {
1145 fprintf(stderr, "Configuration file %s already exists!\n", tinc_conf);
1149 // Either read the invitation from the command line or from stdin.
1153 invitation = argv[1];
1156 fprintf(stderr, "Enter invitation URL: ");
1161 if(!fgets(line, sizeof(line), stdin)) {
1162 fprintf(stderr, "Error while reading stdin: %s\n", strerror(errno));
1169 // Parse the invitation URL.
1172 char *slash = strchr(invitation, '/');
1180 if(strlen(slash) != 48) {
1184 char *address = invitation;
1187 if(*address == '[') {
1189 char *bracket = strchr(address, ']');
1197 if(bracket[1] == ':') {
1201 port = strchr(address, ':');
1208 if(!port || !*port) {
1212 if(!b64decode(slash, hash, 24) || !b64decode(slash + 24, cookie, 24)) {
1216 // Generate a throw-away key for the invitation.
1217 ecdsa_t *key = ecdsa_generate();
1223 char *b64key = ecdsa_get_base64_public_key(key);
1225 // Connect to the tinc daemon mentioned in the URL.
1226 struct addrinfo *ai = str2addrinfo(address, port, SOCK_STREAM);
1232 struct addrinfo *aip = NULL;
1246 sock = socket(aip->ai_family, aip->ai_socktype, aip->ai_protocol);
1249 fprintf(stderr, "Could not open socket: %s\n", strerror(errno));
1253 if(connect(sock, aip->ai_addr, aip->ai_addrlen)) {
1254 char *addrstr, *portstr;
1255 sockaddr2str((sockaddr_t *)aip->ai_addr, &addrstr, &portstr);
1256 fprintf(stderr, "Could not connect to %s port %s: %s\n", addrstr, portstr, strerror(errno));
1263 fprintf(stderr, "Connected to %s port %s...\n", address, port);
1265 // Tell him we have an invitation, and give him our throw-away key.
1266 int len = snprintf(line, sizeof(line), "0 ?%s %d.%d\n", b64key, PROT_MAJOR, PROT_MINOR);
1268 if(len <= 0 || (size_t)len >= sizeof(line)) {
1272 if(!sendline(sock, "0 ?%s %d.%d", b64key, PROT_MAJOR, 1)) {
1273 fprintf(stderr, "Error sending request to %s port %s: %s\n", address, port, strerror(errno));
1278 char hisname[4096] = "";
1279 int code, hismajor, hisminor = 0;
1281 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) {
1282 fprintf(stderr, "Cannot read greeting from peer\n");
1289 // Check if the hash of the key he gave us matches the hash in the URL.
1290 char *fingerprint = line + 2;
1293 if(sha512(fingerprint, strlen(fingerprint), hishash)) {
1294 fprintf(stderr, "Could not create digest\n%s\n", line + 2);
1298 if(memcmp(hishash, hash, 18)) {
1299 fprintf(stderr, "Peer has an invalid key!\n%s\n", line + 2);
1304 ecdsa_t *hiskey = ecdsa_set_base64_public_key(fingerprint);
1310 // Start an SPTPS session
1311 if(!sptps_start(&sptps, NULL, true, false, key, hiskey, "tinc invitation", 15, invitation_send, invitation_receive)) {
1315 // Feed rest of input buffer to SPTPS
1316 if(!sptps_receive_data(&sptps, buffer, blen)) {
1320 while((len = recv(sock, line, sizeof(line), 0))) {
1322 if(errno == EINTR) {
1326 fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, strerror(errno));
1333 int done = sptps_receive_data(&sptps, p, len);
1350 fprintf(stderr, "Connection closed by peer, invitation cancelled.\n");
1357 fprintf(stderr, "Invalid invitation URL.\n");