Skip to content

Commit 5b8d8c6

Browse files
committed
[TEST-ONLY] Mess with internal logic to test epoch data
This rotates/invalidates keys extremely quickly and also jumps forward 1-8 keys instead of always one to test that part of the logic. Change-Id: I7cdf992eb6031315c4978c6a1fbbecfa723fca91 Signed-off-by: Arne Schwabe <[email protected]>
1 parent e9187ea commit 5b8d8c6

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

src/openvpn/crypto.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,9 @@ openvpn_encrypt(struct buffer *buf, struct buffer work,
352352
int64_t
353353
cipher_get_aead_limits(const char *ciphername)
354354
{
355+
/* TESTING: Make AEAD key limits really really really small to force
356+
* key rollever super quickly */
357+
return 256;
355358
if (!cipher_kt_mode_aead(ciphername))
356359
{
357360
return 0;

src/openvpn/crypto_epoch.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,13 @@ epoch_check_send_iterate(struct crypto_options *opt)
414414
if (aead_usage_limit_reached(opt->aead_usage_limit, &opt->key_ctx_bi.encrypt,
415415
opt->packet_id.send.id))
416416
{
417-
/* Send key limit reached */
418-
epoch_iterate_send_key(opt);
417+
int forward = rand() % 8 + 1;
418+
/* Send key limit reached, go one key forward or in this TEST
419+
* gremlin mode, 1 to 8 to test the other side future key stuff */
420+
for (int i = 0; i < forward; i++)
421+
{
422+
epoch_iterate_send_key(opt);
423+
}
419424
}
420425
/* draft 8 of the aead usage limit still had but draft 9 complete
421426
* dropped this statement:
@@ -437,7 +442,13 @@ epoch_check_send_iterate(struct crypto_options *opt)
437442
/* Receive key limit reached. Increase our own send key to signal
438443
* that we want to use a new epoch. Peer should then also move its
439444
* key but is not required to do this */
440-
epoch_iterate_send_key(opt);
445+
int forward = rand() % 8 + 1;
446+
/* gremlin mode, 1 to 8 to test the other side future key stuff */
447+
for (int i = 0; i < forward; i++)
448+
{
449+
epoch_iterate_send_key(opt);
450+
}
451+
441452
}
442453
}
443454

tests/unit_tests/openvpn/test_ssl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ init_crypto_options(const char *cipher, const char *auth, bool epoch,
398398
struct epoch_key e1 = { .epoch = 1, .epoch_key = { 0 }};
399399
memcpy(e1.epoch_key, key2.keys[0].cipher, sizeof(e1.epoch_key));
400400
co.flags |= CO_EPOCH_DATA_KEY_FORMAT;
401-
epoch_init_key_ctx(&co, &kt, &e1, &e1, 5);
401+
epoch_init_key_ctx(&co, &kt, &e1, &e1, 9);
402402

403403
/* Do a little of dancing for the epoch_send_key_iterate to test
404404
* that this works too */

0 commit comments

Comments
 (0)