Move poly1305_get_tag() into poly1305.c, hide poly1305_init().
[tinc] / src / protocol_auth.c
index 211d908..6a7a919 100644 (file)
@@ -44,6 +44,7 @@
 #include "random.h"
 #include "compression.h"
 #include "proxy.h"
+#include "address_cache.h"
 
 #include "ed25519/sha512.h"
 #include "keys.h"
@@ -82,6 +83,7 @@ static bool send_proxyrequest(connection_t *c) {
        case PROXY_EXEC:
                return true;
 
+       case PROXY_NONE:
        default:
                logger(DEBUG_ALWAYS, LOG_ERR, "Unknown proxy type");
                return false;
@@ -94,7 +96,7 @@ bool send_id(connection_t *c) {
        int minor = 0;
 
        if(experimental) {
-               if(c->outgoing && !read_ecdsa_public_key(&c->ecdsa, &c->config_tree, c->name)) {
+               if(c->outgoing && !ecdsa_active(c->ecdsa) && !(c->ecdsa = read_ecdsa_public_key(&c->config_tree, c->name))) {
                        minor = 1;
                } else {
                        minor = myself->connection->protocol_minor;
@@ -138,6 +140,22 @@ static bool finalize_invitation(connection_t *c, const char *data, uint16_t len)
 
        logger(DEBUG_CONNECTIONS, LOG_INFO, "Key successfully received from %s (%s)", c->name, c->hostname);
 
+       if(!c->node) {
+               c->node = lookup_node(c->name);
+       }
+
+       if(!c->node) {
+               c->node = new_node(c->name);
+               c->node->connection = c;
+               node_add(c->node);
+       }
+
+       if(!c->node->address_cache) {
+               c->node->address_cache = open_address_cache(c->node);
+       }
+
+       add_recent_address(c->node->address_cache, &c->address);
+
        // Call invitation-accepted script
        environment_t env;
        char *address, *port;
@@ -341,7 +359,17 @@ bool id_h(connection_t *c, const char *request) {
 
                c->protocol_minor = 2;
 
-               return sptps_start(&c->sptps, c, false, false, invitation_key, c->ecdsa, "tinc invitation", 15, send_meta_sptps, receive_invitation_sptps);
+               sptps_params_t params = {
+                       .handle = c,
+                       .initiator = false,
+                       .mykey = invitation_key,
+                       .hiskey = c->ecdsa,
+                       .label = "tinc invitation",
+                       .send_data = send_meta_sptps,
+                       .receive_record = receive_invitation_sptps,
+               };
+
+               return sptps_start(&c->sptps, &params);
        }
 
        /* Check if identity is a valid name */
@@ -399,8 +427,8 @@ bool id_h(connection_t *c, const char *request) {
                        return false;
                }
 
-               if(experimental) {
-                       read_ecdsa_public_key(&c->ecdsa, &c->config_tree, c->name);
+               if(experimental && !ecdsa_active(c->ecdsa)) {
+                       c->ecdsa = read_ecdsa_public_key(&c->config_tree, c->name);
                }
 
                /* Ignore failures if no key known yet */
@@ -436,7 +464,18 @@ bool id_h(connection_t *c, const char *request) {
                        snprintf(label, labellen, "tinc TCP key expansion %s %s", c->name, myself->name);
                }
 
-               return sptps_start(&c->sptps, c, c->outgoing, false, myself->connection->ecdsa, c->ecdsa, label, labellen, send_meta_sptps, receive_meta_sptps);
+               sptps_params_t params = {
+                       .handle = c,
+                       .initiator = c->outgoing,
+                       .mykey = myself->connection->ecdsa,
+                       .hiskey = c->ecdsa,
+                       .label = label,
+                       .labellen = sizeof(label),
+                       .send_data = send_meta_sptps,
+                       .receive_record = receive_meta_sptps,
+               };
+
+               return sptps_start(&c->sptps, &params);
        } else {
                return send_metakey(c);
        }
@@ -880,7 +919,7 @@ static bool upgrade_h(connection_t *c, const char *request) {
                return false;
        }
 
-       if(ecdsa_active(c->ecdsa) || read_ecdsa_public_key(&c->ecdsa, &c->config_tree, c->name)) {
+       if(ecdsa_active(c->ecdsa) || (c->ecdsa = read_ecdsa_public_key(&c->config_tree, c->name))) {
                char *knownkey = ecdsa_get_base64_public_key(c->ecdsa);
                bool different = strcmp(knownkey, pubkey);
                free(knownkey);
@@ -935,8 +974,7 @@ bool ack_h(connection_t *c, const char *request) {
        n = lookup_node(c->name);
 
        if(!n) {
-               n = new_node();
-               n->name = xstrdup(c->name);
+               n = new_node(c->name);
                node_add(n);
        } else {
                if(n->connection) {