gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 01/09: Changed creation of key for kx to be for every notificat


From: gnunet
Subject: [gnunet] 01/09: Changed creation of key for kx to be for every notification of transport about a new connected peer.
Date: Wed, 10 Jan 2024 11:59:58 +0100

This is an automated email from the git hooks/post-receive script.

t3sserakt pushed a commit to branch master
in repository gnunet.

commit a54d28cd8a4550a5e8345038d451cfd2b936fbba
Author: t3sserakt <t3ss@posteo.de>
AuthorDate: Wed Jan 10 11:04:55 2024 +0100

    Changed creation of key for kx to be for every notification of transport 
about a new connected peer.
---
 src/service/core/gnunet-service-core_kx.c | 106 ++++++++++++++++++++----------
 1 file changed, 71 insertions(+), 35 deletions(-)

diff --git a/src/service/core/gnunet-service-core_kx.c 
b/src/service/core/gnunet-service-core_kx.c
index ca7bccbd9..440c88ca3 100644
--- a/src/service/core/gnunet-service-core_kx.c
+++ b/src/service/core/gnunet-service-core_kx.c
@@ -693,6 +693,14 @@ deliver_message (void *cls, const struct 
GNUNET_MessageHeader *m)
 }
 
 
+static void
+do_rekey (void *cls);
+
+
+static void
+sign_ephemeral_key ();
+
+
 /**
  * Function called by transport to notify us that
  * a peer connected to us (on the network level).
@@ -718,33 +726,66 @@ handle_transport_notify_connect (void *cls,
                             gettext_noop ("# key exchanges initiated"),
                             1,
                             GNUNET_NO);
-  kx = GNUNET_new (struct GSC_KeyExchangeInfo);
-  kx->mst = GNUNET_MST_create (&deliver_message, kx);
-  kx->mq = mq;
-  kx->peer = pid;
-  kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
-  GNUNET_CONTAINER_DLL_insert (kx_head, kx_tail, kx);
-  kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
-  monitor_notify_all (kx);
-  GNUNET_CRYPTO_hash (pid, sizeof(struct GNUNET_PeerIdentity), &h1);
-  GNUNET_CRYPTO_hash (&GSC_my_identity,
-                      sizeof(struct GNUNET_PeerIdentity),
-                      &h2);
-  if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2))
+  for (kx = kx_head; NULL != kx; kx = kx->next)
   {
-    /* peer with "lower" identity starts KX, otherwise we typically end up
-       with both peers starting the exchange and transmit the 'set key'
-       message twice */
-    send_key (kx);
+    if (0 == memcmp (pid, kx->peer, sizeof(struct GNUNET_PeerIdentity)))
+      break;
+  }
+  if (NULL == kx)
+  {
+    GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key);
+    sign_ephemeral_key ();
+    {
+      struct GNUNET_HashCode eh;
+
+      GNUNET_CRYPTO_hash (&current_ekm.ephemeral_key,
+                          sizeof(current_ekm.ephemeral_key),
+                          &eh);
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  "Starting with ephemeral key %s\n",
+                  GNUNET_h2s (&eh));
+    }
+    kx = GNUNET_new (struct GSC_KeyExchangeInfo);
+    kx->mst = GNUNET_MST_create (&deliver_message, kx);
+    kx->mq = mq;
+    kx->peer = pid;
+    kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
+    GNUNET_CONTAINER_DLL_insert (kx_head, kx_tail, kx);
+    kx->status = GNUNET_CORE_KX_STATE_KEY_SENT;
+    monitor_notify_all (kx);
+    GNUNET_CRYPTO_hash (pid, sizeof(struct GNUNET_PeerIdentity), &h1);
+    GNUNET_CRYPTO_hash (&GSC_my_identity,
+                        sizeof(struct GNUNET_PeerIdentity),
+                        &h2);
+    if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2))
+      {
+        /* peer with "lower" identity starts KX, otherwise we typically end up
+           with both peers starting the exchange and transmit the 'set key'
+           message twice */
+        send_key (kx);
+      }
+    else
+      {
+        /* peer with "higher" identity starts a delayed KX, if the "lower" peer
+         * does not start a KX since it sees no reasons to do so  */
+        kx->retry_set_key_task =
+          GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
+                                        &set_key_retry_task,
+                                        kx);
+      }
   }
   else
   {
-    /* peer with "higher" identity starts a delayed KX, if the "lower" peer
-     * does not start a KX since it sees no reasons to do so  */
-    kx->retry_set_key_task =
-      GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
-                                    &set_key_retry_task,
-                                    kx);
+    struct GNUNET_TIME_Relative left;
+
+    left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
+    if (0 == left.rel_value_us)
+    {
+      kx->status = GNUNET_CORE_KX_STATE_DOWN;
+    }
+    else
+      kx->status = GNUNET_CORE_KX_STATE_REKEY_SENT;
+    do_rekey (NULL);
   }
   return kx;
 }
@@ -1754,6 +1795,12 @@ do_rekey (void *cls)
 {
   struct GSC_KeyExchangeInfo *pos;
 
+  (void *) cls;
+  if (NULL != rekey_task)
+  {
+    GNUNET_SCHEDULER_cancel (rekey_task);
+    rekey_task = NULL;
+  }
   rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL);
   GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key);
   sign_ephemeral_key ();
@@ -1816,18 +1863,7 @@ GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
   my_private_key = *pk;
   GNUNET_CRYPTO_eddsa_key_get_public (&my_private_key,
                                       &GSC_my_identity.public_key);
-  GNUNET_CRYPTO_ecdhe_key_create (&my_ephemeral_key);
-  sign_ephemeral_key ();
-  {
-    struct GNUNET_HashCode eh;
-
-    GNUNET_CRYPTO_hash (&current_ekm.ephemeral_key,
-                        sizeof(current_ekm.ephemeral_key),
-                        &eh);
-    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-                "Starting with ephemeral key %s\n",
-                GNUNET_h2s (&eh));
-  }
+  
 
   nc = GNUNET_notification_context_create (1);
   rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY, &do_rekey, NULL);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]