aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2014-12-15 07:18:02 +0000
committerBart Polot <bart@net.in.tum.de>2014-12-15 07:18:02 +0000
commit1f39de8b391b77e1da35cfcad3db0ad40e506d80 (patch)
treee96f4807aa16881c83a89250602172688d89c562 /src
parent9b961dae3220a2f2ed4fc16513d92b4f54360091 (diff)
downloadgnunet-1f39de8b391b77e1da35cfcad3db0ad40e506d80.tar.gz
gnunet-1f39de8b391b77e1da35cfcad3db0ad40e506d80.zip
Fuse PING into KX_EPHEMERAL
Diffstat (limited to 'src')
-rw-r--r--src/cadet/cadet_common.c7
-rw-r--r--src/cadet/cadet_protocol.h31
-rw-r--r--src/cadet/gnunet-service-cadet_tunnel.c102
-rw-r--r--src/include/gnunet_protocols.h5
4 files changed, 32 insertions, 113 deletions
diff --git a/src/cadet/cadet_common.c b/src/cadet/cadet_common.c
index 28c5743de..ec2ed4735 100644
--- a/src/cadet/cadet_common.c
+++ b/src/cadet/cadet_common.c
@@ -173,13 +173,6 @@ GC_m2s (uint16_t m)
173 break; 173 break;
174 174
175 /** 175 /**
176 * Challenge to test peer's session key.
177 */
178 case GNUNET_MESSAGE_TYPE_CADET_KX_PING:
179 t = "KX_PING";
180 break;
181
182 /**
183 * Answer to session key challenge. 176 * Answer to session key challenge.
184 */ 177 */
185 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG: 178 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG:
diff --git a/src/cadet/cadet_protocol.h b/src/cadet/cadet_protocol.h
index 19cdfe4a0..f5e684af6 100644
--- a/src/cadet/cadet_protocol.h
+++ b/src/cadet/cadet_protocol.h
@@ -150,43 +150,24 @@ struct GNUNET_CADET_KX_Ephemeral
150 struct GNUNET_TIME_AbsoluteNBO expiration_time; 150 struct GNUNET_TIME_AbsoluteNBO expiration_time;
151 151
152 /** 152 /**
153 * Ephemeral public ECC key (always for NIST P-521) encoded in a format suitable 153 * Ephemeral public ECC key (always for NIST P-521) encoded in a format
154 * for network transmission as created using 'gcry_sexp_sprint'. 154 * suitable for network transmission as created using 'gcry_sexp_sprint'.
155 */ 155 */
156 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key; 156 struct GNUNET_CRYPTO_EcdhePublicKey ephemeral_key;
157 157
158 /** 158 /**
159 * Public key of the signing peer (persistent version, not the ephemeral public key). 159 * Public key of the signing peer
160 * (persistent version, not the ephemeral public key).
160 */ 161 */
161 struct GNUNET_PeerIdentity origin_identity; 162 struct GNUNET_PeerIdentity origin_identity;
162};
163
164 163
165/**
166 * We're sending an (encrypted) PING to the other peer to check if he
167 * can decrypt. The other peer should respond with a PONG with the
168 * same content, except this time encrypted with the receiver's key.
169 */
170struct GNUNET_CADET_KX_Ping
171{
172 /** 164 /**
173 * Message type is GNUNET_MESSAGE_TYPE_CADET_KX_PING. 165 * Seed for the IV of nonce.
174 */
175 struct GNUNET_MessageHeader header;
176
177 /**
178 * Seed for the IV
179 */ 166 */
180 uint32_t iv GNUNET_PACKED; 167 uint32_t iv GNUNET_PACKED;
181 168
182 /** 169 /**
183 * Intended target of the PING, used primarily to check 170 * Nonce to check liveness of peer.
184 * that decryption actually worked.
185 */
186 struct GNUNET_PeerIdentity target;
187
188 /**
189 * Random number chosen to make reply harder.
190 */ 171 */
191 uint32_t nonce GNUNET_PACKED; 172 uint32_t nonce GNUNET_PACKED;
192}; 173};
diff --git a/src/cadet/gnunet-service-cadet_tunnel.c b/src/cadet/gnunet-service-cadet_tunnel.c
index 98452ba6f..14d8b1d11 100644
--- a/src/cadet/gnunet-service-cadet_tunnel.c
+++ b/src/cadet/gnunet-service-cadet_tunnel.c
@@ -460,7 +460,7 @@ ephemeral_purpose_size (void)
460size_t 460size_t
461ping_encryption_size (void) 461ping_encryption_size (void)
462{ 462{
463 return sizeof (struct GNUNET_PeerIdentity) + sizeof (uint32_t); 463 return sizeof (uint32_t);
464} 464}
465 465
466 466
@@ -885,10 +885,10 @@ create_kx_ctx (struct CadetTunnel *t)
885 else 885 else
886 { 886 {
887 t->kx_ctx = GNUNET_new (struct CadetTunnelKXCtx); 887 t->kx_ctx = GNUNET_new (struct CadetTunnelKXCtx);
888 t->kx_ctx->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
889 UINT32_MAX);
888 } 890 }
889 891
890 t->kx_ctx->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
891 UINT32_MAX);
892 if (CADET_TUNNEL_KEY_OK == t->estate) 892 if (CADET_TUNNEL_KEY_OK == t->estate)
893 { 893 {
894 t->kx_ctx->d_key_old = t->d_key; 894 t->kx_ctx->d_key_old = t->d_key;
@@ -1341,10 +1341,10 @@ send_kx (struct CadetTunnel *t,
1341 switch (type) 1341 switch (type)
1342 { 1342 {
1343 case GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL: 1343 case GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL:
1344 case GNUNET_MESSAGE_TYPE_CADET_KX_PING:
1345 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG: 1344 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG:
1346 memcpy (&msg[1], message, size); 1345 memcpy (&msg[1], message, size);
1347 break; 1346 break;
1347
1348 default: 1348 default:
1349 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n", 1349 LOG (GNUNET_ERROR_TYPE_DEBUG, "unkown type %s\n",
1350 GC_m2s (type)); 1350 GC_m2s (type));
@@ -1370,36 +1370,15 @@ send_ephemeral (struct CadetTunnel *t)
1370 LOG (GNUNET_ERROR_TYPE_INFO, "===> EPHM for %s\n", GCT_2s (t)); 1370 LOG (GNUNET_ERROR_TYPE_INFO, "===> EPHM for %s\n", GCT_2s (t));
1371 1371
1372 kx_msg.sender_status = htonl (t->estate); 1372 kx_msg.sender_status = htonl (t->estate);
1373 kx_msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1374 kx_msg.nonce = t->kx_ctx->challenge;
1375 LOG (GNUNET_ERROR_TYPE_DEBUG, " send nonce c %u\n", kx_msg.nonce);
1376 t_encrypt (t, &kx_msg.nonce, &kx_msg.nonce,
1377 ping_encryption_size(), kx_msg.iv, GNUNET_YES);
1378 LOG (GNUNET_ERROR_TYPE_DEBUG, " send nonce e %u\n", kx_msg.nonce);
1373 send_kx (t, &kx_msg.header); 1379 send_kx (t, &kx_msg.header);
1374} 1380}
1375 1381
1376/**
1377 * Send a ping message on a tunnel.
1378 *
1379 * @param t Tunnel on which to send the ping.
1380 */
1381static void
1382send_ping (struct CadetTunnel *t)
1383{
1384 struct GNUNET_CADET_KX_Ping msg;
1385
1386 LOG (GNUNET_ERROR_TYPE_INFO, "===> PING for %s\n", GCT_2s (t));
1387 msg.header.size = htons (sizeof (msg));
1388 msg.header.type = htons (GNUNET_MESSAGE_TYPE_CADET_KX_PING);
1389 msg.iv = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
1390 msg.target = *GCP_get_id (t->peer);
1391 msg.nonce = t->kx_ctx->challenge;
1392
1393 LOG (GNUNET_ERROR_TYPE_DEBUG, " sending %u\n", msg.nonce);
1394 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s\n", GNUNET_i2s (&msg.target));
1395 t_encrypt (t, &msg.target, &msg.target,
1396 ping_encryption_size(), msg.iv, GNUNET_YES);
1397 LOG (GNUNET_ERROR_TYPE_DEBUG, " e sending %u\n", msg.nonce);
1398 LOG (GNUNET_ERROR_TYPE_DEBUG, " e towards %s\n", GNUNET_i2s (&msg.target));
1399
1400 send_kx (t, &msg.header);
1401}
1402
1403 1382
1404/** 1383/**
1405 * Send a pong message on a tunnel. 1384 * Send a pong message on a tunnel.
@@ -1473,15 +1452,18 @@ rekey_tunnel (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1473 case CADET_TUNNEL_KEY_UNINITIALIZED: 1452 case CADET_TUNNEL_KEY_UNINITIALIZED:
1474 GCT_change_estate (t, CADET_TUNNEL_KEY_SENT); 1453 GCT_change_estate (t, CADET_TUNNEL_KEY_SENT);
1475 break; 1454 break;
1455
1476 case CADET_TUNNEL_KEY_SENT: 1456 case CADET_TUNNEL_KEY_SENT:
1477 break; 1457 break;
1458
1478 case CADET_TUNNEL_KEY_OK: 1459 case CADET_TUNNEL_KEY_OK:
1479 GCT_change_estate (t, CADET_TUNNEL_KEY_REKEY); 1460 GCT_change_estate (t, CADET_TUNNEL_KEY_REKEY);
1480 /* fall-thru */ 1461 break;
1462
1481 case CADET_TUNNEL_KEY_PING: 1463 case CADET_TUNNEL_KEY_PING:
1482 case CADET_TUNNEL_KEY_REKEY: 1464 case CADET_TUNNEL_KEY_REKEY:
1483 send_ping (t);
1484 break; 1465 break;
1466
1485 default: 1467 default:
1486 LOG (GNUNET_ERROR_TYPE_DEBUG, "Unexpected state %u\n", t->estate); 1468 LOG (GNUNET_ERROR_TYPE_DEBUG, "Unexpected state %u\n", t->estate);
1487 } 1469 }
@@ -1529,6 +1511,9 @@ rekey_iterator (void *cls,
1529 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t) n * 100); 1511 r = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, (uint32_t) n * 100);
1530 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, r); 1512 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, r);
1531 t->rekey_task = GNUNET_SCHEDULER_add_delayed (delay, &rekey_tunnel, t); 1513 t->rekey_task = GNUNET_SCHEDULER_add_delayed (delay, &rekey_tunnel, t);
1514 if (NULL != t->kx_ctx)
1515 t->kx_ctx->challenge =
1516 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, INT32_MAX);
1532 1517
1533 return GNUNET_YES; 1518 return GNUNET_YES;
1534} 1519}
@@ -1901,50 +1886,20 @@ handle_ephemeral (struct CadetTunnel *t,
1901 } 1886 }
1902 if (CADET_TUNNEL_KEY_SENT == t->estate) 1887 if (CADET_TUNNEL_KEY_SENT == t->estate)
1903 { 1888 {
1904 LOG (GNUNET_ERROR_TYPE_DEBUG, " our key was sent, sending ping\n"); 1889 LOG (GNUNET_ERROR_TYPE_DEBUG, " our key was sent, sending challenge\n");
1905 send_ping (t); 1890 send_ephemeral (t);
1906 GCT_change_estate (t, CADET_TUNNEL_KEY_PING); 1891 GCT_change_estate (t, CADET_TUNNEL_KEY_PING);
1907 } 1892 }
1908}
1909
1910
1911/**
1912 * Peer wants to check our symmetrical keys by sending an encrypted challenge.
1913 * Answer with by retransmitting the challenge with the "opposite" key.
1914 *
1915 * @param t Tunnel this message came on.
1916 * @param msg Key eXchange Ping message.
1917 */
1918static void
1919handle_ping (struct CadetTunnel *t,
1920 const struct GNUNET_CADET_KX_Ping *msg)
1921{
1922 struct GNUNET_CADET_KX_Ping res;
1923 1893
1924 if (ntohs (msg->header.size) != sizeof (res)) 1894 if (CADET_TUNNEL_KEY_UNINITIALIZED != ntohl(msg->sender_status))
1925 { 1895 {
1926 GNUNET_break_op (0); 1896 uint32_t nonce;
1927 return;
1928 }
1929 1897
1930 LOG (GNUNET_ERROR_TYPE_INFO, "<=== PING for %s\n", GCT_2s (t)); 1898 LOG (GNUNET_ERROR_TYPE_DEBUG, " recv nonce e %u\n", msg->nonce);
1931 t_decrypt (t, &res.target, &msg->target, ping_encryption_size (), msg->iv); 1899 t_decrypt (t, &nonce, &msg->nonce, ping_encryption_size (), msg->iv);
1932 if (0 != memcmp (&my_full_id, &res.target, sizeof (my_full_id))) 1900 LOG (GNUNET_ERROR_TYPE_DEBUG, " recv nonce c %u\n", nonce);
1933 { 1901 send_pong (t, nonce);
1934 /* probably peer hasn't got our new EPHM yet and derived the wrong keys */
1935 GNUNET_STATISTICS_update (stats, "# malformed PINGs", 1, GNUNET_NO);
1936 LOG (GNUNET_ERROR_TYPE_INFO, " malformed PING on %s\n", GCT_2s (t));
1937 LOG (GNUNET_ERROR_TYPE_DEBUG, " e got %u\n", msg->nonce);
1938 LOG (GNUNET_ERROR_TYPE_DEBUG, " e towards %s\n", GNUNET_i2s (&msg->target));
1939 LOG (GNUNET_ERROR_TYPE_DEBUG, " got %u\n", res.nonce);
1940 LOG (GNUNET_ERROR_TYPE_DEBUG, " towards %s\n", GNUNET_i2s (&res.target));
1941 create_kx_ctx (t);
1942 send_ephemeral (t);
1943 send_ping (t);
1944 return;
1945 } 1902 }
1946
1947 send_pong (t, res.nonce);
1948} 1903}
1949 1904
1950 1905
@@ -1976,7 +1931,6 @@ handle_pong (struct CadetTunnel *t,
1976 LOG (GNUNET_ERROR_TYPE_DEBUG, "PONG: %u (e: %u). Expected: %u.\n", 1931 LOG (GNUNET_ERROR_TYPE_DEBUG, "PONG: %u (e: %u). Expected: %u.\n",
1977 challenge, msg->nonce, t->kx_ctx->challenge); 1932 challenge, msg->nonce, t->kx_ctx->challenge);
1978 send_ephemeral (t); 1933 send_ephemeral (t);
1979 send_ping (t);
1980 return; 1934 return;
1981 } 1935 }
1982 GNUNET_SCHEDULER_cancel (t->rekey_task); 1936 GNUNET_SCHEDULER_cancel (t->rekey_task);
@@ -2131,10 +2085,6 @@ GCT_handle_kx (struct CadetTunnel *t,
2131 handle_ephemeral (t, (struct GNUNET_CADET_KX_Ephemeral *) message); 2085 handle_ephemeral (t, (struct GNUNET_CADET_KX_Ephemeral *) message);
2132 break; 2086 break;
2133 2087
2134 case GNUNET_MESSAGE_TYPE_CADET_KX_PING:
2135 handle_ping (t, (struct GNUNET_CADET_KX_Ping *) message);
2136 break;
2137
2138 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG: 2088 case GNUNET_MESSAGE_TYPE_CADET_KX_PONG:
2139 handle_pong (t, (struct GNUNET_CADET_KX_Pong *) message); 2089 handle_pong (t, (struct GNUNET_CADET_KX_Pong *) message);
2140 break; 2090 break;
diff --git a/src/include/gnunet_protocols.h b/src/include/gnunet_protocols.h
index 1279dd703..62f0331d1 100644
--- a/src/include/gnunet_protocols.h
+++ b/src/include/gnunet_protocols.h
@@ -841,11 +841,6 @@ extern "C"
841#define GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL 263 841#define GNUNET_MESSAGE_TYPE_CADET_KX_EPHEMERAL 263
842 842
843/** 843/**
844 * Challenge to test peer's session key.
845 */
846#define GNUNET_MESSAGE_TYPE_CADET_KX_PING 264
847
848/**
849 * Answer to session key challenge. 844 * Answer to session key challenge.
850 */ 845 */
851#define GNUNET_MESSAGE_TYPE_CADET_KX_PONG 265 846#define GNUNET_MESSAGE_TYPE_CADET_KX_PONG 265