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 (always for NIST P-521) encoded in a format suitable
112 * for network transmission as created using 'gcry_sexp_sprint'.
114 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
117 * Public key of the signing peer (persistent version, not the ephemeral public key).
119 struct GNUNET_PeerIdentity origin_identity;
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_SymmetricSessionKey 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_SymmetricSessionKey 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_EddsaPrivateKey *my_private_key;
383 * Our ephemeral private key.
385 static struct GNUNET_CRYPTO_EcdhePrivateKey *my_ephemeral_key;
388 * Current message we send for a key exchange.
390 static struct EphemeralKeyMessage current_ekm;
393 * Our message stream tokenizer (for encrypted payload).
395 static struct GNUNET_SERVER_MessageStreamTokenizer *mst;
400 static struct GSC_KeyExchangeInfo *kx_head;
405 static struct GSC_KeyExchangeInfo *kx_tail;
408 * Task scheduled for periodic re-generation (and thus rekeying) of our
411 static GNUNET_SCHEDULER_TaskIdentifier rekey_task;
415 * Derive an authentication key from "set key" information
417 * @param akey authentication key to derive
418 * @param skey session key to use
419 * @param seed seed to use
422 derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
423 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
425 static const char ctx[] = "authentication key";
427 GNUNET_CRYPTO_hmac_derive_key (akey, skey,
428 &seed, sizeof (seed),
429 skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
436 * Derive an IV from packet information
438 * @param iv initialization vector to initialize
439 * @param skey session key to use
440 * @param seed seed to use
441 * @param identity identity of the other peer to use
444 derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
445 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed,
446 const struct GNUNET_PeerIdentity *identity)
448 static const char ctx[] = "initialization vector";
450 GNUNET_CRYPTO_symmetric_derive_iv (iv, skey, &seed, sizeof (seed),
452 sizeof (struct GNUNET_PeerIdentity), ctx,
458 * Derive an IV from pong packet information
460 * @param iv initialization vector to initialize
461 * @param skey session key to use
462 * @param seed seed to use
463 * @param challenge nonce to use
464 * @param identity identity of the other peer to use
467 derive_pong_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
468 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed,
469 uint32_t challenge, const struct GNUNET_PeerIdentity *identity)
471 static const char ctx[] = "pong initialization vector";
473 GNUNET_CRYPTO_symmetric_derive_iv (iv, skey, &seed, sizeof (seed),
475 sizeof (struct GNUNET_PeerIdentity),
476 &challenge, sizeof (challenge),
483 * Derive an AES key from key material
485 * @param sender peer identity of the sender
486 * @param receiver peer identity of the sender
487 * @param key_material high entropy key material to use
488 * @param skey set to derived session key
491 derive_aes_key (const struct GNUNET_PeerIdentity *sender,
492 const struct GNUNET_PeerIdentity *receiver,
493 const struct GNUNET_HashCode *key_material,
494 struct GNUNET_CRYPTO_SymmetricSessionKey *skey)
496 static const char ctx[] = "aes key generation vector";
498 GNUNET_CRYPTO_kdf (skey, sizeof (struct GNUNET_CRYPTO_SymmetricSessionKey),
500 key_material, sizeof (struct GNUNET_HashCode),
501 sender, sizeof (struct GNUNET_PeerIdentity),
502 receiver, sizeof (struct GNUNET_PeerIdentity),
508 * Encrypt size bytes from in and write the result to out. Use the
509 * key for outbound traffic of the given neighbour.
511 * @param kx key information context
512 * @param iv initialization vector to use
513 * @param in ciphertext
514 * @param out plaintext
515 * @param size size of in/out
516 * @return GNUNET_OK on success
519 do_encrypt (struct GSC_KeyExchangeInfo *kx,
520 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
521 const void *in, void *out, size_t size)
523 if (size != (uint16_t) size)
528 GNUNET_assert (size ==
529 GNUNET_CRYPTO_symmetric_encrypt (in, (uint16_t) size,
530 &kx->encrypt_key, iv, out));
531 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes encrypted"), size,
533 /* the following is too sensitive to write to log files by accident,
534 so we require manual intervention to get this one... */
536 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
537 "Encrypted %u bytes for `%4s' using key %u, IV %u\n",
538 (unsigned int) size, GNUNET_i2s (&kx->peer),
539 (unsigned int) kx->encrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
548 * Decrypt size bytes from in and write the result to out. Use the
549 * key for inbound traffic of the given neighbour. This function does
550 * NOT do any integrity-checks on the result.
552 * @param kx key information context
553 * @param iv initialization vector to use
554 * @param in ciphertext
555 * @param out plaintext
556 * @param size size of @a in / @a out
557 * @return #GNUNET_OK on success
560 do_decrypt (struct GSC_KeyExchangeInfo *kx,
561 const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
562 const void *in, void *out, size_t size)
564 if (size != (uint16_t) size)
569 if ( (kx->status != KX_STATE_KEY_RECEIVED) && (kx->status != KX_STATE_UP) &&
570 (kx->status != KX_STATE_REKEY_SENT) )
573 return GNUNET_SYSERR;
576 GNUNET_CRYPTO_symmetric_decrypt (in, (uint16_t) size, &kx->decrypt_key, iv,
580 return GNUNET_SYSERR;
582 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# bytes decrypted"), size,
584 /* the following is too sensitive to write to log files by accident,
585 so we require manual intervention to get this one... */
587 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
588 "Decrypted %u bytes from `%4s' using key %u, IV %u\n",
589 (unsigned int) size, GNUNET_i2s (&kx->peer),
590 (unsigned int) kx->decrypt_key.crc32, GNUNET_CRYPTO_crc32_n (iv,
599 * Send our key (and encrypted PING) to the other peer.
601 * @param kx key exchange context
604 send_key (struct GSC_KeyExchangeInfo *kx);
608 * Task that will retry "send_key" if our previous attempt failed.
610 * @param cls our 'struct GSC_KeyExchangeInfo'
611 * @param tc scheduler context
614 set_key_retry_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
616 struct GSC_KeyExchangeInfo *kx = cls;
618 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
619 kx->set_key_retry_frequency = GNUNET_TIME_STD_BACKOFF (kx->set_key_retry_frequency);
620 GNUNET_assert (KX_STATE_DOWN != kx->status);
626 * Create a fresh PING message for transmission to the other peer.
628 * @param kx key exchange context to create PING for
631 setup_fresh_ping (struct GSC_KeyExchangeInfo *kx)
633 struct PingMessage pp;
634 struct PingMessage *pm;
635 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
638 pm->header.size = htons (sizeof (struct PingMessage));
639 pm->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PING);
641 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
642 derive_iv (&iv, &kx->encrypt_key, pm->iv_seed, &kx->peer);
643 pp.challenge = kx->ping_challenge;
644 pp.target = kx->peer;
645 do_encrypt (kx, &iv, &pp.target, &pm->target,
646 sizeof (struct PingMessage) - ((void *) &pm->target -
652 * Start the key exchange with the given peer.
654 * @param pid identity of the peer to do a key exchange with
655 * @return key exchange information context
657 struct GSC_KeyExchangeInfo *
658 GSC_KX_start (const struct GNUNET_PeerIdentity *pid)
660 struct GSC_KeyExchangeInfo *kx;
661 struct GNUNET_HashCode h1;
662 struct GNUNET_HashCode h2;
664 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
665 "Initiating key exchange with `%s'\n",
667 GNUNET_STATISTICS_update (GSC_stats,
668 gettext_noop ("# key exchanges initiated"), 1,
670 kx = GNUNET_malloc (sizeof (struct GSC_KeyExchangeInfo));
672 kx->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY;
673 GNUNET_CONTAINER_DLL_insert (kx_head,
676 GNUNET_CRYPTO_hash (pid, sizeof (struct GNUNET_PeerIdentity), &h1);
677 GNUNET_CRYPTO_hash (&GSC_my_identity, sizeof (struct GNUNET_PeerIdentity), &h2);
679 kx->status = KX_STATE_KEY_SENT;
680 if (0 < GNUNET_CRYPTO_hash_cmp (&h1,
683 /* peer with "lower" identity starts KX, otherwise we typically end up
684 with both peers starting the exchange and transmit the 'set key'
690 /* peer with "higher" identity starts a delayed KX, if the "lower" peer
691 * does not start a KX since he sees no reasons to do so */
692 kx->retry_set_key_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
693 &set_key_retry_task, kx);
700 * Stop key exchange with the given peer. Clean up key material.
702 * @param kx key exchange to stop
705 GSC_KX_stop (struct GSC_KeyExchangeInfo *kx)
707 GSC_SESSIONS_end (&kx->peer);
708 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# key exchanges stopped"),
710 if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
712 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
713 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
715 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
717 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
718 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
720 GNUNET_CONTAINER_DLL_remove (kx_head,
728 * Send our PING to the other peer.
730 * @param kx key exchange context
733 send_ping (struct GSC_KeyExchangeInfo *kx)
735 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
740 * We received a SET_KEY message. Validate and update
741 * our key material and status.
743 * @param kx key exchange status for the corresponding peer
744 * @param msg the set key message we received
747 GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
748 const struct GNUNET_MessageHeader *msg)
750 const struct EphemeralKeyMessage *m;
751 struct GNUNET_TIME_Absolute start_t;
752 struct GNUNET_TIME_Absolute end_t;
753 struct GNUNET_TIME_Absolute now;
754 enum KxStateMachine sender_status;
756 struct GNUNET_HashCode key_material;
758 size = ntohs (msg->size);
759 if (sizeof (struct EphemeralKeyMessage) != size)
764 m = (const struct EphemeralKeyMessage *) msg;
765 end_t = GNUNET_TIME_absolute_ntoh (m->expiration_time);
766 if ( ( (KX_STATE_KEY_RECEIVED == kx->status) ||
767 (KX_STATE_UP == kx->status) ||
768 (KX_STATE_REKEY_SENT == kx->status) ) &&
769 (end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) )
771 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
775 start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
777 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# ephemeral keys received"),
780 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
781 "Core service receives `%s' request from `%4s'.\n", "EPHEMERAL_KEY",
782 GNUNET_i2s (&kx->peer));
784 memcmp (&m->origin_identity,
785 &kx->peer.public_key,
786 sizeof (struct GNUNET_PeerIdentity)))
791 if ((ntohl (m->purpose.size) !=
792 sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
793 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
794 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
795 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey) +
796 sizeof (struct GNUNET_CRYPTO_EddsaPublicKey)) ||
798 GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY,
800 &m->signature, &m->origin_identity.public_key)))
802 /* invalid signature */
806 now = GNUNET_TIME_absolute_get ();
807 if ( (end_t.abs_value_us < GNUNET_TIME_absolute_subtract (now, REKEY_TOLERANCE).abs_value_us) ||
808 (start_t.abs_value_us > GNUNET_TIME_absolute_add (now, REKEY_TOLERANCE).abs_value_us) )
810 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
811 _("Ephemeral key message from peer `%s' rejected as its validity range does not match our system time (%llu not in [%llu,%llu]).\n"),
812 GNUNET_i2s (&kx->peer),
814 start_t.abs_value_us,
819 GNUNET_CRYPTO_ecc_ecdh (my_ephemeral_key,
826 GNUNET_STATISTICS_update (GSC_stats,
827 gettext_noop ("# EPHEMERAL_KEY messages decrypted"), 1,
829 derive_aes_key (&GSC_my_identity,
833 derive_aes_key (&kx->peer,
837 /* fresh key, reset sequence numbers */
838 kx->last_sequence_number_received = 0;
839 kx->last_packets_bitmap = 0;
840 kx->foreign_key_expires = end_t;
841 setup_fresh_ping (kx);
843 /* check if we still need to send the sender our key */
844 sender_status = (enum KxStateMachine) ntohl (m->sender_status);
845 switch (sender_status)
850 case KX_STATE_KEY_SENT:
851 /* fine, need to send our key after updating our status, see below */
853 case KX_STATE_KEY_RECEIVED:
855 case KX_STATE_REKEY_SENT:
856 /* other peer already got our key */
862 /* check if we need to confirm everything is fine via PING + PONG */
866 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
867 kx->status = KX_STATE_KEY_RECEIVED;
868 if (KX_STATE_KEY_SENT == sender_status)
872 case KX_STATE_KEY_SENT:
873 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
874 kx->status = KX_STATE_KEY_RECEIVED;
875 if (KX_STATE_KEY_SENT == sender_status)
879 case KX_STATE_KEY_RECEIVED:
880 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
881 if (KX_STATE_KEY_SENT == sender_status)
886 kx->status = KX_STATE_REKEY_SENT;
887 if (KX_STATE_KEY_SENT == sender_status)
889 /* we got a new key, need to reconfirm! */
892 case KX_STATE_REKEY_SENT:
893 if (KX_STATE_KEY_SENT == sender_status)
895 /* we got a new key, need to reconfirm! */
906 * We received a PING message. Validate and transmit
909 * @param kx key exchange status for the corresponding peer
910 * @param msg the encrypted PING message itself
913 GSC_KX_handle_ping (struct GSC_KeyExchangeInfo *kx,
914 const struct GNUNET_MessageHeader *msg)
916 const struct PingMessage *m;
917 struct PingMessage t;
918 struct PongMessage tx;
919 struct PongMessage tp;
920 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
923 msize = ntohs (msg->size);
924 if (msize != sizeof (struct PingMessage))
929 GNUNET_STATISTICS_update (GSC_stats,
930 gettext_noop ("# PING messages received"), 1,
932 if ( (kx->status != KX_STATE_KEY_RECEIVED) &&
933 (kx->status != KX_STATE_UP) &&
934 (kx->status != KX_STATE_REKEY_SENT))
937 GNUNET_STATISTICS_update (GSC_stats,
938 gettext_noop ("# PING messages dropped (out of order)"), 1,
942 m = (const struct PingMessage *) msg;
943 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
944 "Core service receives `%s' request from `%4s'.\n", "PING",
945 GNUNET_i2s (&kx->peer));
946 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
948 do_decrypt (kx, &iv, &m->target, &t.target,
949 sizeof (struct PingMessage) - ((void *) &m->target -
956 memcmp (&t.target, &GSC_my_identity, sizeof (struct GNUNET_PeerIdentity)))
961 GNUNET_snprintf (sender, sizeof (sender), "%8s", GNUNET_i2s (&kx->peer));
962 GNUNET_snprintf (peer, sizeof (peer), "%8s", GNUNET_i2s (&t.target));
963 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
965 ("Received PING from `%s' for different identity: I am `%s', PONG identity: `%s'\n"),
966 sender, GNUNET_i2s (&GSC_my_identity), peer);
972 tx.challenge = t.challenge;
973 tx.target = t.target;
974 tp.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_PONG);
975 tp.header.size = htons (sizeof (struct PongMessage));
977 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
978 derive_pong_iv (&iv, &kx->encrypt_key, tp.iv_seed, t.challenge, &kx->peer);
979 do_encrypt (kx, &iv, &tx.challenge, &tp.challenge,
980 sizeof (struct PongMessage) - ((void *) &tp.challenge -
982 GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# PONG messages created"),
984 GSC_NEIGHBOURS_transmit (&kx->peer, &tp.header,
985 GNUNET_TIME_UNIT_FOREVER_REL /* FIXME: timeout */ );
990 * Task triggered when a neighbour entry is about to time out
991 * (and we should prevent this by sending a PING).
993 * @param cls the 'struct GSC_KeyExchangeInfo'
994 * @param tc scheduler context (not used)
997 send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
999 struct GSC_KeyExchangeInfo *kx = cls;
1000 struct GNUNET_TIME_Relative retry;
1001 struct GNUNET_TIME_Relative left;
1003 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1004 left = GNUNET_TIME_absolute_get_remaining (kx->timeout);
1005 if (0 == left.rel_value_us)
1007 GNUNET_STATISTICS_update (GSC_stats,
1008 gettext_noop ("# sessions terminated by timeout"),
1010 GSC_SESSIONS_end (&kx->peer);
1011 kx->status = KX_STATE_KEY_SENT;
1015 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending KEEPALIVE to `%s'\n",
1016 GNUNET_i2s (&kx->peer));
1017 GNUNET_STATISTICS_update (GSC_stats,
1018 gettext_noop ("# keepalive messages sent"), 1,
1020 setup_fresh_ping (kx);
1021 GSC_NEIGHBOURS_transmit (&kx->peer, &kx->ping.header,
1022 kx->set_key_retry_frequency);
1024 GNUNET_TIME_relative_max (GNUNET_TIME_relative_divide (left, 2),
1025 MIN_PING_FREQUENCY);
1026 kx->keep_alive_task =
1027 GNUNET_SCHEDULER_add_delayed (retry, &send_keep_alive, kx);
1032 * We've seen a valid message from the other peer.
1033 * Update the time when the session would time out
1034 * and delay sending our keep alive message further.
1036 * @param kx key exchange where we saw activity
1039 update_timeout (struct GSC_KeyExchangeInfo *kx)
1042 GNUNET_TIME_relative_to_absolute
1043 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
1044 if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
1045 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1046 kx->keep_alive_task =
1047 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_divide
1048 (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1049 2), &send_keep_alive, kx);
1054 * We received a PONG message. Validate and update our status.
1056 * @param kx key exchange context for the the PONG
1057 * @param msg the encrypted PONG message itself
1060 GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
1061 const struct GNUNET_MessageHeader *msg)
1063 const struct PongMessage *m;
1064 struct PongMessage t;
1065 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1068 msize = ntohs (msg->size);
1069 if (sizeof (struct PongMessage) != msize)
1071 GNUNET_break_op (0);
1074 GNUNET_STATISTICS_update (GSC_stats,
1075 gettext_noop ("# PONG messages received"), 1,
1080 GNUNET_STATISTICS_update (GSC_stats,
1081 gettext_noop ("# PONG messages dropped (connection down)"), 1,
1084 case KX_STATE_KEY_SENT:
1085 GNUNET_STATISTICS_update (GSC_stats,
1086 gettext_noop ("# PONG messages dropped (out of order)"), 1,
1089 case KX_STATE_KEY_RECEIVED:
1093 case KX_STATE_REKEY_SENT:
1099 m = (const struct PongMessage *) msg;
1100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1101 "Core service receives `%s' response from `%4s'.\n", "PONG",
1102 GNUNET_i2s (&kx->peer));
1103 /* mark as garbage, just to be sure */
1104 memset (&t, 255, sizeof (t));
1105 derive_pong_iv (&iv, &kx->decrypt_key, m->iv_seed, kx->ping_challenge,
1108 do_decrypt (kx, &iv, &m->challenge, &t.challenge,
1109 sizeof (struct PongMessage) - ((void *) &m->challenge -
1112 GNUNET_break_op (0);
1115 GNUNET_STATISTICS_update (GSC_stats,
1116 gettext_noop ("# PONG messages decrypted"), 1,
1118 if ((0 != memcmp (&t.target, &kx->peer, sizeof (struct GNUNET_PeerIdentity)))
1119 || (kx->ping_challenge != t.challenge))
1121 /* PONG malformed */
1122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1123 "Received malformed `%s' wanted sender `%4s' with challenge %u\n",
1124 "PONG", GNUNET_i2s (&kx->peer),
1125 (unsigned int) kx->ping_challenge);
1126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1127 "Received malformed `%s' received from `%4s' with challenge %u\n",
1128 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
1131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
1132 GNUNET_i2s (&kx->peer));
1133 /* no need to resend key any longer */
1134 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1136 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1137 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1142 GNUNET_assert (0); /* should be impossible */
1144 case KX_STATE_KEY_SENT:
1145 GNUNET_assert (0); /* should be impossible */
1147 case KX_STATE_KEY_RECEIVED:
1148 GNUNET_STATISTICS_update (GSC_stats,
1150 ("# session keys confirmed via PONG"), 1,
1152 kx->status = KX_STATE_UP;
1153 GSC_SESSIONS_create (&kx->peer, kx);
1154 GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == kx->keep_alive_task);
1155 update_timeout (kx);
1158 GNUNET_STATISTICS_update (GSC_stats,
1160 ("# timeouts prevented via PONG"), 1,
1162 update_timeout (kx);
1164 case KX_STATE_REKEY_SENT:
1165 GNUNET_STATISTICS_update (GSC_stats,
1167 ("# rekey operations confirmed via PONG"), 1,
1169 kx->status = KX_STATE_UP;
1170 update_timeout (kx);
1180 * Send our key to the other peer.
1182 * @param kx key exchange context
1185 send_key (struct GSC_KeyExchangeInfo *kx)
1187 GNUNET_assert (KX_STATE_DOWN != kx->status);
1188 if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
1190 GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);
1191 kx->retry_set_key_task = GNUNET_SCHEDULER_NO_TASK;
1193 /* always update sender status in SET KEY message */
1194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1195 "Sending key to `%s' (my status: %d)\n",
1196 GNUNET_i2s (&kx->peer),
1198 current_ekm.sender_status = htonl ((int32_t) (kx->status));
1199 GSC_NEIGHBOURS_transmit (&kx->peer, ¤t_ekm.header,
1200 kx->set_key_retry_frequency);
1201 kx->retry_set_key_task =
1202 GNUNET_SCHEDULER_add_delayed (kx->set_key_retry_frequency,
1203 &set_key_retry_task, kx);
1208 * Encrypt and transmit a message with the given payload.
1210 * @param kx key exchange context
1211 * @param payload payload of the message
1212 * @param payload_size number of bytes in 'payload'
1215 GSC_KX_encrypt_and_transmit (struct GSC_KeyExchangeInfo *kx,
1216 const void *payload, size_t payload_size)
1218 size_t used = payload_size + sizeof (struct EncryptedMessage);
1219 char pbuf[used]; /* plaintext */
1220 char cbuf[used]; /* ciphertext */
1221 struct EncryptedMessage *em; /* encrypted message */
1222 struct EncryptedMessage *ph; /* plaintext header */
1223 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1224 struct GNUNET_CRYPTO_AuthKey auth_key;
1226 ph = (struct EncryptedMessage *) pbuf;
1228 htonl (GNUNET_CRYPTO_random_u32
1229 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX));
1230 ph->sequence_number = htonl (++kx->last_sequence_number_sent);
1232 ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1233 memcpy (&ph[1], payload, payload_size);
1235 em = (struct EncryptedMessage *) cbuf;
1236 em->header.size = htons (used);
1237 em->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE);
1238 em->iv_seed = ph->iv_seed;
1239 derive_iv (&iv, &kx->encrypt_key, ph->iv_seed, &kx->peer);
1240 GNUNET_assert (GNUNET_OK ==
1241 do_encrypt (kx, &iv, &ph->sequence_number,
1242 &em->sequence_number,
1243 used - ENCRYPTED_HEADER_SIZE));
1244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Encrypted %u bytes for %s\n",
1245 used - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1246 derive_auth_key (&auth_key,
1249 GNUNET_CRYPTO_hmac (&auth_key, &em->sequence_number,
1250 used - ENCRYPTED_HEADER_SIZE, &em->hmac);
1251 GSC_NEIGHBOURS_transmit (&kx->peer, &em->header,
1252 GNUNET_TIME_UNIT_FOREVER_REL);
1257 * Closure for 'deliver_message'
1259 struct DeliverMessageContext
1263 * Key exchange context.
1265 struct GSC_KeyExchangeInfo *kx;
1268 * Sender of the message.
1270 const struct GNUNET_PeerIdentity *peer;
1275 * We received an encrypted message. Decrypt, validate and
1276 * pass on to the appropriate clients.
1278 * @param kx key exchange context for encrypting the message
1279 * @param msg encrypted message
1282 GSC_KX_handle_encrypted_message (struct GSC_KeyExchangeInfo *kx,
1283 const struct GNUNET_MessageHeader *msg)
1285 const struct EncryptedMessage *m;
1286 struct EncryptedMessage *pt; /* plaintext */
1287 struct GNUNET_HashCode ph;
1289 struct GNUNET_TIME_Absolute t;
1290 struct GNUNET_CRYPTO_SymmetricInitializationVector iv;
1291 struct GNUNET_CRYPTO_AuthKey auth_key;
1292 struct DeliverMessageContext dmc;
1293 uint16_t size = ntohs (msg->size);
1294 char buf[size] GNUNET_ALIGN;
1297 sizeof (struct EncryptedMessage) + sizeof (struct GNUNET_MessageHeader))
1299 GNUNET_break_op (0);
1302 m = (const struct EncryptedMessage *) msg;
1303 if (kx->status != KX_STATE_UP)
1305 GNUNET_STATISTICS_update (GSC_stats,
1307 ("# DATA message dropped (out of order)"),
1311 if (0 == GNUNET_TIME_absolute_get_remaining (kx->foreign_key_expires).rel_value_us)
1313 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1314 _("Session to peer `%s' went down due to key expiration (should not happen)\n"),
1315 GNUNET_i2s (&kx->peer));
1316 GNUNET_STATISTICS_update (GSC_stats,
1317 gettext_noop ("# sessions terminated by key expiration"),
1319 GSC_SESSIONS_end (&kx->peer);
1320 if (GNUNET_SCHEDULER_NO_TASK != kx->keep_alive_task)
1322 GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
1323 kx->keep_alive_task = GNUNET_SCHEDULER_NO_TASK;
1325 kx->status = KX_STATE_KEY_SENT;
1331 derive_auth_key (&auth_key, &kx->decrypt_key, m->iv_seed);
1332 GNUNET_CRYPTO_hmac (&auth_key, &m->sequence_number,
1333 size - ENCRYPTED_HEADER_SIZE, &ph);
1334 if (0 != memcmp (&ph, &m->hmac, sizeof (struct GNUNET_HashCode)))
1336 /* checksum failed */
1337 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1338 "Failed checksum validation for a message from `%s'\n",
1339 GNUNET_i2s (&kx->peer));
1342 derive_iv (&iv, &kx->decrypt_key, m->iv_seed, &GSC_my_identity);
1345 do_decrypt (kx, &iv, &m->sequence_number, &buf[ENCRYPTED_HEADER_SIZE],
1346 size - ENCRYPTED_HEADER_SIZE))
1348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Decrypted %u bytes from %s\n",
1349 size - ENCRYPTED_HEADER_SIZE, GNUNET_i2s (&kx->peer));
1350 pt = (struct EncryptedMessage *) buf;
1352 /* validate sequence number */
1353 snum = ntohl (pt->sequence_number);
1354 if (kx->last_sequence_number_received == snum)
1356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1357 "Received duplicate message, ignoring.\n");
1358 /* duplicate, ignore */
1359 GNUNET_STATISTICS_update (GSC_stats,
1360 gettext_noop ("# bytes dropped (duplicates)"),
1364 if ((kx->last_sequence_number_received > snum) &&
1365 (kx->last_sequence_number_received - snum > 32))
1367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1368 "Received ancient out of sequence message, ignoring.\n");
1369 /* ancient out of sequence, ignore */
1370 GNUNET_STATISTICS_update (GSC_stats,
1372 ("# bytes dropped (out of sequence)"), size,
1376 if (kx->last_sequence_number_received > snum)
1378 unsigned int rotbit = 1 << (kx->last_sequence_number_received - snum - 1);
1380 if ((kx->last_packets_bitmap & rotbit) != 0)
1382 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1383 "Received duplicate message, ignoring.\n");
1384 GNUNET_STATISTICS_update (GSC_stats,
1385 gettext_noop ("# bytes dropped (duplicates)"),
1387 /* duplicate, ignore */
1390 kx->last_packets_bitmap |= rotbit;
1392 if (kx->last_sequence_number_received < snum)
1394 unsigned int shift = (snum - kx->last_sequence_number_received);
1396 if (shift >= 8 * sizeof (kx->last_packets_bitmap))
1397 kx->last_packets_bitmap = 0;
1399 kx->last_packets_bitmap <<= shift;
1400 kx->last_sequence_number_received = snum;
1403 /* check timestamp */
1404 t = GNUNET_TIME_absolute_ntoh (pt->timestamp);
1405 if (GNUNET_TIME_absolute_get_duration (t).rel_value_us >
1406 MAX_MESSAGE_AGE.rel_value_us)
1408 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1409 "Message received far too old (%s). Content ignored.\n",
1410 GNUNET_STRINGS_relative_time_to_string (GNUNET_TIME_absolute_get_duration (t), GNUNET_YES));
1411 GNUNET_STATISTICS_update (GSC_stats,
1413 ("# bytes dropped (ancient message)"), size,
1418 /* process decrypted message(s) */
1419 update_timeout (kx);
1420 GNUNET_STATISTICS_update (GSC_stats,
1421 gettext_noop ("# bytes of payload decrypted"),
1422 size - sizeof (struct EncryptedMessage), GNUNET_NO);
1424 dmc.peer = &kx->peer;
1426 GNUNET_SERVER_mst_receive (mst, &dmc,
1427 &buf[sizeof (struct EncryptedMessage)],
1428 size - sizeof (struct EncryptedMessage),
1429 GNUNET_YES, GNUNET_NO))
1430 GNUNET_break_op (0);
1435 * Deliver P2P message to interested clients.
1436 * Invokes send twice, once for clients that want the full message, and once
1437 * for clients that only want the header
1439 * @param cls always NULL
1440 * @param client who sent us the message (struct GSC_KeyExchangeInfo)
1441 * @param m the message
1444 deliver_message (void *cls, void *client, const struct GNUNET_MessageHeader *m)
1446 struct DeliverMessageContext *dmc = client;
1448 if (KX_STATE_UP != dmc->kx->status)
1450 GNUNET_STATISTICS_update (GSC_stats,
1452 ("# PAYLOAD dropped (out of order)"),
1456 switch (ntohs (m->type))
1458 case GNUNET_MESSAGE_TYPE_CORE_BINARY_TYPE_MAP:
1459 case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
1460 GSC_SESSIONS_set_typemap (dmc->peer, m);
1463 GSC_CLIENTS_deliver_message (dmc->peer, m,
1465 GNUNET_CORE_OPTION_SEND_FULL_INBOUND);
1466 GSC_CLIENTS_deliver_message (dmc->peer, m,
1467 sizeof (struct GNUNET_MessageHeader),
1468 GNUNET_CORE_OPTION_SEND_HDR_INBOUND);
1475 * Setup the message that links the ephemeral key to our persistent
1476 * public key and generate the appropriate signature.
1479 sign_ephemeral_key ()
1481 current_ekm.header.size = htons (sizeof (struct EphemeralKeyMessage));
1482 current_ekm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_EPHEMERAL_KEY);
1483 current_ekm.sender_status = 0; /* to be set later */
1484 current_ekm.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_ECC_KEY);
1485 current_ekm.purpose.size = htonl (sizeof (struct GNUNET_CRYPTO_EccSignaturePurpose) +
1486 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1487 sizeof (struct GNUNET_TIME_AbsoluteNBO) +
1488 sizeof (struct GNUNET_CRYPTO_EcdhePublicKey) +
1489 sizeof (struct GNUNET_PeerIdentity));
1490 current_ekm.creation_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ());
1492 GNUNET_CONFIGURATION_get_value_yesno (GSC_cfg,
1494 "USE_EPHEMERAL_KEYS"))
1496 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_relative_to_absolute (GNUNET_TIME_relative_add (REKEY_FREQUENCY,
1501 current_ekm.expiration_time = GNUNET_TIME_absolute_hton (GNUNET_TIME_UNIT_FOREVER_ABS);
1503 GNUNET_CRYPTO_ecdhe_key_get_public (my_ephemeral_key,
1504 ¤t_ekm.ephemeral_key);
1505 current_ekm.origin_identity = GSC_my_identity;
1506 GNUNET_assert (GNUNET_OK ==
1507 GNUNET_CRYPTO_eddsa_sign (my_private_key,
1508 ¤t_ekm.purpose,
1509 ¤t_ekm.signature));
1514 * Task run to trigger rekeying.
1516 * @param cls closure, NULL
1517 * @param tc scheduler context
1520 do_rekey (void *cls,
1521 const struct GNUNET_SCHEDULER_TaskContext *tc)
1523 struct GSC_KeyExchangeInfo *pos;
1525 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1528 if (NULL != my_ephemeral_key)
1529 GNUNET_free (my_ephemeral_key);
1530 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
1531 GNUNET_assert (NULL != my_ephemeral_key);
1532 sign_ephemeral_key ();
1533 for (pos = kx_head; NULL != pos; pos = pos->next)
1535 pos->status = KX_STATE_REKEY_SENT;
1542 * Initialize KX subsystem.
1544 * @param pk private key to use for the peer
1545 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1548 GSC_KX_init (struct GNUNET_CRYPTO_EddsaPrivateKey *pk)
1550 GNUNET_assert (NULL != pk);
1551 my_private_key = pk;
1552 GNUNET_CRYPTO_eddsa_key_get_public (my_private_key,
1553 &GSC_my_identity.public_key);
1554 my_ephemeral_key = GNUNET_CRYPTO_ecdhe_key_create ();
1555 if (NULL == my_ephemeral_key)
1558 GNUNET_free (my_private_key);
1559 my_private_key = NULL;
1560 return GNUNET_SYSERR;
1562 sign_ephemeral_key ();
1563 rekey_task = GNUNET_SCHEDULER_add_delayed (REKEY_FREQUENCY,
1566 mst = GNUNET_SERVER_mst_create (&deliver_message, NULL);
1572 * Shutdown KX subsystem.
1577 if (GNUNET_SCHEDULER_NO_TASK != rekey_task)
1579 GNUNET_SCHEDULER_cancel (rekey_task);
1580 rekey_task = GNUNET_SCHEDULER_NO_TASK;
1582 if (NULL != my_ephemeral_key)
1584 GNUNET_free (my_ephemeral_key);
1585 my_ephemeral_key = NULL;
1587 if (NULL != my_private_key)
1589 GNUNET_free (my_private_key);
1590 my_private_key = NULL;
1594 GNUNET_SERVER_mst_destroy (mst);
1599 /* end of gnunet-service-core_kx.c */