2 This file is part of GNUnet.
3 (C) 2009, 2010, 2011, 2012 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, 1)
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_EccSignature 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 (always for NIST P-521) encoded in a format suitable
112 * for network transmission as created using 'gcry_sexp_sprint'.
114 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded ephemeral_key;
117 * Public key of the signing peer (persistent version, not the ephemeral public key).
119 struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded origin_public_key;
125 * We're sending an (encrypted) PING to the other peer to check if he
126 * can decrypt. The other peer should respond with a PONG with the
127 * same content, except this time encrypted with the receiver's key.
132 * Message type is CORE_PING.
134 struct GNUNET_MessageHeader header;
139 uint32_t iv_seed GNUNET_PACKED;
142 * Intended target of the PING, used primarily to check
143 * that decryption actually worked.
145 struct GNUNET_PeerIdentity target;
148 * Random number chosen to make reply harder.
150 uint32_t challenge GNUNET_PACKED;
155 * Response to a PING. Includes data from the original PING.
160 * Message type is CORE_PONG.
162 struct GNUNET_MessageHeader header;
167 uint32_t iv_seed GNUNET_PACKED;
170 * Random number to make faking the reply harder. Must be
171 * first field after header (this is where we start to encrypt!).
173 uint32_t challenge GNUNET_PACKED;
176 * Reserved, always zero.
181 * Intended target of the PING, used primarily to check
182 * that decryption actually worked.
184 struct GNUNET_PeerIdentity target;
189 * Encapsulation for encrypted messages exchanged between
190 * peers. Followed by the actual encrypted data.
192 struct EncryptedMessage
195 * Message type is either CORE_ENCRYPTED_MESSAGE.
197 struct GNUNET_MessageHeader header;
200 * Random value used for IV generation.
202 uint32_t iv_seed GNUNET_PACKED;
205 * MAC of the encrypted message (starting at 'sequence_number'),
206 * used to verify message integrity. Everything after this value
207 * (excluding this value itself) will be encrypted and authenticated.
208 * ENCRYPTED_HEADER_SIZE must be set to the offset of the *next* field.
210 struct GNUNET_HashCode hmac;
213 * Sequence number, in network byte order. This field
214 * must be the first encrypted/decrypted field
216 uint32_t sequence_number GNUNET_PACKED;
219 * Reserved, always zero.
224 * Timestamp. Used to prevent reply of ancient messages
225 * (recent messages are caught with the sequence number).
227 struct GNUNET_TIME_AbsoluteNBO timestamp;
230 GNUNET_NETWORK_STRUCT_END
234 * Number of bytes (at the beginning) of "struct EncryptedMessage"
235 * that are NOT encrypted.
237 #define ENCRYPTED_HEADER_SIZE (offsetof(struct EncryptedMessage, sequence_number))
241 * State machine for our P2P encryption handshake. Everyone starts in
242 * "DOWN", if we receive the other peer's key (other peer initiated)
243 * we start in state RECEIVED (since we will immediately send our
244 * own); otherwise we start in SENT. If we get back a PONG from
245 * within either state, we move up to CONFIRMED (the PONG will always
246 * be sent back encrypted with the key we sent to the other peer).
256 * We've sent our session key.
261 * We've received the other peers session key.
263 KX_STATE_KEY_RECEIVED,
266 * The other peer has confirmed our session key + PING with a PONG
267 * message encrypted with his session key (which we got). Key
273 * We're rekeying (or had a timeout), so we have sent the other peer
274 * our new ephemeral key, but we did not get a matching PONG yet.
275 * This is equivalent to being 'KX_STATE_KEY_RECEIVED', except that
276 * the session is marked as 'up' with sessions (as we don't want to
277 * drop and re-establish P2P connections simply due to rekeying).
285 * Information about the status of a key exchange with another peer.
287 struct GSC_KeyExchangeInfo
293 struct GSC_KeyExchangeInfo *next;
298 struct GSC_KeyExchangeInfo *prev;
301 * Identity of the peer.
303 struct GNUNET_PeerIdentity peer;
306 * PING message we transmit to the other peer.
308 struct PingMessage ping;
311 * Key we use to encrypt our messages for the other peer
312 * (initialized by us when we do the handshake).
314 struct GNUNET_CRYPTO_AesSessionKey encrypt_key;
317 * Key we use to decrypt messages from the other peer
318 * (given to us by the other peer during the handshake).
320 struct GNUNET_CRYPTO_AesSessionKey decrypt_key;
323 * At what time did the other peer generate the decryption key?
325 struct GNUNET_TIME_Absolute foreign_key_expires;
328 * When should the session time out (if there are no PONGs)?
330 struct GNUNET_TIME_Absolute timeout;
333 * At what frequency are we currently re-trying SET_KEY messages?
335 struct GNUNET_TIME_Relative set_key_retry_frequency;
338 * ID of task used for re-trying SET_KEY and PING message.
340 GNUNET_SCHEDULER_TaskIdentifier retry_set_key_task;
343 * ID of task used for sending keep-alive pings.
345 GNUNET_SCHEDULER_TaskIdentifier keep_alive_task;
348 * Bit map indicating which of the 32 sequence numbers before the last
349 * were received (good for accepting out-of-order packets and
350 * estimating reliability of the connection)
352 unsigned int last_packets_bitmap;
355 * last sequence number received on this connection (highest)
357 uint32_t last_sequence_number_received;
360 * last sequence number transmitted
362 uint32_t last_sequence_number_sent;
365 * What was our PING challenge number (for this peer)?
367 uint32_t ping_challenge;
370 * What is our connection status?
372 enum KxStateMachine status;
380 static struct GNUNET_CRYPTO_EccPrivateKey *my_private_key;
383 * Our ephemeral private key.
385 static struct GNUNET_CRYPTO_EccPrivateKey *my_ephemeral_key;
388 * Current message we send for a key exchange.
390 static struct EphemeralKeyMessage current_ekm;
395 static struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded my_public_key;
398 * Our message stream tokenizer (for encrypted payload).
400 static struct GNUNET_SERVER_MessageStreamTokenizer *mst;
405 static struct GSC_KeyExchangeInfo *kx_head;
410 static struct GSC_KeyExchangeInfo *kx_tail;
413 * Task scheduled for periodic re-generation (and thus rekeying) of our
416 static GNUNET_SCHEDULER_TaskIdentifier rekey_task;
420 * Derive an authentication key from "set key" information
422 * @param akey authentication key to derive
423 * @param skey session key to use
424 * @param seed seed to use
427 derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
428 const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed)
430 static const char ctx[] = "authentication key";
432 GNUNET_CRYPTO_hmac_derive_key (akey, skey, &seed, sizeof (seed), &skey->key,
433 sizeof (skey->key), ctx,
439 * Derive an IV from packet information
441 * @param iv initialization vector to initialize
442 * @param skey session key to use
443 * @param seed seed to use
444 * @param identity identity of the other peer to use
447 derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
448 const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
449 const struct GNUNET_PeerIdentity *identity)
451 static const char ctx[] = "initialization vector";
453 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
454 &identity->hashPubKey.bits,
455 sizeof (identity->hashPubKey.bits), ctx,
461 * Derive an IV from pong packet information
463 * @param iv initialization vector to initialize
464 * @param skey session key to use
465 * @param seed seed to use
466 * @param challenge nonce to use
467 * @param identity identity of the other peer to use
470 derive_pong_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
471 const struct GNUNET_CRYPTO_AesSessionKey *skey, uint32_t seed,
472 uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
474 static const char ctx[] = "pong initialization vector";
476 GNUNET_CRYPTO_aes_derive_iv (iv, skey, &seed, sizeof (seed),
477 &identity->hashPubKey.bits,
478 sizeof (identity->hashPubKey.bits), &challenge,
479 sizeof (challenge), ctx, sizeof (ctx), NULL);
484 * Derive an AES key from key material
486 * @param sender peer identity of the sender
487 * @param receiver peer identity of the sender
488 * @param key_material high entropy key material to use
489 * @param skey set to derived session key
492 derive_aes_key (const struct GNUNET_PeerIdentity *sender,
493 const struct GNUNET_PeerIdentity *receiver,
494 const struct GNUNET_HashCode *key_material,
495 struct GNUNET_CRYPTO_AesSessionKey *skey)
497 static const char ctx[] = "aes key generation vector";
499 GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
501 skey, sizeof (struct GNUNET_CRYPTO_AesSessionKey),
502 sender, sizeof (struct GNUNET_PeerIdentity),
503 receiver, sizeof (struct GNUNET_PeerIdentity),
509 * Encrypt size bytes from in and write the result to out. Use the
510 * key for outbound traffic of the given neighbour.
512 * @param kx key information context
513 * @param iv initialization vector to use
514 * @param in ciphertext
515 * @param out plaintext
516 * @param size size of in/out
517 * @return GNUNET_OK on success
520 do_encrypt (struct GSC_KeyExchangeInfo *kx,
521 const struct GNUNET_CRYPTO_AesInitializationVector *iv,
522 const void *in, void *out, size_t size)
524 if (size != (uint16_t) size)
529 GNUNET_assert (size ==
530 GNUNET_CRYPTO_aes_encrypt (in, (uint16_t) size,
531 &kx->encrypt_key, iv, out));
532 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes encrypted"), size,
534 /* the following is too sensitive to write to log files by accident,
535 so we require manual intervention to get this one... */
537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
538 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
539 (unsigned int) size, GNUNET_i2s (&kx->peer),
540 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
549 * Decrypt size bytes from in and write the result to out. Use the
550 * key for inbound traffic of the given neighbour. This function does
551 * NOT do any integrity-checks on the result.
553 * @param kx key information context
554 * @param iv initialization vector to use
555 * @param in ciphertext
556 * @param out plaintext
557 * @param size size of in/out
558 * @return GNUNET_OK on success
561 do_decrypt (struct GSC_KeyExchangeInfo *kx,
562 const struct GNUNET_CRYPTO_AesInitializationVector *iv,
563 const void *in, void *out, size_t size)
565 if (size != (uint16_t) size)
570 if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) &&
571 (kx->status != KX_STATE_REKEY_SENT) )
574 return GNUNET_SYSERR;
577 GNUNET_CRYPTO_aes_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
581 return GNUNET_SYSERR;
583 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes decrypted"), size,
585 /* the following is too sensitive to write to log files by accident,
586 so we require manual intervention to get this one... */
588 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
589 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
590 (unsigned int) size, GNUNET_i2s (&kx->peer),
591 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
600 * Send our key (and encrypted PING) to the other peer.
602 * @param kx key exchange context
605 send_key (struct GSC_KeyExchangeInfo *kx);
609 * Task that will retry "send_key" if our previous attempt failed.
611 * @param cls our 'struct GSC_KeyExchangeInfo'
612 * @param tc scheduler context
615 set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
617 struct GSC_KeyExchangeInfo *kx = cls;
619 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
620 kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency);
621 GNUNET_assert (KX_STATE_DOWN != kx->status);
627 * Create a fresh PING message for transmission to the other peer.
629 * @param kx key exchange context to create PING for
632 setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
634 struct PingMessage pp;
635 struct PingMessage *pm;
636 struct GNUNET_CRYPTO_AesInitializationVector iv;
639 pm->header.size = htons (sizeof (struct PingMessage));
640 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
642 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
643 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
644 pp.challenge = kx->ping_challenge;
645 pp.target = kx->peer;
646 do_encrypt (kx, &iv, &pp.target, &pm->target,
647 sizeof (struct PingMessage) - ((void *) &pm->target -
653 * Start the key exchange with the given peer.
655 * @param pid identity of the peer to do a key exchange with
656 * @return key exchange information context
658 struct GSC_KeyExchangeInfo *
659 GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
661 struct GSC_KeyExchangeInfo *kx;
663 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
664 "Initiating key exchange with `%s'\n",
666 GNUNET_STATISTICS_update (GSC_stats,
667 gettext_noop ("# key exchanges initiated"), 1,
669 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
671 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
672 GNUNET_CONTAINER_DLL_insert (kx_head,
675 if (0 < GNUNET_CRYPTO_hash_cmp (&pid->hashPubKey,
676 &GSC_my_identity.hashPubKey))
678 /* peer with "lower" identity starts KX, otherwise we typically end up
679 with both peers starting the exchange and transmit the 'set key'
681 kx->status = KX_STATE_KEY_SENT;
689 * Stop key exchange with the given peer. Clean up key material.
691 * @param kx key exchange to stop
694 GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
696 GSC_SESSIONS_end (&kx->peer);
697 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
699 if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
701 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
702 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
704 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
706 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
707 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
709 GNUNET_CONTAINER_DLL_remove (kx_head,
717 * Send our PING to the other peer.
719 * @param kx key exchange context
722 send_ping (struct GSC_KeyExchangeInfo *kx)
724 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
729 * We received a SET_KEY message. Validate and update
730 * our key material and status.
732 * @param kx key exchange status for the corresponding peer
733 * @param msg the set key message we received
736 GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
737 const struct GNUNET_MessageHeader *msg)
739 const struct EphemeralKeyMessage *m;
740 struct GNUNET_TIME_Absolute start_t;
741 struct GNUNET_TIME_Absolute end_t;
742 struct GNUNET_TIME_Absolute now;
743 struct GNUNET_PeerIdentity signer_id;
744 enum KxStateMachine sender_status;
746 struct GNUNET_HashCode key_material;
748 size = ntohs (msg->size);
749 if (sizeof (struct EphemeralKeyMessage) != size)
754 m = (const struct EphemeralKeyMessage *) msg;
755 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
756 if ( ( (KX_STATE_KEY_RECEIVED == kx->status) ||
757 (KX_STATE_UP == kx->status) ||
758 (KX_STATE_REKEY_SENT == kx->status) ) &&
759 (end_t.abs_value <= kx->foreign_key_expires.abs_value) )
761 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
765 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
767 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# ephemeral keys received"),
770 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
771 "Core service receives `%s' request from `%4s'.\n", "EPHEMERAL_KEY",
772 GNUNET_i2s (&kx->peer));
773 GNUNET_CRYPTO_hash (&m->origin_public_key,
774 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded),
775 &signer_id.hashPubKey);
777 memcmp (&signer_id, &kx->peer,
778 sizeof (struct GNUNET_PeerIdentity)))
783 if ((ntohl (m->purpose.size) !=
784 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
785 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
786 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
787 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
788 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded)) ||
790 GNUNET_CRYPTO_ecc_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY,
792 &m->signature, &m->origin_public_key)))
794 /* invalid signature */
798 now = GNUNET_TIME_absolute_get ();
799 if ( (end_t.abs_value < GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value) ||
800 (start_t.abs_value > GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value) )
802 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
803 _("Ephemeral key message rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
810 GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
817 GNUNET_STATISTICS_update (GSC_stats,
818 gettext_noop ("# EPHEMERAL_KEY messages decrypted"), 1,
820 derive_aes_key (&GSC_my_identity,
824 derive_aes_key (&kx->peer,
828 /* fresh key, reset sequence numbers */
829 kx->last_sequence_number_received = 0;
830 kx->last_packets_bitmap = 0;
831 kx->foreign_key_expires = end_t;
832 setup_fresh_ping (kx);
834 /* check if we still need to send the sender our key */
835 sender_status = (enum KxStateMachine) ntohl (m->sender_status);
836 switch (sender_status)
841 case KX_STATE_KEY_SENT:
842 /* fine, need to send our key after updating our status, see below */
844 case KX_STATE_KEY_RECEIVED:
846 case KX_STATE_REKEY_SENT:
847 /* other peer already got our key */
853 /* check if we need to confirm everything is fine via PING + PONG */
857 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
858 kx->status = KX_STATE_KEY_RECEIVED;
859 if (KX_STATE_KEY_SENT == sender_status)
863 case KX_STATE_KEY_SENT:
864 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
865 kx->status = KX_STATE_KEY_RECEIVED;
866 if (KX_STATE_KEY_SENT == sender_status)
870 case KX_STATE_KEY_RECEIVED:
871 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
872 if (KX_STATE_KEY_SENT == sender_status)
877 kx->status = KX_STATE_REKEY_SENT;
878 if (KX_STATE_KEY_SENT == sender_status)
880 /* we got a new key, need to reconfirm! */
883 case KX_STATE_REKEY_SENT:
884 if (KX_STATE_KEY_SENT == sender_status)
886 /* we got a new key, need to reconfirm! */
897 * We received a PING message. Validate and transmit
900 * @param kx key exchange status for the corresponding peer
901 * @param msg the encrypted PING message itself
904 GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
905 const struct GNUNET_MessageHeader *msg)
907 const struct PingMessage *m;
908 struct PingMessage t;
909 struct PongMessage tx;
910 struct PongMessage tp;
911 struct GNUNET_CRYPTO_AesInitializationVector iv;
914 msize = ntohs (msg->size);
915 if (msize != sizeof (struct PingMessage))
920 GNUNET_STATISTICS_update (GSC_stats,
921 gettext_noop ("# PING messages received"), 1,
923 if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
924 (kx->status != KX_STATE_UP) &&
925 (kx->status != KX_STATE_REKEY_SENT))
928 GNUNET_STATISTICS_update (GSC_stats,
929 gettext_noop ("# PING messages dropped (out of order)"), 1,
933 m = (const struct PingMessage *) msg;
934 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
935 "Core service receives `%s' request from `%4s'.\n", "PING",
936 GNUNET_i2s (&kx->peer));
937 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
939 do_decrypt (kx, &iv, &m->target, &t.target,
940 sizeof (struct PingMessage) - ((void *) &m->target -
947 memcmp (&t.target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
952 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
953 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
954 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
956 ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
957 sender, GNUNET_i2s (&GSC_my_identity), peer);
963 tx.challenge = t.challenge;
964 tx.target = t.target;
965 tp.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG);
966 tp.header.size = htons (sizeof (struct PongMessage));
968 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
969 derive_pong_iv (&iv, &kx->encrypt_key, tp.iv_seed, t.challenge, &kx->peer);
970 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
971 sizeof (struct PongMessage) - ((void *) &tp.challenge -
973 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
975 GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
976 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
981 * Task triggered when a neighbour entry is about to time out
982 * (and we should prevent this by sending a PING).
984 * @param cls the 'struct GSC_KeyExchangeInfo'
985 * @param tc scheduler context (not used)
988 send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
990 struct GSC_KeyExchangeInfo *kx = cls;
991 struct GNUNET_TIME_Relative retry;
992 struct GNUNET_TIME_Relative left;
994 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
995 left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
996 if (0 == left.rel_value)
998 GNUNET_STATISTICS_update (GSC_stats,
999 gettext_noop ("# sessions terminated by timeout"),
1001 GSC_SESSIONS_end (&kx->peer);
1002 kx->status = KX_STATE_KEY_SENT;
1006 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
1007 GNUNET_i2s (&kx->peer));
1008 GNUNET_STATISTICS_update (GSC_stats,
1009 gettext_noop ("# keepalive messages sent"), 1,
1011 setup_fresh_ping (kx);
1012 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1013 kx->set_key_retry_frequency);
1015 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1016 MIN_PING_FREQUENCY);
1017 kx->keep_alive_task =
1018 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
1023 * We've seen a valid message from the other peer.
1024 * Update the time when the session would time out
1025 * and delay sending our keep alive message further.
1027 * @param kx key exchange where we saw activity
1030 update_timeout (struct GSC_KeyExchangeInfo *kx)
1033 GNUNET_TIME_relative_to_absolute
1034 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1035 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1036 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1037 kx->keep_alive_task =
1038 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1039 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1040 2), &send_keep_alive, kx);
1045 * We received a PONG message. Validate and update our status.
1047 * @param kx key exchange context for the the PONG
1048 * @param msg the encrypted PONG message itself
1051 GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1052 const struct GNUNET_MessageHeader *msg)
1054 const struct PongMessage *m;
1055 struct PongMessage t;
1056 struct GNUNET_CRYPTO_AesInitializationVector iv;
1059 msize = ntohs (msg->size);
1060 if (sizeof (struct PongMessage) != msize)
1062 GNUNET_break_op (0);
1065 GNUNET_STATISTICS_update (GSC_stats,
1066 gettext_noop ("# PONG messages received"), 1,
1071 GNUNET_STATISTICS_update (GSC_stats,
1072 gettext_noop ("# PONG messages dropped (connection down)"), 1,
1075 case KX_STATE_KEY_SENT:
1076 GNUNET_STATISTICS_update (GSC_stats,
1077 gettext_noop ("# PONG messages dropped (out of order)"), 1,
1080 case KX_STATE_KEY_RECEIVED:
1084 case KX_STATE_REKEY_SENT:
1090 m = (const struct PongMessage *) msg;
1091 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1092 "Core service receives `%s' response from `%4s'.\n", "PONG",
1093 GNUNET_i2s (&kx->peer));
1094 /* mark as garbage, just to be sure */
1095 memset (&t, 255, sizeof (t));
1096 derive_pong_iv (&iv, &kx->decrypt_key, m->iv_seed, kx->ping_challenge,
1099 do_decrypt (kx, &iv, &m->challenge, &t.challenge,
1100 sizeof (struct PongMessage) - ((void *) &m->challenge -
1103 GNUNET_break_op (0);
1106 GNUNET_STATISTICS_update (GSC_stats,
1107 gettext_noop ("# PONG messages decrypted"), 1,
1109 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
1110 || (kx->ping_challenge != t.challenge))
1112 /* PONG malformed */
1113 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1114 "Received malformed `%s' wanted sender `%4s' with challenge %u\n",
1115 "PONG", GNUNET_i2s (&kx->peer),
1116 (unsigned int) kx->ping_challenge);
1117 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1118 "Received malformed `%s' received from `%4s' with challenge %u\n",
1119 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
1123 GNUNET_i2s (&kx->peer));
1124 /* no need to resend key any longer */
1125 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1127 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1128 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1133 GNUNET_assert (0); /* should be impossible */
1135 case KX_STATE_KEY_SENT:
1136 GNUNET_assert (0); /* should be impossible */
1138 case KX_STATE_KEY_RECEIVED:
1139 GNUNET_STATISTICS_update (GSC_stats,
1141 ("# session keys confirmed via PONG"), 1,
1143 kx->status = KX_STATE_UP;
1144 GSC_SESSIONS_create (&kx->peer, kx);
1145 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
1146 update_timeout (kx);
1149 GNUNET_STATISTICS_update (GSC_stats,
1151 ("# timeouts prevented via PONG"), 1,
1153 update_timeout (kx);
1155 case KX_STATE_REKEY_SENT:
1156 GNUNET_STATISTICS_update (GSC_stats,
1158 ("# rekey operations confirmed via PONG"), 1,
1160 kx->status = KX_STATE_UP;
1161 update_timeout (kx);
1171 * Send our key to the other peer.
1173 * @param kx key exchange context
1176 send_key (struct GSC_KeyExchangeInfo *kx)
1178 GNUNET_assert (KX_STATE_DOWN != kx->status);
1179 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1181 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1182 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1184 /* always update sender status in SET KEY message */
1185 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1186 "Sending key to `%s' (my status: %d)\n",
1187 GNUNET_i2s (&kx->peer),
1189 current_ekm.sender_status = htonl ((int32_t) (kx->status));
1190 GSC_NEIGHBOURS_transmit (&kx->peer, ¤t_ekm.header,
1191 kx->set_key_retry_frequency);
1192 kx->retry_set_key_task =
1193 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
1194 &set_key_retry_task, kx);
1199 * Encrypt and transmit a message with the given payload.
1201 * @param kx key exchange context
1202 * @param payload payload of the message
1203 * @param payload_size number of bytes in 'payload'
1206 GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1207 const void *payload, size_t payload_size)
1209 size_t used = payload_size + sizeof (struct EncryptedMessage);
1210 char pbuf[used]; /* plaintext */
1211 char cbuf[used]; /* ciphertext */
1212 struct EncryptedMessage *em; /* encrypted message */
1213 struct EncryptedMessage *ph; /* plaintext header */
1214 struct GNUNET_CRYPTO_AesInitializationVector iv;
1215 struct GNUNET_CRYPTO_AuthKey auth_key;
1217 ph = (struct EncryptedMessage *) pbuf;
1219 htonl (GNUNET_CRYPTO_random_u32
1220 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
1221 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1223 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1224 memcpy (&ph[1], payload, payload_size);
1226 em = (struct EncryptedMessage *) cbuf;
1227 em->header.size = htons (used);
1228 em->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE);
1229 em->iv_seed = ph->iv_seed;
1230 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
1231 GNUNET_assert (GNUNET_OK ==
1232 do_encrypt (kx, &iv, &ph->sequence_number,
1233 &em->sequence_number,
1234 used - ENCRYPTED_HEADER_SIZE));
1235 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
1236 used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1237 derive_auth_key (&auth_key,
1240 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
1241 used - ENCRYPTED_HEADER_SIZE, &em->hmac);
1242 GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
1243 GNUNET_TIME_UNIT_FOREVER_REL);
1248 * Closure for 'deliver_message'
1250 struct DeliverMessageContext
1254 * Performance information for the connection.
1256 const struct GNUNET_ATS_Information *atsi;
1259 * Key exchange context.
1261 struct GSC_KeyExchangeInfo *kx;
1264 * Sender of the message.
1266 const struct GNUNET_PeerIdentity *peer;
1269 * Number of entries in 'atsi' array.
1271 uint32_t atsi_count;
1276 * We received an encrypted message. Decrypt, validate and
1277 * pass on to the appropriate clients.
1279 * @param kx key exchange context for encrypting the message
1280 * @param msg encrypted message
1281 * @param atsi performance data
1282 * @param atsi_count number of entries in ats (excluding 0-termination)
1285 GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1286 const struct GNUNET_MessageHeader *msg,
1287 const struct GNUNET_ATS_Information *atsi,
1288 uint32_t atsi_count)
1290 const struct EncryptedMessage *m;
1291 struct EncryptedMessage *pt; /* plaintext */
1292 struct GNUNET_HashCode ph;
1294 struct GNUNET_TIME_Absolute t;
1295 struct GNUNET_CRYPTO_AesInitializationVector iv;
1296 struct GNUNET_CRYPTO_AuthKey auth_key;
1297 struct DeliverMessageContext dmc;
1298 uint16_t size = ntohs (msg->size);
1299 char buf[size] GNUNET_ALIGN;
1302 sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader))
1304 GNUNET_break_op (0);
1307 m = (const struct EncryptedMessage *) msg;
1308 if (kx->status != KX_STATE_UP)
1310 GNUNET_STATISTICS_update (GSC_stats,
1312 ("# DATA message dropped (out of order)"),
1316 if (0 == GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value)
1318 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1319 _("Session to peer `%s' went down due to key expiration (should not happen)\n"),
1320 GNUNET_i2s (&kx->peer));
1321 GNUNET_STATISTICS_update (GSC_stats,
1322 gettext_noop ("# sessions terminated by key expiration"),
1324 GSC_SESSIONS_end (&kx->peer);
1325 if (GNUNET_SCHEDULER_NO_TASK != kx->keep_alive_task)
1327 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1328 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1330 kx->status = KX_STATE_KEY_SENT;
1336 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed);
1337 GNUNET_CRYPTO_hmac (&auth_key, &m->sequence_number,
1338 size - ENCRYPTED_HEADER_SIZE, &ph);
1339 if (0 != memcmp (&ph, &m->hmac, sizeof (struct GNUNET_HashCode)))
1341 /* checksum failed */
1342 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1343 "Failed checksum validation for a message from `%s'\n",
1344 GNUNET_i2s (&kx->peer));
1347 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1350 do_decrypt (kx, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
1351 size - ENCRYPTED_HEADER_SIZE))
1353 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
1354 size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1355 pt = (struct EncryptedMessage *) buf;
1357 /* validate sequence number */
1358 snum = ntohl (pt->sequence_number);
1359 if (kx->last_sequence_number_received == snum)
1361 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1362 "Received duplicate message, ignoring.\n");
1363 /* duplicate, ignore */
1364 GNUNET_STATISTICS_update (GSC_stats,
1365 gettext_noop ("# bytes dropped (duplicates)"),
1369 if ((kx->last_sequence_number_received > snum) &&
1370 (kx->last_sequence_number_received - snum > 32))
1372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1373 "Received ancient out of sequence message, ignoring.\n");
1374 /* ancient out of sequence, ignore */
1375 GNUNET_STATISTICS_update (GSC_stats,
1377 ("# bytes dropped (out of sequence)"), size,
1381 if (kx->last_sequence_number_received > snum)
1383 unsigned int rotbit = 1 << (kx->last_sequence_number_received - snum - 1);
1385 if ((kx->last_packets_bitmap & rotbit) != 0)
1387 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1388 "Received duplicate message, ignoring.\n");
1389 GNUNET_STATISTICS_update (GSC_stats,
1390 gettext_noop ("# bytes dropped (duplicates)"),
1392 /* duplicate, ignore */
1395 kx->last_packets_bitmap |= rotbit;
1397 if (kx->last_sequence_number_received < snum)
1399 unsigned int shift = (snum - kx->last_sequence_number_received);
1401 if (shift >= 8 * sizeof (kx->last_packets_bitmap))
1402 kx->last_packets_bitmap = 0;
1404 kx->last_packets_bitmap <<= shift;
1405 kx->last_sequence_number_received = snum;
1408 /* check timestamp */
1409 t = GNUNET_TIME_absolute_ntoh (pt->timestamp);
1410 if (GNUNET_TIME_absolute_get_duration (t).rel_value >
1411 MAX_MESSAGE_AGE.rel_value)
1413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1414 "Message received far too old (%s). Content ignored.\n",
1415 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t), GNUNET_YES));
1416 GNUNET_STATISTICS_update (GSC_stats,
1418 ("# bytes dropped (ancient message)"), size,
1423 /* process decrypted message(s) */
1424 update_timeout (kx);
1425 GNUNET_STATISTICS_update (GSC_stats,
1426 gettext_noop ("# bytes of payload decrypted"),
1427 size - sizeof (struct EncryptedMessage), GNUNET_NO);
1430 dmc.atsi_count = atsi_count;
1431 dmc.peer = &kx->peer;
1433 GNUNET_SERVER_mst_receive (mst, &dmc,
1434 &buf[sizeof (struct EncryptedMessage)],
1435 size - sizeof (struct EncryptedMessage),
1436 GNUNET_YES, GNUNET_NO))
1437 GNUNET_break_op (0);
1442 * Deliver P2P message to interested clients.
1443 * Invokes send twice, once for clients that want the full message, and once
1444 * for clients that only want the header
1446 * @param cls always NULL
1447 * @param client who sent us the message (struct GSC_KeyExchangeInfo)
1448 * @param m the message
1451 deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1453 struct DeliverMessageContext *dmc = client;
1455 if (KX_STATE_UP != dmc->kx->status)
1457 GNUNET_STATISTICS_update (GSC_stats,
1459 ("# PAYLOAD dropped (out of order)"),
1463 switch (ntohs (m->type))
1465 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
1466 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
1467 GSC_SESSIONS_set_typemap (dmc->peer, m);
1470 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1472 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
1473 GSC_CLIENTS_deliver_message (dmc->peer, dmc->atsi, dmc->atsi_count, m,
1474 sizeof (struct GNUNET_MessageHeader),
1475 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1482 * Setup the message that links the ephemeral key to our persistent
1483 * public key and generate the appropriate signature.
1486 sign_ephemeral_key ()
1488 current_ekm.header.size = htons (sizeof (struct EphemeralKeyMessage));
1489 current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY);
1490 current_ekm.sender_status = 0; /* to be set later */
1491 current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY);
1492 current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1493 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1494 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1495 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded) +
1496 sizeof (struct GNUNET_CRYPTO_EccPublicKeyBinaryEncoded));
1497 current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1499 GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
1501 "USE_EPHEMERAL_KEYS"))
1503 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_add (REKEY_FREQUENCY,
1508 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1510 GNUNET_CRYPTO_ecc_key_get_public (my_ephemeral_key,
1511 ¤t_ekm.ephemeral_key);
1512 current_ekm.origin_public_key = my_public_key;
1513 GNUNET_assert (GNUNET_OK ==
1514 GNUNET_CRYPTO_ecc_sign (my_private_key,
1515 ¤t_ekm.purpose,
1516 ¤t_ekm.signature));
1521 * Task run to trigger rekeying.
1523 * @param cls closure, NULL
1524 * @param tc scheduler context
1527 do_rekey (void *cls,
1528 const struct GNUNET_SCHEDULER_TaskContext *tc)
1530 struct GSC_KeyExchangeInfo *pos;
1532 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1535 if (NULL != my_ephemeral_key)
1536 GNUNET_CRYPTO_ecc_key_free (my_ephemeral_key);
1537 my_ephemeral_key = GNUNET_CRYPTO_ecc_key_create ();
1538 GNUNET_assert (NULL != my_ephemeral_key);
1539 sign_ephemeral_key ();
1540 for (pos = kx_head; NULL != pos; pos = pos->next)
1542 pos->status = KX_STATE_REKEY_SENT;
1549 * Initialize KX subsystem.
1551 * @param pk private key to use for the peer
1552 * @return GNUNET_OK on success, GNUNET_SYSERR on failure
1555 GSC_KX_init (struct GNUNET_CRYPTO_EccPrivateKey *pk)
1557 GNUNET_assert (NULL != pk);
1558 my_private_key = pk;
1559 GNUNET_CRYPTO_ecc_key_get_public (my_private_key, &my_public_key);
1560 GNUNET_CRYPTO_hash (&my_public_key, sizeof (my_public_key),
1561 &GSC_my_identity.hashPubKey);
1563 GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
1565 "USE_EPHEMERAL_KEYS"))
1567 my_ephemeral_key = GNUNET_CRYPTO_ecc_key_create ();
1568 if (NULL == my_ephemeral_key)
1571 GNUNET_CRYPTO_ecc_key_free (my_private_key);
1572 my_private_key = NULL;
1573 return GNUNET_SYSERR;
1575 sign_ephemeral_key ();
1576 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1582 my_ephemeral_key = my_private_key;
1583 sign_ephemeral_key ();
1585 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
1591 * Shutdown KX subsystem.
1596 if (GNUNET_SCHEDULER_NO_TASK != rekey_task)
1598 GNUNET_SCHEDULER_cancel (rekey_task);
1599 rekey_task = GNUNET_SCHEDULER_NO_TASK;
1601 if ( (NULL != my_ephemeral_key) &&
1602 (my_ephemeral_key != my_private_key) )
1604 GNUNET_CRYPTO_ecc_key_free (my_ephemeral_key);
1605 my_ephemeral_key = NULL;
1607 if (NULL != my_private_key)
1609 GNUNET_CRYPTO_ecc_key_free (my_private_key);
1610 my_private_key = NULL;
1614 GNUNET_SERVER_mst_destroy (mst);
1619 /* end of gnunet-service-core_kx.c */