aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-23 08:35:38 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-23 08:35:38 +0000
commitc152d8bdaea04a9227a89ae6de51665545d300f6 (patch)
tree9430f57cf93e309b03097f26859808165d069ed0 /src/core
parent925dc5dabc3df7457f185eff6b5cb401cf7dc60c (diff)
downloadgnunet-c152d8bdaea04a9227a89ae6de51665545d300f6.tar.gz
gnunet-c152d8bdaea04a9227a89ae6de51665545d300f6.zip
-trying to fix amatus's KX issue
Diffstat (limited to 'src/core')
-rw-r--r--src/core/gnunet-service-core_kx.c71
-rw-r--r--src/core/test_core_defaults.conf3
2 files changed, 49 insertions, 25 deletions
diff --git a/src/core/gnunet-service-core_kx.c b/src/core/gnunet-service-core_kx.c
index d1990f8f4..f6b64f367 100644
--- a/src/core/gnunet-service-core_kx.c
+++ b/src/core/gnunet-service-core_kx.c
@@ -108,8 +108,7 @@ struct EphemeralKeyMessage
108 struct GNUNET_TIME_AbsoluteNBO expiration_time; 108 struct GNUNET_TIME_AbsoluteNBO expiration_time;
109 109
110 /** 110 /**
111 * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable 111 * Ephemeral public ECC key.
112 * for network transmission as created using 'gcry_sexp_sprint'.
113 */ 112 */
114 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; 113 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
115 114
@@ -308,6 +307,11 @@ struct GSC_KeyExchangeInfo
308 struct PingMessage ping; 307 struct PingMessage ping;
309 308
310 /** 309 /**
310 * Ephemeral public ECC key of the other peer.
311 */
312 struct GNUNET_CRYPTO_EcdhePublicKey other_ephemeral_key;
313
314 /**
311 * Key we use to encrypt our messages for the other peer 315 * Key we use to encrypt our messages for the other peer
312 * (initialized by us when we do the handshake). 316 * (initialized by us when we do the handshake).
313 */ 317 */
@@ -736,6 +740,41 @@ send_ping (struct GSC_KeyExchangeInfo *kx)
736 MIN_PING_FREQUENCY); 740 MIN_PING_FREQUENCY);
737} 741}
738 742
743
744/**
745 * Derive fresh session keys from the current ephemeral keys.
746 *
747 * @param kx session to derive keys for
748 */
749static void
750derive_session_keys (struct GSC_KeyExchangeInfo *kx)
751{
752 struct GNUNET_HashCode key_material;
753
754 if (GNUNET_OK !=
755 GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
756 &kx->other_ephemeral_key,
757 &key_material))
758 {
759 GNUNET_break (0);
760 return;
761 }
762 derive_aes_key (&GSC_my_identity,
763 &kx->peer,
764 &key_material,
765 &kx->encrypt_key);
766 derive_aes_key (&kx->peer,
767 &GSC_my_identity,
768 &key_material,
769 &kx->decrypt_key);
770 memset (&key_material, 0, sizeof (key_material));
771 /* fresh key, reset sequence numbers */
772 kx->last_sequence_number_received = 0;
773 kx->last_packets_bitmap = 0;
774 setup_fresh_ping (kx);
775}
776
777
739/** 778/**
740 * We received a SET_KEY message. Validate and update 779 * We received a SET_KEY message. Validate and update
741 * our key material and status. 780 * our key material and status.
@@ -753,7 +792,6 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
753 struct GNUNET_TIME_Absolute now; 792 struct GNUNET_TIME_Absolute now;
754 enum KxStateMachine sender_status; 793 enum KxStateMachine sender_status;
755 uint16_t size; 794 uint16_t size;
756 struct GNUNET_HashCode key_material;
757 795
758 size = ntohs (msg->size); 796 size = ntohs (msg->size);
759 if (sizeof (struct EphemeralKeyMessage) != size) 797 if (sizeof (struct EphemeralKeyMessage) != size)
@@ -815,30 +853,12 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
815 end_t.abs_value_us); 853 end_t.abs_value_us);
816 return; 854 return;
817 } 855 }
818 if (GNUNET_OK != 856 kx->other_ephemeral_key = m->ephemeral_key;
819 GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key, 857 kx->foreign_key_expires = end_t;
820 &m->ephemeral_key, 858 derive_session_keys (kx);
821 &key_material))
822 {
823 GNUNET_break (0);
824 return;
825 }
826 GNUNET_STATISTICS_update (GSC_stats, 859 GNUNET_STATISTICS_update (GSC_stats,
827 gettext_noop ("# EPHEMERAL_KEY messages decrypted"), 1, 860 gettext_noop ("# EPHEMERAL_KEY messages received"), 1,
828 GNUNET_NO); 861 GNUNET_NO);
829 derive_aes_key (&GSC_my_identity,
830 &kx->peer,
831 &key_material,
832 &kx->encrypt_key);
833 derive_aes_key (&kx->peer,
834 &GSC_my_identity,
835 &key_material,
836 &kx->decrypt_key);
837 /* fresh key, reset sequence numbers */
838 kx->last_sequence_number_received = 0;
839 kx->last_packets_bitmap = 0;
840 kx->foreign_key_expires = end_t;
841 setup_fresh_ping (kx);
842 862
843 /* check if we still need to send the sender our key */ 863 /* check if we still need to send the sender our key */
844 sender_status = (enum KxStateMachine) ntohl (m->sender_status); 864 sender_status = (enum KxStateMachine) ntohl (m->sender_status);
@@ -1533,6 +1553,7 @@ do_rekey (void *cls,
1533 for (pos = kx_head; NULL != pos; pos = pos->next) 1553 for (pos = kx_head; NULL != pos; pos = pos->next)
1534 { 1554 {
1535 pos->status = KX_STATE_REKEY_SENT; 1555 pos->status = KX_STATE_REKEY_SENT;
1556 derive_session_keys (pos);
1536 send_key (pos); 1557 send_key (pos);
1537 } 1558 }
1538} 1559}
diff --git a/src/core/test_core_defaults.conf b/src/core/test_core_defaults.conf
index b3e717d5b..587c47f1d 100644
--- a/src/core/test_core_defaults.conf
+++ b/src/core/test_core_defaults.conf
@@ -92,3 +92,6 @@ AUTOSTART = NO
92 92
93[namecache] 93[namecache]
94AUTOSTART = NO 94AUTOSTART = NO
95
96[set]
97AUTOSTART = NO