if(!f) {
fprintf(stderr, "Could not write %s: %s\n", filename, strerror(errno));
- free(key);
+ ecdsa_free(key);
return 1;
}
if(!ecdsa_write_pem_private_key(key, f)) {
fprintf(stderr, "Could not write ECDSA private key\n");
fclose(f);
- free(key);
+ ecdsa_free(key);
return 1;
}
sha512(fingerprint, strlen(fingerprint), hash);
b64encode_urlsafe(hash, hash, 18);
- free(key);
+ ecdsa_free(key);
// Create a random cookie for this invitation.
char cookie[25];
}
if(!netname) {
- netname = grep(data, "NetName");
+ netname = xstrdup(grep(data, "NetName"));
if(netname && !check_netname(netname, true)) {
fprintf(stderr, "Unsafe NetName found in invitation!\n");
if(!ai) {
free(b64key);
+ ecdsa_free(key);
return 1;
}
if(!aip) {
freeaddrinfo(ai);
free(b64key);
+ ecdsa_free(key);
return 1;
}
}
if(sha512(fingerprint, strlen(fingerprint), hishash)) {
fprintf(stderr, "Could not create digest\n%s\n", line + 2);
+ ecdsa_free(key);
return 1;
}
if(memcmp(hishash, hash, 18)) {
fprintf(stderr, "Peer has an invalid key!\n%s\n", line + 2);
+ ecdsa_free(key);
return 1;
}
ecdsa_t *hiskey = ecdsa_set_base64_public_key(fingerprint);
if(!hiskey) {
+ ecdsa_free(key);
return 1;
}
// Start an SPTPS session
if(!sptps_start(&sptps, NULL, true, false, key, hiskey, "tinc invitation", 15, invitation_send, invitation_receive)) {
+ ecdsa_free(hiskey);
+ ecdsa_free(key);
return 1;
}
// Feed rest of input buffer to SPTPS
if(!sptps_receive_data(&sptps, buffer, blen)) {
- return 1;
+ success = false;
+ goto exit;
}
while((len = recv(sock, line, sizeof(line), 0))) {
#endif
fprintf(stderr, "Error reading data from %s port %s: %s\n", address, port, sockstrerror(sockerrno));
- return 1;
+ success = false;
+ goto exit;
}
char *p = line;
size_t done = sptps_receive_data(&sptps, p, len);
if(!done) {
- return 1;
+ success = false;
+ goto exit;
}
len -= (ssize_t) done;
}
}
+exit:
sptps_stop(&sptps);
ecdsa_free(hiskey);
ecdsa_free(key);
closesocket(sock);
if(!success) {
- fprintf(stderr, "Connection closed by peer, invitation cancelled.\n");
+ fprintf(stderr, "Invitation cancelled.\n");
return 1;
}