}
ecdsa_t *ecdsa = xzalloc(sizeof(*ecdsa));
- len = b64decode(p, ecdsa->public, len);
+ len = b64decode_tinc(p, ecdsa->public, len);
if(len != 32) {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid format of public key! len = %zu", len);
char *ecdsa_get_base64_public_key(ecdsa_t *ecdsa) {
char *base64 = xmalloc(44);
- b64encode(ecdsa->public, base64, sizeof(ecdsa->public));
+ b64encode_tinc(ecdsa->public, base64, sizeof(ecdsa->public));
return base64;
}
}
size_t linelen = strcspn(line, "\r\n");
- size_t len = b64decode(line, line, linelen);
+ size_t len = b64decode_tinc(line, line, linelen);
if(!len) {
logger(DEBUG_ALWAYS, LOG_ERR, "Invalid base64 data in PEM file\n");
while(size) {
size_t todo = size > 48 ? 48 : size;
- b64encode(buf, base64, todo);
+ b64encode_tinc(buf, base64, todo);
fprintf(fp, "%s\n", base64);
buf += todo;
size -= todo;
char hash[64];
char *fingerprint = ecdsa_get_base64_public_key(key);
sha512(fingerprint, strlen(fingerprint), hash);
- b64encode_urlsafe(hash, hash, 18);
+ b64encode_tinc_urlsafe(hash, hash, 18);
ecdsa_free(key);
memcpy(buf, cookie, 18);
memcpy(buf + 18, fingerprint, sizeof(buf) - 18);
sha512(buf, sizeof(buf), cookiehash);
- b64encode_urlsafe(cookiehash, cookiehash, 18);
+ b64encode_tinc_urlsafe(cookiehash, cookiehash, 18);
free(fingerprint);
- b64encode_urlsafe(cookie, cookie, 18);
+ b64encode_tinc_urlsafe(cookie, cookie, 18);
// Create a file containing the details of the invitation.
snprintf(filename, sizeof(filename), "%s" SLASH "invitations" SLASH "%s", confbase, cookiehash);
port = "655";
}
- if(!b64decode(slash, hash, 24) || !b64decode(slash + 24, cookie, 24)) {
+ if(!b64decode_tinc(slash, hash, 24) || !b64decode_tinc(slash + 24, cookie, 24)) {
goto invalid;
}
return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf));
}
- char buf[len * 4 / 3 + 5];
- b64encode(data, buf, len);
+ char buf[B64_SIZE(len)];
+ b64encode_tinc(data, buf, len);
/* If this is a handshake packet, use ANS_KEY instead of REQ_KEY, for two reasons:
- We don't want intermediate nodes to switch to UDP to relay these packets;
memcpy(hashbuf, data, 18);
memcpy(hashbuf + 18, fingerprint, sizeof(hashbuf) - 18);
sha512(hashbuf, sizeof(hashbuf), cookie);
- b64encode_urlsafe(cookie, cookie, 18);
+ b64encode_tinc_urlsafe(cookie, cookie, 18);
free(fingerprint);
char filename[PATH_MAX], usedname[PATH_MAX];
(void)type;
node_t *to = handle;
to->sptps.send_data = send_sptps_data_myself;
- char buf[len * 4 / 3 + 5];
- b64encode(data, buf, len);
+ char buf[B64_SIZE(len)];
+ b64encode_tinc(data, buf, len);
return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf);
}
char buf[MAX_STRING_SIZE];
size_t len;
- if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) {
+ if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode_tinc(buf, buf, strlen(buf)))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s) to %s (%s): %s", "SPTPS_PACKET", from->name, from->hostname, to->name, to->hostname, "invalid SPTPS data");
return true;
}
char buf[MAX_STRING_SIZE];
size_t len;
- if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode(buf, buf, strlen(buf)))) {
+ if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode_tinc(buf, buf, strlen(buf)))) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data");
return true;
}
if(from->status.sptps) {
uint8_t buf[strlen(key)];
- size_t len = b64decode(key, buf, strlen(key));
+ size_t len = b64decode_tinc(key, buf, strlen(key));
if(!len || !sptps_receive_data(&from->sptps, buf, len)) {
/* Uh-oh. It might be that the tunnel is stuck in some corrupted state,
while((ent = readdir(dir))) {
char buf[MAX_STRING_SIZE];
- if(b64decode(ent->d_name, buf, 24) != 18) {
+ if(b64decode_tinc(ent->d_name, buf, 24) != 18) {
continue;
}
return 1;
}
- b64encode(sig, sig, 64);
+ b64encode_tinc(sig, sig, 64);
ecdsa_free(key);
fprintf(stdout, "Signature = %s %ld %s\n", name, t, sig);
fclose(fp);
- if(b64decode(sig, sig, 86) != 64 || !ecdsa_verify(key, newline, len + trailer_len - (newline - data), sig)) {
+ if(b64decode_tinc(sig, sig, 86) != 64 || !ecdsa_verify(key, newline, len + trailer_len - (newline - data), sig)) {
fprintf(stderr, "Invalid signature\n");
free(data);
ecdsa_free(key);
return length * 2;
}
-size_t b64decode(const char *src, void *dst, size_t length) {
+size_t b64decode_tinc(const char *src, void *dst, size_t length) {
size_t i;
uint32_t triplet = 0;
unsigned char *udst = (unsigned char *)dst;
}
}
-static size_t b64encode_internal(const void *src, char *dst, size_t length, const char *alphabet) {
+static size_t b64encode_tinc_internal(const void *src, char *dst, size_t length, const char *alphabet) {
uint32_t triplet;
const unsigned char *usrc = (unsigned char *)src;
size_t si = length / 3 * 3;
return length;
}
-size_t b64encode(const void *src, char *dst, size_t length) {
- return b64encode_internal(src, dst, length, base64_original);
+size_t b64encode_tinc(const void *src, char *dst, size_t length) {
+ return b64encode_tinc_internal(src, dst, length, base64_original);
}
-size_t b64encode_urlsafe(const void *src, char *dst, size_t length) {
- return b64encode_internal(src, dst, length, base64_urlsafe);
+size_t b64encode_tinc_urlsafe(const void *src, char *dst, size_t length) {
+ return b64encode_tinc_internal(src, dst, length, base64_urlsafe);
}
#ifdef HAVE_MINGW
#include "system.h"
+#define B64_SIZE(len) ((len) * 4 / 3 + 5)
+
extern size_t hex2bin(const char *src, void *dst, size_t length);
extern size_t bin2hex(const void *src, char *dst, size_t length);
-extern size_t b64encode(const void *src, char *dst, size_t length);
-extern size_t b64encode_urlsafe(const void *src, char *dst, size_t length);
-extern size_t b64decode(const char *src, void *dst, size_t length);
+extern size_t b64encode_tinc(const void *src, char *dst, size_t length);
+extern size_t b64encode_tinc_urlsafe(const void *src, char *dst, size_t length);
+extern size_t b64decode_tinc(const char *src, void *dst, size_t length);
#ifdef HAVE_MINGW
extern const char *winerror(int);