mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-06 11:45:07 -05:00
nts: negotiate compliant export of AES-128-GCM-SIV keys
Add client and server support for a new NTS-KE record to negotiate use of the compliant key exporter context with the AES-128-GCM-SIV AEAD as specified here: https://chrony-project.org/doc/spec/nts-compliant-128gcm.html
This commit is contained in:
@@ -50,6 +50,7 @@ struct NKC_Instance_Record {
|
||||
int got_response;
|
||||
int resolving_name;
|
||||
|
||||
int compliant_128gcm;
|
||||
NKE_Context context;
|
||||
NKE_Cookie cookies[NKE_MAX_COOKIES];
|
||||
int num_cookies;
|
||||
@@ -103,7 +104,7 @@ prepare_request(NKC_Instance inst)
|
||||
{
|
||||
NKSN_Instance session = inst->session;
|
||||
uint16_t data[2];
|
||||
int length;
|
||||
int i, length;
|
||||
|
||||
NKSN_BeginMessage(session);
|
||||
|
||||
@@ -120,6 +121,14 @@ prepare_request(NKC_Instance inst)
|
||||
length * sizeof (data[0])))
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < length; i++) {
|
||||
if (data[i] == htons(AEAD_AES_128_GCM_SIV)) {
|
||||
if (!NKSN_AddRecord(session, 0, NKE_RECORD_COMPLIANT_128GCM_EXPORT, NULL, 0))
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!NKSN_EndMessage(session))
|
||||
return 0;
|
||||
|
||||
@@ -139,6 +148,7 @@ process_response(NKC_Instance inst)
|
||||
assert(sizeof (data) % sizeof (uint16_t) == 0);
|
||||
assert(sizeof (uint16_t) == 2);
|
||||
|
||||
inst->compliant_128gcm = 0;
|
||||
inst->num_cookies = 0;
|
||||
inst->ntp_address.ip_addr.family = IPADDR_UNSPEC;
|
||||
inst->ntp_address.port = 0;
|
||||
@@ -175,6 +185,15 @@ process_response(NKC_Instance inst)
|
||||
aead_algorithm = ntohs(data[0]);
|
||||
inst->context.algorithm = aead_algorithm;
|
||||
break;
|
||||
case NKE_RECORD_COMPLIANT_128GCM_EXPORT:
|
||||
if (length != 0) {
|
||||
DEBUG_LOG("Non-empty compliant-128gcm record");
|
||||
error = 1;
|
||||
break;
|
||||
}
|
||||
DEBUG_LOG("Compliant AES-128-GCM-SIV export");
|
||||
inst->compliant_128gcm = 1;
|
||||
break;
|
||||
case NKE_RECORD_ERROR:
|
||||
if (length == 2)
|
||||
DEBUG_LOG("NTS-KE error %d", ntohs(data[0]));
|
||||
@@ -266,8 +285,9 @@ handle_message(void *arg)
|
||||
exporter_algorithm = inst->context.algorithm;
|
||||
|
||||
/* With AES-128-GCM-SIV, set the algorithm ID in the RFC5705 key exporter
|
||||
context incorrectly for compatibility with older chrony servers */
|
||||
if (exporter_algorithm == AEAD_AES_128_GCM_SIV)
|
||||
context incorrectly for compatibility with older chrony servers unless
|
||||
the server confirmed support for the compliant context */
|
||||
if (exporter_algorithm == AEAD_AES_128_GCM_SIV && !inst->compliant_128gcm)
|
||||
exporter_algorithm = AEAD_AES_SIV_CMAC_256;
|
||||
|
||||
if (!NKSN_GetKeys(inst->session, inst->context.algorithm, exporter_algorithm,
|
||||
|
||||
Reference in New Issue
Block a user