From 62e273beeae391a44615e350e48f4ee40f2eab7a Mon Sep 17 00:00:00 2001 From: Sree Harsha Totakura Date: Fri, 6 Jun 2014 12:01:32 +0000 Subject: [PATCH] Enable (X)DHT service to be compiled with malicious code. --- configure.ac | 17 ++++ src/dht/dht.h | 18 +++++ src/dht/gnunet-service-xdht.c | 7 ++ src/dht/gnunet-service-xdht_clients.c | 31 ++++++++ src/include/gnunet_dht_service.h | 13 +++ src/include/gnunet_protocols.h | 110 +++++++++++++++----------- 6 files changed, 149 insertions(+), 47 deletions(-) diff --git a/configure.ac b/configure.ac index 7a488dd6e..3c315afe6 100644 --- a/configure.ac +++ b/configure.ac @@ -1209,6 +1209,23 @@ AC_ARG_ENABLE([experimental], AC_MSG_RESULT($enable_experimental) AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"]) +# should malicious code be compiled (should only be used for testing)? +AC_MSG_CHECKING(whether to compile malicious code) +AC_ARG_ENABLE([malicious], + [AS_HELP_STRING([--enable-malicious], [enable compiling malicious code])], + [if test "x$enableval" = "xno" + then + malicious=0 + else + malicious=1 + fi], + [malicious=0 + enable_malicious=no]) +AC_MSG_RESULT($enable_malicious) +AM_CONDITIONAL([ENABLE_MALICIOUS], [$malicious]) +AC_DEFINE_UNQUOTED([ENABLE_MALICIOUS], [$malicious], + [enable compilation of malicious code]) + # should services be started by default when a peer starts? Some services may # choose to never start by default and it is upto the service/module developer to # decide it by having "AUTOSTART = NO" instead of "AUTOSTART = @AUTOSTART" in diff --git a/src/dht/dht.h b/src/dht/dht.h index 86fbc16bb..f630e5a33 100644 --- a/src/dht/dht.h +++ b/src/dht/dht.h @@ -441,6 +441,24 @@ struct GNUNET_DHT_MonitorGetRespMessage }; +#if ENABLE_MALICIOUS +/** + * Message to turn the service malicious + */ +struct GNUNET_DHT_ActMaliciousMessage +{ + /** + * Type: #GNUNET_MESSAGE_TYPE_ACT_MALICIOUS + */ + struct GNUNET_MessageHeader header; + + /** + * Type of malicious behaviour expected; 0 turning peer benign + */ + uint32_t action; +}; +#endif + GNUNET_NETWORK_STRUCT_END #endif diff --git a/src/dht/gnunet-service-xdht.c b/src/dht/gnunet-service-xdht.c index 432fea354..40aa71a0f 100644 --- a/src/dht/gnunet-service-xdht.c +++ b/src/dht/gnunet-service-xdht.c @@ -77,6 +77,13 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh; */ struct GNUNET_TIME_Relative hello_expiration; +#if ENABLE_MALICIOUS +/** + * Should this peer act malicious? + */ +unsigned int malicious; +#endif + /** * Receive the HELLO from transport service, free current and replace diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c index 0621f8ea8..59fbd6f17 100644 --- a/src/dht/gnunet-service-xdht_clients.c +++ b/src/dht/gnunet-service-xdht_clients.c @@ -43,6 +43,13 @@ #define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) +#if ENABLE_MALICIOUS +/** + * Should this peer act malicious? + */ +extern unsigned int malicious; +#endif + /** * Linked list of messages to send to clients. */ @@ -1303,6 +1310,25 @@ handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client, } +#if ENABLE_MALICIOUS +/** + * Handler for monitor stop messages + * + * @param cls closure for the service + * @param client the client we received this message from + * @param message the actual message received + * + */ +static void +handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client, + const struct GNUNET_MessageHeader *message) +{ + /* FIXME: parse message and set malicious */ + malicious = 1; +} +#endif + + /** * Functions with this signature are called whenever a client * is disconnected on the network level. @@ -1378,6 +1404,11 @@ GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server) sizeof (struct GNUNET_DHT_MonitorStartStopMessage)}, {&handle_dht_local_get_result_seen, NULL, GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0}, + #if ENABLE_MALICIOUS + {&handle_dht_act_malicious, NULL, + GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS, + sizeof (struct GNUNET_DHT_ActMaliciousMessage)}, + #endif {NULL, NULL, 0, 0} }; forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); diff --git a/src/include/gnunet_dht_service.h b/src/include/gnunet_dht_service.h index 33c6551db..31d66ccf0 100644 --- a/src/include/gnunet_dht_service.h +++ b/src/include/gnunet_dht_service.h @@ -391,6 +391,19 @@ void GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle); +#if ENABLE_MALICIOUS +/** + * Turn the DHT service to act malicious depending on @a flag + * + * @param handle the DHT handle + * @param action 1 to make the service malicious; 0 to make it benign + FIXME: perhaps make this an enum of known malicious behaviors? + */ +void +GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action); +#endif + + #if 0 /* keep Emacsens' auto-indent happy */ { #endif diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h index bd54062f1..d329c6da8 100644 --- a/src/include/gnunet_protocols.h +++ b/src/include/gnunet_protocols.h @@ -611,54 +611,9 @@ extern "C" #define GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN 156 /** - * Trail setup request is received by a peer. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP 157 - -/** - * Trail to a particular peer is returned to this peer. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT 158 - -/** - * Verify if your immediate successor is still your immediate successor. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR 159 - -/** - * Notify your new immediate successor that you are its new predecessor. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR 160 - -/** - * Message which contains the immediate predecessor of requested successor - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT 161 - -/** - * Message which contains the get result. + * Further X-VINE DHT messages continued from 880 */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT 162 -/** - * Trail Rejection Message. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_REJECTION 163 - -/** - * Trail Tear down Message. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN 164 - -/** - * Routing table add message. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL 165 - -/** - * Trail compression message. - */ -#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_COMPRESSION 166 /******************************************************************************* * HOSTLIST message types ******************************************************************************/ @@ -2537,11 +2492,72 @@ extern "C" /** C->S->P: decision about a join request */ #define GNUNET_MESSAGE_TYPE_SOCIAL_JOIN_DECISION 848 +/******************************************************************************* + * X-VINE DHT messages + ******************************************************************************/ + +/** + * Trail setup request is received by a peer. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP 880 + +/** + * Trail to a particular peer is returned to this peer. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_SETUP_RESULT 881 /** - * Next available: 880 + * Verify if your immediate successor is still your immediate successor. */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR 882 +/** + * Notify your new immediate successor that you are its new predecessor. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_NOTIFY_NEW_SUCCESSOR 883 + +/** + * Message which contains the immediate predecessor of requested successor + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_VERIFY_SUCCESSOR_RESULT 884 + +/** + * Message which contains the get result. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_GET_RESULT 885 + +/** + * Trail Rejection Message. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_REJECTION 886 + +/** + * Trail Tear down Message. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_TEARDOWN 887 + +/** + * Routing table add message. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_ADD_TRAIL 888 + +/** + * Trail compression message. + */ +#define GNUNET_MESSAGE_TYPE_DHT_P2P_TRAIL_COMPRESSION 889 + +#if ENABLE_MALICIOUS +/** + * Turn X-VINE DHT service malicious + */ +#define GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS 890 +#endif + +/*******************************************************************************/ + +/** + * Next available: 900 + */ /** * Type used to match 'all' message types. -- 2.25.1