[Git][NTPsec/ntpsec][nts] 8 commits: ntpd/refclock_jjy.c: Just remove tabs. Weird comments...
Hal Murray (@hal.murray)
gitlab at mg.gitlab.com
Thu Aug 6 17:22:03 UTC 2026
Hal Murray pushed to branch nts at NTPsec / ntpsec
Commits:
676d82c4 by Gary E. Miller at 2026-08-04T22:13:07-07:00
ntpd/refclock_jjy.c: Just remove tabs. Weird comments...
- - - - -
b2ca71a7 by Gary E. Miller at 2026-08-06T10:14:33-07:00
ntpd/nts_server.c: Remove tabs, Single line /* comments to //
- - - - -
4d7554c9 by Gary E. Miller at 2026-08-06T10:15:46-07:00
attic/aes-siv-timing.c: Remove tabs, Single line /* comments to //
No functional changes.
- - - - -
d73d3498 by Gary E. Miller at 2026-08-06T10:16:50-07:00
tests/ntpd/nts_cookie.c: Remove tabs, Single line /* comments to //
No functional changes.
- - - - -
2255add0 by Gary E. Miller at 2026-08-06T10:16:50-07:00
tests/ntpd/nts_cookie.c: restore previous comment indents
No functional changes.
- - - - -
e69a219e by Gary E. Miller at 2026-08-06T10:17:37-07:00
tests/ntpd/nts.c: Remove tabs, Single line /* comments to //
No functional changes.
- - - - -
17c215a5 by Gary E. Miller at 2026-08-06T10:21:40-07:00
include/nts.h: Remove tabs, Single line /* comments to //
No functional changes.
- - - - -
2e634bbc by Gary E. Miller at 2026-08-06T10:21:40-07:00
incluyde/nts.h: restore previous comment indents
No functional changes.
- - - - -
6 changed files:
- attic/aes-siv-timing.c
- include/nts.h
- ntpd/nts_server.c
- ntpd/refclock_jjy.c
- tests/ntpd/nts.c
- tests/ntpd/nts_cookie.c
Changes:
=====================================
attic/aes-siv-timing.c
=====================================
@@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-/* Last modified on Sat Aug 28 14:30:11 PDT 1999 by murray */
+// Last modified on Sat Aug 28 14:30:11 PDT 1999 by murray
/*
* Hack to time aead routines from libaes_siv
@@ -44,7 +44,7 @@ int key_K_length;
pthread_mutex_t cookie_lock = PTHREAD_MUTEX_INITIALIZER;
-/* sizeof(key_I) + sizeof(NONCE) */
+// sizeof(key_I) + sizeof(NONCE)
#define AD_LENGTH 20
static void ssl_init(void)
@@ -85,44 +85,44 @@ static void ntp_RAND_bytes(unsigned char *buf, int num) {
static void DoLock(void)
{
- struct timespec start, stop;
- double fast;
- int samplesize = SAMPLESIZE;
+ struct timespec start, stop;
+ double fast;
+ int samplesize = SAMPLESIZE;
- clock_gettime(CLOCK_MONOTONIC, &start);
- for (int i = 0; i < samplesize; i++) {
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < samplesize; i++) {
nts_lock_cookielock();
nts_unlock_cookielock();
- }
- clock_gettime(CLOCK_MONOTONIC, &stop);
- fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
- printf("LocK %6.0f %7.3f",
- fast/samplesize, fast/1E9);
- printf("\n");
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
+ fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
+ printf("LocK %6.0f %7.3f",
+ fast/samplesize, fast/1E9);
+ printf("\n");
}
static void DoNonce(void)
{
uint8_t nonce[NONCE_LENGTH];
- struct timespec start, stop;
- double fast;
- int samplesize = SAMPLESIZE;
+ struct timespec start, stop;
+ double fast;
+ int samplesize = SAMPLESIZE;
- clock_gettime(CLOCK_MONOTONIC, &start);
- for (int i = 0; i < samplesize; i++) {
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < samplesize; i++) {
ntp_RAND_bytes(nonce, NONCE_LENGTH);
- }
- clock_gettime(CLOCK_MONOTONIC, &stop);
- fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
- printf("Nonce %3d %6.0f %7.3f",
- NONCE_LENGTH, fast/samplesize, fast/1E9);
- printf("\n");
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
+ fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
+ printf("Nonce %3d %6.0f %7.3f",
+ NONCE_LENGTH, fast/samplesize, fast/1E9);
+ printf("\n");
}
-/* Clone of nts_make_cookie() from ntpd/nts_cookie.c */
-/* returns actual length */
+// Clone of nts_make_cookie() from ntpd/nts_cookie.c
+// returns actual length
int nts_make_cookie(uint8_t *cookie,
uint16_t aead,
uint8_t *c2s, uint8_t *s2c, int keylen) {
@@ -131,11 +131,11 @@ int nts_make_cookie(uint8_t *cookie,
int used, plainlength;
bool ok;
uint8_t * finger;
- uint32_t temp; /* keep 4 byte alignment */
+ uint32_t temp; // keep 4 byte alignment
size_t left;
if (NULL == cookie_ctx)
- return 0; /* We aren't initialized yet. */
+ return 0; // We aren't initialized yet.
// nts_cookie_make++;
@@ -151,7 +151,7 @@ int nts_make_cookie(uint8_t *cookie,
finger += keylen;
plainlength = finger-plaintext;
- /* collect associated data */
+ // collect associated data
finger = cookie;
memcpy(finger, &key_I, sizeof(key_I));
@@ -166,7 +166,7 @@ int nts_make_cookie(uint8_t *cookie,
nts_lock_cookielock();
ok = AES_SIV_Encrypt(cookie_ctx,
- finger, &left, /* left: in: max out length, out: length used */
+ finger, &left, // left: in: max out length, out: length used
key_K, key_K_length,
nonce, NONCE_LENGTH,
plaintext, plainlength,
@@ -186,84 +186,84 @@ int nts_make_cookie(uint8_t *cookie,
static void DoMakeCookie(
- const char *name, /* name of aead */
- int aead, /* algorithm used to make cookie */
- int keylength /* length of c2s and s2c */
+ const char *name, // name of aead
+ int aead, // algorithm used to make cookie
+ int keylength // length of c2s and s2c
)
{
- uint8_t cookie[NTS_MAX_COOKIELEN];
- uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
- struct timespec start, stop;
- double fast;
- int cookielength = 0;
- int samplesize = SAMPLESIZE;
-
- switch (aead) {
- case AEAD_AES_SIV_CMAC_256:
- key_K_length = AEAD_AES_SIV_CMAC_256_KEYLEN;
- break;
- case AEAD_AES_SIV_CMAC_384:
- key_K_length = AEAD_AES_SIV_CMAC_384_KEYLEN;
- break;
- case AEAD_AES_SIV_CMAC_512:
- key_K_length = AEAD_AES_SIV_CMAC_512_KEYLEN;
- break;
- default:
- printf("Bogus aead\n");
- exit(1);
- }
+ uint8_t cookie[NTS_MAX_COOKIELEN];
+ uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
+ struct timespec start, stop;
+ double fast;
+ int cookielength = 0;
+ int samplesize = SAMPLESIZE;
+
+ switch (aead) {
+ case AEAD_AES_SIV_CMAC_256:
+ key_K_length = AEAD_AES_SIV_CMAC_256_KEYLEN;
+ break;
+ case AEAD_AES_SIV_CMAC_384:
+ key_K_length = AEAD_AES_SIV_CMAC_384_KEYLEN;
+ break;
+ case AEAD_AES_SIV_CMAC_512:
+ key_K_length = AEAD_AES_SIV_CMAC_512_KEYLEN;
+ break;
+ default:
+ printf("Bogus aead\n");
+ exit(1);
+ }
ntp_RAND_bytes(c2s, NTS_MAX_KEYLEN);
ntp_RAND_bytes(s2c, NTS_MAX_KEYLEN);
- clock_gettime(CLOCK_MONOTONIC, &start);
- for (int i = 0; i < samplesize; i++) {
- cookielength = nts_make_cookie(
- cookie, aead, c2s, s2c, keylength);
- }
- clock_gettime(CLOCK_MONOTONIC, &stop);
- fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
- printf("%12s %2d %4d %6.0f %7.3f",
- name, keylength, cookielength, fast/samplesize, fast/1E9);
- printf("\n");
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < samplesize; i++) {
+ cookielength = nts_make_cookie(
+ cookie, aead, c2s, s2c, keylength);
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
+ fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
+ printf("%12s %2d %4d %6.0f %7.3f",
+ name, keylength, cookielength, fast/samplesize, fast/1E9);
+ printf("\n");
}
static void DoMakeCrypto(
- const char *name, /* name of aead */
- int aead, /* algorithm used to make cookie */
- int keylen /* length of c2s and s2c */
+ const char *name, // name of aead
+ int aead, // algorithm used to make cookie
+ int keylen // length of c2s and s2c
)
{
- uint8_t cookie[NTS_MAX_COOKIELEN];
- uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
- struct timespec start, stop;
- double fast;
- int cookielength = 0;
- int samplesize = SAMPLESIZE;
+ uint8_t cookie[NTS_MAX_COOKIELEN];
+ uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
+ struct timespec start, stop;
+ double fast;
+ int cookielength = 0;
+ int samplesize = SAMPLESIZE;
uint8_t plaintext[NTS_MAX_COOKIELEN];
uint8_t *nonce;
int used, plainlength;
int ok = 0;
uint8_t * finger;
- uint32_t temp; /* keep 4 byte alignment */
+ uint32_t temp; // keep 4 byte alignment
size_t left;
- switch (aead) {
- case AEAD_AES_SIV_CMAC_256:
- key_K_length = AEAD_AES_SIV_CMAC_256_KEYLEN;
- break;
- case AEAD_AES_SIV_CMAC_384:
- key_K_length = AEAD_AES_SIV_CMAC_384_KEYLEN;
- break;
- case AEAD_AES_SIV_CMAC_512:
- key_K_length = AEAD_AES_SIV_CMAC_512_KEYLEN;
- break;
- default:
- printf("Bogus aead\n");
- exit(1);
- }
+ switch (aead) {
+ case AEAD_AES_SIV_CMAC_256:
+ key_K_length = AEAD_AES_SIV_CMAC_256_KEYLEN;
+ break;
+ case AEAD_AES_SIV_CMAC_384:
+ key_K_length = AEAD_AES_SIV_CMAC_384_KEYLEN;
+ break;
+ case AEAD_AES_SIV_CMAC_512:
+ key_K_length = AEAD_AES_SIV_CMAC_512_KEYLEN;
+ break;
+ default:
+ printf("Bogus aead\n");
+ exit(1);
+ }
ntp_RAND_bytes(c2s, NTS_MAX_KEYLEN);
ntp_RAND_bytes(s2c, NTS_MAX_KEYLEN);
@@ -278,7 +278,7 @@ static void DoMakeCrypto(
finger += keylen;
plainlength = finger-plaintext;
- /* collect associated data */
+ // collect associated data
finger = cookie;
memcpy(finger, &key_I, sizeof(key_I));
@@ -291,16 +291,16 @@ static void DoMakeCrypto(
used = finger-cookie;
left = NTS_MAX_COOKIELEN-used;
- clock_gettime(CLOCK_MONOTONIC, &start);
- for (int i = 0; i < samplesize; i++) {
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ for (int i = 0; i < samplesize; i++) {
ok += AES_SIV_Encrypt(cookie_ctx,
- finger, &left, /* left: in: max out length, out: length used */
+ finger, &left, // left: in: max out length, out: length used
key_K, key_K_length,
nonce, NONCE_LENGTH,
plaintext, plainlength,
cookie, AD_LENGTH);
- }
- clock_gettime(CLOCK_MONOTONIC, &stop);
+ }
+ clock_gettime(CLOCK_MONOTONIC, &stop);
if (samplesize != ok) {
printf("NTS: nts_make_cookie - Error from AES_SIV_Encrypt\n");
@@ -310,69 +310,69 @@ static void DoMakeCrypto(
used += left;
INSIST(used <= NTS_MAX_COOKIELEN);
- cookielength = used;
+ cookielength = used;
- fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
- printf("%12s %2d %4d %6.0f %7.3f",
- name, keylen, cookielength, fast/samplesize, fast/1E9);
- printf("\n");
+ fast = (stop.tv_sec-start.tv_sec)*1E9 + (stop.tv_nsec-start.tv_nsec);
+ printf("%12s %2d %4d %6.0f %7.3f",
+ name, keylen, cookielength, fast/samplesize, fast/1E9);
+ printf("\n");
}
int main(int argc, char *argv[])
{
- char *ctimetxt;
- time_t now;
- char buff[256];
+ char *ctimetxt;
+ time_t now;
+ char buff[256];
- UNUSED_ARG(argc);
- UNUSED_ARG(argv);
+ UNUSED_ARG(argc);
+ UNUSED_ARG(argv);
- setlinebuf(stdout);
+ setlinebuf(stdout);
- ssl_init();
+ ssl_init();
ntp_RAND_bytes(key_K, NTS_MAX_KEYLEN);
- now = time(NULL);
- ctimetxt = ctime(&now);
- ctimetxt[24] = 0; /* Hack: smash return */
- gethostname(buff, sizeof(buff));
- printf("# %s on %s\n", ctimetxt, buff);
- printf("# %s\n", OPENSSL_VERSION_TEXT);
+ now = time(NULL);
+ ctimetxt = ctime(&now);
+ ctimetxt[24] = 0; // Hack: smash return
+ gethostname(buff, sizeof(buff));
+ printf("# %s on %s\n", ctimetxt, buff);
+ printf("# %s\n", OPENSSL_VERSION_TEXT);
- printf("\n");
- printf("# bytes ns/op sec/run\n");
- DoLock();
- DoNonce();
+ printf("\n");
+ printf("# bytes ns/op sec/run\n");
+ DoLock();
+ DoNonce();
- printf("\n");
- printf("# wKL=sizeof(c2s), CL=sizeof(cookie)\n");
- printf("# Make cookie wKL CL ns/op sec/run\n");
+ printf("\n");
+ printf("# wKL=sizeof(c2s), CL=sizeof(cookie)\n");
+ printf("# Make cookie wKL CL ns/op sec/run\n");
// Sample numbers using old cmac.h
// run on a Dell 9020/MT with Intel i7-4790 @ 3.60GHz
- /* 3rd arg is length of c2s and s2c */
- DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 32);
- DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 48);
- DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 64);
+ // 3rd arg is length of c2s and s2c
+ DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 32);
+ DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 48);
+ DoMakeCookie("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 64);
// AES_SIV_CMAC_256 32 104 3127 3.127
// AES_SIV_CMAC_256 48 136 3186 3.186
// AES_SIV_CMAC_256 64 168 3220 3.220
- DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 32);
- DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 48);
- DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 64);
+ DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 32);
+ DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 48);
+ DoMakeCookie("AES_SIV_CMAC_512", AEAD_AES_SIV_CMAC_512, 64);
// AES_SIV_CMAC_512 32 104 3183 3.183
// AES_SIV_CMAC_512 48 136 3247 3.247
// AES_SIV_CMAC_512 64 168 3303 3.303
- printf("\n");
+ printf("\n");
- printf("# Cookie Crypto wKL CL ns/op sec/run\n");
- DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 32);
- DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 48);
- DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 64);
+ printf("# Cookie Crypto wKL CL ns/op sec/run\n");
+ DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 32);
+ DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 48);
+ DoMakeCrypto("AES_SIV_CMAC_256", AEAD_AES_SIV_CMAC_256, 64);
// AES_SIV_CMAC_256 32 104 2066 2.066
// AES_SIV_CMAC_256 48 136 2119 2.119
// AES_SIV_CMAC_256 64 168 2157 2.157
- return 0;
+ return 0;
}
=====================================
include/nts.h
=====================================
@@ -12,20 +12,20 @@
#include "ntp_fp.h"
-/* default file names */
+// default file names
#define NTS_CERT_FILE "/etc/ntp/cert-chain.pem"
#define NTS_KEY_FILE "/etc/ntp/key.pem"
#define NTS_COOKIE_KEY_FILE "/var/lib/ntp/nts-keys"
-#define NTS_KE_PORT 4460
-#define NTS_KE_PORTA "4460"
+#define NTS_KE_PORT 4460
+#define NTS_KE_PORTA "4460"
-#define NTS_KE_TIMEOUT 3
+#define NTS_KE_TIMEOUT 3
bool nts_server_init(void);
bool nts_client_init(void);
bool nts_cookie_init(void);
-bool nts_server_init2(void); /* after sandbox */
+bool nts_server_init2(void); // after sandbox
bool nts_cookie_init2(void);
void nts_cert_timer(void);
@@ -42,18 +42,18 @@ bool nts_unpack_cookie(uint8_t *cookie, int cookielen,
uint16_t *aead,
uint8_t *c2s, uint8_t *s2c, int *keylen);
-/* working finger into a buffer - updated by append/unpack routines */
+// working finger into a buffer - updated by append/unpack routines
struct BufCtl_t {
- uint8_t *next; /* pointer to next data/space */
- int left; /* data left or space available */
+ uint8_t *next; // pointer to next data/space
+ int left; // data left or space available
};
typedef struct BufCtl_t BufCtl;
-/* Here for test routines */
+// Here for test routines
bool nts_ke_process_receive(struct BufCtl_t *buf, int *aead,
char *errbuf, int errlng, const char **errtxt);
-/***********************************************************/
+// *********************************************************
/* buffer packing/unpacking routines.
* NB: The length field in NTP extensions includes the header
@@ -67,12 +67,12 @@ bool nts_ke_process_receive(struct BufCtl_t *buf, int *aead,
*/
-/* 2 byte type, 2 byte length */
+// 2 byte type, 2 byte length
#define NTS_KE_HDR_LNG 4
#define NTS_KE_U16_LNG 2
-/* xxx_append_record_foo makes whole record with one foo */
-/* append_foo appends foo to existing partial record */
+// xxx_append_record_foo makes whole record with one foo
+// append_foo appends foo to existing partial record
void ke_append_record_null(BufCtl* buf, uint16_t type);
void ke_append_record_uint16(BufCtl* buf, uint16_t type, uint16_t data);
void ke_append_record_bytes(BufCtl* buf, uint16_t type, uint8_t *data, int length);
@@ -87,19 +87,19 @@ void append_uint16(BufCtl* buf, uint16_t data);
void append_bytes(BufCtl* buf, uint8_t *data, int length);
uint16_t ke_next_record(BufCtl* buf, int *length);
-uint16_t ex_next_record(BufCtl* buf, int *length); /* body length */
+uint16_t ex_next_record(BufCtl* buf, int *length); // body length
uint16_t next_uint16(BufCtl* buf);
uint16_t next_bytes(BufCtl* buf, uint8_t *data, int length);
-/***********************************************************/
+// *********************************************************
-#define NTS_MAX_KEYLEN 64 /* used in cookies */
-#define NTS_MAX_COOKIELEN 192 /* see nts_cookie.c */
-#define NTS_MAX_COOKIES 8 /* RFC 4.1.6 */
-#define NTS_UID_LENGTH 32 /* RFC 5.3 */
-#define NTS_UID_MAX_LENGTH 64
+#define NTS_MAX_KEYLEN 64 // used in cookies
+#define NTS_MAX_COOKIELEN 192 // see nts_cookie.c
+#define NTS_MAX_COOKIES 8 // RFC 4.1.6
+#define NTS_UID_LENGTH 32 // RFC 5.3
+#define NTS_UID_MAX_LENGTH 64
-/* Here for tester */
+// Here for tester
struct NTS_Key {
uint8_t K[NTS_MAX_KEYLEN];
uint32_t I;
@@ -108,87 +108,87 @@ struct NTS_Key {
#define NTS_nKEYS 10
#endif
extern struct NTS_Key nts_keys[NTS_nKEYS];
-extern int nts_nKeys; /* for tester */
+extern int nts_nKeys; // for tester
/* Client side configuration data for an NTS association
* All are optional.
* part of peer struct */
struct ntscfg_t {
- char *ca; /* root/trusted certificates */
- char *aead; /* AEAD algorithms on wire */
+ char *ca; // root/trusted certificates
+ char *aead; // AEAD algorithms on wire
};
-/* Client-side state per connection to server */
+// Client-side state per connection to server
struct ntsclient_t {
- /* wire connection */
- uint16_t aead; /* AEAD algorithm used on wire */
- int keylen;
- uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
- /* UID of last request sent - RFC 5.3 */
- uint8_t UID[NTS_UID_LENGTH];
- /* cookies */
- int readIdx, writeIdx;
- int count; /* -1 if not in NTS mode */
- int cookielen;
- uint8_t cookies[NTS_MAX_COOKIES][NTS_MAX_COOKIELEN];
+ // wire connection
+ uint16_t aead; // AEAD algorithm used on wire
+ int keylen;
+ uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
+ // UID of last request sent - RFC 5.3
+ uint8_t UID[NTS_UID_LENGTH];
+ // cookies
+ int readIdx, writeIdx;
+ int count; // -1 if not in NTS mode
+ int cookielen;
+ uint8_t cookies[NTS_MAX_COOKIES][NTS_MAX_COOKIELEN];
};
-/* Server-side state per packet */
+// Server-side state per packet
struct ntspacket_t {
- bool valid;
- int uidlen;
- uint8_t UID[NTS_UID_MAX_LENGTH];
- int needed;
- uint16_t aead;
- int keylen;
- uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
+ bool valid;
+ int uidlen;
+ uint8_t UID[NTS_UID_MAX_LENGTH];
+ int needed;
+ uint16_t aead;
+ int keylen;
+ uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
};
-/* Configuration data for an NTS server or client instance */
+// Configuration data for an NTS server or client instance
struct ntsconfig_t {
- bool ntsenable; /* enable NTS KE server on this ntpd */
- const char * mintls; /* minimum TLS version allowed */
- const char * maxtls; /* maximum TLS version allowed */
- const char *tlsciphersuites;/* allowed TLS 1.3 ciphersuites */
- const char *tlsecdhcurves; /* allowed ecdhcurves list*/
- const char *cert; /* file holding server certificate key */
- const char *key; /* file holding server private key */
- const char *KI; /* file holding K/I for making cookies */
- const char *ca; /* root cert dir/file */
- const char *aead; /* AEAD algorithms on wire */
- bool tlscipherserverpreference; /* OpenSSL 3.0 default is client */
+ bool ntsenable; // enable NTS KE server on this ntpd
+ const char * mintls; // minimum TLS version allowed
+ const char * maxtls; // maximum TLS version allowed
+ const char *tlsciphersuites; // allowed TLS 1.3 ciphersuites
+ const char *tlsecdhcurves; // allowed ecdhcurves list
+ const char *cert; // file holding server certificate key
+ const char *key; // file holding server private key
+ const char *KI; // file holding K/I for making cookies
+ const char *ca; // root cert dir/file
+ const char *aead; // AEAD algorithms on wire
+ bool tlscipherserverpreference; // OpenSSL 3.0 default is client
};
-/* CMAC length is wired into AEAD_AES_SIV_CMAC_nnn. */
+// CMAC length is wired into AEAD_AES_SIV_CMAC_nnn.
#define CMAC_LENGTH 16
-/* The NONCE length comes from RFC 5116 and/or 5297. */
+// The NONCE length comes from RFC 5116 and/or 5297.
#define NONCE_LENGTH 16
-/* NTS protocol constants */
+// NTS protocol constants
#define NTS_CRITICAL 0x8000
enum nts_record_type {
- nts_end_of_message = 0, /* CRITICAL */
- nts_next_protocol_negotiation = 1, /* CRITICAL */
- nts_error = 2, /* CRITICAL */
- nts_warning = 3,
- nts_algorithm_negotiation = 4,
- nts_new_cookie = 5,
- nts_server_negotiation = 6,
- nts_port_negotiation = 7
+ nts_end_of_message = 0, // CRITICAL
+ nts_next_protocol_negotiation = 1, // CRITICAL
+ nts_error = 2, // CRITICAL
+ nts_warning = 3,
+ nts_algorithm_negotiation = 4,
+ nts_new_cookie = 5,
+ nts_server_negotiation = 6,
+ nts_port_negotiation = 7
};
enum nts_protocol_type {
- nts_protocol_NTP = 0,
+ nts_protocol_NTP = 0,
};
enum nts_errors_type {
- nts_unrecognized_critical_section = 0,
- nts_bad_request = 1
+ nts_unrecognized_critical_section = 0,
+ nts_bad_request = 1
};
@@ -197,50 +197,50 @@ enum nts_errors_type {
*/
enum aead_ciphers {
#define NO_AEAD 0xffff
- AEAD_AES_128_GCM = 1,
- AEAD_AES_256_GCM = 2,
- AEAD_AES_128_CCM = 3,
- AEAD_AES_256_CCM = 4,
-
- AEAD_AES_128_GCM_8 = 5,
- AEAD_AES_256_GCM_8 = 6,
- AEAD_AES_128_GCM_12 = 7,
- AEAD_AES_256_GCM_12 = 8,
-
- AEAD_AES_128_CCM_SHORT = 9,
- AEAD_AES_256_CCM_SHORT = 10,
- AEAD_AES_128_CCM_SHORT_8 = 11,
- AEAD_AES_256_CCM_SHORT_8 = 12,
- AEAD_AES_128_CCM_SHORT_12 = 13,
- AEAD_AES_256_CCM_SHORT_12 = 14,
-
- AEAD_AES_SIV_CMAC_256 = 15, /* RFC 5297 */
- AEAD_AES_SIV_CMAC_384 = 16, /* These 3 are the ones we use */
- AEAD_AES_SIV_CMAC_512 = 17,
+ AEAD_AES_128_GCM = 1,
+ AEAD_AES_256_GCM = 2,
+ AEAD_AES_128_CCM = 3,
+ AEAD_AES_256_CCM = 4,
+
+ AEAD_AES_128_GCM_8 = 5,
+ AEAD_AES_256_GCM_8 = 6,
+ AEAD_AES_128_GCM_12 = 7,
+ AEAD_AES_256_GCM_12 = 8,
+
+ AEAD_AES_128_CCM_SHORT = 9,
+ AEAD_AES_256_CCM_SHORT = 10,
+ AEAD_AES_128_CCM_SHORT_8 = 11,
+ AEAD_AES_256_CCM_SHORT_8 = 12,
+ AEAD_AES_128_CCM_SHORT_12 = 13,
+ AEAD_AES_256_CCM_SHORT_12 = 14,
+
+ AEAD_AES_SIV_CMAC_256 = 15, // RFC 5297
+ AEAD_AES_SIV_CMAC_384 = 16, // These 3 are the ones we use
+ AEAD_AES_SIV_CMAC_512 = 17,
#define AEAD_AES_SIV_CMAC_256_KEYLEN 32
#define AEAD_AES_SIV_CMAC_384_KEYLEN 48
#define AEAD_AES_SIV_CMAC_512_KEYLEN 64
- AEAD_AES_128_CCM_8 = 18,
- AEAD_AES_256_CCM_8 = 19,
+ AEAD_AES_128_CCM_8 = 18,
+ AEAD_AES_256_CCM_8 = 19,
- AEAD_AES_128_OCB_TAGLEN128 = 20,
- AEAD_AES_128_OCB_TAGLEN96 = 21,
- AEAD_AES_128_OCB_TAGLEN64 = 22,
- AEAD_AES_192_OCB_TAGLEN128 = 23,
- AEAD_AES_192_OCB_TAGLEN96 = 24,
- AEAD_AES_192_OCB_TAGLEN64 = 25,
- AEAD_AES_256_OCB_TAGLEN128 = 26,
- AEAD_AES_256_OCB_TAGLEN96 = 27,
- AEAD_AES_256_OCB_TAGLEN64 = 28,
+ AEAD_AES_128_OCB_TAGLEN128 = 20,
+ AEAD_AES_128_OCB_TAGLEN96 = 21,
+ AEAD_AES_128_OCB_TAGLEN64 = 22,
+ AEAD_AES_192_OCB_TAGLEN128 = 23,
+ AEAD_AES_192_OCB_TAGLEN96 = 24,
+ AEAD_AES_192_OCB_TAGLEN64 = 25,
+ AEAD_AES_256_OCB_TAGLEN128 = 26,
+ AEAD_AES_256_OCB_TAGLEN96 = 27,
+ AEAD_AES_256_OCB_TAGLEN64 = 28,
- AEAD_CHACHA20_POLY1305 = 29,
+ AEAD_CHACHA20_POLY1305 = 29,
- AEAD_AES_128_GCM_SIV = 30,
- AEAD_AES_256_GCM_SIV = 31,
+ AEAD_AES_128_GCM_SIV = 30,
+ AEAD_AES_256_GCM_SIV = 31,
- AEAD_AEGIS128L = 32,
- AEAD_AEGIS256 = 33
+ AEAD_AEGIS128L = 32,
+ AEAD_AEGIS256 = 33
};
@@ -249,7 +249,7 @@ extern struct ntsconfig_t ntsconfig;
-/* NTS-related statistics visible via ntpq -c nts */
+// NTS-related statistics visible via ntpq -c nts
struct nts_counters {
uint64_t client_send;
uint64_t client_recv_good;
@@ -258,17 +258,17 @@ struct nts_counters {
uint64_t server_recv_good;
uint64_t server_recv_bad;
uint64_t cookie_make;
- uint64_t cookie_not_server; /* we are not a NTS server */
- uint64_t cookie_decode_total; /* total attempts, includes too old */
+ uint64_t cookie_not_server; // we are not a NTS server
+ uint64_t cookie_decode_total; // total attempts, includes too old
uint64_t cookie_decode_current;
uint64_t cookie_decode_old;
uint64_t cookie_decode_old2;
uint64_t cookie_decode_older;
- uint64_t cookie_decode_too_old; /* or garbage */
+ uint64_t cookie_decode_too_old; // or garbage
uint64_t cookie_decode_error;
};
struct ntske_counters {
- /* Server */
+ // Server
uint64_t serves_nossl;
l_fp serves_nossl_wall;
l_fp serves_nossl_cpu;
@@ -278,7 +278,7 @@ struct ntske_counters {
uint64_t serves_good;
l_fp serves_good_wall;
l_fp serves_good_cpu;
- /* Client */
+ // Client
uint64_t probes_good;
uint64_t probes_bad;
};
@@ -286,4 +286,4 @@ extern struct nts_counters nts_cnt, old_nts_cnt;
extern struct ntske_counters ntske_cnt, old_ntske_cnt;
-#endif /* GUARD_NTS_H */
+#endif // GUARD_NTS_H
=====================================
ntpd/nts_server.c
=====================================
@@ -56,200 +56,200 @@ static void nts_ke_setup_send(struct BufCtl_t *buf, int aead,
pthread_mutex_t certificate_lock = PTHREAD_MUTEX_INITIALIZER;
static int alpn_select_cb(SSL *ssl,
- const unsigned char **out,
- unsigned char *outlen,
- const unsigned char *in,
- unsigned int inlen,
- void *arg)
+ const unsigned char **out,
+ unsigned char *outlen,
+ const unsigned char *in,
+ unsigned int inlen,
+ void *arg)
{
- static const unsigned char alpn[] = {
+ static const unsigned char alpn[] = {
'n', 't', 's', 'k', 'e', '/', '1' };
- unsigned i, len;
+ unsigned i, len;
- UNUSED_ARG(ssl);
- UNUSED_ARG(arg);
+ UNUSED_ARG(ssl);
+ UNUSED_ARG(arg);
- for (i = 0; i < inlen; i += len+1) {
- len = in[i]; // first byte is the length
+ for (i = 0; i < inlen; i += len+1) {
+ len = in[i]; // first byte is the length
#if 0
- char foo[256];
- strlcpy(foo, (const char*)in+i+1, len);
- msyslog(LOG_DEBUG, "DEBUG: alpn_select_cb: %u, %u, %s", inlen-i, len, foo);
+ char foo[256];
+ strlcpy(foo, (const char*)in+i+1, len);
+ msyslog(LOG_DEBUG, "DEBUG: alpn_select_cb: %u, %u, %s", inlen-i, len, foo);
#endif
- if (len+1 > inlen-i)
- /* bogus arg: length overlaps end of in buffer */
- return SSL_TLSEXT_ERR_ALERT_FATAL;
- if (len == sizeof(alpn) && !memcmp(in+i+1, alpn, len)) {
- *out = in+i+1;
- *outlen = len;
- return SSL_TLSEXT_ERR_OK;
- }
- }
-
- return SSL_TLSEXT_ERR_NOACK;
+ if (len+1 > inlen-i)
+ // bogus arg: length overlaps end of in buffer
+ return SSL_TLSEXT_ERR_ALERT_FATAL;
+ if (len == sizeof(alpn) && !memcmp(in+i+1, alpn, len)) {
+ *out = in+i+1;
+ *outlen = len;
+ return SSL_TLSEXT_ERR_OK;
+ }
+ }
+
+ return SSL_TLSEXT_ERR_NOACK;
}
bool nts_server_init(void) {
- bool ok = true;
-
- msyslog(LOG_INFO, "NTSs: starting NTS-KE server listening on port %d",
- NTS_KE_PORT);
-
- server_ctx = SSL_CTX_new(TLS_server_method());
- if (NULL == server_ctx) {
- /* Happens if no ciphers */
- msyslog(LOG_INFO, "NTSs: NULL server_ctx");
- nts_log_ssl_error();
- return false;
- }
-
- SSL_CTX_set_alpn_select_cb(server_ctx, alpn_select_cb, NULL);
- SSL_CTX_set_session_cache_mode(server_ctx, SSL_SESS_CACHE_OFF);
- SSL_CTX_set_timeout(server_ctx, NTS_KE_TIMEOUT); /* session lifetime */
-
- ok &= nts_load_versions(server_ctx);
- ok &= nts_load_ciphers(server_ctx);
- ok &= nts_load_ecdhcurves(server_ctx);
- ok &= nts_set_cipher_order(server_ctx);
-
- if (!ok) {
- msyslog(LOG_ERR, "NTSs: Disabling NTS-KE server");
- SSL_CTX_free(server_ctx);
- server_ctx = NULL;
- return false;
- };
-
- msyslog(LOG_INFO, "NTSs: OpenSSL security level is %d",
- SSL_CTX_get_security_level(server_ctx));
-
- msyslog(LOG_INFO, "NTSs: starting NTS-KE server listening on port %d",
- NTS_KE_PORT);
- ok &= create_listener4(NTS_KE_PORT);
- ok &= create_listener6(NTS_KE_PORT);
-
- return ok;
+ bool ok = true;
+
+ msyslog(LOG_INFO, "NTSs: starting NTS-KE server listening on port %d",
+ NTS_KE_PORT);
+
+ server_ctx = SSL_CTX_new(TLS_server_method());
+ if (NULL == server_ctx) {
+ // Happens if no ciphers
+ msyslog(LOG_INFO, "NTSs: NULL server_ctx");
+ nts_log_ssl_error();
+ return false;
+ }
+
+ SSL_CTX_set_alpn_select_cb(server_ctx, alpn_select_cb, NULL);
+ SSL_CTX_set_session_cache_mode(server_ctx, SSL_SESS_CACHE_OFF);
+ SSL_CTX_set_timeout(server_ctx, NTS_KE_TIMEOUT); // session lifetime
+
+ ok &= nts_load_versions(server_ctx);
+ ok &= nts_load_ciphers(server_ctx);
+ ok &= nts_load_ecdhcurves(server_ctx);
+ ok &= nts_set_cipher_order(server_ctx);
+
+ if (!ok) {
+ msyslog(LOG_ERR, "NTSs: Disabling NTS-KE server");
+ SSL_CTX_free(server_ctx);
+ server_ctx = NULL;
+ return false;
+ };
+
+ msyslog(LOG_INFO, "NTSs: OpenSSL security level is %d",
+ SSL_CTX_get_security_level(server_ctx));
+
+ msyslog(LOG_INFO, "NTSs: starting NTS-KE server listening on port %d",
+ NTS_KE_PORT);
+ ok &= create_listener4(NTS_KE_PORT);
+ ok &= create_listener6(NTS_KE_PORT);
+
+ return ok;
}
bool nts_server_init2(void) {
- pthread_t worker;
- sigset_t block_mask, saved_sig_mask;
- int rc;
- char errbuf[100];
-
- if (!nts_load_certificate(server_ctx)) {
- return false;
- }
-
- sigfillset(&block_mask);
- pthread_sigmask(SIG_BLOCK, &block_mask, &saved_sig_mask);
- if (listener4_sock != -1) {
- rc = pthread_create(&worker, NULL, nts_ke_listener, &listener4_sock);
- if (rc) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: nts_start_server4: error from pthread_create: %s", errbuf);
- }
- }
- if (listener6_sock != -1) {
- rc = pthread_create(&worker, NULL, nts_ke_listener, &listener6_sock);
- if (rc) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: nts_start_server6: error from pthread_create: %s", errbuf);
- }
- }
- pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
-
- return true;
+ pthread_t worker;
+ sigset_t block_mask, saved_sig_mask;
+ int rc;
+ char errbuf[100];
+
+ if (!nts_load_certificate(server_ctx)) {
+ return false;
+ }
+
+ sigfillset(&block_mask);
+ pthread_sigmask(SIG_BLOCK, &block_mask, &saved_sig_mask);
+ if (listener4_sock != -1) {
+ rc = pthread_create(&worker, NULL, nts_ke_listener, &listener4_sock);
+ if (rc) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: nts_start_server4: error from pthread_create: %s", errbuf);
+ }
+ }
+ if (listener6_sock != -1) {
+ rc = pthread_create(&worker, NULL, nts_ke_listener, &listener6_sock);
+ if (rc) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: nts_start_server6: error from pthread_create: %s", errbuf);
+ }
+ }
+ pthread_sigmask(SIG_SETMASK, &saved_sig_mask, NULL);
+
+ return true;
}
-/* called every hour */
+// called every hour
void nts_cert_timer(void) {
- check_cert_file();
+ check_cert_file();
}
-/* call hourly and by SIGHUP */
+// call hourly and by SIGHUP
void check_cert_file(void) {
- if (NULL == server_ctx)
- return;
- nts_lock_certlock();
- nts_reload_certificate(server_ctx);
- nts_unlock_certlock();
+ if (NULL == server_ctx)
+ return;
+ nts_lock_certlock();
+ nts_reload_certificate(server_ctx);
+ nts_unlock_certlock();
}
void nts_lock_certlock(void) {
- int err = pthread_mutex_lock(&certificate_lock);
- if (0 != err) {
- msyslog(LOG_ERR, "ERR: Can't lock certificate_lock: %d", err);
- exit(2);
- }
+ int err = pthread_mutex_lock(&certificate_lock);
+ if (0 != err) {
+ msyslog(LOG_ERR, "ERR: Can't lock certificate_lock: %d", err);
+ exit(2);
+ }
}
void nts_unlock_certlock(void) {
- int err = pthread_mutex_unlock(&certificate_lock);
- if (0 != err) {
- msyslog(LOG_ERR, "ERR: Can't unlock certificate_lock: %d", err);
- exit(2);
- }
+ int err = pthread_mutex_unlock(&certificate_lock);
+ if (0 != err) {
+ msyslog(LOG_ERR, "ERR: Can't unlock certificate_lock: %d", err);
+ exit(2);
+ }
}
-/* lfptod goes to long double */
+// lfptod goes to long double
static inline double lfptox(l_fp r) {
-/* l_fp to double */
+// l_fp to double
return ldexp((double)((int64_t)r), -32);
}
void* nts_ke_listener(void* arg) {
- struct timeval timeout = {.tv_sec = NTS_KE_TIMEOUT, .tv_usec = 0};
- int sock = *(int*)arg;
- char errbuf[100];
- char addrbuf[100];
- char usingbuf[100];
- struct timespec start, finish; /* wall clock */
- l_fp wall, usr, sys;
- const char *errtxt; /* not NULL if error */
+ struct timeval timeout = {.tv_sec = NTS_KE_TIMEOUT, .tv_usec = 0};
+ int sock = *(int*)arg;
+ char errbuf[100];
+ char addrbuf[100];
+ char usingbuf[100];
+ struct timespec start, finish; // wall clock
+ l_fp wall, usr, sys;
+ const char *errtxt; // not NULL if error
#ifdef RUSAGE_THREAD
- /* Not in NetBSD 10.1, 2026-Apr-05 */
- struct timespec start_u, finish_u; /* CPU user */
- struct timespec start_s, finish_s; /* CPU system */
- struct rusage usage;
+ // Not in NetBSD 10.1, 2026-Apr-05
+ struct timespec start_u, finish_u; // CPU user
+ struct timespec start_s, finish_s; // CPU system
+ struct rusage usage;
#endif
#ifdef HAVE_SECCOMP_H
- setup_SIGSYS_trap(); /* enable trap for this thread */
+ setup_SIGSYS_trap(); // enable trap for this thread
#endif
#ifdef RUSAGE_THREAD
- /* NB: start_u and start_s are from near the end of the previous cycle.
- * Thus usage timing includes the TCP accept and
- * writing the previous msyslog message.
- */
- getrusage(RUSAGE_THREAD, &usage);
- start_u = tval_to_tspec(usage.ru_utime);
- start_s = tval_to_tspec(usage.ru_stime);
+ /* NB: start_u and start_s are from near the end of the previous cycle.
+ * Thus usage timing includes the TCP accept and
+ * writing the previous msyslog message.
+ */
+ getrusage(RUSAGE_THREAD, &usage);
+ start_u = tval_to_tspec(usage.ru_utime);
+ start_s = tval_to_tspec(usage.ru_stime);
#else
- usr = 0;
- sys = 0;
+ usr = 0;
+ sys = 0;
#endif
- while(1) {
- NTSKE_Status status = NTSKE_SSL_Failed;
- sockaddr_u addr;
- socklen_t len = sizeof(addr);
- SSL *ssl;
- int client, err;
-
- sleep(1); /* FIXME: log clutter/DoS */
- errtxt = NULL;
- client = accept(sock, &addr.sa, &len);
- if (client < 0) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: TCP accept failed: %s", errbuf);
- if (EBADF == errno)
- return NULL;
- continue;
- }
- clock_gettime(CLOCK_MONOTONIC, &start);
- sockporttoa_r(&addr, addrbuf, sizeof(addrbuf));
+ while(1) {
+ NTSKE_Status status = NTSKE_SSL_Failed;
+ sockaddr_u addr;
+ socklen_t len = sizeof(addr);
+ SSL *ssl;
+ int client, err;
+
+ sleep(1); // FIXME: log clutter/DoS
+ errtxt = NULL;
+ client = accept(sock, &addr.sa, &len);
+ if (client < 0) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: TCP accept failed: %s", errbuf);
+ if (EBADF == errno)
+ return NULL;
+ continue;
+ }
+ clock_gettime(CLOCK_MONOTONIC, &start);
+ sockporttoa_r(&addr, addrbuf, sizeof(addrbuf));
/* This is disabled in order to reduce clutter in the log file.
* The client's address is now included in the final message.
@@ -266,85 +266,85 @@ void* nts_ke_listener(void* arg) {
* fall into the normal (non-error) path which does include the address.
* Enabling this might make strange cases easier to understand.
*/
-/* msyslog(LOG_INFO, "NTSs: TCP accept-ed from %s", addrbuf); */
-
- err = setsockopt(client, SOL_SOCKET, SO_RCVTIMEO,
- &timeout, sizeof(timeout));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't set recv timeout: %s", errbuf);
- close(client);
- ntske_cnt.serves_bad++;
- continue;
- }
- err = setsockopt(client, SOL_SOCKET, SO_SNDTIMEO,
- &timeout, sizeof(timeout));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't set send timeout: %s", errbuf);
- close(client);
- ntske_cnt.serves_bad++;
- continue;
- }
-
- /* WARN: For high volume servers, this should go in a new thread. */
- nts_lock_certlock();
- ssl = SSL_new(server_ctx);
- nts_unlock_certlock();
- SSL_set_fd(ssl, client);
-
- err = SSL_accept(ssl);
- if (0 >= err) {
- int code = SSL_get_error(ssl, err);
- SSL_free(ssl);
- close(client);
- clock_gettime(CLOCK_MONOTONIC, &finish);
- wall = tspec_intv_to_lfp(sub_tspec(finish, start));
+// msyslog(LOG_INFO, "NTSs: TCP accept-ed from %s", addrbuf);
+
+ err = setsockopt(client, SOL_SOCKET, SO_RCVTIMEO,
+ &timeout, sizeof(timeout));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't set recv timeout: %s", errbuf);
+ close(client);
+ ntske_cnt.serves_bad++;
+ continue;
+ }
+ err = setsockopt(client, SOL_SOCKET, SO_SNDTIMEO,
+ &timeout, sizeof(timeout));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't set send timeout: %s", errbuf);
+ close(client);
+ ntske_cnt.serves_bad++;
+ continue;
+ }
+
+ // WARN: For high volume servers, this should go in a new thread.
+ nts_lock_certlock();
+ ssl = SSL_new(server_ctx);
+ nts_unlock_certlock();
+ SSL_set_fd(ssl, client);
+
+ err = SSL_accept(ssl);
+ if (0 >= err) {
+ int code = SSL_get_error(ssl, err);
+ SSL_free(ssl);
+ close(client);
+ clock_gettime(CLOCK_MONOTONIC, &finish);
+ wall = tspec_intv_to_lfp(sub_tspec(finish, start));
#ifdef RUSAGE_THREAD
- getrusage(RUSAGE_THREAD, &usage);
- finish_u = tval_to_tspec(usage.ru_utime);
- finish_s = tval_to_tspec(usage.ru_stime);
- usr = tspec_intv_to_lfp(sub_tspec(finish_u, start_u));
- sys = tspec_intv_to_lfp(sub_tspec(finish_s, start_s));
- start_u = finish_u;
- start_s = finish_s;
+ getrusage(RUSAGE_THREAD, &usage);
+ finish_u = tval_to_tspec(usage.ru_utime);
+ finish_s = tval_to_tspec(usage.ru_stime);
+ usr = tspec_intv_to_lfp(sub_tspec(finish_u, start_u));
+ sys = tspec_intv_to_lfp(sub_tspec(finish_s, start_s));
+ start_u = finish_u;
+ start_s = finish_s;
#endif
- nts_ke_accept_fail(addrbuf,
- lfptox(wall), lfptox(usr), lfptox(sys), code);
- continue;
- }
-
- /* Save info for final message. */
- snprintf(usingbuf, sizeof(usingbuf), "%s:%s(%d)",
- SSL_get_version(ssl),
- SSL_get_cipher_name(ssl),
- SSL_get_cipher_bits(ssl, NULL));
-
- status = NTSKE_Failed;
- nts_ke_request(ssl, errbuf, sizeof(errbuf), &errtxt);
- if (NULL==errtxt) status = NTSKE_OK;
-
- SSL_shutdown(ssl);
- SSL_free(ssl);
- close(client);
-
- clock_gettime(CLOCK_MONOTONIC, &finish);
- wall = tspec_intv_to_lfp(sub_tspec(finish, start));
+ nts_ke_accept_fail(addrbuf,
+ lfptox(wall), lfptox(usr), lfptox(sys), code);
+ continue;
+ }
+
+ // Save info for final message.
+ snprintf(usingbuf, sizeof(usingbuf), "%s:%s(%d)",
+ SSL_get_version(ssl),
+ SSL_get_cipher_name(ssl),
+ SSL_get_cipher_bits(ssl, NULL));
+
+ status = NTSKE_Failed;
+ nts_ke_request(ssl, errbuf, sizeof(errbuf), &errtxt);
+ if (NULL==errtxt) status = NTSKE_OK;
+
+ SSL_shutdown(ssl);
+ SSL_free(ssl);
+ close(client);
+
+ clock_gettime(CLOCK_MONOTONIC, &finish);
+ wall = tspec_intv_to_lfp(sub_tspec(finish, start));
#ifdef RUSAGE_THREAD
- getrusage(RUSAGE_THREAD, &usage);
- finish_u = tval_to_tspec(usage.ru_utime);
- finish_s = tval_to_tspec(usage.ru_stime);
- usr = tspec_intv_to_lfp(sub_tspec(finish_u, start_u));
- sys = tspec_intv_to_lfp(sub_tspec(finish_s, start_s));
- start_u = finish_u;
- start_s = finish_s;
+ getrusage(RUSAGE_THREAD, &usage);
+ finish_u = tval_to_tspec(usage.ru_utime);
+ finish_s = tval_to_tspec(usage.ru_stime);
+ usr = tspec_intv_to_lfp(sub_tspec(finish_u, start_u));
+ sys = tspec_intv_to_lfp(sub_tspec(finish_s, start_s));
+ start_u = finish_u;
+ start_s = finish_s;
#endif
- record_ntske_log(status, addrbuf, usingbuf,
- lfptox(wall), lfptox(usr), lfptox(sys),
- errtxt);
- }
+ record_ntske_log(status, addrbuf, usingbuf,
+ lfptox(wall), lfptox(usr), lfptox(sys),
+ errtxt);
+ }
- return NULL;
+ return NULL;
}
/* Analyze failure from SSL_accept
@@ -353,329 +353,329 @@ void* nts_ke_listener(void* arg) {
*/
void nts_ke_accept_fail(char* hostname,
double wall, double usr, double sys, int code) {
- unsigned long err = ERR_peek_error();
- char errbuf[100];
- char buff[200];
- const char *msg = NULL;
- const char *errmsg = NULL;
- if (0 == err) {
- switch (code) {
- case SSL_ERROR_WANT_READ:
- msg = "Timeout";
- break;
- case SSL_ERROR_SYSCALL:
- if (ECONNRESET==errno) {
- msg = "Connection reset";
- break;
- }
- /* fall through */
- default:
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- snprintf(buff, sizeof(buff), "code %d, errno=>%d, %s",
- code, errno, errbuf);
- msg = buff;
- break;
- }
- } else {
- if (code==SSL_ERROR_SSL) {
- msg = ERR_reason_error_string(err);
- err = 0;
- } else {
- // Maybe we need to handle other codes
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- snprintf(buff, sizeof(buff), "code %d, errno=>%d, %s, %lx=>%s",
- code, errno, errbuf, err, ERR_reason_error_string(err));
- err = 0;
- msg = buff;
- }
- }
- record_ntske_log(NTSKE_SSL_Failed, hostname, msg,
- wall, usr, sys, errmsg);
+ unsigned long err = ERR_peek_error();
+ char errbuf[100];
+ char buff[200];
+ const char *msg = NULL;
+ const char *errmsg = NULL;
+ if (0 == err) {
+ switch (code) {
+ case SSL_ERROR_WANT_READ:
+ msg = "Timeout";
+ break;
+ case SSL_ERROR_SYSCALL:
+ if (ECONNRESET==errno) {
+ msg = "Connection reset";
+ break;
+ }
+ // fall through
+ default:
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ snprintf(buff, sizeof(buff), "code %d, errno=>%d, %s",
+ code, errno, errbuf);
+ msg = buff;
+ break;
+ }
+ } else {
+ if (code==SSL_ERROR_SSL) {
+ msg = ERR_reason_error_string(err);
+ err = 0;
+ } else {
+ // Maybe we need to handle other codes
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ snprintf(buff, sizeof(buff), "code %d, errno=>%d, %s, %lx=>%s",
+ code, errno, errbuf, err, ERR_reason_error_string(err));
+ err = 0;
+ msg = buff;
+ }
+ }
+ record_ntske_log(NTSKE_SSL_Failed, hostname, msg,
+ wall, usr, sys, errmsg);
}
void nts_ke_request(SSL *ssl,
char *errbuf, int errlng, const char **errtxt) {
- /* RFC 4: servers must accept 1024
- * Our cookies can be 104, 136, or 168 for AES_SIV_CMAC_xxx
- * 8*168 fits comfortably into 2K.
- */
- uint8_t buff[2048];
- uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
- int aead = NO_AEAD, keylen;
- struct BufCtl_t buf;
- int bytes_read, bytes_written;
- int used;
-
- bytes_read = nts_ssl_read(ssl, buff, sizeof(buff), errtxt);
- if (0 >= bytes_read)
- return;
-
- buf.next = buff;
- buf.left = bytes_read;
- if (!nts_ke_process_receive(&buf, &aead, errbuf, errlng, errtxt)) {
- return;
- }
-
- if ((NO_AEAD == aead) && (NULL != ntsconfig.aead))
- aead = nts_string_to_aead(ntsconfig.aead);
- if (NO_AEAD == aead)
- aead = AEAD_AES_SIV_CMAC_256; /* default */
-
- keylen = nts_get_key_length(aead);
- if (!nts_make_keys(ssl, aead, c2s, s2c, keylen)) {
- *errtxt = "Can't make keys";
- return;
- }
-
- buf.next = buff;
- buf.left = sizeof(buff);
- nts_ke_setup_send(&buf, aead, c2s, s2c, keylen);
-
- used = sizeof(buff)-buf.left;
- bytes_written = nts_ssl_write(ssl, buff, used, errtxt);
- if (bytes_written != used)
- return;
-
-/* FIXME: Need counters for AEAD */
-
- return;
+ /* RFC 4: servers must accept 1024
+ * Our cookies can be 104, 136, or 168 for AES_SIV_CMAC_xxx
+ * 8*168 fits comfortably into 2K.
+ */
+ uint8_t buff[2048];
+ uint8_t c2s[NTS_MAX_KEYLEN], s2c[NTS_MAX_KEYLEN];
+ int aead = NO_AEAD, keylen;
+ struct BufCtl_t buf;
+ int bytes_read, bytes_written;
+ int used;
+
+ bytes_read = nts_ssl_read(ssl, buff, sizeof(buff), errtxt);
+ if (0 >= bytes_read)
+ return;
+
+ buf.next = buff;
+ buf.left = bytes_read;
+ if (!nts_ke_process_receive(&buf, &aead, errbuf, errlng, errtxt)) {
+ return;
+ }
+
+ if ((NO_AEAD == aead) && (NULL != ntsconfig.aead))
+ aead = nts_string_to_aead(ntsconfig.aead);
+ if (NO_AEAD == aead)
+ aead = AEAD_AES_SIV_CMAC_256; // default
+
+ keylen = nts_get_key_length(aead);
+ if (!nts_make_keys(ssl, aead, c2s, s2c, keylen)) {
+ *errtxt = "Can't make keys";
+ return;
+ }
+
+ buf.next = buff;
+ buf.left = sizeof(buff);
+ nts_ke_setup_send(&buf, aead, c2s, s2c, keylen);
+
+ used = sizeof(buff)-buf.left;
+ bytes_written = nts_ssl_write(ssl, buff, used, errtxt);
+ if (bytes_written != used)
+ return;
+
+// FIXME: Need counters for AEAD
+
+ return;
}
bool create_listener4(int port) {
- int sock = -1;
- sockaddr_u addr;
- int on = 1;
- int err;
- char errbuf[100];
-
- addr.sa4.sin_family = AF_INET;
- addr.sa4.sin_port = htons(port);
- addr.sa4.sin_addr.s_addr= htonl(INADDR_ANY);
- sock = socket(AF_INET, SOCK_STREAM, 0);
- if (sock < 0) {
- if (EAFNOSUPPORT == errno) {
- msyslog(LOG_ERR, "NTSs: No IPv4 support, disabling NTS-KE listener");
- return true;
- }
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: Can't create socket4: %s", errbuf);
- return false;
- }
- err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't setsockopt4: %s", errbuf);
- close(sock);
- return false;
- }
- err = bind(sock, &addr.sa, sizeof(addr.sa4));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't bind4: %s", errbuf);
- close(sock);
- return false;
- }
- if (listen(sock, 6) < 0) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't listen4: %s", errbuf);
- close(sock);
- return false;
- }
- msyslog(LOG_INFO, "NTSs: listen4 worked");
-
- listener4_sock = sock;
- return true;
+ int sock = -1;
+ sockaddr_u addr;
+ int on = 1;
+ int err;
+ char errbuf[100];
+
+ addr.sa4.sin_family = AF_INET;
+ addr.sa4.sin_port = htons(port);
+ addr.sa4.sin_addr.s_addr= htonl(INADDR_ANY);
+ sock = socket(AF_INET, SOCK_STREAM, 0);
+ if (sock < 0) {
+ if (EAFNOSUPPORT == errno) {
+ msyslog(LOG_ERR, "NTSs: No IPv4 support, disabling NTS-KE listener");
+ return true;
+ }
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: Can't create socket4: %s", errbuf);
+ return false;
+ }
+ err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't setsockopt4: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ err = bind(sock, &addr.sa, sizeof(addr.sa4));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't bind4: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ if (listen(sock, 6) < 0) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't listen4: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ msyslog(LOG_INFO, "NTSs: listen4 worked");
+
+ listener4_sock = sock;
+ return true;
}
bool create_listener6(int port) {
- int sock = -1;
- sockaddr_u addr;
- int on = 1;
- int err;
- char errbuf[100];
-
- addr.sa6.sin6_family = AF_INET6;
- addr.sa6.sin6_port = htons(port);
- addr.sa6.sin6_addr = in6addr_any;
- sock = socket(AF_INET6, SOCK_STREAM, 0);
- if (sock < 0) {
- if (EAFNOSUPPORT == errno) {
- msyslog(LOG_ERR, "NTSs: No IPv6 support, disabling NTS-KE listener");
- return true;
- }
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: Can't create socket6: %s", errbuf);
- return false;
- }
- /* Hack to keep IPV6 from listening on IPV4 too */
- err = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't setsockopt6only: %s", errbuf);
- close(sock);
- return false;
- }
- err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't setsockopt6: %s", errbuf);
- close(sock);
- return false;
- }
- err = bind(sock, &addr.sa, sizeof(addr.sa6));
- if (0 > err) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't bind6: %s", errbuf);
- close(sock);
- return false;
- }
- if (listen(sock, 6) < 0) {
- ntp_strerror_r(errno, errbuf, sizeof(errbuf));
- msyslog(LOG_ERR, "NTSs: can't listen6: %s", errbuf);
- close(sock);
- return false;
- }
- msyslog(LOG_INFO, "NTSs: listen6 worked");
-
- listener6_sock = sock;
- return true;
+ int sock = -1;
+ sockaddr_u addr;
+ int on = 1;
+ int err;
+ char errbuf[100];
+
+ addr.sa6.sin6_family = AF_INET6;
+ addr.sa6.sin6_port = htons(port);
+ addr.sa6.sin6_addr = in6addr_any;
+ sock = socket(AF_INET6, SOCK_STREAM, 0);
+ if (sock < 0) {
+ if (EAFNOSUPPORT == errno) {
+ msyslog(LOG_ERR, "NTSs: No IPv6 support, disabling NTS-KE listener");
+ return true;
+ }
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: Can't create socket6: %s", errbuf);
+ return false;
+ }
+ // Hack to keep IPV6 from listening on IPV4 too
+ err = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't setsockopt6only: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ err = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't setsockopt6: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ err = bind(sock, &addr.sa, sizeof(addr.sa6));
+ if (0 > err) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't bind6: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ if (listen(sock, 6) < 0) {
+ ntp_strerror_r(errno, errbuf, sizeof(errbuf));
+ msyslog(LOG_ERR, "NTSs: can't listen6: %s", errbuf);
+ close(sock);
+ return false;
+ }
+ msyslog(LOG_INFO, "NTSs: listen6 worked");
+
+ listener6_sock = sock;
+ return true;
}
bool nts_ke_process_receive(struct BufCtl_t *buf, int *aead,
char *errbuf, int errlng, const char **errtxt) {
- while (buf->left >= NTS_KE_HDR_LNG) {
- uint16_t type, data;
- int length;
- bool critical = false;
- type = ke_next_record(buf, &length);
+ while (buf->left >= NTS_KE_HDR_LNG) {
+ uint16_t type, data;
+ int length;
+ bool critical = false;
+ type = ke_next_record(buf, &length);
if (length > buf->left) {
- snprintf(errbuf, errlng,
- "Chunk too big: 0x%x, %d, %d",
+ snprintf(errbuf, errlng,
+ "Chunk too big: 0x%x, %d, %d",
type, buf->left, length);
- *errtxt = errbuf;
+ *errtxt = errbuf;
return false;
}
- if (NTS_CRITICAL & type) {
- critical = true;
- type &= ~NTS_CRITICAL;
- }
- if (0) // Handy for debugging but very verbose
- msyslog(LOG_INFO, "NTSs: Record: T=%d, L=%d, C=%d", type, length, critical);
- switch (type) {
- case nts_error:
- if (sizeof(data) != length) {
- snprintf(errbuf, errlng,
- "Wrong length on error: %d", length);
- *errtxt = errbuf;
- return false;
- }
- data = next_uint16(buf);
- snprintf(errbuf, errlng,
- "Received error: %d", data);
- *errtxt = errbuf;
- return false;
- case nts_next_protocol_negotiation:
- if (sizeof(data) != length) {
- snprintf(errbuf, errlng,
- "NPN-Wrong length: %d", length);
- *errtxt = errbuf;
- return false;
- }
- data = next_uint16(buf);
- if (data != nts_protocol_NTP) {
- snprintf(errbuf, errlng,
- "NPN-Bad data: %d", data);
- *errtxt = errbuf;
- return false;
- }
- break;
- case nts_algorithm_negotiation:
- if (length % sizeof(uint16_t) > 0) {
- snprintf(errbuf, errlng,
- "AN-Wrong length: %d", length);
- *errtxt = errbuf;
- return false;
- }
- for (int i=0; i<length; i+=sizeof(uint16_t)) {
- data = next_uint16(buf);
- if (0 == nts_get_key_length(data)) {
- if (0) /* for debugging */
- msyslog(LOG_ERR, "NTSs: AN-Unsupported AEAN type: %d", data);
- continue; /* ignore types we don't support */
- }
- if (*aead != NO_AEAD)
- continue; /* already got one */
- *aead = data; /* take this one */
- }
- break;
- case nts_end_of_message:
- if ((0 != length) || !critical) {
- snprintf(errbuf, errlng,
- "EOM-Wrong length or not Critical: %d, %d",
- length, critical);
- *errtxt = errbuf;
- return false;
- }
- if (0 != buf->left) {
- snprintf(errbuf, errlng,
- "EOM not at end: %d", buf->left);
- *errtxt = errbuf;
- return false;
- }
- return true;
- default:
- if (critical) {
- // This only logs the first one from a connection
- snprintf(errbuf, errlng,
- "Received strange type: T=%d, C=%d, L=%d",
- type, critical, length);
- // There is an error code for this
- return false;
- }
- // It might be interesting to log non-critical
- // but that needs rate limiting
- buf->next += length;
- buf->left -= length;
- break;
- } /* case */
- } /* while */
-
- /* If we get here, we ran off the end without finding an EOM.
- * nts_ssl_read() should have complained, so this check
- * should never happen.
- */
- if (buf->left > 0) {
- *errtxt = "*** Leftovers";
- return false;
- }
-
- *errtxt = "*** Missing EOM";
- return false;
+ if (NTS_CRITICAL & type) {
+ critical = true;
+ type &= ~NTS_CRITICAL;
+ }
+ if (0) // Handy for debugging but very verbose
+ msyslog(LOG_INFO, "NTSs: Record: T=%d, L=%d, C=%d", type, length, critical);
+ switch (type) {
+ case nts_error:
+ if (sizeof(data) != length) {
+ snprintf(errbuf, errlng,
+ "Wrong length on error: %d", length);
+ *errtxt = errbuf;
+ return false;
+ }
+ data = next_uint16(buf);
+ snprintf(errbuf, errlng,
+ "Received error: %d", data);
+ *errtxt = errbuf;
+ return false;
+ case nts_next_protocol_negotiation:
+ if (sizeof(data) != length) {
+ snprintf(errbuf, errlng,
+ "NPN-Wrong length: %d", length);
+ *errtxt = errbuf;
+ return false;
+ }
+ data = next_uint16(buf);
+ if (data != nts_protocol_NTP) {
+ snprintf(errbuf, errlng,
+ "NPN-Bad data: %d", data);
+ *errtxt = errbuf;
+ return false;
+ }
+ break;
+ case nts_algorithm_negotiation:
+ if (length % sizeof(uint16_t) > 0) {
+ snprintf(errbuf, errlng,
+ "AN-Wrong length: %d", length);
+ *errtxt = errbuf;
+ return false;
+ }
+ for (int i=0; i<length; i+=sizeof(uint16_t)) {
+ data = next_uint16(buf);
+ if (0 == nts_get_key_length(data)) {
+ if (0) // for debugging
+ msyslog(LOG_ERR, "NTSs: AN-Unsupported AEAN type: %d", data);
+ continue; // ignore types we don't support
+ }
+ if (*aead != NO_AEAD)
+ continue; // already got one
+ *aead = data; // take this one
+ }
+ break;
+ case nts_end_of_message:
+ if ((0 != length) || !critical) {
+ snprintf(errbuf, errlng,
+ "EOM-Wrong length or not Critical: %d, %d",
+ length, critical);
+ *errtxt = errbuf;
+ return false;
+ }
+ if (0 != buf->left) {
+ snprintf(errbuf, errlng,
+ "EOM not at end: %d", buf->left);
+ *errtxt = errbuf;
+ return false;
+ }
+ return true;
+ default:
+ if (critical) {
+ // This only logs the first one from a connection
+ snprintf(errbuf, errlng,
+ "Received strange type: T=%d, C=%d, L=%d",
+ type, critical, length);
+ // There is an error code for this
+ return false;
+ }
+ // It might be interesting to log non-critical
+ // but that needs rate limiting
+ buf->next += length;
+ buf->left -= length;
+ break;
+ } // case
+ } // while
+
+ /* If we get here, we ran off the end without finding an EOM.
+ * nts_ssl_read() should have complained, so this check
+ * should never happen.
+ */
+ if (buf->left > 0) {
+ *errtxt = "*** Leftovers";
+ return false;
+ }
+
+ *errtxt = "*** Missing EOM";
+ return false;
}
void nts_ke_setup_send(struct BufCtl_t *buf, int aead,
uint8_t *c2s, uint8_t *s2c, int keylen) {
- /* 4.1.2 Next Protocol */
- ke_append_record_uint16(buf,
- NTS_CRITICAL+nts_next_protocol_negotiation, nts_protocol_NTP);
- /* 4.1.5 AEAD Algorithm List */
- ke_append_record_uint16(buf, nts_algorithm_negotiation, aead);
+ // 4.1.2 Next Protocol
+ ke_append_record_uint16(buf,
+ NTS_CRITICAL+nts_next_protocol_negotiation, nts_protocol_NTP);
+ // 4.1.5 AEAD Algorithm List
+ ke_append_record_uint16(buf, nts_algorithm_negotiation, aead);
- if (extra_port)
- ke_append_record_uint16(buf, nts_port_negotiation, extra_port);
+ if (extra_port)
+ ke_append_record_uint16(buf, nts_port_negotiation, extra_port);
- for (int i=0; i<NTS_MAX_COOKIES; i++) {
- uint8_t cookie[NTS_MAX_COOKIELEN];
- int cookielen = nts_make_cookie(cookie, aead, c2s, s2c, keylen);
- ke_append_record_bytes(buf, nts_new_cookie, cookie, cookielen);
- }
+ for (int i=0; i<NTS_MAX_COOKIES; i++) {
+ uint8_t cookie[NTS_MAX_COOKIELEN];
+ int cookielen = nts_make_cookie(cookie, aead, c2s, s2c, keylen);
+ ke_append_record_bytes(buf, nts_new_cookie, cookie, cookielen);
+ }
- /* 4.1.1: End, Critical */
- ke_append_record_null(buf, NTS_CRITICAL+nts_end_of_message);
+ // 4.1.1: End, Critical
+ ke_append_record_null(buf, NTS_CRITICAL+nts_end_of_message);
}
-/* end */
+// end
=====================================
ntpd/refclock_jjy.c
=====================================
The diff for this file was not included because it is too large.
=====================================
tests/ntpd/nts.c
=====================================
@@ -15,405 +15,405 @@ TEST_SETUP(nts) {}
TEST_TEAR_DOWN(nts) {}
TEST(nts, nts_translate_version) {
- TEST_ASSERT_EQUAL_INT32(0, nts_translate_version(NULL));
- TEST_ASSERT_EQUAL_INT32(TLS1_3_VERSION, nts_translate_version("TLS1.3"));
- TEST_ASSERT_EQUAL_INT32(-1, nts_translate_version("blah"));
+ TEST_ASSERT_EQUAL_INT32(0, nts_translate_version(NULL));
+ TEST_ASSERT_EQUAL_INT32(TLS1_3_VERSION, nts_translate_version("TLS1.3"));
+ TEST_ASSERT_EQUAL_INT32(-1, nts_translate_version("blah"));
}
TEST(nts, nts_string_to_aead) {
- TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_256,
- nts_string_to_aead("AES_SIV_CMAC_256"));
- TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_384,
- nts_string_to_aead("AES_SIV_CMAC_384"));
- TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_512,
- nts_string_to_aead("AES_SIV_CMAC_512"));
- TEST_ASSERT_EQUAL_INT16(NO_AEAD, nts_string_to_aead("blah"));
+ TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_256,
+ nts_string_to_aead("AES_SIV_CMAC_256"));
+ TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_384,
+ nts_string_to_aead("AES_SIV_CMAC_384"));
+ TEST_ASSERT_EQUAL_INT16(AEAD_AES_SIV_CMAC_512,
+ nts_string_to_aead("AES_SIV_CMAC_512"));
+ TEST_ASSERT_EQUAL_INT16(NO_AEAD, nts_string_to_aead("blah"));
}
TEST(nts, nts_get_key_length) {
- TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_256_KEYLEN,
- nts_get_key_length(AEAD_AES_SIV_CMAC_256));
- TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_384_KEYLEN,
- nts_get_key_length(AEAD_AES_SIV_CMAC_384));
- TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_512_KEYLEN,
- nts_get_key_length(AEAD_AES_SIV_CMAC_512));
- TEST_ASSERT_EQUAL_INT32(0, nts_get_key_length(-23));
+ TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_256_KEYLEN,
+ nts_get_key_length(AEAD_AES_SIV_CMAC_256));
+ TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_384_KEYLEN,
+ nts_get_key_length(AEAD_AES_SIV_CMAC_384));
+ TEST_ASSERT_EQUAL_INT32(AEAD_AES_SIV_CMAC_512_KEYLEN,
+ nts_get_key_length(AEAD_AES_SIV_CMAC_512));
+ TEST_ASSERT_EQUAL_INT32(0, nts_get_key_length(-23));
}
TEST(nts, ke_append_record_null) {
- /* Setup */
- uint8_t buf[128];
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 128;
- /* Run test */
- ke_append_record_null(&cursor, 0xFA7E);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0x7E, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[3]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(124, cursor.left);
+ // Setup
+ uint8_t buf[128];
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 128;
+ // Run test
+ ke_append_record_null(&cursor, 0xFA7E);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0x7E, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[3]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(124, cursor.left);
}
TEST(nts, ke_append_record_uint16) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x02, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0x12, buf[4]);
- TEST_ASSERT_EQUAL_UINT8(0x34, buf[5]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(10, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x02, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0x12, buf[4]);
+ TEST_ASSERT_EQUAL_UINT8(0x34, buf[5]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(10, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, ke_append_record_bytes) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- uint8_t data[6] = {0, 1, 2, 3, 4, 5};
- /* Run test */
- ke_append_record_bytes(&cursor, 0xCAFE, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x06, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_EQUAL_UINT8(1, buf[5]);
- TEST_ASSERT_EQUAL_UINT8(2, buf[6]);
- TEST_ASSERT_EQUAL_UINT8(3, buf[7]);
- TEST_ASSERT_EQUAL_UINT8(4, buf[8]);
- TEST_ASSERT_EQUAL_UINT8(5, buf[9]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
- TEST_ASSERT_EQUAL_INT(6, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- ke_append_record_bytes(&cursor, 0xCAFE, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[10]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ uint8_t data[6] = {0, 1, 2, 3, 4, 5};
+ // Run test
+ ke_append_record_bytes(&cursor, 0xCAFE, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x06, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_EQUAL_UINT8(1, buf[5]);
+ TEST_ASSERT_EQUAL_UINT8(2, buf[6]);
+ TEST_ASSERT_EQUAL_UINT8(3, buf[7]);
+ TEST_ASSERT_EQUAL_UINT8(4, buf[8]);
+ TEST_ASSERT_EQUAL_UINT8(5, buf[9]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
+ TEST_ASSERT_EQUAL_INT(6, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ ke_append_record_bytes(&cursor, 0xCAFE, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[10]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, ex_append_record_null) {
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- ex_append_record_null(&cursor, 0xFADE);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(4, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(12, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ ex_append_record_null(&cursor, 0xFADE);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(4, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(12, cursor.left);
}
TEST(nts, ex_append_record_uint16) {
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- ex_append_record_uint16(&cursor, 0xFADE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x06, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0x12, buf[4]);
- TEST_ASSERT_EQUAL_UINT8(0x34, buf[5]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(10, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ ex_append_record_uint16(&cursor, 0xFADE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x06, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0x12, buf[4]);
+ TEST_ASSERT_EQUAL_UINT8(0x34, buf[5]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(10, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ ke_append_record_uint16(&cursor, 0xCAFE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, ex_append_record_bytes) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- uint8_t data[6] = {0, 1, 2, 3, 4, 5};
- /* Run test */
- ex_append_record_bytes(&cursor, 0xCAFE, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x0A, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_EQUAL_UINT8(1, buf[5]);
- TEST_ASSERT_EQUAL_UINT8(2, buf[6]);
- TEST_ASSERT_EQUAL_UINT8(3, buf[7]);
- TEST_ASSERT_EQUAL_UINT8(4, buf[8]);
- TEST_ASSERT_EQUAL_UINT8(5, buf[9]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
- TEST_ASSERT_EQUAL_INT(6, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- ex_append_record_bytes(&cursor, 0xCAFE, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[10]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ uint8_t data[6] = {0, 1, 2, 3, 4, 5};
+ // Run test
+ ex_append_record_bytes(&cursor, 0xCAFE, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xCA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xFE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x00, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x0A, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_EQUAL_UINT8(1, buf[5]);
+ TEST_ASSERT_EQUAL_UINT8(2, buf[6]);
+ TEST_ASSERT_EQUAL_UINT8(3, buf[7]);
+ TEST_ASSERT_EQUAL_UINT8(4, buf[8]);
+ TEST_ASSERT_EQUAL_UINT8(5, buf[9]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
+ TEST_ASSERT_EQUAL_INT(6, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ ex_append_record_bytes(&cursor, 0xCAFE, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[10]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[10], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, ex_append_header) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- ex_append_header(&cursor, 0xFADE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x12, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x38, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(12, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- ex_append_header(&cursor, 0xFEED, 0xABCD);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ ex_append_header(&cursor, 0xFADE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x12, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x38, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(12, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ ex_append_header(&cursor, 0xFEED, 0xABCD);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, append_header) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- append_header(&cursor, 0xFADE, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(0x12, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(0x34, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(12, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- append_header(&cursor, 0xFEED, 0xABCD);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ append_header(&cursor, 0xFADE, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFA, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xDE, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(0x12, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(0x34, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(12, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ append_header(&cursor, 0xFEED, 0xABCD);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[4]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, append_uint16) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- /* Run test */
- append_uint16(&cursor, 0x1234);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0x12, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(0x34, buf[1]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
- TEST_ASSERT_EQUAL_INT(14, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- append_uint16(&cursor, 0x5678);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ // Run test
+ append_uint16(&cursor, 0x1234);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0x12, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(0x34, buf[1]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
+ TEST_ASSERT_EQUAL_INT(14, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ append_uint16(&cursor, 0x5678);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[2]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, append_bytes) {
- /* Test change */
- /* Setup */
- uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- uint8_t data[6] = {0, 1, 2, 3, 4, 5};
- /* Run test */
- append_bytes(&cursor, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[0]);
- TEST_ASSERT_EQUAL_UINT8(1, buf[1]);
- TEST_ASSERT_EQUAL_UINT8(2, buf[2]);
- TEST_ASSERT_EQUAL_UINT8(3, buf[3]);
- TEST_ASSERT_EQUAL_UINT8(4, buf[4]);
- TEST_ASSERT_EQUAL_UINT8(5, buf[5]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(10, cursor.left);
- /* Test no change */
- /* Setup */
- cursor.left = 0;
- /* Run test */
- append_bytes(&cursor, data, 6);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
- TEST_ASSERT_EQUAL_INT(0, cursor.left);
+ // Test change
+ // Setup
+ uint8_t buf[16] = {0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ uint8_t data[6] = {0, 1, 2, 3, 4, 5};
+ // Run test
+ append_bytes(&cursor, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[0]);
+ TEST_ASSERT_EQUAL_UINT8(1, buf[1]);
+ TEST_ASSERT_EQUAL_UINT8(2, buf[2]);
+ TEST_ASSERT_EQUAL_UINT8(3, buf[3]);
+ TEST_ASSERT_EQUAL_UINT8(4, buf[4]);
+ TEST_ASSERT_EQUAL_UINT8(5, buf[5]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(10, cursor.left);
+ // Test no change
+ // Setup
+ cursor.left = 0;
+ // Run test
+ append_bytes(&cursor, data, 6);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0, buf[6]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[6], cursor.next);
+ TEST_ASSERT_EQUAL_INT(0, cursor.left);
}
TEST(nts, ke_next_record) {
- /* Setup */
- uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- int length;
- uint16_t type;
- /* Run test */
- type = ke_next_record(&cursor, &length);
- /* Check */
- TEST_ASSERT_EQUAL_INT(4, length);
- TEST_ASSERT_EQUAL_INT(0xFACE, type);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(12, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ int length;
+ uint16_t type;
+ // Run test
+ type = ke_next_record(&cursor, &length);
+ // Check
+ TEST_ASSERT_EQUAL_INT(4, length);
+ TEST_ASSERT_EQUAL_INT(0xFACE, type);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(12, cursor.left);
}
TEST(nts, ex_next_record) {
- /* Setup */
- uint8_t buf[16] = {0xFA, 0xCE, 0, 8, 0xFF, 0xEE, 0xDD, 0xCC,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- int length;
- uint16_t type;
- /* Run test */
- type = ex_next_record(&cursor, &length);
- /* Check */
- TEST_ASSERT_EQUAL_INT(4, length);
- TEST_ASSERT_EQUAL_INT(0xFACE, type);
- TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
- TEST_ASSERT_EQUAL_INT(12, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0xFA, 0xCE, 0, 8, 0xFF, 0xEE, 0xDD, 0xCC,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ int length;
+ uint16_t type;
+ // Run test
+ type = ex_next_record(&cursor, &length);
+ // Check
+ TEST_ASSERT_EQUAL_INT(4, length);
+ TEST_ASSERT_EQUAL_INT(0xFACE, type);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[4], cursor.next);
+ TEST_ASSERT_EQUAL_INT(12, cursor.left);
}
TEST(nts, next_uint16) {
- /* Setup */
- uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- uint16_t data;
- /* Run test */
- data = next_uint16(&cursor);
- /* Check */
- TEST_ASSERT_EQUAL_UINT8(0xFACE, data);
- TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
- TEST_ASSERT_EQUAL_INT(14, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ uint16_t data;
+ // Run test
+ data = next_uint16(&cursor);
+ // Check
+ TEST_ASSERT_EQUAL_UINT8(0xFACE, data);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[2], cursor.next);
+ TEST_ASSERT_EQUAL_INT(14, cursor.left);
}
TEST(nts, next_bytes) {
- /* Setup */
- uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
- 0, 0, 0, 0, 0, 0, 0, 0};
- BufCtl cursor;
- cursor.next = buf;
- cursor.left = 16;
- uint8_t data[8];
- uint16_t length;
- /* Run test */
- length = next_bytes(&cursor, data, 8);
- /* Check */
- TEST_ASSERT_EQUAL_INT(8, length);
- TEST_ASSERT_EQUAL_UINT8(0xFA, data[0]);
- TEST_ASSERT_EQUAL_UINT8(0xCE, data[1]);
- TEST_ASSERT_EQUAL_UINT8(0, data[2]);
- TEST_ASSERT_EQUAL_UINT8(4, data[3]);
- TEST_ASSERT_EQUAL_UINT8(0xFF, data[4]);
- TEST_ASSERT_EQUAL_UINT8(0xEE, data[5]);
- TEST_ASSERT_EQUAL_UINT8(0xDD, data[6]);
- TEST_ASSERT_EQUAL_UINT8(0xCC, data[7]);
- TEST_ASSERT_POINTERS_EQUAL(&buf[8], cursor.next);
- TEST_ASSERT_EQUAL_INT(8, cursor.left);
+ // Setup
+ uint8_t buf[16] = {0xFA, 0xCE, 0, 4, 0xFF, 0xEE, 0xDD, 0xCC,
+ 0, 0, 0, 0, 0, 0, 0, 0};
+ BufCtl cursor;
+ cursor.next = buf;
+ cursor.left = 16;
+ uint8_t data[8];
+ uint16_t length;
+ // Run test
+ length = next_bytes(&cursor, data, 8);
+ // Check
+ TEST_ASSERT_EQUAL_INT(8, length);
+ TEST_ASSERT_EQUAL_UINT8(0xFA, data[0]);
+ TEST_ASSERT_EQUAL_UINT8(0xCE, data[1]);
+ TEST_ASSERT_EQUAL_UINT8(0, data[2]);
+ TEST_ASSERT_EQUAL_UINT8(4, data[3]);
+ TEST_ASSERT_EQUAL_UINT8(0xFF, data[4]);
+ TEST_ASSERT_EQUAL_UINT8(0xEE, data[5]);
+ TEST_ASSERT_EQUAL_UINT8(0xDD, data[6]);
+ TEST_ASSERT_EQUAL_UINT8(0xCC, data[7]);
+ TEST_ASSERT_POINTERS_EQUAL(&buf[8], cursor.next);
+ TEST_ASSERT_EQUAL_INT(8, cursor.left);
}
TEST_GROUP_RUNNER(nts) {
- RUN_TEST_CASE(nts, nts_translate_version);
- RUN_TEST_CASE(nts, nts_string_to_aead);
- RUN_TEST_CASE(nts, nts_get_key_length);
- RUN_TEST_CASE(nts, ke_append_record_null);
- RUN_TEST_CASE(nts, ke_append_record_uint16);
- RUN_TEST_CASE(nts, ke_append_record_bytes);
- RUN_TEST_CASE(nts, ex_append_record_null);
- RUN_TEST_CASE(nts, ex_append_record_uint16);
- RUN_TEST_CASE(nts, ex_append_record_bytes);
- RUN_TEST_CASE(nts, ex_append_header);
- RUN_TEST_CASE(nts, append_header);
- RUN_TEST_CASE(nts, append_uint16);
- RUN_TEST_CASE(nts, append_bytes);
- RUN_TEST_CASE(nts, ke_next_record);
- RUN_TEST_CASE(nts, ex_next_record);
- RUN_TEST_CASE(nts, next_uint16);
- RUN_TEST_CASE(nts, next_bytes);
+ RUN_TEST_CASE(nts, nts_translate_version);
+ RUN_TEST_CASE(nts, nts_string_to_aead);
+ RUN_TEST_CASE(nts, nts_get_key_length);
+ RUN_TEST_CASE(nts, ke_append_record_null);
+ RUN_TEST_CASE(nts, ke_append_record_uint16);
+ RUN_TEST_CASE(nts, ke_append_record_bytes);
+ RUN_TEST_CASE(nts, ex_append_record_null);
+ RUN_TEST_CASE(nts, ex_append_record_uint16);
+ RUN_TEST_CASE(nts, ex_append_record_bytes);
+ RUN_TEST_CASE(nts, ex_append_header);
+ RUN_TEST_CASE(nts, append_header);
+ RUN_TEST_CASE(nts, append_uint16);
+ RUN_TEST_CASE(nts, append_bytes);
+ RUN_TEST_CASE(nts, ke_next_record);
+ RUN_TEST_CASE(nts, ex_next_record);
+ RUN_TEST_CASE(nts, next_uint16);
+ RUN_TEST_CASE(nts, next_bytes);
}
=====================================
tests/ntpd/nts_cookie.c
=====================================
@@ -22,99 +22,99 @@ TEST_SETUP(nts_cookie) {}
TEST_TEAR_DOWN(nts_cookie) {}
TEST(nts_cookie, nts_make_cookie_key) {
- /* init */
- struct NTS_Key k0 = {.K={1, 2, 3, 4, 5}, .I=123};
- struct NTS_Key k1 = {.K={10, 20, 30, 40, 50}, .I=456};
- /* copy to key variables */
- nts_keys[0] = k0;
- nts_keys[1] = k1;
- /* run test */
- nts_nKeys = 2;
- nts_make_cookie_key(); /* push k0 to k1 */
- /* check that K[1] now equals former-K[0] */
- TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[1].K, k0.K, NTS_MAX_KEYLEN);
- TEST_ASSERT_EQUAL(nts_keys[1].I, k0.I);
- /* check that K[0] does not equal former-K[0] */
- /* There is no "TEST UNEQUAL", do it manually */
- bool equal = true;
- for (unsigned int i = 0; i < NTS_MAX_KEYLEN; i++) {
- if (nts_keys[0].K[i] != k0.K[i]) {
- equal = false;
- break;
- }
- }
- TEST_ASSERT_EQUAL(false, equal);
- /* Check that I[0] does not equal former-I[0] */
- TEST_ASSERT_NOT_EQUAL(nts_keys[0].I, k0.I);
+ // init
+ struct NTS_Key k0 = {.K={1, 2, 3, 4, 5}, .I=123};
+ struct NTS_Key k1 = {.K={10, 20, 30, 40, 50}, .I=456};
+ // copy to key variables
+ nts_keys[0] = k0;
+ nts_keys[1] = k1;
+ // run test
+ nts_nKeys = 2;
+ nts_make_cookie_key(); // push k0 to k1
+ // check that K[1] now equals former-K[0]
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[1].K, k0.K, NTS_MAX_KEYLEN);
+ TEST_ASSERT_EQUAL(nts_keys[1].I, k0.I);
+ // check that K[0] does not equal former-K[0]
+ // There is no "TEST UNEQUAL", do it manually
+ bool equal = true;
+ for (unsigned int i = 0; i < NTS_MAX_KEYLEN; i++) {
+ if (nts_keys[0].K[i] != k0.K[i]) {
+ equal = false;
+ break;
+ }
+ }
+ TEST_ASSERT_EQUAL(false, equal);
+ // Check that I[0] does not equal former-I[0]
+ TEST_ASSERT_NOT_EQUAL(nts_keys[0].I, k0.I);
}
TEST(nts_cookie, nts_make_unpack_cookie) {
- /* init */
- uint8_t cookie[NTS_MAX_COOKIELEN];
- /* Using 16 bytes in test for ease of handling */
- uint8_t c2s[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
- uint8_t s2c[16] = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- uint8_t c2s_2[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- uint8_t s2c_2[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int len;
- int keylen;
- bool ok;
- uint16_t aead; /* retrieved on unpack */
- /* Init for cookie_ctx */
- nts_cookie_init();
- nts_nKeys = 0;
- nts_make_cookie_key();
- /* Test */
- len = nts_make_cookie(cookie, AEAD_AES_SIV_CMAC_256, c2s, s2c, sizeof(c2s));
- TEST_ASSERT_EQUAL(72, len);
- /* Very limited in what data can be directly checked here */
- /* Reverse the test */
- ok = nts_unpack_cookie(cookie, len, &aead, c2s_2, s2c_2, &keylen);
- TEST_ASSERT_EQUAL(true, ok);
- TEST_ASSERT_EQUAL(AEAD_AES_SIV_CMAC_256, aead);
- TEST_ASSERT_EQUAL(16, keylen);
- TEST_ASSERT_EQUAL_UINT8_ARRAY(c2s, c2s_2, 16);
- TEST_ASSERT_EQUAL_UINT8_ARRAY(s2c, s2c_2, 16);
+ // init
+ uint8_t cookie[NTS_MAX_COOKIELEN];
+ // Using 16 bytes in test for ease of handling
+ uint8_t c2s[16] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
+ uint8_t s2c[16] = {16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+ uint8_t c2s_2[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ uint8_t s2c_2[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
+ int len;
+ int keylen;
+ bool ok;
+ uint16_t aead; // retrieved on unpack
+ // Init for cookie_ctx
+ nts_cookie_init();
+ nts_nKeys = 0;
+ nts_make_cookie_key();
+ // Test
+ len = nts_make_cookie(cookie, AEAD_AES_SIV_CMAC_256, c2s, s2c, sizeof(c2s));
+ TEST_ASSERT_EQUAL(72, len);
+ // Very limited in what data can be directly checked here
+ // Reverse the test
+ ok = nts_unpack_cookie(cookie, len, &aead, c2s_2, s2c_2, &keylen);
+ TEST_ASSERT_EQUAL(true, ok);
+ TEST_ASSERT_EQUAL(AEAD_AES_SIV_CMAC_256, aead);
+ TEST_ASSERT_EQUAL(16, keylen);
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(c2s, c2s_2, 16);
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(s2c, s2c_2, 16);
}
const char *cookie_file_name = "test-cookie-keys";
TEST(nts_cookie, nts_read_write_cookies) {
- struct NTS_Key k0, k1, k2;
- bool ok;
- ntsconfig.KI = cookie_file_name;
- nts_nKeys = 0;
- nts_make_cookie_key();
- nts_make_cookie_key();
- nts_make_cookie_key();
- k0 = nts_keys[0];
- k1 = nts_keys[1];
- k2 = nts_keys[2];
- TEST_ASSERT_EQUAL(nts_nKeys, 3);
- ok = nts_write_cookie_keys();
- TEST_ASSERT_EQUAL(true, ok);
- nts_make_cookie_key(); /* scramble things */
- ZERO(nts_keys);
- nts_nKeys = 377;
- ok = nts_read_cookie_keys();
- TEST_ASSERT_EQUAL(true, ok);
- TEST_ASSERT_EQUAL(nts_nKeys, 3);
- TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[0].K, k0.K, NTS_MAX_KEYLEN);
- TEST_ASSERT_EQUAL(nts_keys[0].I, k0.I);
- TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[1].K, k1.K, NTS_MAX_KEYLEN);
- TEST_ASSERT_EQUAL(nts_keys[1].I, k1.I);
- TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[2].K, k2.K, NTS_MAX_KEYLEN);
- TEST_ASSERT_EQUAL(nts_keys[2].I, k2.I);
+ struct NTS_Key k0, k1, k2;
+ bool ok;
+ ntsconfig.KI = cookie_file_name;
+ nts_nKeys = 0;
+ nts_make_cookie_key();
+ nts_make_cookie_key();
+ nts_make_cookie_key();
+ k0 = nts_keys[0];
+ k1 = nts_keys[1];
+ k2 = nts_keys[2];
+ TEST_ASSERT_EQUAL(nts_nKeys, 3);
+ ok = nts_write_cookie_keys();
+ TEST_ASSERT_EQUAL(true, ok);
+ nts_make_cookie_key(); // scramble things
+ ZERO(nts_keys);
+ nts_nKeys = 377;
+ ok = nts_read_cookie_keys();
+ TEST_ASSERT_EQUAL(true, ok);
+ TEST_ASSERT_EQUAL(nts_nKeys, 3);
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[0].K, k0.K, NTS_MAX_KEYLEN);
+ TEST_ASSERT_EQUAL(nts_keys[0].I, k0.I);
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[1].K, k1.K, NTS_MAX_KEYLEN);
+ TEST_ASSERT_EQUAL(nts_keys[1].I, k1.I);
+ TEST_ASSERT_EQUAL_UINT8_ARRAY(nts_keys[2].K, k2.K, NTS_MAX_KEYLEN);
+ TEST_ASSERT_EQUAL(nts_keys[2].I, k2.I);
}
TEST_GROUP_RUNNER(nts_cookie) {
- RUN_TEST_CASE(nts_cookie, nts_make_unpack_cookie);
- RUN_TEST_CASE(nts_cookie, nts_make_cookie_key);
- RUN_TEST_CASE(nts_cookie, nts_read_write_cookies);
- /* This test gets run as root during install
- * that leaves the cookie file that we can't read/write
- * so clean it up now.
- * If we crash, we don't get here so the evidence is still
- * left around in case it helps debugging. */
- unlink(cookie_file_name);
+ RUN_TEST_CASE(nts_cookie, nts_make_unpack_cookie);
+ RUN_TEST_CASE(nts_cookie, nts_make_cookie_key);
+ RUN_TEST_CASE(nts_cookie, nts_read_write_cookies);
+ /* This test gets run as root during install
+ * that leaves the cookie file that we can't read/write
+ * so clean it up now.
+ * If we crash, we don't get here so the evidence is still
+ * left around in case it helps debugging. */
+ unlink(cookie_file_name);
}
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/f606871219748070ff3de1d2466e44287d4cd260...2e634bbc0a8fbf434b158368c7f6b7b0a1560fe5
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/f606871219748070ff3de1d2466e44287d4cd260...2e634bbc0a8fbf434b158368c7f6b7b0a1560fe5
You're receiving this email because of your account on gitlab.com. Manage all notifications: https://gitlab.com/-/profile/notifications | Help: https://gitlab.com/help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20260806/734e8841/attachment-0001.htm>
More information about the vc
mailing list