GNUnet 0.22.2
gnunet-service-core_kx.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009-2013, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
31#include "gnunet-service-core.h"
32#include "gnunet_constants.h"
33#include "gnunet_signatures.h"
34#include "gnunet_protocols.h"
35
39#define DEBUG_KX 0
40
41
45#define INITIAL_SET_KEY_RETRY_FREQUENCY \
46 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
47
51#define MIN_PING_FREQUENCY \
52 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
53
57#define REKEY_FREQUENCY \
58 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
59
63#define REKEY_TOLERANCE \
64 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
65
73#define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS
74
75
76#if CONG_CRYPTO_ENABLED
78
84{
89
93 unsigned char nonce[crypto_aead_xchacha20poly1305_ietf_NPUBBYTES];
94
103 unsigned char tag[crypto_aead_xchacha20poly1305_ietf_ABYTES];
104
110
114 uint32_t reserved GNUNET_PACKED;
115
121};
123
124#else
125
127
133{
138
143
152
158
163
169};
171
172#endif
173
178#define ENCRYPTED_HEADER_SIZE \
179 (offsetof (struct EncryptedMessage, sequence_number))
180
181
186{
191
196
201
206
211
216
221
222#if CONG_CRYPTO_ENABLED
227 unsigned char encrypt_key[crypto_aead_xchacha20poly1305_ietf_KEYBYTES];
228
233 unsigned char decrypt_key[crypto_aead_xchacha20poly1305_ietf_KEYBYTES];
234#else
240
246#endif
247
252
257
262
267
272
277
284
289
294
299
304
309};
310
311
316
321
326
331
336
341
347
352
353#if ! CONG_CRYPTO_ENABLED
359static uint32_t
361{
362 /* Note: may want to make this non-random and instead
363 derive from key material to avoid having an undetectable
364 side-channel */
365 return htonl (
367}
368
369
370#endif
371
377static void
379{
381
383 msg.header.size = htons (sizeof(msg));
384 msg.state = htonl ((uint32_t) kx->status);
385 msg.peer = *kx->peer;
386 msg.timeout = GNUNET_TIME_absolute_hton (kx->timeout);
389}
390
391
392#if ! CONG_CRYPTO_ENABLED
400static void
402 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
403 uint32_t seed)
404{
405 static const char ctx[] = "authentication key";
406
407#if DEBUG_KX
408 struct GNUNET_HashCode sh;
409
410 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
412 "Deriving Auth key from SKEY %s and seed %u\n",
413 GNUNET_h2s (&sh),
414 (unsigned int) seed);
415#endif
417 skey,
418 &seed,
419 sizeof(seed),
420 skey,
421 sizeof(
423 ctx,
424 sizeof(ctx),
425 NULL);
426}
427
428
437static void
439 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
440 uint32_t seed,
441 const struct GNUNET_PeerIdentity *identity)
442{
443 static const char ctx[] = "initialization vector";
444
445#if DEBUG_KX
446 struct GNUNET_HashCode sh;
447
448 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
450 "Deriving IV from SKEY %s and seed %u for peer %s\n",
451 GNUNET_h2s (&sh),
452 (unsigned int) seed,
454#endif
456 skey,
457 &seed,
458 sizeof(seed),
459 identity,
460 sizeof(struct GNUNET_PeerIdentity),
461 ctx,
462 sizeof(ctx),
463 NULL);
464}
465
466
476static void
478 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
479 uint32_t seed,
480 uint32_t challenge,
481 const struct GNUNET_PeerIdentity *identity)
482{
483 static const char ctx[] = "pong initialization vector";
484
485#if DEBUG_KX
486 struct GNUNET_HashCode sh;
487
488 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
490 "Deriving PONG IV from SKEY %s and seed %u/%u for %s\n",
491 GNUNET_h2s (&sh),
492 (unsigned int) seed,
493 (unsigned int) challenge,
495#endif
497 skey,
498 &seed,
499 sizeof(seed),
500 identity,
501 sizeof(struct GNUNET_PeerIdentity),
502 &challenge,
503 sizeof(challenge),
504 ctx,
505 sizeof(ctx),
506 NULL);
507}
508
509
510#endif
511
512
513#if CONG_CRYPTO_ENABLED
522static void
523derive_symmetric_key (const struct GNUNET_PeerIdentity *sender,
524 const struct GNUNET_PeerIdentity *receiver,
525 const struct GNUNET_HashCode *key_material,
526 unsigned char *skey)
527{
528 static const char ctx[] = "xchacha20 key generation vector";
529
530#if DEBUG_KX
532 "Deriving XChaCha20 Key for %s to %s from %s\n",
533 GNUNET_i2s (sender),
535 GNUNET_h2s (key_material));
536#endif
537 GNUNET_CRYPTO_kdf (skey,
538 crypto_aead_xchacha20poly1305_ietf_KEYBYTES,
539 ctx,
540 sizeof(ctx),
541 key_material,
542 sizeof(struct GNUNET_HashCode),
543 sender,
544 sizeof(struct GNUNET_PeerIdentity),
545 receiver,
546 sizeof(struct GNUNET_PeerIdentity),
547 NULL);
548}
549
550
551#else
552
561static void
563 const struct GNUNET_PeerIdentity *receiver,
564 const struct GNUNET_HashCode *key_material,
566{
567 static const char ctx[] = "aes key generation vector";
568
569#if DEBUG_KX
570 struct GNUNET_HashCode sh;
571
572 GNUNET_CRYPTO_hash (skey, sizeof(*skey), &sh);
574 "Deriving AES Keys for %s to %s from %s\n",
575 GNUNET_i2s (sender),
577 GNUNET_h2s (key_material));
578#endif
579 GNUNET_CRYPTO_kdf (skey,
581 ctx,
582 sizeof(ctx),
583 key_material,
584 sizeof(struct GNUNET_HashCode),
585 sender,
586 sizeof(struct GNUNET_PeerIdentity),
587 receiver,
588 sizeof(struct GNUNET_PeerIdentity),
589 NULL);
590}
591
592
593#endif
594
595#if ! CONG_CRYPTO_ENABLED
608static int
611 const void *in,
612 void *out,
613 size_t size)
614{
615 if (size != (uint16_t) size)
616 {
617 GNUNET_break (0);
618 return GNUNET_NO;
619 }
621 (uint16_t) size,
622 &kx->encrypt_key,
623 iv,
624 out));
626 gettext_noop ("# bytes encrypted"),
627 size,
628 GNUNET_NO);
629 /* the following is too sensitive to write to log files by accident,
630 so we require manual intervention to get this one... */
631#if DEBUG_KX
633 "Encrypted %u bytes for `%s' using key %s, IV %u\n",
634 (unsigned int) size,
635 GNUNET_i2s (kx->peer),
637 GNUNET_CRYPTO_crc32_n (iv, sizeof(iv)));
638#endif
639 return GNUNET_OK;
640}
641
642
643#endif
644
645#if ! CONG_CRYPTO_ENABLED
658static int
661 const void *in,
662 void *out,
663 size_t size)
664{
665 if (size != (uint16_t) size)
666 {
667 GNUNET_break (0);
668 return GNUNET_NO;
669 }
673 {
674 GNUNET_break_op (0);
675 return GNUNET_SYSERR;
676 }
678 (uint16_t) size,
679 &kx->decrypt_key,
680 iv,
681 out))
682 {
683 GNUNET_break (0);
684 return GNUNET_SYSERR;
685 }
687 gettext_noop ("# bytes decrypted"),
688 size,
689 GNUNET_NO);
690 /* the following is too sensitive to write to log files by accident,
691 so we require manual intervention to get this one... */
692#if DEBUG_KX
694 "Decrypted %u bytes from `%s' using key %s, IV %u\n",
695 (unsigned int) size,
696 GNUNET_i2s (kx->peer),
698 GNUNET_CRYPTO_crc32_n (iv, sizeof(*iv)));
699#endif
700 return GNUNET_OK;
701}
702
703
704#endif
705
711static void
712send_key (struct GSC_KeyExchangeInfo *kx);
713
714
720static void
722{
723 struct GSC_KeyExchangeInfo *kx = cls;
724
725 kx->retry_set_key_task = NULL;
729 send_key (kx);
730}
731
732
738static void
740{
741 struct PingMessage pp;
742 struct PingMessage *pm;
743
744 pm = &kx->ping;
745 kx->ping_challenge =
747 pm->header.size = htons (sizeof(struct PingMessage));
748 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
749 pp.challenge = kx->ping_challenge;
750 pp.target = *kx->peer;
751#if CONG_CRYPTO_ENABLED
752 randombytes_buf (pm->nonce, sizeof (pm->nonce));
753 GNUNET_assert (0 ==
754 crypto_aead_xchacha20poly1305_ietf_encrypt_detached (
755 (unsigned char*) &pm->target,
756 pm->tag,
757 NULL,
758 (unsigned char*) &pp.target,
759 sizeof(pp.target) + sizeof (pp.challenge),
760 NULL, 0,
761 NULL,
762 pm->nonce,
763 kx->encrypt_key));
764#else
765 {
767 pm->iv_seed = calculate_seed (kx);
768 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, kx->peer);
769 do_encrypt (kx,
770 &iv,
771 &pp.target,
772 &pm->target,
773 sizeof(struct PingMessage)
774 - ((void *) &pm->target - (void *) pm));
775 }
776#endif
777}
778
779
791static int
792deliver_message (void *cls, const struct GNUNET_MessageHeader *m)
793{
794 struct GSC_KeyExchangeInfo *kx = cls;
795
797 "Decrypted message of type %d from %s\n",
798 ntohs (m->type),
799 GNUNET_i2s (kx->peer));
801 {
803 gettext_noop ("# PAYLOAD dropped (out of order)"),
804 1,
805 GNUNET_NO);
806 return GNUNET_OK;
807 }
808 switch (ntohs (m->type))
809 {
813 return GNUNET_OK;
814
817 return GNUNET_OK;
818
819 default:
821 m,
822 ntohs (m->size),
825 m,
826 sizeof(struct GNUNET_MessageHeader),
828 }
829 return GNUNET_OK;
830}
831
832
842static void *
844 const struct GNUNET_PeerIdentity *pid,
845 struct GNUNET_MQ_Handle *mq)
846{
847 struct GSC_KeyExchangeInfo *kx;
848 struct GNUNET_HashCode h1;
849 struct GNUNET_HashCode h2;
850
852 "Initiating key exchange with `%s'\n",
853 GNUNET_i2s (pid));
855 gettext_noop ("# key exchanges initiated"),
856 1,
857 GNUNET_NO);
858
859 kx = GNUNET_new (struct GSC_KeyExchangeInfo);
861 kx->mq = mq;
862 kx->peer = pid;
867 GNUNET_CRYPTO_hash (pid, sizeof(struct GNUNET_PeerIdentity), &h1);
869 sizeof(struct GNUNET_PeerIdentity),
870 &h2);
871 if (0 < GNUNET_CRYPTO_hash_cmp (&h1, &h2))
872 {
873 /* peer with "lower" identity starts KX, otherwise we typically end up
874 with both peers starting the exchange and transmit the 'set key'
875 message twice */
876 send_key (kx);
877 }
878 else
879 {
880 /* peer with "higher" identity starts a delayed KX, if the "lower" peer
881 * does not start a KX since it sees no reasons to do so */
885 kx);
886 }
887 return kx;
888}
889
890
900static void
902 const struct GNUNET_PeerIdentity *peer,
903 void *handler_cls)
904{
905 struct GSC_KeyExchangeInfo *kx = handler_cls;
906
908 "Peer `%s' disconnected from us.\n",
909 GNUNET_i2s (peer));
912 gettext_noop ("# key exchanges stopped"),
913 1,
914 GNUNET_NO);
915 if (NULL != kx->retry_set_key_task)
916 {
918 kx->retry_set_key_task = NULL;
919 }
920 if (NULL != kx->keep_alive_task)
921 {
923 kx->keep_alive_task = NULL;
924 }
929 GNUNET_free (kx);
930}
931
932
938static void
940{
941 struct GNUNET_MQ_Envelope *env;
942
944 gettext_noop ("# PING messages transmitted"),
945 1,
946 GNUNET_NO);
948 GNUNET_MQ_send (kx->mq, env);
949}
950
951
957static void
959{
960 struct GNUNET_HashCode key_material;
961
962 if (GNUNET_OK !=
965 &key_material))
966 {
967 GNUNET_break (0);
968 return;
969 }
970#if CONG_CRYPTO_ENABLED
971 derive_symmetric_key (&GSC_my_identity, kx->peer, &key_material, kx->
972 encrypt_key);
973 derive_symmetric_key (kx->peer, &GSC_my_identity, &key_material, kx->
974 decrypt_key);
975#else
976 derive_aes_key (&GSC_my_identity, kx->peer, &key_material, &kx->
977 encrypt_key);
978 derive_aes_key (kx->peer, &GSC_my_identity, &key_material, &kx->
979 decrypt_key);
980#endif
981 memset (&key_material, 0, sizeof(key_material));
982 /* fresh key, reset sequence numbers */
984 kx->last_packets_bitmap = 0;
985 setup_fresh_ping (kx);
986}
987
988
996static void
998{
999 struct GSC_KeyExchangeInfo *kx = cls;
1000 struct GNUNET_TIME_Absolute start_t;
1001 struct GNUNET_TIME_Absolute end_t;
1002 struct GNUNET_TIME_Absolute now;
1003 enum GNUNET_CORE_KxState sender_status;
1004 enum GNUNET_GenericReturnValue do_verify = GNUNET_YES;
1005
1006 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
1011 {
1013 gettext_noop ("# old ephemeral keys ignored"),
1014 1,
1015 GNUNET_NO);
1017 "Received expired EPHEMERAL_KEY from %s\n",
1018 GNUNET_i2s (&m->origin_identity));
1019 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1020 return;
1021 }
1022 if (0 == memcmp (&m->ephemeral_key,
1024 sizeof(m->ephemeral_key)))
1025 {
1027 gettext_noop (
1028 "# duplicate ephemeral keys. Not verifying."),
1029 1,
1030 GNUNET_NO);
1032 "Duplicate EPHEMERAL_KEY from %s, do not verify\n",
1033 GNUNET_i2s (&m->origin_identity));
1034 do_verify = GNUNET_NO;
1035 }
1036 if (0 != memcmp (&m->origin_identity,
1037 kx->peer,
1038 sizeof(struct GNUNET_PeerIdentity)))
1039 {
1041 "Received EPHEMERAL_KEY from %s, but expected %s\n",
1042 GNUNET_i2s (&m->origin_identity),
1043 GNUNET_i2s_full (kx->peer));
1044 GNUNET_break_op (0);
1045 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1046 return;
1047 }
1048 if (do_verify && ((ntohl (m->purpose.size) !=
1050 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1051 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1052 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)
1053 + sizeof(struct GNUNET_CRYPTO_EddsaPublicKey)) ||
1054 (GNUNET_OK !=
1057 &m->purpose,
1058 &m->signature,
1059 &m->origin_identity.public_key
1060 ))))
1061 {
1062 /* invalid signature */
1063 GNUNET_break_op (0);
1065 gettext_noop (
1066 "# EPHEMERAL_KEYs rejected (bad signature)"),
1067 1,
1068 GNUNET_NO);
1070 "Received EPHEMERAL_KEY from %s with bad signature\n",
1071 GNUNET_i2s (&m->origin_identity));
1072 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1073 return;
1074 }
1075 now = GNUNET_TIME_absolute_get ();
1076 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
1077 if ((end_t.abs_value_us <
1079 (start_t.abs_value_us >
1081 {
1082 GNUNET_log (
1084 _ (
1085 "EPHEMERAL_KEY from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
1086 GNUNET_i2s (kx->peer),
1087 (unsigned long long) now.abs_value_us,
1088 (unsigned long long) start_t.abs_value_us,
1089 (unsigned long long) end_t.abs_value_us);
1091 gettext_noop (
1092 "# EPHEMERAL_KEY messages rejected due to time")
1093 ,
1094 1,
1095 GNUNET_NO);
1096 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1097 return;
1098 }
1099#if DEBUG_KX
1100 {
1101 struct GNUNET_HashCode eh;
1102
1103 GNUNET_CRYPTO_hash (&m->ephemeral_key, sizeof(m->ephemeral_key), &eh);
1105 "Received valid EPHEMERAL_KEY `%s' from `%s' in state %d.\n",
1106 GNUNET_h2s (&eh),
1107 GNUNET_i2s (kx->peer),
1108 kx->status);
1109 }
1110#endif
1112 gettext_noop ("# valid ephemeral keys received"),
1113 1,
1114 GNUNET_NO);
1115 kx->other_ephemeral_key = m->ephemeral_key;
1116 kx->foreign_key_expires = end_t;
1118
1119 /* check if we still need to send the sender our key */
1120 sender_status = ntohl (m->sender_status);
1121 switch (sender_status)
1122 {
1124 GNUNET_break_op (0);
1125 break;
1126
1128 /* fine, need to send our key after updating our status, see below */
1130 break;
1131
1133 /* other peer already got our key, but typemap did go down */
1135 break;
1136
1138 /* other peer already got our key, typemap NOT down */
1139 break;
1140
1142 /* other peer already got our key, typemap NOT down */
1143 break;
1144
1145 default:
1146 GNUNET_break (0);
1147 break;
1148 }
1149 /* check if we need to confirm everything is fine via PING + PONG */
1150 switch (kx->status)
1151 {
1153 GNUNET_assert (NULL == kx->keep_alive_task);
1155 monitor_notify_all (kx);
1156 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1157 send_key (kx);
1158 else
1159 send_ping (kx);
1160 break;
1161
1163 GNUNET_assert (NULL == kx->keep_alive_task);
1165 monitor_notify_all (kx);
1166 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1167 send_key (kx);
1168 else
1169 send_ping (kx);
1170 break;
1171
1173 GNUNET_assert (NULL == kx->keep_alive_task);
1174 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1175 send_key (kx);
1176 else
1177 send_ping (kx);
1178 break;
1179
1182 monitor_notify_all (kx);
1183 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1184 send_key (kx);
1185 else
1186 send_ping (kx);
1187 break;
1188
1190 if (GNUNET_CORE_KX_STATE_KEY_SENT == sender_status)
1191 send_key (kx);
1192 else
1193 send_ping (kx);
1194 break;
1195
1196 default:
1197 GNUNET_break (0);
1198 break;
1199 }
1200 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1201}
1202
1203
1204static void
1205send_keep_alive (void *cls);
1206
1207
1215static void
1216handle_ping (void *cls, const struct PingMessage *m)
1217{
1218 struct GSC_KeyExchangeInfo *kx = cls;
1219 struct PingMessage t;
1220 struct PongMessage tx;
1221 struct PongMessage *tp;
1222 struct GNUNET_MQ_Envelope *env;
1223#if CONG_CRYPTO_ENABLED
1224#else
1226#endif
1227
1229 gettext_noop ("# PING messages received"),
1230 1,
1231 GNUNET_NO);
1235 {
1236 /* ignore */
1238 gettext_noop (
1239 "# PING messages dropped (out of order)"),
1240 1,
1241 GNUNET_NO);
1242 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1243 return;
1244 }
1246 "Core service receives PING request from `%s'.\n",
1247 GNUNET_i2s (kx->peer));
1248#if CONG_CRYPTO_ENABLED
1249 if (0 != crypto_aead_xchacha20poly1305_ietf_decrypt_detached (
1250 (unsigned char*) &t.target,
1251 NULL,
1252 (unsigned char*) &m->target,
1253 sizeof (m->target) + sizeof (m->challenge),
1254 m->tag,
1255 NULL, 0,
1256 m->nonce,
1257 kx->decrypt_key))
1258 {
1259 GNUNET_break_op (0);
1260 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1261 return;
1262 }
1263#else
1264 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1265 if (GNUNET_OK != do_decrypt (kx,
1266 &iv,
1267 &m->target,
1268 &t.target,
1269 sizeof(struct PingMessage)
1270 - ((void *) &m->target - (void *) m)))
1271 {
1272 GNUNET_break_op (0);
1273 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1274 return;
1275 }
1276#endif
1277 if (0 !=
1278 memcmp (&t.target, &GSC_my_identity, sizeof(struct GNUNET_PeerIdentity)))
1279 {
1282 "Decryption of PING from peer `%s' failed, PING for `%s'?\n",
1283 GNUNET_i2s (kx->peer),
1284 GNUNET_i2s2 (&t.target));
1285 else
1286 GNUNET_log (
1288 "Decryption of PING from peer `%s' failed after rekey (harmless)\n",
1289 GNUNET_i2s (kx->peer));
1290 GNUNET_break_op (0);
1291 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1292 return;
1293 }
1294 /* construct PONG */
1295 tx.reserved = 0;
1296 tx.challenge = t.challenge;
1297 tx.target = t.target;
1299#if CONG_CRYPTO_ENABLED
1300 randombytes_buf (tp->nonce, sizeof (tp->nonce));
1301 GNUNET_assert (0 ==
1302 crypto_aead_xchacha20poly1305_ietf_encrypt_detached (
1303 (unsigned char*) &tp->challenge,
1304 tp->tag,
1305 NULL,
1306 (unsigned char*) &tx.challenge,
1307 sizeof(struct PongMessage)
1308 - ((void *) &tp->challenge - (void *) tp),
1309 NULL, 0,
1310 NULL,
1311 tp->nonce,
1312 kx->encrypt_key));
1313#else
1314 tp->iv_seed = calculate_seed (kx);
1315 derive_pong_iv (&iv, &kx->encrypt_key, tp->iv_seed, t.challenge, kx->peer);
1316 do_encrypt (kx,
1317 &iv,
1318 &tx.challenge,
1319 &tp->challenge,
1320 sizeof(struct PongMessage)
1321 - ((void *) &tp->challenge - (void *) tp));
1322#endif
1324 gettext_noop ("# PONG messages created"),
1325 1,
1326 GNUNET_NO);
1327 GNUNET_MQ_send (kx->mq, env);
1328 if (NULL != kx->keep_alive_task)
1329 {
1332 send_keep_alive, kx);
1333 }
1334 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1335}
1336
1337
1344static void
1346{
1347 struct GSC_KeyExchangeInfo *kx = cls;
1348 struct GNUNET_TIME_Relative retry;
1349 struct GNUNET_TIME_Relative left;
1350
1351 kx->keep_alive_task = NULL;
1353 if (0 == left.rel_value_us)
1354 {
1356 gettext_noop ("# sessions terminated by timeout"),
1357 1,
1358 GNUNET_NO);
1359 GSC_SESSIONS_end (kx->peer);
1361 monitor_notify_all (kx);
1362 send_key (kx);
1363 return;
1364 }
1366 "Sending KEEPALIVE to `%s'\n",
1367 GNUNET_i2s (kx->peer));
1369 gettext_noop ("# keepalive messages sent"),
1370 1,
1371 GNUNET_NO);
1372 setup_fresh_ping (kx);
1373 send_ping (kx);
1376 kx->keep_alive_task =
1378}
1379
1380
1388static void
1390{
1392
1393 kx->timeout =
1395 delta =
1397 if (delta.rel_value_us > 5LL * 1000LL * 1000LL)
1398 {
1399 /* we only notify monitors about timeout changes if those
1400 are bigger than the threshold (5s) */
1401 monitor_notify_all (kx);
1402 }
1403 if (NULL != kx->keep_alive_task)
1408 kx);
1409}
1410
1411
1418static void
1419handle_pong (void *cls, const struct PongMessage *m)
1420{
1421 struct GSC_KeyExchangeInfo *kx = cls;
1422 struct PongMessage t;
1423#if CONG_CRYPTO_ENABLED
1424#else
1426#endif
1427
1429 gettext_noop ("# PONG messages received"),
1430 1,
1431 GNUNET_NO);
1432 switch (kx->status)
1433 {
1436 gettext_noop (
1437 "# PONG messages dropped (connection down)"),
1438 1,
1439 GNUNET_NO);
1440 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1441 return;
1442
1445 gettext_noop (
1446 "# PONG messages dropped (out of order)"),
1447 1,
1448 GNUNET_NO);
1449 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1450 return;
1451
1453 break;
1454
1456 break;
1457
1459 break;
1460
1461 default:
1462 GNUNET_break (0);
1463 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1464 return;
1465 }
1467 "Core service receives PONG response from `%s'.\n",
1468 GNUNET_i2s (kx->peer));
1469 /* mark as garbage, just to be sure */
1470 memset (&t, 255, sizeof(t));
1471#if CONG_CRYPTO_ENABLED
1472 if (0 != crypto_aead_xchacha20poly1305_ietf_decrypt_detached (
1473 (unsigned char*) &t.challenge,
1474 NULL,
1475 (unsigned char*) &m->challenge,
1476 sizeof(struct PongMessage)
1477 - ((void *) &m->challenge - (void *) m),
1478 m->tag,
1479 NULL, 0,
1480 m->nonce,
1481 kx->decrypt_key))
1482 {
1483 GNUNET_break_op (0);
1484 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1485 return;
1486 }
1487#else
1488 derive_pong_iv (&iv,
1489 &kx->decrypt_key,
1490 m->iv_seed,
1491 kx->ping_challenge,
1493 if (GNUNET_OK != do_decrypt (kx,
1494 &iv,
1495 &m->challenge,
1496 &t.challenge,
1497 sizeof(struct PongMessage)
1498 - ((void *) &m->challenge - (void *) m)))
1499 {
1500 GNUNET_break_op (0);
1501 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1502 return;
1503 }
1504#endif
1506 gettext_noop ("# PONG messages decrypted"),
1507 1,
1508 GNUNET_NO);
1509 if ((0 !=
1510 memcmp (&t.target, kx->peer, sizeof(struct GNUNET_PeerIdentity))) ||
1511 (kx->ping_challenge != t.challenge))
1512 {
1513 /* PONG malformed */
1515 "Received malformed PONG wanted sender `%s' with challenge %u\n",
1516 GNUNET_i2s (kx->peer),
1517 (unsigned int) kx->ping_challenge);
1519 "Received malformed PONG received from `%s' with challenge %u\n",
1520 GNUNET_i2s (&t.target),
1521 (unsigned int) t.challenge);
1522 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1523 return;
1524 }
1526 "Received valid PONG from `%s'\n",
1527 GNUNET_i2s (kx->peer));
1528 /* no need to resend key any longer */
1529 if (NULL != kx->retry_set_key_task)
1530 {
1532 kx->retry_set_key_task = NULL;
1533 }
1534 switch (kx->status)
1535 {
1537 GNUNET_assert (0); /* should be impossible */
1538 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1539 return;
1540
1542 GNUNET_assert (0); /* should be impossible */
1543 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1544 return;
1545
1548 gettext_noop (
1549 "# session keys confirmed via PONG"),
1550 1,
1551 GNUNET_NO);
1553 monitor_notify_all (kx);
1554 GSC_SESSIONS_create (kx->peer, kx);
1555 GNUNET_assert (NULL == kx->keep_alive_task);
1556 update_timeout (kx);
1557 break;
1558
1561 gettext_noop ("# timeouts prevented via PONG"),
1562 1,
1563 GNUNET_NO);
1564 update_timeout (kx);
1565 break;
1566
1569 gettext_noop (
1570 "# rekey operations confirmed via PONG"),
1571 1,
1572 GNUNET_NO);
1574 monitor_notify_all (kx);
1575 update_timeout (kx);
1576 break;
1577
1578 default:
1579 GNUNET_break (0);
1580 break;
1581 }
1582 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1583}
1584
1585
1591static void
1593{
1594 struct GNUNET_MQ_Envelope *env;
1595
1597 if (NULL != kx->retry_set_key_task)
1598 {
1600 kx->retry_set_key_task = NULL;
1601 }
1602 /* always update sender status in SET KEY message */
1603#if DEBUG_KX
1604 {
1605 struct GNUNET_HashCode hc;
1606
1608 sizeof(current_ekm.ephemeral_key),
1609 &hc);
1611 "Sending EPHEMERAL_KEY %s to `%s' (my status: %d)\n",
1612 GNUNET_h2s (&hc),
1613 GNUNET_i2s (kx->peer),
1614 kx->status);
1615 }
1616#endif
1617 current_ekm.sender_status = htonl ((int32_t) (kx->status));
1619 GNUNET_MQ_send (kx->mq, env);
1621 send_ping (kx);
1622 kx->retry_set_key_task =
1625 kx);
1626}
1627
1628
1629void
1631 const void *payload,
1632 size_t payload_size)
1633{
1634 size_t used = payload_size + sizeof(struct EncryptedMessage);
1635 char pbuf[used]; /* plaintext */
1636 struct EncryptedMessage *em; /* encrypted message */
1637 struct EncryptedMessage *ph; /* plaintext header */
1638 struct GNUNET_MQ_Envelope *env;
1639#if CONG_CRYPTO_ENABLED
1640#else
1642 struct GNUNET_CRYPTO_AuthKey auth_key;
1643#endif
1644
1645 ph = (struct EncryptedMessage *) pbuf;
1646 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1647 ph->reserved = 0;
1649 GNUNET_memcpy (&ph[1], payload, payload_size);
1651 payload_size,
1653#if CONG_CRYPTO_ENABLED
1654 randombytes_buf (ph->nonce, sizeof (ph->nonce));
1655 GNUNET_assert (0 ==
1656 crypto_aead_xchacha20poly1305_ietf_encrypt_detached (
1657 (unsigned char*) &em->sequence_number,
1658 em->tag,
1659 NULL,
1660 (unsigned char*) &ph->sequence_number,
1661 used - ENCRYPTED_HEADER_SIZE,
1662 NULL, 0,
1663 NULL,
1664 ph->nonce,
1665 kx->encrypt_key));
1666#else
1667 ph->iv_seed = calculate_seed (kx);
1668 em->iv_seed = ph->iv_seed;
1669 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, kx->peer);
1671 &iv,
1672 &ph->sequence_number,
1673 &em->sequence_number,
1674 used - ENCRYPTED_HEADER_SIZE));
1675#if DEBUG_KX
1676 {
1677 struct GNUNET_HashCode hc;
1678
1680 used - ENCRYPTED_HEADER_SIZE,
1681 &hc);
1683 "Encrypted payload `%s' of %u bytes for %s\n",
1684 GNUNET_h2s (&hc),
1685 (unsigned int) (used - ENCRYPTED_HEADER_SIZE),
1686 GNUNET_i2s (kx->peer));
1687 }
1688#endif
1689 derive_auth_key (&auth_key, &kx->encrypt_key, ph->iv_seed);
1690 GNUNET_CRYPTO_hmac (&auth_key,
1691 &em->sequence_number,
1692 used - ENCRYPTED_HEADER_SIZE,
1693 &em->hmac);
1694#if DEBUG_KX
1695 {
1696 struct GNUNET_HashCode hc;
1697
1698 GNUNET_CRYPTO_hash (&auth_key, sizeof(auth_key), &hc);
1700 "For peer %s, used AC %s to create hmac %s\n",
1701 GNUNET_i2s (kx->peer),
1702 GNUNET_h2s (&hc),
1703 GNUNET_h2s2 (&em->hmac));
1704 }
1705#endif
1706#endif
1708 GNUNET_MQ_send (kx->mq, env);
1709}
1710
1711
1720static int
1721check_encrypted (void *cls, const struct EncryptedMessage *m)
1722{
1723 uint16_t size = ntohs (m->header.size) - sizeof(*m);
1724
1725 if (size < sizeof(struct GNUNET_MessageHeader))
1726 {
1727 GNUNET_break_op (0);
1728 return GNUNET_SYSERR;
1729 }
1730 return GNUNET_OK;
1731}
1732
1733
1741static void
1742handle_encrypted (void *cls, const struct EncryptedMessage *m)
1743{
1744 struct GSC_KeyExchangeInfo *kx = cls;
1745 struct EncryptedMessage *pt; /* plaintext */
1746 uint32_t snum;
1747 struct GNUNET_TIME_Absolute t;
1748 uint16_t size = ntohs (m->header.size);
1749 char buf[size] GNUNET_ALIGN;
1750
1752 {
1754 gettext_noop (
1755 "# DATA message dropped (out of order)"),
1756 1,
1757 GNUNET_NO);
1758 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1759 return;
1760 }
1761 if (0 ==
1763 {
1764 GNUNET_log (
1766 _ (
1767 "Session to peer `%s' went down due to key expiration (should not happen)\n"),
1768 GNUNET_i2s (kx->peer));
1770 gettext_noop (
1771 "# sessions terminated by key expiration"),
1772 1,
1773 GNUNET_NO);
1774 GSC_SESSIONS_end (kx->peer);
1775 if (NULL != kx->keep_alive_task)
1776 {
1778 kx->keep_alive_task = NULL;
1779 }
1781 monitor_notify_all (kx);
1782 send_key (kx);
1783 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1784 return;
1785 }
1786
1787 /* validate hash */
1788#if DEBUG_KX
1789 {
1790 struct GNUNET_HashCode hc;
1791
1792 GNUNET_CRYPTO_hash (&m->sequence_number, size - ENCRYPTED_HEADER_SIZE, &hc);
1794 "Received encrypted payload `%s' of %u bytes from %s\n",
1795 GNUNET_h2s (&hc),
1796 (unsigned int) (size - ENCRYPTED_HEADER_SIZE),
1797 GNUNET_i2s (kx->peer));
1798 }
1799#endif
1800
1801#if CONG_CRYPTO_ENABLED
1802 if (0 != crypto_aead_xchacha20poly1305_ietf_decrypt_detached (
1803 (unsigned char*) &buf[ENCRYPTED_HEADER_SIZE],
1804 NULL,
1805 (unsigned char*) &m->sequence_number,
1807 m->tag,
1808 NULL, 0,
1809 m->nonce,
1810 kx->decrypt_key))
1811 {
1812 GNUNET_break_op (0);
1813 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1814 return;
1815 }
1816#else
1817 {
1819 struct GNUNET_CRYPTO_AuthKey auth_key;
1820 struct GNUNET_HashCode ph;
1821 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed);
1822 GNUNET_CRYPTO_hmac (&auth_key,
1823 &m->sequence_number,
1825 &ph);
1826#if DEBUG_KX
1827 {
1828 struct GNUNET_HashCode hc;
1829
1830 GNUNET_CRYPTO_hash (&auth_key, sizeof(auth_key), &hc);
1832 "For peer %s, used AC %s to verify hmac %s\n",
1833 GNUNET_i2s (kx->peer),
1834 GNUNET_h2s (&hc),
1835 GNUNET_h2s2 (&m->hmac));
1836 }
1837#endif
1838 if (0 != memcmp (&ph, &m->hmac, sizeof(struct GNUNET_HashCode)))
1839 {
1840 /* checksum failed */
1842 "Failed checksum validation for a message from `%s'\n",
1843 GNUNET_i2s (kx->peer));
1844 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1845 return;
1846 }
1847 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1848 /* decrypt */
1849 if (GNUNET_OK != do_decrypt (kx,
1850 &iv,
1851 &m->sequence_number,
1854 {
1855 GNUNET_break_op (0);
1856 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1857 return;
1858 }
1859 }
1860#endif
1862 "Decrypted %u bytes from %s\n",
1863 (unsigned int) (size - ENCRYPTED_HEADER_SIZE),
1864 GNUNET_i2s (kx->peer));
1865 pt = (struct EncryptedMessage *) buf;
1866
1867 /* validate sequence number */
1868 snum = ntohl (pt->sequence_number);
1869 if (kx->last_sequence_number_received == snum)
1870 {
1872 "Received duplicate message, ignoring.\n");
1873 /* duplicate, ignore */
1875 gettext_noop ("# bytes dropped (duplicates)"),
1876 size,
1877 GNUNET_NO);
1878 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1879 return;
1880 }
1881 if ((kx->last_sequence_number_received > snum) &&
1882 (kx->last_sequence_number_received - snum > 32))
1883 {
1885 "Received ancient out of sequence message, ignoring.\n");
1886 /* ancient out of sequence, ignore */
1888 gettext_noop (
1889 "# bytes dropped (out of sequence)"),
1890 size,
1891 GNUNET_NO);
1892 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1893 return;
1894 }
1895 if (kx->last_sequence_number_received > snum)
1896 {
1897 uint32_t rotbit = 1U << (kx->last_sequence_number_received - snum - 1);
1898
1899 if ((kx->last_packets_bitmap & rotbit) != 0)
1900 {
1902 "Received duplicate message, ignoring.\n");
1904 gettext_noop ("# bytes dropped (duplicates)"),
1905 size,
1906 GNUNET_NO);
1907 /* duplicate, ignore */
1908 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1909 return;
1910 }
1911 kx->last_packets_bitmap |= rotbit;
1912 }
1913 if (kx->last_sequence_number_received < snum)
1914 {
1915 unsigned int shift = (snum - kx->last_sequence_number_received);
1916
1917 if (shift >= 8 * sizeof(kx->last_packets_bitmap))
1918 kx->last_packets_bitmap = 0;
1919 else
1920 kx->last_packets_bitmap <<= shift;
1922 }
1923
1924 /* check timestamp */
1926 if (GNUNET_TIME_absolute_get_duration (t).rel_value_us >
1927 MAX_MESSAGE_AGE.rel_value_us)
1928 {
1930 "Message received far too old (%s). Content ignored.\n",
1933 GNUNET_YES));
1935 gettext_noop (
1936 "# bytes dropped (ancient message)"),
1937 size,
1938 GNUNET_NO);
1939 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1940 return;
1941 }
1942
1943 /* process decrypted message(s) */
1944 update_timeout (kx);
1946 gettext_noop ("# bytes of payload decrypted"),
1947 size - sizeof(struct EncryptedMessage),
1948 GNUNET_NO);
1949 if (GNUNET_OK !=
1951 &buf[sizeof(struct EncryptedMessage)],
1952 size - sizeof(struct EncryptedMessage),
1953 GNUNET_YES,
1954 GNUNET_NO))
1955 GNUNET_break_op (0);
1956
1957 GNUNET_TRANSPORT_core_receive_continue (transport, kx->peer);
1958}
1959
1960
1965static void
1967{
1968 current_ekm.header.size = htons (sizeof(struct EphemeralKeyMessage));
1970 current_ekm.sender_status = 0; /* to be set later */
1973 htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
1974 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1975 + sizeof(struct GNUNET_TIME_AbsoluteNBO)
1976 + sizeof(struct GNUNET_CRYPTO_EcdhePublicKey)
1977 + sizeof(struct GNUNET_PeerIdentity));
1981 "core",
1982 "USE_EPHEMERAL_KEYS"))
1983 {
1987 REKEY_TOLERANCE)));
1988 }
1989 else
1990 {
1993 }
2001}
2002
2003
2009static void
2010do_rekey (void *cls)
2011{
2012 struct GSC_KeyExchangeInfo *pos;
2013
2014 (void) cls;
2018 {
2019 struct GNUNET_HashCode eh;
2020
2022 sizeof(current_ekm.ephemeral_key),
2023 &eh);
2024 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Rekeying to %s\n", GNUNET_h2s (&eh));
2025 }
2026 for (pos = kx_head; NULL != pos; pos = pos->next)
2027 {
2028 if (GNUNET_CORE_KX_STATE_UP == pos->status)
2029 {
2031 derive_session_keys (pos);
2032 }
2033 else if (GNUNET_CORE_KX_STATE_DOWN == pos->status)
2034 {
2036 }
2037 monitor_notify_all (pos);
2038 send_key (pos);
2039 }
2040}
2041
2042
2049int
2051{
2053 GNUNET_MQ_hd_fixed_size (ephemeral_key,
2055 struct EphemeralKeyMessage,
2056 NULL),
2059 struct PingMessage,
2060 NULL),
2063 struct PongMessage,
2064 NULL),
2065 GNUNET_MQ_hd_var_size (encrypted,
2067 struct EncryptedMessage,
2068 NULL),
2070 };
2071
2072 my_private_key = *pk;
2077 {
2078 struct GNUNET_HashCode eh;
2079
2081 sizeof(current_ekm.ephemeral_key),
2082 &eh);
2084 "Starting with ephemeral key %s\n",
2085 GNUNET_h2s (&eh));
2086 }
2087
2090 transport =
2093 handlers,
2094 NULL,
2097 if (NULL == transport)
2098 {
2099 GSC_KX_done ();
2100 return GNUNET_SYSERR;
2101 }
2102 return GNUNET_OK;
2103}
2104
2105
2109void
2111{
2112 if (NULL != transport)
2113 {
2115 transport = NULL;
2116 }
2117 if (NULL != rekey_task)
2118 {
2120 rekey_task = NULL;
2121 }
2122 memset (&my_ephemeral_key,
2123 0,
2124 sizeof (my_ephemeral_key));
2125 memset (&my_private_key,
2126 0,
2127 sizeof (my_private_key));
2128 if (NULL != nc)
2129 {
2131 nc = NULL;
2132 }
2133}
2134
2135
2142unsigned int
2144{
2145 return GNUNET_MQ_get_length (kxinfo->mq);
2146}
2147
2148
2149int
2151{
2152 return kxinfo->has_excess_bandwidth;
2153}
2154
2155
2164void
2166{
2167 struct GNUNET_MQ_Envelope *env;
2168 struct MonitorNotifyMessage *done_msg;
2169 struct GSC_KeyExchangeInfo *kx;
2170
2172 for (kx = kx_head; NULL != kx; kx = kx->next)
2173 {
2174 struct GNUNET_MQ_Envelope *env_notify;
2175 struct MonitorNotifyMessage *msg;
2176
2178 msg->state = htonl ((uint32_t) kx->status);
2179 msg->peer = *kx->peer;
2180 msg->timeout = GNUNET_TIME_absolute_hton (kx->timeout);
2181 GNUNET_MQ_send (mq, env_notify);
2182 }
2184 done_msg->state = htonl ((uint32_t) GNUNET_CORE_KX_ITERATION_FINISHED);
2187}
2188
2189
2190/* end of gnunet-service-core_kx.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_CORE_OPTION_SEND_FULL_INBOUND
Client wants all inbound messages in full.
Definition: core.h:53
#define GNUNET_CORE_OPTION_SEND_HDR_INBOUND
Client just wants the 4-byte message headers of all inbound messages.
Definition: core.h:59
#define gettext_noop(String)
Definition: gettext.h:74
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:103
static struct GNUNET_FS_Handle * ctx
static uint8_t seed
static struct GNUNET_IDENTITY_Handle * sh
Handle to IDENTITY service.
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_IDENTITY_Handle * identity
Which namespace do we publish to? NULL if we do not publish to a namespace.
const struct GNUNET_CONFIGURATION_Handle * GSC_cfg
Our configuration.
struct GNUNET_PeerIdentity GSC_my_identity
Our identity.
void GSC_CLIENTS_deliver_message(const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, uint16_t msize, uint32_t options)
Deliver P2P message to interested clients.
struct GNUNET_STATISTICS_Handle * GSC_stats
For creating statistics.
Globals for gnunet-service-core.
static void handle_pong(void *cls, const struct PongMessage *m)
We received a PONG message.
static void handle_encrypted(void *cls, const struct EncryptedMessage *m)
We received an encrypted message.
static void set_key_retry_task(void *cls)
Task that will retry send_key() if our previous attempt failed.
#define REKEY_TOLERANCE
What time difference do we tolerate?
unsigned int GSC_NEIGHBOURS_get_queue_length(const struct GSC_KeyExchangeInfo *kxinfo)
Check how many messages are queued for the given neighbour.
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
Our private key.
static struct GNUNET_CRYPTO_EcdhePrivateKey my_ephemeral_key
Our ephemeral private key.
int GSC_NEIGHBOURS_check_excess_bandwidth(const struct GSC_KeyExchangeInfo *kxinfo)
Check if the given neighbour has excess bandwidth available.
static void derive_aes_key(const struct GNUNET_PeerIdentity *sender, const struct GNUNET_PeerIdentity *receiver, const struct GNUNET_HashCode *key_material, struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
Derive an AES key from key material.
#define MIN_PING_FREQUENCY
What is the minimum frequency for a PING message?
static struct GSC_KeyExchangeInfo * kx_tail
DLL tail.
void GSC_KX_handle_client_monitor_peers(struct GNUNET_MQ_Handle *mq)
Handle GNUNET_MESSAGE_TYPE_CORE_MONITOR_PEERS request.
static void handle_ephemeral_key(void *cls, const struct EphemeralKeyMessage *m)
We received a GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY message.
#define REKEY_FREQUENCY
How often do we rekey?
static void sign_ephemeral_key()
Setup the message that links the ephemeral key to our persistent public key and generate the appropri...
static void handle_transport_notify_disconnect(void *cls, const struct GNUNET_PeerIdentity *peer, void *handler_cls)
Function called by transport telling us that a peer disconnected.
static struct GNUNET_NotificationContext * nc
Notification context for broadcasting to monitors.
void GSC_KX_encrypt_and_transmit(struct GSC_KeyExchangeInfo *kx, const void *payload, size_t payload_size)
Encrypt and transmit a message with the given payload.
static int check_encrypted(void *cls, const struct EncryptedMessage *m)
We received an encrypted message.
static void send_key(struct GSC_KeyExchangeInfo *kx)
Send our key (and encrypted PING) to the other peer.
static uint32_t calculate_seed(struct GSC_KeyExchangeInfo *kx)
Calculate seed value we should use for a message.
static void handle_ping(void *cls, const struct PingMessage *m)
We received a PING message.
static struct GSC_KeyExchangeInfo * kx_head
DLL head.
static struct EphemeralKeyMessage current_ekm
Current message we send for a key exchange.
int GSC_KX_init(struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
Initialize KX subsystem.
static void do_rekey(void *cls)
Task run to trigger rekeying.
#define MAX_MESSAGE_AGE
What is the maximum age of a message for us to consider processing it? Note that this looks at the ti...
#define INITIAL_SET_KEY_RETRY_FREQUENCY
How long do we wait for SET_KEY confirmation initially?
void GSC_KX_done()
Shutdown KX subsystem.
#define ENCRYPTED_HEADER_SIZE
Number of bytes (at the beginning) of struct EncryptedMessage that are NOT encrypted.
static void derive_session_keys(struct GSC_KeyExchangeInfo *kx)
Derive fresh session keys from the current ephemeral keys.
static void * handle_transport_notify_connect(void *cls, const struct GNUNET_PeerIdentity *pid, struct GNUNET_MQ_Handle *mq)
Function called by transport to notify us that a peer connected to us (on the network level).
static void derive_auth_key(struct GNUNET_CRYPTO_AuthKey *akey, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
Derive an authentication key from "set key" information.
static void setup_fresh_ping(struct GSC_KeyExchangeInfo *kx)
Create a fresh PING message for transmission to the other peer.
static void update_timeout(struct GSC_KeyExchangeInfo *kx)
We've seen a valid message from the other peer.
static void send_ping(struct GSC_KeyExchangeInfo *kx)
Send our PING to the other peer.
static void derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, const struct GNUNET_PeerIdentity *identity)
Derive an IV from packet information.
static void send_keep_alive(void *cls)
Task triggered when a neighbour entry is about to time out (and we should prevent this by sending a P...
static int do_decrypt(struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
Decrypt size bytes from in and write the result to out.
static int deliver_message(void *cls, const struct GNUNET_MessageHeader *m)
Deliver P2P message to interested clients.
static void monitor_notify_all(struct GSC_KeyExchangeInfo *kx)
Inform all monitors about the KX state of the given peer.
static struct GNUNET_SCHEDULER_Task * rekey_task
Task scheduled for periodic re-generation (and thus rekeying) of our ephemeral key.
static struct GNUNET_TRANSPORT_CoreHandle * transport
Transport service.
static int do_encrypt(struct GSC_KeyExchangeInfo *kx, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const void *in, void *out, size_t size)
Encrypt size bytes from in and write the result to out.
static void derive_pong_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed, uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
Derive an IV from pong packet information.
code for managing the key exchange (SET_KEY, PING, PONG) with other peers
void GSC_SESSIONS_reinit(const struct GNUNET_PeerIdentity *peer)
The other peer has indicated that it 'lost' the session (KX down), reinitialize the session on our en...
void GSC_SESSIONS_end(const struct GNUNET_PeerIdentity *pid)
End the session with the given peer (we are no longer connected).
void GSC_SESSIONS_confirm_typemap(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
The other peer has confirmed receiving our type map, check if it is current and if so,...
void GSC_SESSIONS_create(const struct GNUNET_PeerIdentity *peer, struct GSC_KeyExchangeInfo *kx)
Create a session, a key exchange was just completed.
void GSC_SESSIONS_set_typemap(const struct GNUNET_PeerIdentity *peer, const struct GNUNET_MessageHeader *msg)
We've received a typemap message from a peer, update ours.
static unsigned long long payload
How much data are we currently storing in the database?
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
static struct GNUNET_TRANSPORT_PluginMonitor * pm
Handle if we are monitoring plugin session activity.
static struct GNUNET_SCHEDULER_Task * t
Main task.
Constants for network protocols.
#define GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY
Purpose is to set a session key.
API of the transport service towards the CORE service (TNG version)
struct GNUNET_TRANSPORT_CoreHandle * GNUNET_TRANSPORT_core_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd)
Connect to the transport service.
void GNUNET_TRANSPORT_core_disconnect(struct GNUNET_TRANSPORT_CoreHandle *handle)
Disconnect from the transport service.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
#define GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT
After how long do we consider a connection to a peer dead if we don't receive messages from the peer?
GNUNET_CORE_KxState
State machine for our P2P encryption handshake.
@ GNUNET_CORE_KX_PEER_DISCONNECT
Last state of a KX (when it is being terminated).
@ GNUNET_CORE_KX_STATE_UP
The other peer has confirmed our session key + PING with a PONG message encrypted with their session ...
@ GNUNET_CORE_KX_STATE_DOWN
No handshake yet.
@ GNUNET_CORE_KX_STATE_KEY_SENT
We've sent our session key.
@ GNUNET_CORE_KX_STATE_KEY_RECEIVED
We've received the other peers session key.
@ GNUNET_CORE_KX_ITERATION_FINISHED
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
@ GNUNET_CORE_KX_STATE_REKEY_SENT
We're rekeying (or had a timeout), so we have sent the other peer our new ephemeral key,...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_ecc_ecdh(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, const struct GNUNET_CRYPTO_EcdhePublicKey *pub, struct GNUNET_HashCode *key_material)
Derive key material from a public and a private ECC key.
Definition: crypto_ecc.c:732
void GNUNET_CRYPTO_ecdhe_key_create(struct GNUNET_CRYPTO_EcdhePrivateKey *pk)
Create a new private key.
Definition: crypto_ecc.c:454
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:201
ssize_t GNUNET_CRYPTO_symmetric_encrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Encrypt a block using a symmetric sessionkey.
void GNUNET_CRYPTO_symmetric_derive_iv(struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, const void *salt, size_t salt_len,...)
Derive an IV.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_sign_(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose, struct GNUNET_CRYPTO_EddsaSignature *sig)
EdDSA sign a given block.
Definition: crypto_ecc.c:625
uint32_t GNUNET_CRYPTO_random_u32(enum GNUNET_CRYPTO_Quality mode, uint32_t i)
Produce a random value.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_verify_(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EddsaSignature *sig, const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Verify EdDSA signature.
Definition: crypto_ecc.c:708
void GNUNET_CRYPTO_ecdhe_key_get_public(const struct GNUNET_CRYPTO_EcdhePrivateKey *priv, struct GNUNET_CRYPTO_EcdhePublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:217
ssize_t GNUNET_CRYPTO_symmetric_decrypt(const void *block, size_t size, const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey, const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv, void *result)
Decrypt a given block using a symmetric sessionkey.
@ GNUNET_CRYPTO_QUALITY_WEAK
No good quality of the operation is needed (i.e., random numbers can be pseudo-random).
@ GNUNET_CRYPTO_QUALITY_NONCE
Randomness for IVs etc.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
void GNUNET_CRYPTO_hash(const void *block, size_t size, struct GNUNET_HashCode *ret)
Compute hash of a given block.
Definition: crypto_hash.c:41
int32_t GNUNET_CRYPTO_crc32_n(const void *buf, size_t len)
Compute the CRC32 checksum for the first len bytes of the buffer.
Definition: crypto_crc.c:99
void GNUNET_CRYPTO_hmac(const struct GNUNET_CRYPTO_AuthKey *key, const void *plaintext, size_t plaintext_len, struct GNUNET_HashCode *hmac)
Calculate HMAC of a message (RFC 2104)
Definition: crypto_hash.c:327
int GNUNET_CRYPTO_hash_cmp(const struct GNUNET_HashCode *h1, const struct GNUNET_HashCode *h2)
Compare function for HashCodes, producing a total ordering of all hashcodes.
Definition: crypto_hash.c:218
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_kdf(void *result, size_t out_len, const void *xts, size_t xts_len, const void *skm, size_t skm_len,...)
Derive key.
Definition: crypto_kdf.c:62
void GNUNET_CRYPTO_hmac_derive_key(struct GNUNET_CRYPTO_AuthKey *key, const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey, const void *salt, size_t salt_len,...)
Derive an authentication key.
Definition: crypto_hash.c:264
#define GNUNET_NETWORK_STRUCT_BEGIN
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
#define GNUNET_log(kind,...)
#define GNUNET_NETWORK_STRUCT_END
Define as empty, GNUNET_PACKED should suffice, but this won't work on W32;.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_PACKED
gcc-ism to get packed structs.
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_h2s(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_h2s2(const struct GNUNET_HashCode *hc)
Convert a hash value to a string (for printing debug messages).
const char * GNUNET_i2s2(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_DEBUG
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:138
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:550
unsigned int GNUNET_MQ_get_length(struct GNUNET_MQ_Handle *mq)
Obtain the current length of the message queue.
Definition: mq.c:293
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:305
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:61
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:190
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:76
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:161
#define GNUNET_MESSAGE_TYPE_CORE_PING
Check that other peer is alive (challenge).
#define GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP
uncompressed type map of the sender
#define GNUNET_MESSAGE_TYPE_CORE_PONG
Confirmation that other peer is alive.
#define GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE
Encapsulation for an encrypted message between peers.
#define GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP
gzip-compressed type map of the sender
#define GNUNET_MESSAGE_TYPE_CORE_MONITOR_NOTIFY
Reply for monitor by CORE service.
#define GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP
Other peer confirms having received the type map.
#define GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY
Session key exchange between peers.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:980
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1277
enum GNUNET_GenericReturnValue GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:101
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:86
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:404
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:438
struct GNUNET_TIME_Relative GNUNET_TIME_relative_max(struct GNUNET_TIME_Relative t1, struct GNUNET_TIME_Relative t2)
Return the maximum of two relative time values.
Definition: time.c:352
#define GNUNET_TIME_UNIT_SECONDS
One second.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:406
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:579
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_ntoh(struct GNUNET_TIME_AbsoluteNBO a)
Convert absolute time from network byte order.
Definition: time.c:741
struct GNUNET_TIME_Relative GNUNET_TIME_relative_add(struct GNUNET_TIME_Relative a1, struct GNUNET_TIME_Relative a2)
Add relative times together.
Definition: time.c:587
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_subtract(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Subtract a given relative duration from the given start time.
Definition: time.c:471
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:316
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:452
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:552
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_difference(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end)
Compute the time difference between the given start and end times.
Definition: time.c:423
struct GNUNET_TIME_AbsoluteNBO GNUNET_TIME_absolute_hton(struct GNUNET_TIME_Absolute a)
Convert absolute time to network byte order.
Definition: time.c:640
#define GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
static unsigned int size
Size of the "table".
Definition: peer.c:68
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:330
static struct GNUNET_TIME_Relative delta
Definition: speedup.c:36
Encapsulation for encrypted messages exchanged between peers.
uint32_t iv_seed
Random value used for IV generation.
struct GNUNET_TIME_AbsoluteNBO timestamp
Timestamp.
uint32_t sequence_number
Sequence number, in network byte order.
struct GNUNET_HashCode hmac
MAC of the encrypted message (starting at sequence_number), used to verify message integrity.
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE.
uint32_t reserved
Reserved, always zero.
Message transmitted with the signed ephemeral key of a peer.
struct GNUNET_PeerIdentity origin_identity
Public key of the signing peer (persistent version, not the ephemeral public key).
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY.
int32_t sender_status
Status of the sender (should be in enum PeerStateMachine), nbo.
struct GNUNET_TIME_AbsoluteNBO expiration_time
When does the given ephemeral key expire (end of validity).
struct GNUNET_CRYPTO_EddsaSignature signature
An ECC signature of the origin_identity asserting the validity of the given ephemeral key.
struct GNUNET_TIME_AbsoluteNBO creation_time
At what time was this key created (beginning of validity).
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Information about what is being signed.
struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key
Ephemeral public ECC key.
type for (message) authentication keys
header of what an ECC signature signs this must be followed by "size - 8" bytes of the actual signed ...
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!...
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
Private ECC key encoded for transmission.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and encr...
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
unsigned char aes_key[(256/8)]
Actual key for AES.
A 512-bit hashcode.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Handle to a message stream tokenizer.
Definition: mst.c:45
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:77
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for absolute time used by GNUnet, in microseconds and in network byte order.
Time for absolute times used by GNUnet, in microseconds.
uint64_t abs_value_us
The actual value.
Time for relative time used by GNUnet, in microseconds.
uint64_t rel_value_us
The actual value.
Handle for the transport service (includes all of the state for the transport service).
Information about the status of a key exchange with another peer.
struct GSC_KeyExchangeInfo * prev
DLL.
struct GNUNET_CRYPTO_SymmetricSessionKey encrypt_key
Key we use to encrypt our messages for the other peer (initialized by us when we do the handshake).
struct GNUNET_SCHEDULER_Task * retry_set_key_task
ID of task used for re-trying SET_KEY and PING message.
struct GNUNET_TIME_Relative set_key_retry_frequency
At what frequency are we currently re-trying SET_KEY messages?
struct GNUNET_TIME_Absolute last_notify_timeout
What was the last timeout we informed our monitors about?
const struct GNUNET_PeerIdentity * peer
Identity of the peer.
uint32_t last_sequence_number_sent
last sequence number transmitted
struct GNUNET_MessageStreamTokenizer * mst
Our message stream tokenizer (for encrypted payload).
struct GSC_KeyExchangeInfo * next
DLL.
uint32_t ping_challenge
What was our PING challenge number (for this peer)?
struct GNUNET_MQ_Handle * mq
Message queue for sending messages to peer.
uint32_t last_sequence_number_received
last sequence number received on this connection (highest)
struct GNUNET_CRYPTO_EcdhePublicKey other_ephemeral_key
Ephemeral public ECC key of the other peer.
struct GNUNET_CRYPTO_SymmetricSessionKey decrypt_key
Key we use to decrypt messages from the other peer (given to us by the other peer during the handshak...
struct GNUNET_TIME_Absolute timeout
When should the session time out (if there are no PONGs)?
int has_excess_bandwidth
GNUNET_YES if this peer currently has excess bandwidth.
struct PingMessage ping
PING message we transmit to the other peer.
struct GNUNET_SCHEDULER_Task * keep_alive_task
ID of task used for sending keep-alive pings.
enum GNUNET_CORE_KxState status
What is our connection status?
struct GNUNET_TIME_Absolute foreign_key_expires
At what time did the other peer generate the decryption key?
uint32_t last_packets_bitmap
Bit map indicating which of the 32 sequence numbers before the last were received (good for accepting...
Message sent by the service to monitor clients to notify them about a peer changing status.
Definition: core.h:301
uint32_t state
New peer state, an enum GNUNET_CORE_KxState in NBO.
Definition: core.h:310
struct GNUNET_TIME_AbsoluteNBO timeout
How long will we stay in this state (if nothing else happens)?
Definition: core.h:320
We're sending an (encrypted) PING to the other peer to check if it can decrypt.
struct GNUNET_MessageHeader header
Message type is GNUNET_MESSAGE_TYPE_CORE_PING.
struct GNUNET_PeerIdentity target
Intended target of the PING, used primarily to check that decryption actually worked.
uint32_t challenge
Random number chosen to make replay harder.
Response to a PING.
uint32_t challenge
Random number to make replay attacks harder.
uint32_t reserved
Reserved, always zero.
uint32_t iv_seed
Seed for the IV.
struct GNUNET_PeerIdentity target
Intended target of the PING, used primarily to check that decryption actually worked.