2 This file is part of GNUnet.
3 (C) 2009-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file core/gnunet-service-core_kx.c
23 * @brief code for managing the key exchange (SET_KEY, PING, PONG) with other peers
24 * @author Christian Grothoff
27 #include "gnunet-service-core_kx.h"
28 #include "gnunet-service-core.h"
29 #include "gnunet-service-core_clients.h"
30 #include "gnunet-service-core_neighbours.h"
31 #include "gnunet-service-core_sessions.h"
32 #include "gnunet_statistics_service.h"
33 #include "gnunet_constants.h"
34 #include "gnunet_signatures.h"
35 #include "gnunet_protocols.h"
40 * How long do we wait for SET_KEY confirmation initially?
42 #define INITIAL_SET_KEY_RETRY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10)
45 * What is the minimum frequency for a PING message?
47 #define MIN_PING_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
50 * How often do we rekey?
52 #define REKEY_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_HOURS, 12)
55 * What time difference do we tolerate?
57 #define REKEY_TOLERANCE GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
60 * What is the maximum age of a message for us to consider processing
61 * it? Note that this looks at the timestamp used by the other peer,
62 * so clock skew between machines does come into play here. So this
63 * should be picked high enough so that a little bit of clock skew
64 * does not prevent peers from connecting to us.
66 #define MAX_MESSAGE_AGE GNUNET_TIME_UNIT_DAYS
70 GNUNET_NETWORK_STRUCT_BEGIN
73 * Message transmitted with the signed ephemeral key of a peer. The
74 * session key is then derived from the two ephemeral keys (ECDHE).
76 struct EphemeralKeyMessage
80 * Message type is CORE_EPHEMERAL_KEY.
82 struct GNUNET_MessageHeader header;
85 * Status of the sender (should be in "enum PeerStateMachine"), nbo.
87 int32_t sender_status GNUNET_PACKED;
90 * An ECC signature of the 'origin' asserting the validity of
91 * the given ephemeral key.
93 struct GNUNET_CRYPTO_EddsaSignature signature;
96 * Information about what is being signed.
98 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
101 * At what time was this key created (beginning of validity).
103 struct GNUNET_TIME_AbsoluteNBO creation_time;
106 * When does the given ephemeral key expire (end of validity).
108 struct GNUNET_TIME_AbsoluteNBO expiration_time;
111 * Ephemeral public ECC key.
113 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
116 * Public key of the signing peer (persistent version, not the ephemeral public key).
118 struct GNUNET_PeerIdentity origin_identity;
124 * We're sending an (encrypted) PING to the other peer to check if he
125 * can decrypt. The other peer should respond with a PONG with the
126 * same content, except this time encrypted with the receiver's key.
131 * Message type is CORE_PING.
133 struct GNUNET_MessageHeader header;
138 uint32_t iv_seed GNUNET_PACKED;
141 * Intended target of the PING, used primarily to check
142 * that decryption actually worked.
144 struct GNUNET_PeerIdentity target;
147 * Random number chosen to make reply harder.
149 uint32_t challenge GNUNET_PACKED;
154 * Response to a PING. Includes data from the original PING.
159 * Message type is CORE_PONG.
161 struct GNUNET_MessageHeader header;
166 uint32_t iv_seed GNUNET_PACKED;
169 * Random number to make faking the reply harder. Must be
170 * first field after header (this is where we start to encrypt!).
172 uint32_t challenge GNUNET_PACKED;
175 * Reserved, always zero.
180 * Intended target of the PING, used primarily to check
181 * that decryption actually worked.
183 struct GNUNET_PeerIdentity target;
188 * Encapsulation for encrypted messages exchanged between
189 * peers. Followed by the actual encrypted data.
191 struct EncryptedMessage
194 * Message type is either CORE_ENCRYPTED_MESSAGE.
196 struct GNUNET_MessageHeader header;
199 * Random value used for IV generation.
201 uint32_t iv_seed GNUNET_PACKED;
204 * MAC of the encrypted message (starting at 'sequence_number'),
205 * used to verify message integrity. Everything after this value
206 * (excluding this value itself) will be encrypted and authenticated.
207 * ENCRYPTED_HEADER_SIZE must be set to the offset of the *next* field.
209 struct GNUNET_HashCode hmac;
212 * Sequence number, in network byte order. This field
213 * must be the first encrypted/decrypted field
215 uint32_t sequence_number GNUNET_PACKED;
218 * Reserved, always zero.
223 * Timestamp. Used to prevent reply of ancient messages
224 * (recent messages are caught with the sequence number).
226 struct GNUNET_TIME_AbsoluteNBO timestamp;
229 GNUNET_NETWORK_STRUCT_END
233 * Number of bytes (at the beginning) of "struct EncryptedMessage"
234 * that are NOT encrypted.
236 #define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
240 * State machine for our P2P encryption handshake. Everyone starts in
241 * "DOWN", if we receive the other peer's key (other peer initiated)
242 * we start in state RECEIVED (since we will immediately send our
243 * own); otherwise we start in SENT. If we get back a PONG from
244 * within either state, we move up to CONFIRMED (the PONG will always
245 * be sent back encrypted with the key we sent to the other peer).
255 * We've sent our session key.
260 * We've received the other peers session key.
262 KX_STATE_KEY_RECEIVED,
265 * The other peer has confirmed our session key + PING with a PONG
266 * message encrypted with his session key (which we got). Key
272 * We're rekeying (or had a timeout), so we have sent the other peer
273 * our new ephemeral key, but we did not get a matching PONG yet.
274 * This is equivalent to being 'KX_STATE_KEY_RECEIVED', except that
275 * the session is marked as 'up' with sessions (as we don't want to
276 * drop and re-establish P2P connections simply due to rekeying).
284 * Information about the status of a key exchange with another peer.
286 struct GSC_KeyExchangeInfo
292 struct GSC_KeyExchangeInfo *next;
297 struct GSC_KeyExchangeInfo *prev;
300 * Identity of the peer.
302 struct GNUNET_PeerIdentity peer;
305 * PING message we transmit to the other peer.
307 struct PingMessage ping;
310 * Ephemeral public ECC key of the other peer.
312 struct GNUNET_CRYPTO_EcdhePublicKey other_ephemeral_key;
315 * Key we use to encrypt our messages for the other peer
316 * (initialized by us when we do the handshake).
318 struct GNUNET_CRYPTO_SymmetricSessionKey encrypt_key;
321 * Key we use to decrypt messages from the other peer
322 * (given to us by the other peer during the handshake).
324 struct GNUNET_CRYPTO_SymmetricSessionKey decrypt_key;
327 * At what time did the other peer generate the decryption key?
329 struct GNUNET_TIME_Absolute foreign_key_expires;
332 * When should the session time out (if there are no PONGs)?
334 struct GNUNET_TIME_Absolute timeout;
337 * At what frequency are we currently re-trying SET_KEY messages?
339 struct GNUNET_TIME_Relative set_key_retry_frequency;
342 * ID of task used for re-trying SET_KEY and PING message.
344 GNUNET_SCHEDULER_TaskIdentifier retry_set_key_task;
347 * ID of task used for sending keep-alive pings.
349 GNUNET_SCHEDULER_TaskIdentifier keep_alive_task;
352 * Bit map indicating which of the 32 sequence numbers before the last
353 * were received (good for accepting out-of-order packets and
354 * estimating reliability of the connection)
356 unsigned int last_packets_bitmap;
359 * last sequence number received on this connection (highest)
361 uint32_t last_sequence_number_received;
364 * last sequence number transmitted
366 uint32_t last_sequence_number_sent;
369 * What was our PING challenge number (for this peer)?
371 uint32_t ping_challenge;
374 * What is our connection status?
376 enum KxStateMachine status;
384 static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
387 * Our ephemeral private key.
389 static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key;
392 * Current message we send for a key exchange.
394 static struct EphemeralKeyMessage current_ekm;
397 * Our message stream tokenizer (for encrypted payload).
399 static struct GNUNET_SERVER_MessageStreamTokenizer *mst;
404 static struct GSC_KeyExchangeInfo *kx_head;
409 static struct GSC_KeyExchangeInfo *kx_tail;
412 * Task scheduled for periodic re-generation (and thus rekeying) of our
415 static GNUNET_SCHEDULER_TaskIdentifier rekey_task;
419 * Derive an authentication key from "set key" information
421 * @param akey authentication key to derive
422 * @param skey session key to use
423 * @param seed seed to use
426 derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
427 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
429 static const char ctx[] = "authentication key";
431 GNUNET_CRYPTO_hmac_derive_key (akey, skey,
432 &seed, sizeof (seed),
433 skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
440 * Derive an IV from packet information
442 * @param iv initialization vector to initialize
443 * @param skey session key to use
444 * @param seed seed to use
445 * @param identity identity of the other peer to use
448 derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
449 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed,
450 const struct GNUNET_PeerIdentity *identity)
452 static const char ctx[] = "initialization vector";
454 GNUNET_CRYPTO_symmetric_derive_iv (iv, skey, &seed, sizeof (seed),
456 sizeof (struct GNUNET_PeerIdentity), ctx,
462 * Derive an IV from pong packet information
464 * @param iv initialization vector to initialize
465 * @param skey session key to use
466 * @param seed seed to use
467 * @param challenge nonce to use
468 * @param identity identity of the other peer to use
471 derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
472 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed,
473 uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
475 static const char ctx[] = "pong initialization vector";
477 GNUNET_CRYPTO_symmetric_derive_iv (iv, skey, &seed, sizeof (seed),
479 sizeof (struct GNUNET_PeerIdentity),
480 &challenge, sizeof (challenge),
487 * Derive an AES key from key material
489 * @param sender peer identity of the sender
490 * @param receiver peer identity of the sender
491 * @param key_material high entropy key material to use
492 * @param skey set to derived session key
495 derive_aes_key (const struct GNUNET_PeerIdentity *sender,
496 const struct GNUNET_PeerIdentity *receiver,
497 const struct GNUNET_HashCode *key_material,
498 struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
500 static const char ctx[] = "aes key generation vector";
502 GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
504 key_material, sizeof (struct GNUNET_HashCode),
505 sender, sizeof (struct GNUNET_PeerIdentity),
506 receiver, sizeof (struct GNUNET_PeerIdentity),
512 * Encrypt size bytes from in and write the result to out. Use the
513 * key for outbound traffic of the given neighbour.
515 * @param kx key information context
516 * @param iv initialization vector to use
517 * @param in ciphertext
518 * @param out plaintext
519 * @param size size of in/out
520 * @return GNUNET_OK on success
523 do_encrypt (struct GSC_KeyExchangeInfo *kx,
524 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
525 const void *in, void *out, size_t size)
527 if (size != (uint16_t) size)
532 GNUNET_assert (size ==
533 GNUNET_CRYPTO_symmetric_encrypt (in, (uint16_t) size,
534 &kx->encrypt_key, iv, out));
535 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes encrypted"), size,
537 /* the following is too sensitive to write to log files by accident,
538 so we require manual intervention to get this one... */
540 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
541 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
542 (unsigned int) size, GNUNET_i2s (&kx->peer),
543 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
552 * Decrypt size bytes from in and write the result to out. Use the
553 * key for inbound traffic of the given neighbour. This function does
554 * NOT do any integrity-checks on the result.
556 * @param kx key information context
557 * @param iv initialization vector to use
558 * @param in ciphertext
559 * @param out plaintext
560 * @param size size of @a in / @a out
561 * @return #GNUNET_OK on success
564 do_decrypt (struct GSC_KeyExchangeInfo *kx,
565 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
566 const void *in, void *out, size_t size)
568 if (size != (uint16_t) size)
573 if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) &&
574 (kx->status != KX_STATE_REKEY_SENT) )
577 return GNUNET_SYSERR;
580 GNUNET_CRYPTO_symmetric_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
584 return GNUNET_SYSERR;
586 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes decrypted"), size,
588 /* the following is too sensitive to write to log files by accident,
589 so we require manual intervention to get this one... */
591 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
592 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
593 (unsigned int) size, GNUNET_i2s (&kx->peer),
594 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
603 * Send our key (and encrypted PING) to the other peer.
605 * @param kx key exchange context
608 send_key (struct GSC_KeyExchangeInfo *kx);
612 * Task that will retry "send_key" if our previous attempt failed.
614 * @param cls our 'struct GSC_KeyExchangeInfo'
615 * @param tc scheduler context
618 set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 struct GSC_KeyExchangeInfo *kx = cls;
622 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
623 kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency);
624 GNUNET_assert (KX_STATE_DOWN != kx->status);
630 * Create a fresh PING message for transmission to the other peer.
632 * @param kx key exchange context to create PING for
635 setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
637 struct PingMessage pp;
638 struct PingMessage *pm;
639 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
642 pm->header.size = htons (sizeof (struct PingMessage));
643 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
645 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
646 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
647 pp.challenge = kx->ping_challenge;
648 pp.target = kx->peer;
649 do_encrypt (kx, &iv, &pp.target, &pm->target,
650 sizeof (struct PingMessage) - ((void *) &pm->target -
656 * Start the key exchange with the given peer.
658 * @param pid identity of the peer to do a key exchange with
659 * @return key exchange information context
661 struct GSC_KeyExchangeInfo *
662 GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
664 struct GSC_KeyExchangeInfo *kx;
665 struct GNUNET_HashCode h1;
666 struct GNUNET_HashCode h2;
668 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
669 "Initiating key exchange with `%s'\n",
671 GNUNET_STATISTICS_update (GSC_stats,
672 gettext_noop ("# key exchanges initiated"), 1,
674 kx = GNUNET_new (struct GSC_KeyExchangeInfo);
676 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
677 GNUNET_CONTAINER_DLL_insert (kx_head,
680 GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1);
681 GNUNET_CRYPTO_hash (&GSC_my_identity, sizeof (struct GNUNET_PeerIdentity), &h2);
683 kx->status = KX_STATE_KEY_SENT;
684 if (0 < GNUNET_CRYPTO_hash_cmp (&h1,
687 /* peer with "lower" identity starts KX, otherwise we typically end up
688 with both peers starting the exchange and transmit the 'set key'
694 /* peer with "higher" identity starts a delayed KX, if the "lower" peer
695 * does not start a KX since he sees no reasons to do so */
696 kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
697 &set_key_retry_task, kx);
704 * Stop key exchange with the given peer. Clean up key material.
706 * @param kx key exchange to stop
709 GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
711 GSC_SESSIONS_end (&kx->peer);
712 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
714 if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
716 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
717 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
719 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
721 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
722 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
724 GNUNET_CONTAINER_DLL_remove (kx_head,
732 * Send our PING to the other peer.
734 * @param kx key exchange context
737 send_ping (struct GSC_KeyExchangeInfo *kx)
739 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
745 * Derive fresh session keys from the current ephemeral keys.
747 * @param kx session to derive keys for
750 derive_session_keys (struct GSC_KeyExchangeInfo *kx)
752 struct GNUNET_HashCode key_material;
755 GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
756 &kx->other_ephemeral_key,
762 derive_aes_key (&GSC_my_identity,
766 derive_aes_key (&kx->peer,
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);
779 * We received a SET_KEY message. Validate and update
780 * our key material and status.
782 * @param kx key exchange status for the corresponding peer
783 * @param msg the set key message we received
786 GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
787 const struct GNUNET_MessageHeader *msg)
789 const struct EphemeralKeyMessage *m;
790 struct GNUNET_TIME_Absolute start_t;
791 struct GNUNET_TIME_Absolute end_t;
792 struct GNUNET_TIME_Absolute now;
793 enum KxStateMachine sender_status;
796 size = ntohs (msg->size);
797 if (sizeof (struct EphemeralKeyMessage) != size)
802 m = (const struct EphemeralKeyMessage *) msg;
803 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
804 if ( ( (KX_STATE_KEY_RECEIVED == kx->status) ||
805 (KX_STATE_UP == kx->status) ||
806 (KX_STATE_REKEY_SENT == kx->status) ) &&
807 (end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) )
809 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
813 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
815 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# ephemeral keys received"),
818 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
819 "Core service receives `%s' request from `%4s'.\n", "EPHEMERAL_KEY",
820 GNUNET_i2s (&kx->peer));
822 memcmp (&m->origin_identity,
823 &kx->peer.public_key,
824 sizeof (struct GNUNET_PeerIdentity)))
829 if ((ntohl (m->purpose.size) !=
830 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
831 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
832 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
833 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
834 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) ||
836 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY,
838 &m->signature, &m->origin_identity.public_key)))
840 /* invalid signature */
844 now = GNUNET_TIME_absolute_get ();
845 if ( (end_t.abs_value_us < GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value_us) ||
846 (start_t.abs_value_us > GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value_us) )
848 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
849 _("Ephemeral key message from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
850 GNUNET_i2s (&kx->peer),
852 start_t.abs_value_us,
856 kx->other_ephemeral_key = m->ephemeral_key;
857 kx->foreign_key_expires = end_t;
858 derive_session_keys (kx);
859 GNUNET_STATISTICS_update (GSC_stats,
860 gettext_noop ("# EPHEMERAL_KEY messages received"), 1,
863 /* check if we still need to send the sender our key */
864 sender_status = (enum KxStateMachine) ntohl (m->sender_status);
865 switch (sender_status)
870 case KX_STATE_KEY_SENT:
871 /* fine, need to send our key after updating our status, see below */
873 case KX_STATE_KEY_RECEIVED:
875 case KX_STATE_REKEY_SENT:
876 /* other peer already got our key */
882 /* check if we need to confirm everything is fine via PING + PONG */
886 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
887 kx->status = KX_STATE_KEY_RECEIVED;
888 if (KX_STATE_KEY_SENT == sender_status)
892 case KX_STATE_KEY_SENT:
893 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
894 kx->status = KX_STATE_KEY_RECEIVED;
895 if (KX_STATE_KEY_SENT == sender_status)
899 case KX_STATE_KEY_RECEIVED:
900 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
901 if (KX_STATE_KEY_SENT == sender_status)
906 kx->status = KX_STATE_REKEY_SENT;
907 if (KX_STATE_KEY_SENT == sender_status)
909 /* we got a new key, need to reconfirm! */
912 case KX_STATE_REKEY_SENT:
913 if (KX_STATE_KEY_SENT == sender_status)
915 /* we got a new key, need to reconfirm! */
926 * We received a PING message. Validate and transmit
929 * @param kx key exchange status for the corresponding peer
930 * @param msg the encrypted PING message itself
933 GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
934 const struct GNUNET_MessageHeader *msg)
936 const struct PingMessage *m;
937 struct PingMessage t;
938 struct PongMessage tx;
939 struct PongMessage tp;
940 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
943 msize = ntohs (msg->size);
944 if (msize != sizeof (struct PingMessage))
949 GNUNET_STATISTICS_update (GSC_stats,
950 gettext_noop ("# PING messages received"), 1,
952 if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
953 (kx->status != KX_STATE_UP) &&
954 (kx->status != KX_STATE_REKEY_SENT))
957 GNUNET_STATISTICS_update (GSC_stats,
958 gettext_noop ("# PING messages dropped (out of order)"), 1,
962 m = (const struct PingMessage *) msg;
963 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
964 "Core service receives `%s' request from `%4s'.\n", "PING",
965 GNUNET_i2s (&kx->peer));
966 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
968 do_decrypt (kx, &iv, &m->target, &t.target,
969 sizeof (struct PingMessage) - ((void *) &m->target -
976 memcmp (&t.target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
981 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
982 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
983 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
985 ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
986 sender, GNUNET_i2s (&GSC_my_identity), peer);
992 tx.challenge = t.challenge;
993 tx.target = t.target;
994 tp.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG);
995 tp.header.size = htons (sizeof (struct PongMessage));
997 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
998 derive_pong_iv (&iv, &kx->encrypt_key, tp.iv_seed, t.challenge, &kx->peer);
999 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
1000 sizeof (struct PongMessage) - ((void *) &tp.challenge -
1002 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
1004 GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
1005 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
1010 * Task triggered when a neighbour entry is about to time out
1011 * (and we should prevent this by sending a PING).
1013 * @param cls the 'struct GSC_KeyExchangeInfo'
1014 * @param tc scheduler context (not used)
1017 send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1019 struct GSC_KeyExchangeInfo *kx = cls;
1020 struct GNUNET_TIME_Relative retry;
1021 struct GNUNET_TIME_Relative left;
1023 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1024 left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
1025 if (0 == left.rel_value_us)
1027 GNUNET_STATISTICS_update (GSC_stats,
1028 gettext_noop ("# sessions terminated by timeout"),
1030 GSC_SESSIONS_end (&kx->peer);
1031 kx->status = KX_STATE_KEY_SENT;
1035 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
1036 GNUNET_i2s (&kx->peer));
1037 GNUNET_STATISTICS_update (GSC_stats,
1038 gettext_noop ("# keepalive messages sent"), 1,
1040 setup_fresh_ping (kx);
1041 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1042 kx->set_key_retry_frequency);
1044 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1045 MIN_PING_FREQUENCY);
1046 kx->keep_alive_task =
1047 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
1052 * We've seen a valid message from the other peer.
1053 * Update the time when the session would time out
1054 * and delay sending our keep alive message further.
1056 * @param kx key exchange where we saw activity
1059 update_timeout (struct GSC_KeyExchangeInfo *kx)
1062 GNUNET_TIME_relative_to_absolute
1063 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1064 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1065 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1066 kx->keep_alive_task =
1067 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1068 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1069 2), &send_keep_alive, kx);
1074 * We received a PONG message. Validate and update our status.
1076 * @param kx key exchange context for the the PONG
1077 * @param msg the encrypted PONG message itself
1080 GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1081 const struct GNUNET_MessageHeader *msg)
1083 const struct PongMessage *m;
1084 struct PongMessage t;
1085 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1088 msize = ntohs (msg->size);
1089 if (sizeof (struct PongMessage) != msize)
1091 GNUNET_break_op (0);
1094 GNUNET_STATISTICS_update (GSC_stats,
1095 gettext_noop ("# PONG messages received"), 1,
1100 GNUNET_STATISTICS_update (GSC_stats,
1101 gettext_noop ("# PONG messages dropped (connection down)"), 1,
1104 case KX_STATE_KEY_SENT:
1105 GNUNET_STATISTICS_update (GSC_stats,
1106 gettext_noop ("# PONG messages dropped (out of order)"), 1,
1109 case KX_STATE_KEY_RECEIVED:
1113 case KX_STATE_REKEY_SENT:
1119 m = (const struct PongMessage *) msg;
1120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1121 "Core service receives `%s' response from `%4s'.\n", "PONG",
1122 GNUNET_i2s (&kx->peer));
1123 /* mark as garbage, just to be sure */
1124 memset (&t, 255, sizeof (t));
1125 derive_pong_iv (&iv, &kx->decrypt_key, m->iv_seed, kx->ping_challenge,
1128 do_decrypt (kx, &iv, &m->challenge, &t.challenge,
1129 sizeof (struct PongMessage) - ((void *) &m->challenge -
1132 GNUNET_break_op (0);
1135 GNUNET_STATISTICS_update (GSC_stats,
1136 gettext_noop ("# PONG messages decrypted"), 1,
1138 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
1139 || (kx->ping_challenge != t.challenge))
1141 /* PONG malformed */
1142 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1143 "Received malformed `%s' wanted sender `%4s' with challenge %u\n",
1144 "PONG", GNUNET_i2s (&kx->peer),
1145 (unsigned int) kx->ping_challenge);
1146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1147 "Received malformed `%s' received from `%4s' with challenge %u\n",
1148 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
1151 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
1152 GNUNET_i2s (&kx->peer));
1153 /* no need to resend key any longer */
1154 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1156 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1157 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1162 GNUNET_assert (0); /* should be impossible */
1164 case KX_STATE_KEY_SENT:
1165 GNUNET_assert (0); /* should be impossible */
1167 case KX_STATE_KEY_RECEIVED:
1168 GNUNET_STATISTICS_update (GSC_stats,
1170 ("# session keys confirmed via PONG"), 1,
1172 kx->status = KX_STATE_UP;
1173 GSC_SESSIONS_create (&kx->peer, kx);
1174 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
1175 update_timeout (kx);
1178 GNUNET_STATISTICS_update (GSC_stats,
1180 ("# timeouts prevented via PONG"), 1,
1182 update_timeout (kx);
1184 case KX_STATE_REKEY_SENT:
1185 GNUNET_STATISTICS_update (GSC_stats,
1187 ("# rekey operations confirmed via PONG"), 1,
1189 kx->status = KX_STATE_UP;
1190 update_timeout (kx);
1200 * Send our key to the other peer.
1202 * @param kx key exchange context
1205 send_key (struct GSC_KeyExchangeInfo *kx)
1207 GNUNET_assert (KX_STATE_DOWN != kx->status);
1208 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1210 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1211 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1213 /* always update sender status in SET KEY message */
1214 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1215 "Sending key to `%s' (my status: %d)\n",
1216 GNUNET_i2s (&kx->peer),
1218 current_ekm.sender_status = htonl ((int32_t) (kx->status));
1219 GSC_NEIGHBOURS_transmit (&kx->peer, ¤t_ekm.header,
1220 kx->set_key_retry_frequency);
1221 kx->retry_set_key_task =
1222 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
1223 &set_key_retry_task, kx);
1228 * Encrypt and transmit a message with the given payload.
1230 * @param kx key exchange context
1231 * @param payload payload of the message
1232 * @param payload_size number of bytes in 'payload'
1235 GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1236 const void *payload, size_t payload_size)
1238 size_t used = payload_size + sizeof (struct EncryptedMessage);
1239 char pbuf[used]; /* plaintext */
1240 char cbuf[used]; /* ciphertext */
1241 struct EncryptedMessage *em; /* encrypted message */
1242 struct EncryptedMessage *ph; /* plaintext header */
1243 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1244 struct GNUNET_CRYPTO_AuthKey auth_key;
1246 ph = (struct EncryptedMessage *) pbuf;
1248 htonl (GNUNET_CRYPTO_random_u32
1249 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
1250 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1252 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1253 memcpy (&ph[1], payload, payload_size);
1255 em = (struct EncryptedMessage *) cbuf;
1256 em->header.size = htons (used);
1257 em->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE);
1258 em->iv_seed = ph->iv_seed;
1259 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
1260 GNUNET_assert (GNUNET_OK ==
1261 do_encrypt (kx, &iv, &ph->sequence_number,
1262 &em->sequence_number,
1263 used - ENCRYPTED_HEADER_SIZE));
1264 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
1265 used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1266 derive_auth_key (&auth_key,
1269 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
1270 used - ENCRYPTED_HEADER_SIZE, &em->hmac);
1271 GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
1272 GNUNET_TIME_UNIT_FOREVER_REL);
1277 * Closure for #deliver_message()
1279 struct DeliverMessageContext
1283 * Key exchange context.
1285 struct GSC_KeyExchangeInfo *kx;
1288 * Sender of the message.
1290 const struct GNUNET_PeerIdentity *peer;
1295 * We received an encrypted message. Decrypt, validate and
1296 * pass on to the appropriate clients.
1298 * @param kx key exchange context for encrypting the message
1299 * @param msg encrypted message
1302 GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1303 const struct GNUNET_MessageHeader *msg)
1305 const struct EncryptedMessage *m;
1306 struct EncryptedMessage *pt; /* plaintext */
1307 struct GNUNET_HashCode ph;
1309 struct GNUNET_TIME_Absolute t;
1310 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1311 struct GNUNET_CRYPTO_AuthKey auth_key;
1312 struct DeliverMessageContext dmc;
1313 uint16_t size = ntohs (msg->size);
1314 char buf[size] GNUNET_ALIGN;
1317 sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader))
1319 GNUNET_break_op (0);
1322 m = (const struct EncryptedMessage *) msg;
1323 if (KX_STATE_UP != kx->status)
1325 GNUNET_STATISTICS_update (GSC_stats,
1327 ("# DATA message dropped (out of order)"),
1331 if (0 == GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value_us)
1333 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1334 _("Session to peer `%s' went down due to key expiration (should not happen)\n"),
1335 GNUNET_i2s (&kx->peer));
1336 GNUNET_STATISTICS_update (GSC_stats,
1337 gettext_noop ("# sessions terminated by key expiration"),
1339 GSC_SESSIONS_end (&kx->peer);
1340 if (GNUNET_SCHEDULER_NO_TASK != kx->keep_alive_task)
1342 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1343 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1345 kx->status = KX_STATE_KEY_SENT;
1351 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed);
1352 GNUNET_CRYPTO_hmac (&auth_key, &m->sequence_number,
1353 size - ENCRYPTED_HEADER_SIZE, &ph);
1354 if (0 != memcmp (&ph, &m->hmac, sizeof (struct GNUNET_HashCode)))
1356 /* checksum failed */
1357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1358 "Failed checksum validation for a message from `%s'\n",
1359 GNUNET_i2s (&kx->peer));
1362 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1365 do_decrypt (kx, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
1366 size - ENCRYPTED_HEADER_SIZE))
1368 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1369 "Decrypted %u bytes from %s\n",
1370 size - ENCRYPTED_HEADER_SIZE,
1371 GNUNET_i2s (&kx->peer));
1372 pt = (struct EncryptedMessage *) buf;
1374 /* validate sequence number */
1375 snum = ntohl (pt->sequence_number);
1376 if (kx->last_sequence_number_received == snum)
1378 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1379 "Received duplicate message, ignoring.\n");
1380 /* duplicate, ignore */
1381 GNUNET_STATISTICS_update (GSC_stats,
1382 gettext_noop ("# bytes dropped (duplicates)"),
1386 if ((kx->last_sequence_number_received > snum) &&
1387 (kx->last_sequence_number_received - snum > 32))
1389 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1390 "Received ancient out of sequence message, ignoring.\n");
1391 /* ancient out of sequence, ignore */
1392 GNUNET_STATISTICS_update (GSC_stats,
1394 ("# bytes dropped (out of sequence)"), size,
1398 if (kx->last_sequence_number_received > snum)
1400 unsigned int rotbit = 1 << (kx->last_sequence_number_received - snum - 1);
1402 if ((kx->last_packets_bitmap & rotbit) != 0)
1404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1405 "Received duplicate message, ignoring.\n");
1406 GNUNET_STATISTICS_update (GSC_stats,
1407 gettext_noop ("# bytes dropped (duplicates)"),
1409 /* duplicate, ignore */
1412 kx->last_packets_bitmap |= rotbit;
1414 if (kx->last_sequence_number_received < snum)
1416 unsigned int shift = (snum - kx->last_sequence_number_received);
1418 if (shift >= 8 * sizeof (kx->last_packets_bitmap))
1419 kx->last_packets_bitmap = 0;
1421 kx->last_packets_bitmap <<= shift;
1422 kx->last_sequence_number_received = snum;
1425 /* check timestamp */
1426 t = GNUNET_TIME_absolute_ntoh (pt->timestamp);
1427 if (GNUNET_TIME_absolute_get_duration (t).rel_value_us >
1428 MAX_MESSAGE_AGE.rel_value_us)
1430 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1431 "Message received far too old (%s). Content ignored.\n",
1432 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t),
1434 GNUNET_STATISTICS_update (GSC_stats,
1436 ("# bytes dropped (ancient message)"), size,
1441 /* process decrypted message(s) */
1442 update_timeout (kx);
1443 GNUNET_STATISTICS_update (GSC_stats,
1444 gettext_noop ("# bytes of payload decrypted"),
1445 size - sizeof (struct EncryptedMessage),
1448 dmc.peer = &kx->peer;
1450 GNUNET_SERVER_mst_receive (mst, &dmc,
1451 &buf[sizeof (struct EncryptedMessage)],
1452 size - sizeof (struct EncryptedMessage),
1455 GNUNET_break_op (0);
1460 * Deliver P2P message to interested clients.
1461 * Invokes send twice, once for clients that want the full message, and once
1462 * for clients that only want the header
1464 * @param cls always NULL
1465 * @param client who sent us the message (struct GSC_KeyExchangeInfo)
1466 * @param m the message
1469 deliver_message (void *cls,
1471 const struct GNUNET_MessageHeader *m)
1473 struct DeliverMessageContext *dmc = client;
1475 if (KX_STATE_UP != dmc->kx->status)
1477 GNUNET_STATISTICS_update (GSC_stats,
1479 ("# PAYLOAD dropped (out of order)"),
1483 switch (ntohs (m->type))
1485 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
1486 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
1487 GSC_SESSIONS_set_typemap (dmc->peer, m);
1490 GSC_CLIENTS_deliver_message (dmc->peer, m,
1492 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
1493 GSC_CLIENTS_deliver_message (dmc->peer, m,
1494 sizeof (struct GNUNET_MessageHeader),
1495 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1502 * Setup the message that links the ephemeral key to our persistent
1503 * public key and generate the appropriate signature.
1506 sign_ephemeral_key ()
1508 current_ekm.header.size = htons (sizeof (struct EphemeralKeyMessage));
1509 current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY);
1510 current_ekm.sender_status = 0; /* to be set later */
1511 current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY);
1512 current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1513 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1514 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1515 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
1516 sizeof (struct GNUNET_PeerIdentity));
1517 current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1519 GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
1521 "USE_EPHEMERAL_KEYS"))
1523 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_add (REKEY_FREQUENCY,
1528 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1530 GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key,
1531 ¤t_ekm.ephemeral_key);
1532 current_ekm.origin_identity = GSC_my_identity;
1533 GNUNET_assert (GNUNET_OK ==
1534 GNUNET_CRYPTO_eddsa_sign (my_private_key,
1535 ¤t_ekm.purpose,
1536 ¤t_ekm.signature));
1541 * Task run to trigger rekeying.
1543 * @param cls closure, NULL
1544 * @param tc scheduler context
1547 do_rekey (void *cls,
1548 const struct GNUNET_SCHEDULER_TaskContext *tc)
1550 struct GSC_KeyExchangeInfo *pos;
1552 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1555 if (NULL != my_ephemeral_key)
1556 GNUNET_free (my_ephemeral_key);
1557 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
1558 GNUNET_assert (NULL != my_ephemeral_key);
1559 sign_ephemeral_key ();
1560 for (pos = kx_head; NULL != pos; pos = pos->next)
1562 if (KX_STATE_UP == pos->status)
1564 pos->status = KX_STATE_REKEY_SENT;
1565 derive_session_keys (pos);
1567 if (KX_STATE_DOWN == pos->status)
1569 pos->status = KX_STATE_KEY_SENT;
1577 * Initialize KX subsystem.
1579 * @param pk private key to use for the peer
1580 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1583 GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
1585 my_private_key = pk;
1586 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
1587 &GSC_my_identity.public_key);
1588 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
1589 if (NULL == my_ephemeral_key)
1592 GNUNET_free (my_private_key);
1593 my_private_key = NULL;
1594 return GNUNET_SYSERR;
1596 sign_ephemeral_key ();
1597 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1600 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
1606 * Shutdown KX subsystem.
1611 if (GNUNET_SCHEDULER_NO_TASK != rekey_task)
1613 GNUNET_SCHEDULER_cancel (rekey_task);
1614 rekey_task = GNUNET_SCHEDULER_NO_TASK;
1616 if (NULL != my_ephemeral_key)
1618 GNUNET_free (my_ephemeral_key);
1619 my_ephemeral_key = NULL;
1621 if (NULL != my_private_key)
1623 GNUNET_free (my_private_key);
1624 my_private_key = NULL;
1628 GNUNET_SERVER_mst_destroy (mst);
1633 /* end of gnunet-service-core_kx.c */