/*
This file is part of GNUnet.
- (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+ (C) 2009, 2010, 2011, 2012 Christian Grothoff (and other contributing authors)
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
#include "core.h"
+/**
+ * Set to GNUNET_YES to perform some slightly expensive internal invariant checks.
+ */
+#define EXTRA_CHECKS GNUNET_NO
+
+
/**
* How long do we wait for SET_KEY confirmation initially?
*/
static struct GNUNET_SERVER_MessageStreamTokenizer *mst;
+#if EXTRA_CHECKS
+/**
+ * Check internal invariants of the given KX record.
+ *
+ * @param kx record to check
+ * @param file filename for error reporting
+ * @param line line number for error reporting
+ */
+static void
+check_kx_record (struct GSC_KeyExchangeInfo *kx,
+ const char *file,
+ int line)
+{
+ struct GNUNET_HashCode hc;
+
+ if (NULL == kx->public_key)
+ return;
+ GNUNET_CRYPTO_hash (kx->public_key, sizeof (*kx->public_key), &hc);
+ GNUNET_assert_at (0 == memcmp (&hc, &kx->peer, sizeof (struct GNUNET_HashCode)), file, line);
+}
+
+
+/**
+ * Check internal invariants of the given KX record.
+ *
+ * @param kx record to check
+ */
+#define CHECK_KX(kx) check_kx_record(kx, __FILE__, __LINE__)
+#else
+#define CHECK_KX(kx)
+#endif
+
/**
* Derive an authentication key from "set key" information
*
struct GSC_KeyExchangeInfo *kx = cls;
struct SetKeyMessage *skm;
+ CHECK_KX (kx);
if (err_msg != NULL)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
&set_key_retry_task, kx);
return;
}
+ GNUNET_break (0 == memcmp (peer, &kx->peer, sizeof (struct GNUNET_PeerIdentity)));
if (kx->public_key != NULL)
{
/* already have public key, why are we here? */
GNUNET_break (0);
GNUNET_free (kx->public_key);
kx->public_key = NULL;
+ CHECK_KX (kx);
return;
}
+ CHECK_KX (kx);
send_key (kx);
if (NULL != kx->skm_received)
{
GNUNET_PEERINFO_iterate (peerinfo, pid,
GNUNET_TIME_UNIT_FOREVER_REL /* timeout? */ ,
&process_hello, kx);
+ CHECK_KX (kx);
return kx;
}
struct PongMessage *pong;
enum KxStateMachine sender_status;
uint16_t size;
-
+
+ CHECK_KX (kx);
size = ntohs (msg->size);
if (size != sizeof (struct SetKeyMessage))
{
&m->signature, kx->public_key)))
{
/* invalid signature */
+ CHECK_KX (kx);
GNUNET_break_op (0);
return;
}
skm->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_SET_KEY);
skm->creation_time = GNUNET_TIME_absolute_hton (kx->encrypt_key_created);
skm->target = kx->peer;
+ CHECK_KX (kx);
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_rsa_encrypt (&kx->encrypt_key,
sizeof (struct
GNUNET_NO);
kx->status = KX_STATE_UP;
GSC_SESSIONS_create (&kx->peer, kx);
+ CHECK_KX (kx);
schedule_rekey (kx);
GNUNET_assert (kx->keep_alive_task == GNUNET_SCHEDULER_NO_TASK);
if (kx->emsg_received != NULL)
static void
send_key (struct GSC_KeyExchangeInfo *kx)
{
+ CHECK_KX (kx);
if (kx->retry_set_key_task != GNUNET_SCHEDULER_NO_TASK)
{
GNUNET_SCHEDULER_cancel (kx->retry_set_key_task);