Check validity of Ed25519 key during an upgrade.
[tinc] / src / protocol_auth.c
index b8d4ee8..be90d92 100644 (file)
@@ -379,8 +379,8 @@ bool id_h(connection_t *c, const char *request) {
                }
 
                if(experimental)
-                       if(!read_ecdsa_public_key(c))
-                               return false;
+                       read_ecdsa_public_key(c);
+                       /* Ignore failures if no key known yet */
        } else {
                if(c->protocol_minor && !ecdsa_active(c->ecdsa))
                        c->protocol_minor = 1;
@@ -730,6 +730,12 @@ static bool upgrade_h(connection_t *c, const char *request) {
                return false;
        }
 
+       c->ecdsa = ecdsa_set_base64_public_key(pubkey);
+       if(!c->ecdsa) {
+               logger(DEBUG_ALWAYS, LOG_INFO, "Got bad Ed25519 public key from %s (%s), not upgrading.", c->name, c->hostname);
+               return false;
+       }
+
        logger(DEBUG_ALWAYS, LOG_INFO, "Got Ed25519 public key from %s (%s), upgrading!", c->name, c->hostname);
        append_config_file(c->name, "Ed25519PublicKey", pubkey);
        c->allow_request = TERMREQ;
@@ -805,7 +811,6 @@ bool ack_h(connection_t *c, const char *request) {
        /* Activate this connection */
 
        c->allow_request = ALL;
-       c->status.active = true;
 
        logger(DEBUG_CONNECTIONS, LOG_NOTICE, "Connection with %s (%s) activated", c->name,
                           c->hostname);
@@ -822,6 +827,16 @@ bool ack_h(connection_t *c, const char *request) {
        sockaddr2str(&c->address, &hisaddress, NULL);
        c->edge->address = str2sockaddr(hisaddress, hisport);
        free(hisaddress);
+       sockaddr_t local_sa;
+       socklen_t local_salen = sizeof local_sa;
+       if (getsockname(c->socket, &local_sa.sa, &local_salen) < 0)
+               logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get local socket address for connection with %s", c->name);
+       else {
+               char *local_address;
+               sockaddr2str(&local_sa, &local_address, NULL);
+               c->edge->local_address = str2sockaddr(local_address, myport);
+               free(local_address);
+       }
        c->edge->weight = (weight + c->estimated_weight) / 2;
        c->edge->connection = c;
        c->edge->options = c->options;