Add AES-256-GCM support to SPTPS.
[tinc] / src / protocol_key.c
1 /*
2     protocol_key.c -- handle the meta-protocol, key exchange
3     Copyright (C) 1999-2005 Ivo Timmermans,
4                   2000-2017 Guus Sliepen <guus@tinc-vpn.org>
5
6     This program is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License along
17     with this program; if not, write to the Free Software Foundation, Inc.,
18     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #include "system.h"
22
23 #include "cipher.h"
24 #include "connection.h"
25 #include "crypto.h"
26 #include "logger.h"
27 #include "net.h"
28 #include "netutl.h"
29 #include "node.h"
30 #include "protocol.h"
31 #include "route.h"
32 #include "sptps.h"
33 #include "utils.h"
34 #include "compression.h"
35 #include "random.h"
36 #include "xalloc.h"
37
38 void send_key_changed(void) {
39 #ifndef DISABLE_LEGACY
40         send_request(everyone, "%d %x %s", KEY_CHANGED, prng(UINT32_MAX), myself->name);
41
42         /* Immediately send new keys to directly connected nodes to keep UDP mappings alive */
43
44         for list_each(connection_t, c, &connection_list) {
45                 if(c->edge && c->node && c->node->status.reachable && !c->node->status.sptps) {
46                         send_ans_key(c->node);
47                 }
48         }
49
50 #endif
51
52         /* Force key exchange for connections using SPTPS */
53
54         if(experimental) {
55                 for splay_each(node_t, n, &node_tree) {
56                         if(n->status.reachable && n->status.validkey && n->status.sptps) {
57                                 sptps_force_kex(&n->sptps);
58                         }
59                 }
60         }
61 }
62
63 bool key_changed_h(connection_t *c, const char *request) {
64         char name[MAX_STRING_SIZE];
65         node_t *n;
66
67         if(sscanf(request, "%*d %*x " MAX_STRING, name) != 1) {
68                 logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "KEY_CHANGED",
69                        c->name, c->hostname);
70                 return false;
71         }
72
73         if(seen_request(request)) {
74                 return true;
75         }
76
77         n = lookup_node(name);
78
79         if(!n) {
80                 logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) origin %s which does not exist",
81                        "KEY_CHANGED", c->name, c->hostname, name);
82                 return true;
83         }
84
85         if(!n->status.sptps) {
86                 n->status.validkey = false;
87                 n->last_req_key = 0;
88         }
89
90         /* Tell the others */
91
92         if(!tunnelserver) {
93                 forward_request(c, request);
94         }
95
96         return true;
97 }
98
99 static bool send_sptps_data_myself(void *handle, uint8_t type, const void *data, size_t len) {
100         return send_sptps_data(handle, myself, type, data, len);
101 }
102
103 static bool send_initial_sptps_data(void *handle, uint8_t type, const void *data, size_t len) {
104         (void)type;
105         node_t *to = handle;
106         to->sptps.send_data = send_sptps_data_myself;
107
108         char *buf = alloca(B64_SIZE(len));
109         b64encode_tinc(data, buf, len);
110
111         return send_request(to->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, to->name, REQ_KEY, buf);
112 }
113
114 bool send_req_key(node_t *to) {
115         if(to->status.sptps) {
116                 if(!node_read_ecdsa_public_key(to)) {
117                         logger(DEBUG_PROTOCOL, LOG_DEBUG, "No Ed25519 key known for %s (%s)", to->name, to->hostname);
118                         send_request(to->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, to->name, REQ_PUBKEY);
119                         return true;
120                 }
121
122                 const size_t labellen = 25 + strlen(myself->name) + strlen(to->name);
123                 char *label = alloca(labellen);
124                 snprintf(label, labellen, "tinc UDP key expansion %s %s", myself->name, to->name);
125
126                 sptps_stop(&to->sptps);
127                 to->status.validkey = false;
128                 to->status.waitingforkey = true;
129                 to->last_req_key = now.tv_sec;
130                 to->incompression = myself->incompression;
131
132                 sptps_params_t params = {
133                         .handle = to,
134                         .initiator = true,
135                         .datagram = true,
136                         .mykey = myself->connection->ecdsa,
137                         .hiskey = to->ecdsa,
138                         .label = label,
139                         .labellen = sizeof(label),
140                         .send_data = send_initial_sptps_data,
141                         .receive_record = receive_sptps_record,
142                 };
143
144                 return sptps_start(&to->sptps, &params);
145         }
146
147         return send_request(to->nexthop->connection, "%d %s %s", REQ_KEY, myself->name, to->name);
148 }
149
150 /* REQ_KEY is overloaded to allow arbitrary requests to be routed between two nodes. */
151
152 static bool req_key_ext_h(connection_t *c, const char *request, node_t *from, node_t *to, int reqno) {
153         (void)c;
154
155         /* If this is a SPTPS packet, see if sending UDP info helps.
156            Note that we only do this if we're the destination or the static relay;
157            otherwise every hop would initiate its own UDP info message, resulting in elevated chatter. */
158         if((reqno == REQ_KEY || reqno == SPTPS_PACKET) && to->via == myself) {
159                 send_udp_info(myself, from);
160         }
161
162         if(reqno == SPTPS_PACKET) {
163                 /* This is a SPTPS data packet. */
164
165                 char buf[MAX_STRING_SIZE];
166                 size_t len;
167
168                 if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode_tinc(buf, buf, strlen(buf)))) {
169                         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");
170                         return true;
171                 }
172
173                 if(to != myself) {
174                         /* We don't just forward the request, because we want to use UDP if it's available. */
175                         if(forwarding_mode == FMODE_INTERNAL) {
176                                 send_sptps_data(to, from, 0, buf, len);
177                                 try_tx(to, true);
178                         }
179                 } else {
180                         /* The packet is for us */
181                         if(!sptps_receive_data(&from->sptps, buf, len)) {
182                                 /* Uh-oh. It might be that the tunnel is stuck in some corrupted state,
183                                    so let's restart SPTPS in case that helps. But don't do that too often
184                                    to prevent storms. */
185                                 if(from->last_req_key < now.tv_sec - 10) {
186                                         logger(DEBUG_PROTOCOL, LOG_ERR, "Failed to decode TCP packet from %s (%s), restarting SPTPS", from->name, from->hostname);
187                                         send_req_key(from);
188                                 }
189
190                                 return true;
191                         }
192
193                         send_mtu_info(myself, from, MTU);
194                 }
195
196                 return true;
197         }
198
199         /* Requests that are not SPTPS data packets are forwarded as-is. */
200
201         if(to != myself) {
202                 return send_request(to->nexthop->connection, "%s", request);
203         }
204
205         /* The request is for us */
206
207         switch(reqno) {
208         case REQ_PUBKEY: {
209                 if(!node_read_ecdsa_public_key(from)) {
210                         /* Request their key *before* we send our key back. Otherwise the first SPTPS packet from them will get dropped. */
211                         logger(DEBUG_PROTOCOL, LOG_DEBUG, "Preemptively requesting Ed25519 key for %s (%s)", from->name, from->hostname);
212                         send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, from->name, REQ_PUBKEY);
213                 }
214
215                 char *pubkey = ecdsa_get_base64_public_key(myself->connection->ecdsa);
216                 send_request(from->nexthop->connection, "%d %s %s %d %s", REQ_KEY, myself->name, from->name, ANS_PUBKEY, pubkey);
217                 free(pubkey);
218                 return true;
219         }
220
221         case ANS_PUBKEY: {
222                 if(node_read_ecdsa_public_key(from)) {
223                         logger(DEBUG_PROTOCOL, LOG_WARNING, "Got ANS_PUBKEY from %s (%s) even though we already have his pubkey", from->name, from->hostname);
224                         return true;
225                 }
226
227                 char pubkey[MAX_STRING_SIZE];
228
229                 if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, pubkey) != 1 || !(from->ecdsa = ecdsa_set_base64_public_key(pubkey))) {
230                         logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "ANS_PUBKEY", from->name, from->hostname, "invalid pubkey");
231                         return true;
232                 }
233
234                 logger(DEBUG_PROTOCOL, LOG_INFO, "Learned Ed25519 public key from %s (%s)", from->name, from->hostname);
235                 append_config_file(from->name, "Ed25519PublicKey", pubkey);
236                 return true;
237         }
238
239         case REQ_KEY: {
240                 if(!node_read_ecdsa_public_key(from)) {
241                         logger(DEBUG_PROTOCOL, LOG_DEBUG, "No Ed25519 key known for %s (%s)", from->name, from->hostname);
242                         send_request(from->nexthop->connection, "%d %s %s %d", REQ_KEY, myself->name, from->name, REQ_PUBKEY);
243                         return true;
244                 }
245
246                 if(from->sptps.label) {
247                         logger(DEBUG_ALWAYS, LOG_DEBUG, "Got REQ_KEY from %s while we already started a SPTPS session!", from->name);
248                 }
249
250                 char buf[MAX_STRING_SIZE];
251                 size_t len;
252
253                 if(sscanf(request, "%*d %*s %*s %*d " MAX_STRING, buf) != 1 || !(len = b64decode_tinc(buf, buf, strlen(buf)))) {
254                         logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_SPTPS_START", from->name, from->hostname, "invalid SPTPS data");
255                         return true;
256                 }
257
258                 const size_t labellen = 25 + strlen(from->name) + strlen(myself->name);
259                 char *label = alloca(labellen);
260                 snprintf(label, labellen, "tinc UDP key expansion %s %s", from->name, myself->name);
261                 sptps_stop(&from->sptps);
262                 from->status.validkey = false;
263                 from->status.waitingforkey = true;
264                 from->last_req_key = now.tv_sec;
265
266                 sptps_params_t params = {
267                         .handle = from,
268                         .initiator = false,
269                         .datagram = true,
270                         .mykey = myself->connection->ecdsa,
271                         .hiskey = from->ecdsa,
272                         .label = label,
273                         .labellen = sizeof(label),
274                         .send_data = send_sptps_data_myself,
275                         .receive_record = receive_sptps_record,
276                 };
277
278                 sptps_start(&from->sptps, &params);
279                 sptps_receive_data(&from->sptps, buf, len);
280                 send_mtu_info(myself, from, MTU);
281                 return true;
282         }
283
284         default:
285                 logger(DEBUG_ALWAYS, LOG_ERR, "Unknown extended REQ_KEY request from %s (%s): %s", from->name, from->hostname, request);
286                 return true;
287         }
288 }
289
290 bool req_key_h(connection_t *c, const char *request) {
291         char from_name[MAX_STRING_SIZE];
292         char to_name[MAX_STRING_SIZE];
293         node_t *from, *to;
294         int reqno = 0;
295
296         if(sscanf(request, "%*d " MAX_STRING " " MAX_STRING " %d", from_name, to_name, &reqno) < 2) {
297                 logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "REQ_KEY", c->name,
298                        c->hostname);
299                 return false;
300         }
301
302         if(!check_id(from_name) || !check_id(to_name)) {
303                 logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "REQ_KEY", c->name, c->hostname, "invalid name");
304                 return false;
305         }
306
307         from = lookup_node(from_name);
308
309         if(!from) {
310                 logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
311                        "REQ_KEY", c->name, c->hostname, from_name);
312                 return true;
313         }
314
315         to = lookup_node(to_name);
316
317         if(!to) {
318                 logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
319                        "REQ_KEY", c->name, c->hostname, to_name);
320                 return true;
321         }
322
323         /* Check if this key request is for us */
324
325         if(to == myself) {                      /* Yes */
326                 if(!from->status.reachable) {
327                         logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) origin %s which is not reachable",
328                                "REQ_KEY", c->name, c->hostname, from_name);
329                         return true;
330                 }
331
332                 /* Is this an extended REQ_KEY message? */
333                 if(experimental && reqno) {
334                         return req_key_ext_h(c, request, from, to, reqno);
335                 }
336
337                 /* No, just send our key back */
338                 send_ans_key(from);
339         } else {
340                 if(tunnelserver) {
341                         return true;
342                 }
343
344                 if(!to->status.reachable) {
345                         logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
346                                "REQ_KEY", c->name, c->hostname, to_name);
347                         return true;
348                 }
349
350                 /* Is this an extended REQ_KEY message? */
351                 if(experimental && reqno) {
352                         return req_key_ext_h(c, request, from, to, reqno);
353                 }
354
355                 send_request(to->nexthop->connection, "%s", request);
356         }
357
358         return true;
359 }
360
361 bool send_ans_key(node_t *to) {
362         if(to->status.sptps) {
363                 abort();
364         }
365
366 #ifdef DISABLE_LEGACY
367         return false;
368 #else
369         size_t keylen = myself->incipher ? cipher_keylength(myself->incipher) : 1;
370         size_t keyhexlen = HEX_SIZE(keylen);
371         char *key = alloca(keyhexlen);
372
373         randomize(key, keylen);
374
375         cipher_free(to->incipher);
376         to->incipher = NULL;
377
378         digest_free(to->indigest);
379         to->indigest = NULL;
380
381         if(myself->incipher) {
382                 to->incipher = cipher_alloc();
383
384                 if(!cipher_open_by_nid(to->incipher, cipher_get_nid(myself->incipher))) {
385                         abort();
386                 }
387
388                 if(!cipher_set_key(to->incipher, key, false)) {
389                         abort();
390                 }
391         }
392
393         if(myself->indigest) {
394                 to->indigest = digest_alloc();
395
396                 if(!digest_open_by_nid(to->indigest,
397                                        digest_get_nid(myself->indigest),
398                                        digest_length(myself->indigest))) {
399                         abort();
400                 }
401
402                 if(!digest_set_key(to->indigest, key, keylen)) {
403                         abort();
404                 }
405         }
406
407         to->incompression = myself->incompression;
408
409         bin2hex(key, key, keylen);
410
411         // Reset sequence number and late packet window
412         to->received_seqno = 0;
413         to->received = 0;
414
415         if(replaywin) {
416                 memset(to->late, 0, replaywin);
417         }
418
419         to->status.validkey_in = true;
420
421         bool sent = send_request(to->nexthop->connection, "%d %s %s %s %d %d %lu %d", ANS_KEY,
422                                  myself->name, to->name, key,
423                                  cipher_get_nid(to->incipher),
424                                  digest_get_nid(to->indigest),
425                                  (unsigned long)digest_length(to->indigest),
426                                  to->incompression);
427
428         memzero(key, keyhexlen);
429
430         return sent;
431 #endif
432 }
433
434 bool ans_key_h(connection_t *c, const char *request) {
435         char from_name[MAX_STRING_SIZE];
436         char to_name[MAX_STRING_SIZE];
437         char key[MAX_STRING_SIZE];
438         char address[MAX_STRING_SIZE] = "";
439         char port[MAX_STRING_SIZE] = "";
440         int cipher, digest;
441         unsigned long maclength;
442         int compression;
443         node_t *from, *to;
444
445         if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %lu %d "MAX_STRING" "MAX_STRING,
446                         from_name, to_name, key, &cipher, &digest, &maclength,
447                         &compression, address, port) < 7) {
448                 logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ANS_KEY", c->name,
449                        c->hostname);
450                 return false;
451         }
452
453         if(!check_id(from_name) || !check_id(to_name)) {
454                 logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s): %s", "ANS_KEY", c->name, c->hostname, "invalid name");
455                 return false;
456         }
457
458         from = lookup_node(from_name);
459
460         if(!from) {
461                 logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) origin %s which does not exist in our connection list",
462                        "ANS_KEY", c->name, c->hostname, from_name);
463                 return true;
464         }
465
466         to = lookup_node(to_name);
467
468         if(!to) {
469                 logger(DEBUG_ALWAYS, LOG_ERR, "Got %s from %s (%s) destination %s which does not exist in our connection list",
470                        "ANS_KEY", c->name, c->hostname, to_name);
471                 return true;
472         }
473
474         /* Forward it if necessary */
475
476         if(to != myself) {
477                 if(tunnelserver) {
478                         return true;
479                 }
480
481                 if(!to->status.reachable) {
482                         logger(DEBUG_ALWAYS, LOG_WARNING, "Got %s from %s (%s) destination %s which is not reachable",
483                                "ANS_KEY", c->name, c->hostname, to_name);
484                         return true;
485                 }
486
487                 if(!*address && from->address.sa.sa_family != AF_UNSPEC && to->minmtu) {
488                         char *address, *port;
489                         logger(DEBUG_PROTOCOL, LOG_DEBUG, "Appending reflexive UDP address to ANS_KEY from %s to %s", from->name, to->name);
490                         sockaddr2str(&from->address, &address, &port);
491                         send_request(to->nexthop->connection, "%s %s %s", request, address, port);
492                         free(address);
493                         free(port);
494                         return true;
495                 }
496
497                 return send_request(to->nexthop->connection, "%s", request);
498         }
499
500 #ifndef DISABLE_LEGACY
501         /* Don't use key material until every check has passed. */
502         cipher_free(from->outcipher);
503         from->outcipher = NULL;
504
505         digest_free(from->outdigest);
506         from->outdigest = NULL;
507 #endif
508
509         if(!from->status.sptps) {
510                 from->status.validkey = false;
511         }
512
513         switch(compression) {
514         case COMPRESS_LZ4:
515 #ifdef HAVE_LZ4
516                 break;
517 #else
518                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
519                 logger(DEBUG_ALWAYS, LOG_ERR, "LZ4 compression is unavailable on this node.");
520                 return true;
521 #endif
522
523         case COMPRESS_LZO_HI:
524         case COMPRESS_LZO_LO:
525 #ifdef HAVE_LZO
526                 break;
527 #else
528                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
529                 logger(DEBUG_ALWAYS, LOG_ERR, "LZO compression is unavailable on this node.");
530                 return true;
531 #endif
532
533         case COMPRESS_ZLIB_9:
534         case COMPRESS_ZLIB_8:
535         case COMPRESS_ZLIB_7:
536         case COMPRESS_ZLIB_6:
537         case COMPRESS_ZLIB_5:
538         case COMPRESS_ZLIB_4:
539         case COMPRESS_ZLIB_3:
540         case COMPRESS_ZLIB_2:
541         case COMPRESS_ZLIB_1:
542 #ifdef HAVE_ZLIB
543                 break;
544 #else
545                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
546                 logger(DEBUG_ALWAYS, LOG_ERR, "ZLIB compression is unavailable on this node.");
547                 return true;
548 #endif
549
550         case COMPRESS_NONE:
551                 break;
552
553         default:
554                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus compression level!", from->name, from->hostname);
555                 logger(DEBUG_ALWAYS, LOG_ERR, "Compression level %i is unrecognized by this node.", compression);
556                 return true;
557         }
558
559         from->outcompression = compression;
560
561         /* SPTPS or old-style key exchange? */
562
563         if(from->status.sptps) {
564                 const size_t buflen = strlen(key);
565                 uint8_t *buf = alloca(buflen);
566                 size_t len = b64decode_tinc(key, buf, buflen);
567
568                 if(!len || !sptps_receive_data(&from->sptps, buf, len)) {
569                         /* Uh-oh. It might be that the tunnel is stuck in some corrupted state,
570                            so let's restart SPTPS in case that helps. But don't do that too often
571                            to prevent storms.
572                            Note that simply relying on handshake timeout is not enough, because
573                            that doesn't apply to key regeneration. */
574                         if(from->last_req_key < now.tv_sec - 10) {
575                                 logger(DEBUG_PROTOCOL, LOG_ERR, "Failed to decode handshake TCP packet from %s (%s), restarting SPTPS", from->name, from->hostname);
576                                 send_req_key(from);
577                         }
578
579                         return true;
580                 }
581
582                 if(from->status.validkey) {
583                         if(*address && *port) {
584                                 logger(DEBUG_PROTOCOL, LOG_DEBUG, "Using reflexive UDP address from %s: %s port %s", from->name, address, port);
585                                 sockaddr_t sa = str2sockaddr(address, port);
586                                 update_node_udp(from, &sa);
587                         }
588                 }
589
590                 send_mtu_info(myself, from, MTU);
591
592                 return true;
593         }
594
595 #ifdef DISABLE_LEGACY
596         logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses legacy protocol!", from->name, from->hostname);
597         return false;
598 #else
599         /* Check and lookup cipher and digest algorithms */
600
601         if(cipher) {
602                 from->outcipher = cipher_alloc();
603
604                 if(!cipher_open_by_nid(from->outcipher, cipher)) {
605                         cipher_free(from->outcipher);
606                         from->outcipher = NULL;
607                         logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses unknown cipher!", from->name, from->hostname);
608                         return false;
609                 }
610         } else {
611                 from->outcipher = NULL;
612         }
613
614         if(digest) {
615                 from->outdigest = digest_alloc();
616
617                 if(!digest_open_by_nid(from->outdigest, digest, maclength)) {
618                         digest_free(from->outdigest);
619                         from->outdigest = NULL;
620                         logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses unknown digest!", from->name, from->hostname);
621                         return false;
622                 }
623         } else {
624                 from->outdigest = NULL;
625         }
626
627         if(maclength != digest_length(from->outdigest)) {
628                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses bogus MAC length!", from->name, from->hostname);
629                 return false;
630         }
631
632         /* Process key */
633
634         size_t keylen = hex2bin(key, key, sizeof(key));
635
636         if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) {
637                 logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
638                 return true;
639         }
640
641         /* Update our copy of the origin's packet key */
642
643         if(from->outcipher && !cipher_set_key(from->outcipher, key, true)) {
644                 return false;
645         }
646
647         if(from->outdigest && !digest_set_key(from->outdigest, key, keylen)) {
648                 return false;
649         }
650
651         from->status.validkey = true;
652         from->sent_seqno = 0;
653
654         if(*address && *port) {
655                 logger(DEBUG_PROTOCOL, LOG_DEBUG, "Using reflexive UDP address from %s: %s port %s", from->name, address, port);
656                 sockaddr_t sa = str2sockaddr(address, port);
657                 update_node_udp(from, &sa);
658         }
659
660         return true;
661 #endif
662 }