From e297df78e4a49b52b56a046d80459e1fde8c8960 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Wed, 10 Feb 2021 12:23:13 +0100 Subject: [PATCH] nts: load cookies early Instead of waiting for the first request, try to load the cookies as soon as the instance is created, or the NTS address is changed. This enables loading of dump files for servers that are negotiated in NTS-KE. --- nts_ntp_client.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/nts_ntp_client.c b/nts_ntp_client.c index ed89edd..7e8e3fc 100644 --- a/nts_ntp_client.c +++ b/nts_ntp_client.c @@ -60,7 +60,6 @@ struct NNC_Instance_Record { NKC_Instance nke; SIV_Instance siv; - int load_attempt; int nke_attempts; double next_nke_attempt; double last_nke_success; @@ -94,7 +93,6 @@ reset_instance(NNC_Instance inst) SIV_DestroyInstance(inst->siv); inst->siv = NULL; - inst->load_attempt = 0; inst->nke_attempts = 0; inst->next_nke_attempt = 0.0; inst->last_nke_success = 0.0; @@ -129,6 +127,9 @@ NNC_CreateInstance(IPSockAddr *nts_address, const char *name, uint16_t ntp_port) reset_instance(inst); + /* Try to reload saved keys and cookies */ + load_cookies(inst); + return inst; } @@ -288,12 +289,6 @@ NNC_PrepareForAuth(NNC_Instance inst) UTI_GetRandomBytes(inst->uniq_id, sizeof (inst->uniq_id)); UTI_GetRandomBytes(inst->nonce, sizeof (inst->nonce)); - /* Try to reload saved keys and cookies (once for the NTS-KE address) */ - if (!inst->load_attempt) { - load_cookies(inst); - inst->load_attempt = 1; - } - /* Get new cookies if there are not any, or they are no longer usable */ if (!check_cookies(inst)) { if (!get_cookies(inst)) @@ -529,6 +524,8 @@ NNC_ChangeAddress(NNC_Instance inst, IPAddr *address) reset_instance(inst); DEBUG_LOG("NTS reset"); + + load_cookies(inst); } /* ================================================== */