]> git.meshlink.io Git - meshlink/commitdiff
Allow sptps_force_kex() while a key exchange is in progress
authorGuus Sliepen <guus@meshlink.io>
Thu, 10 Sep 2020 21:13:39 +0000 (23:13 +0200)
committerGuus Sliepen <guus@meshlink.io>
Thu, 10 Sep 2020 21:13:39 +0000 (23:13 +0200)
We should not do anything if we are already exchanging a new key, and
just return true. This change prevents higher layers in MeshLink from
terminating a connection between two nodes if both peers call
sptps_force_kex() at nearly the same time.

src/sptps.c

index ed1f67ff95afd11ac1adfd6f6b95edcca72bf7de..267a47f1f30f2484cbab4a6830f2bff06f4ebd0f 100644 (file)
@@ -374,10 +374,15 @@ static bool receive_sig(sptps_t *s, const char *data, uint16_t len) {
 
 // Force another Key EXchange (for testing purposes).
 bool sptps_force_kex(sptps_t *s) {
 
 // Force another Key EXchange (for testing purposes).
 bool sptps_force_kex(sptps_t *s) {
-       if(!s->outstate || s->state != SPTPS_SECONDARY_KEX) {
+       if(!s->outstate || s->state < SPTPS_SECONDARY_KEX) {
                return error(s, EINVAL, "Cannot force KEX in current state");
        }
 
                return error(s, EINVAL, "Cannot force KEX in current state");
        }
 
+       if(s->state > SPTPS_SECONDARY_KEX) {
+               // We are already in the middle of a secondary key exchange
+               return true;
+       }
+
        s->state = SPTPS_KEX;
        return send_kex(s);
 }
        s->state = SPTPS_KEX;
        return send_kex(s);
 }