mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-06 20:35:07 -05:00
nts: refactor NTS context
Add a context structure for the algorithm and keys established by NTS-KE. Modify the client to save the context and reset the SIV key to the C2S/S2C key before each request/response instead of keeping two SIV instances. This will make it easier for the server to support different algorithms and allow the client to save the context with cookies to disk.
This commit is contained in:
@@ -49,8 +49,7 @@ struct NKC_Instance_Record {
|
||||
int got_response;
|
||||
int resolving_name;
|
||||
|
||||
SIV_Algorithm siv_algorithm;
|
||||
NKE_Key c2s, s2c;
|
||||
NKE_Context context;
|
||||
NKE_Cookie cookies[NKE_MAX_COOKIES];
|
||||
int num_cookies;
|
||||
char server_name[NKE_MAX_RECORD_BODY_LENGTH + 1];
|
||||
@@ -156,7 +155,7 @@ process_response(NKC_Instance inst)
|
||||
break;
|
||||
}
|
||||
aead_algorithm = AEAD_AES_SIV_CMAC_256;
|
||||
inst->siv_algorithm = aead_algorithm;
|
||||
inst->context.algorithm = aead_algorithm;
|
||||
break;
|
||||
case NKE_RECORD_ERROR:
|
||||
if (length == 2)
|
||||
@@ -237,7 +236,8 @@ handle_message(void *arg)
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!NKSN_GetKeys(inst->session, inst->siv_algorithm, &inst->c2s, &inst->s2c))
|
||||
if (!NKSN_GetKeys(inst->session, inst->context.algorithm,
|
||||
&inst->context.c2s, &inst->context.s2c))
|
||||
return 0;
|
||||
|
||||
if (inst->server_name[0] != '\0') {
|
||||
@@ -371,8 +371,7 @@ NKC_IsActive(NKC_Instance inst)
|
||||
/* ================================================== */
|
||||
|
||||
int
|
||||
NKC_GetNtsData(NKC_Instance inst,
|
||||
SIV_Algorithm *siv_algorithm, NKE_Key *c2s, NKE_Key *s2c,
|
||||
NKC_GetNtsData(NKC_Instance inst, NKE_Context *context,
|
||||
NKE_Cookie *cookies, int *num_cookies, int max_cookies,
|
||||
IPSockAddr *ntp_address)
|
||||
{
|
||||
@@ -381,9 +380,7 @@ NKC_GetNtsData(NKC_Instance inst,
|
||||
if (!inst->got_response || inst->resolving_name)
|
||||
return 0;
|
||||
|
||||
*siv_algorithm = inst->siv_algorithm;
|
||||
*c2s = inst->c2s;
|
||||
*s2c = inst->s2c;
|
||||
*context = inst->context;
|
||||
|
||||
for (i = 0; i < inst->num_cookies && i < max_cookies; i++)
|
||||
cookies[i] = inst->cookies[i];
|
||||
|
||||
Reference in New Issue
Block a user