From: Kirill Isakov Date: Tue, 17 Aug 2021 18:30:01 +0000 (+0600) Subject: Rename base64 funcs to show they're not RFC-compliant. X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=b2701c7c54b11cda71461c5dbbc985476bf5b221 Rename base64 funcs to show they're not RFC-compliant. --- diff --git a/src/ed25519/ecdsa.c b/src/ed25519/ecdsa.c index 8dee1246..0e80d910 100644 --- a/src/ed25519/ecdsa.c +++ b/src/ed25519/ecdsa.c @@ -43,7 +43,7 @@ ecdsa_t *ecdsa_set_base64_public_key(const char *p) { } 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); @@ -56,7 +56,7 @@ ecdsa_t *ecdsa_set_base64_public_key(const char *p) { 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; } @@ -88,7 +88,7 @@ static bool read_pem(FILE *fp, const char *type, void *vbuf, size_t size) { } 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"); diff --git a/src/ed25519/ecdsagen.c b/src/ed25519/ecdsagen.c index ede51367..06b41c86 100644 --- a/src/ed25519/ecdsagen.c +++ b/src/ed25519/ecdsagen.c @@ -54,7 +54,7 @@ static bool write_pem(FILE *fp, const char *type, void *vbuf, size_t size) { 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; diff --git a/src/invitation.c b/src/invitation.c index 2163d6fe..e70a0ec8 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -448,7 +448,7 @@ int cmd_invite(int argc, char *argv[]) { 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); @@ -462,11 +462,11 @@ int cmd_invite(int argc, char *argv[]) { 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); @@ -1230,7 +1230,7 @@ int cmd_join(int argc, char *argv[]) { 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; } diff --git a/src/net_packet.c b/src/net_packet.c index 7bb182db..24ebdff8 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -967,8 +967,8 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ 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; diff --git a/src/protocol_auth.c b/src/protocol_auth.c index d4bb4074..12dc144a 100644 --- a/src/protocol_auth.c +++ b/src/protocol_auth.c @@ -246,7 +246,7 @@ static bool receive_invitation_sptps(void *handle, uint8_t type, const void *dat 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]; diff --git a/src/protocol_key.c b/src/protocol_key.c index f045009f..4398e528 100644 --- a/src/protocol_key.c +++ b/src/protocol_key.c @@ -102,9 +102,9 @@ static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data (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); } @@ -148,7 +148,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no 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; } @@ -233,7 +233,7 @@ static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, no 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; } @@ -520,7 +520,7 @@ bool ans_key_h(connection_t *c, const char *request) { 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, diff --git a/src/tincctl.c b/src/tincctl.c index ef29c992..a1446369 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -1100,7 +1100,7 @@ static int dump_invitations(void) { 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; } @@ -2802,7 +2802,7 @@ static int cmd_sign(int argc, char *argv[]) { return 1; } - b64encode(sig, sig, 64); + b64encode_tinc(sig, sig, 64); ecdsa_free(key); fprintf(stdout, "Signature = %s %ld %s\n", name, t, sig); @@ -2936,7 +2936,7 @@ static int cmd_verify(int argc, char *argv[]) { 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); diff --git a/src/utils.c b/src/utils.c index 57983241..6104fada 100644 --- a/src/utils.c +++ b/src/utils.c @@ -79,7 +79,7 @@ size_t bin2hex(const void *vsrc, char *dst, size_t length) { 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; @@ -119,7 +119,7 @@ size_t b64decode(const char *src, void *dst, size_t length) { } } -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; @@ -168,12 +168,12 @@ static size_t b64encode_internal(const void *src, char *dst, size_t length, cons 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 diff --git a/src/utils.h b/src/utils.h index a966adb1..10de2d41 100644 --- a/src/utils.h +++ b/src/utils.h @@ -23,12 +23,14 @@ #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);