aboutsummaryrefslogtreecommitdiff
path: root/src/transport
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-16 19:57:15 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-16 19:57:15 +0200
commit3266ea560ea1b243810dce4d46ee2889da7b4f6c (patch)
tree555ce759adf099350f89fd520f11d04161e8df1c /src/transport
parentcb169441f0ed127dd07e2c6f98436dcd0ece8f61 (diff)
downloadgnunet-3266ea560ea1b243810dce4d46ee2889da7b4f6c.tar.gz
gnunet-3266ea560ea1b243810dce4d46ee2889da7b4f6c.zip
implement backchannel encryption/decryption
Diffstat (limited to 'src/transport')
-rw-r--r--src/transport/Makefile.am1
-rw-r--r--src/transport/gnunet-communicator-tcp.c10
-rw-r--r--src/transport/gnunet-service-tng.c68
3 files changed, 57 insertions, 22 deletions
diff --git a/src/transport/Makefile.am b/src/transport/Makefile.am
index f83fa669c..53fd9c973 100644
--- a/src/transport/Makefile.am
+++ b/src/transport/Makefile.am
@@ -374,6 +374,7 @@ gnunet_service_tng_LDADD = \
374 $(top_builddir)/src/hello/libgnunethello.la \ 374 $(top_builddir)/src/hello/libgnunethello.la \
375 $(top_builddir)/src/statistics/libgnunetstatistics.la \ 375 $(top_builddir)/src/statistics/libgnunetstatistics.la \
376 $(top_builddir)/src/util/libgnunetutil.la \ 376 $(top_builddir)/src/util/libgnunetutil.la \
377 $(LIBGCRYPT_LIBS) \
377 $(GN_LIBINTL) 378 $(GN_LIBINTL)
378 379
379plugin_LTLIBRARIES = \ 380plugin_LTLIBRARIES = \
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c
index a8f88c5e4..e9223401f 100644
--- a/src/transport/gnunet-communicator-tcp.c
+++ b/src/transport/gnunet-communicator-tcp.c
@@ -814,9 +814,9 @@ pass_plaintext_to_core (struct Queue *queue,
814 */ 814 */
815static void 815static void
816setup_cipher (const struct GNUNET_HashCode *dh, 816setup_cipher (const struct GNUNET_HashCode *dh,
817 const struct GNUNET_PeerIdentity *pid, 817 const struct GNUNET_PeerIdentity *pid,
818 gcry_cipher_hd_t *cipher, 818 gcry_cipher_hd_t *cipher,
819 struct GNUNET_HashCode *hmac_key) 819 struct GNUNET_HashCode *hmac_key)
820{ 820{
821 char key[256/8]; 821 char key[256/8];
822 char ctr[128/8]; 822 char ctr[128/8];
@@ -872,7 +872,7 @@ setup_cipher (const struct GNUNET_HashCode *dh,
872 */ 872 */
873static void 873static void
874setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral, 874setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
875 struct Queue *queue) 875 struct Queue *queue)
876{ 876{
877 struct GNUNET_HashCode dh; 877 struct GNUNET_HashCode dh;
878 878
@@ -896,7 +896,7 @@ setup_in_cipher (const struct GNUNET_CRYPTO_EcdhePublicKey *ephemeral,
896 */ 896 */
897static void 897static void
898do_rekey (struct Queue *queue, 898do_rekey (struct Queue *queue,
899 const struct TCPRekey *rekey) 899 const struct TCPRekey *rekey)
900{ 900{
901 struct TcpHandshakeSignature thp; 901 struct TcpHandshakeSignature thp;
902 902
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c
index bb1656876..53b9ba0c8 100644
--- a/src/transport/gnunet-service-tng.c
+++ b/src/transport/gnunet-service-tng.c
@@ -33,7 +33,6 @@
33 * transport-to-transport traffic) 33 * transport-to-transport traffic)
34 * 34 *
35 * Implement next: 35 * Implement next:
36 * - backchannel message encryption & decryption
37 * - DV data structures: 36 * - DV data structures:
38 * + using DV routes! 37 * + using DV routes!
39 * - handling of DV-boxed messages that need to be forwarded 38 * - handling of DV-boxed messages that need to be forwarded
@@ -59,7 +58,6 @@
59 * FIXME (without marks in the code!): 58 * FIXME (without marks in the code!):
60 * - proper use/initialization of timestamps in messages exchanged 59 * - proper use/initialization of timestamps in messages exchanged
61 * during DV learning 60 * during DV learning
62 * -
63 * 61 *
64 * Optimizations: 62 * Optimizations:
65 * - use shorthashmap on msg_uuid's when matching reliability/fragment ACKs 63 * - use shorthashmap on msg_uuid's when matching reliability/fragment ACKs
@@ -3238,21 +3236,32 @@ route_message (const struct GNUNET_PeerIdentity *target,
3238 */ 3236 */
3239struct BackchannelKeyState 3237struct BackchannelKeyState
3240{ 3238{
3241 // FIXME: actual data types in this struct are likely still totally wrong
3242 /** 3239 /**
3243 * 3240 * State of our block cipher.
3244 */ 3241 */
3245 char hdr_key[128]; 3242 gcry_cipher_hd_t cipher;
3246 3243
3247 /** 3244 /**
3248 * 3245 * Actual key material.
3249 */ 3246 */
3250 char body_key[128]; 3247 struct {
3251 3248
3252 /** 3249 /**
3253 * 3250 * Key used for HMAC calculations (via #GNUNET_CRYPTO_hmac()).
3254 */ 3251 */
3255 char hmac_key[128]; 3252 struct GNUNET_CRYPTO_AuthKey hmac_key;
3253
3254 /**
3255 * Symmetric key to use for encryption.
3256 */
3257 char aes_key[256/8];
3258
3259 /**
3260 * Counter value to use during setup.
3261 */
3262 char aes_ctr[128/8];
3263
3264 } material;
3256}; 3265};
3257 3266
3258 3267
@@ -3263,14 +3272,24 @@ bc_setup_key_state_from_km (const struct GNUNET_HashCode *km,
3263{ 3272{
3264 /* must match #dh_key_derive_eph_pub */ 3273 /* must match #dh_key_derive_eph_pub */
3265 GNUNET_assert (GNUNET_YES == 3274 GNUNET_assert (GNUNET_YES ==
3266 GNUNET_CRYPTO_kdf (key, 3275 GNUNET_CRYPTO_kdf (&key->material,
3267 sizeof (*key), 3276 sizeof (key->material),
3268 "transport-backchannel-key", 3277 "transport-backchannel-key",
3269 strlen ("transport-backchannel-key"), 3278 strlen ("transport-backchannel-key"),
3270 &km, 3279 &km,
3271 sizeof (km), 3280 sizeof (km),
3272 iv, 3281 iv,
3273 sizeof (*iv))); 3282 sizeof (*iv)));
3283 gcry_cipher_open (&key->cipher,
3284 GCRY_CIPHER_AES256 /* low level: go for speed */,
3285 GCRY_CIPHER_MODE_CTR,
3286 0 /* flags */);
3287 gcry_cipher_setkey (key->cipher,
3288 &key->material.aes_key,
3289 sizeof (key->material.aes_key));
3290 gcry_cipher_setctr (key->cipher,
3291 &key->material.aes_ctr,
3292 sizeof (key->material.aes_ctr));
3274} 3293}
3275 3294
3276 3295
@@ -3342,7 +3361,10 @@ bc_hmac (const struct BackchannelKeyState *key,
3342 const void *data, 3361 const void *data,
3343 size_t data_size) 3362 size_t data_size)
3344{ 3363{
3345 // FIXME! 3364 GNUNET_CRYPTO_hmac (&key->material.hmac_key,
3365 data,
3366 data_size,
3367 hmac);
3346} 3368}
3347 3369
3348 3370
@@ -3361,7 +3383,12 @@ bc_encrypt (struct BackchannelKeyState *key,
3361 void *dst, 3383 void *dst,
3362 size_t in_size) 3384 size_t in_size)
3363{ 3385{
3364 // FIXME! 3386 GNUNET_assert (0 ==
3387 gcry_cipher_encrypt (key->cipher,
3388 dst,
3389 in_size,
3390 in,
3391 in_size));
3365} 3392}
3366 3393
3367 3394
@@ -3380,7 +3407,12 @@ bc_decrypt (struct BackchannelKeyState *key,
3380 const void *ciph, 3407 const void *ciph,
3381 size_t out_size) 3408 size_t out_size)
3382{ 3409{
3383 // FIXME! 3410 GNUNET_assert (0 ==
3411 gcry_cipher_decrypt (key->cipher,
3412 out,
3413 out_size,
3414 ciph,
3415 out_size));
3384} 3416}
3385 3417
3386 3418
@@ -3392,7 +3424,9 @@ bc_decrypt (struct BackchannelKeyState *key,
3392static void 3424static void
3393bc_key_clean (struct BackchannelKeyState *key) 3425bc_key_clean (struct BackchannelKeyState *key)
3394{ 3426{
3395 // FIXME! 3427 gcry_cipher_close (key->cipher);
3428 GNUNET_CRYPTO_zero_keys (&key->material,
3429 sizeof (key->material));
3396} 3430}
3397 3431
3398 3432