[Git][NTPsec/ntpsec][master] 2 commits: Formatting cleanup (tabs/spaces)
Hal Murray
gitlab at mg.gitlab.com
Fri Feb 14 19:31:19 UTC 2020
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
27204468 by Hal Murray at 2020-02-10T20:53:20-08:00
Formatting cleanup (tabs/spaces)
- - - - -
94ded261 by Hal Murray at 2020-02-13T12:02:46-08:00
Crash if error return from RAND_bytes and RAND_priv_bytes
- - - - -
5 changed files:
- include/nts.h
- libntp/ntp_random.c
- ntpd/nts_cookie.c
- ntpd/nts_extens.c
- tests/ntpd/nts_cookie.c
Changes:
=====================================
include/nts.h
=====================================
@@ -29,7 +29,7 @@ void nts_cert_timer(void);
void nts_cookie_timer(void);
bool nts_read_cookie_keys(void);
-bool nts_make_cookie_key(void);
+void nts_make_cookie_key(void);
bool nts_write_cookie_keys(void);
int nts_make_cookie(uint8_t *cookie,
=====================================
libntp/ntp_random.c
=====================================
@@ -25,7 +25,7 @@ ntp_random(void)
err = RAND_bytes((unsigned char *)&rnd, sizeof(rnd));
if (1 != err) {
msyslog(LOG_ERR, "ERR: ntp_random - RAND_bytes failed");
- exit(1);
+ exit(1);
}
return rnd;
}
@@ -33,13 +33,13 @@ ntp_random(void)
uint64_t
ntp_random64(void)
{
- int err;
- uint64_t rnd = 0;
- err = RAND_bytes((unsigned char *)&rnd, sizeof(rnd));
- if (1 != err) {
- msyslog(LOG_ERR, "ERR: ntp_random - RAND_bytes failed");
- exit(1);
- }
- return rnd;
+ int err;
+ uint64_t rnd = 0;
+ err = RAND_bytes((unsigned char *)&rnd, sizeof(rnd));
+ if (1 != err) {
+ msyslog(LOG_ERR, "ERR: ntp_random64 - RAND_bytes failed");
+ exit(1);
+ }
+ return rnd;
}
=====================================
ntpd/nts_cookie.c
=====================================
@@ -48,7 +48,18 @@
/* K and I should be preserved across boots, and rotated every day or so.
* We need to support the old K/I for another day.
- * Encryption within cookies uses AEAD_AES_SIV_CMAC_nnn. That's the
+ *
+ * If the file gets corrupted, blow it away and reboot. It will get
+ * recreated, we will start using new cookies, packets from clients
+ * with old cookies will get dropped, and eventually clients will
+ * run out of cookies and use NTS-KE to get new ones.
+ *
+ * It would be possible to run without a cookie file. Nobody would
+ * notice until the server was restarted. Then there would be a flurry
+ * of NTS-KE requests until all clients obtained new/working cookies.
+ */
+
+/* Encryption within cookies uses AEAD_AES_SIV_CMAC_nnn. That's the
* same family of algorithms as NTS uses on the wire.
* The nnn is selected by the key length.
* 32 => 256
@@ -231,17 +242,21 @@ bool nts_read_cookie_keys(void) {
* The KE server and the NTP servers stay in sync without communication
* after a one-time copy of the cookie file from NTP server to KE server.
*/
-bool nts_make_cookie_key(void) {
- bool OK = true;
+void nts_make_cookie_key(void) {
+ int err;
memcpy(&K2, &K, sizeof(K2)); /* Push current cookie to old */
I2 = I;
#if (OPENSSL_VERSION_NUMBER > 0x1010100fL)
- OK &= RAND_priv_bytes(K, sizeof(K));
+ err = RAND_priv_bytes(K, sizeof(K));
#else
- OK &= RAND_bytes(K, sizeof(K));
+ err = RAND_bytes(K, sizeof(K));
#endif
- OK &= RAND_bytes((uint8_t *)&I, sizeof(I));
- return OK;
+ err += RAND_bytes((uint8_t *)&I, sizeof(I));
+ if (2 != err) {
+ msyslog(LOG_ERR, "ERR: nts_make_cookie_key - RAND_bytes failed");
+ exit(1);
+ }
+ return;
}
bool nts_write_cookie_keys(void) {
@@ -284,7 +299,7 @@ int nts_make_cookie(uint8_t *cookie,
uint8_t *c2s, uint8_t *s2c, int keylen) {
uint8_t plaintext[NTS_MAX_COOKIELEN];
uint8_t *nonce;
- int used, plainlength;
+ int err, used, plainlength;
bool ok;
uint8_t * finger;
uint32_t temp; /* keep 4 byte alignment */
@@ -318,7 +333,11 @@ int nts_make_cookie(uint8_t *cookie,
finger += sizeof(I);
nonce = finger;
- RAND_bytes(finger, NONCE_LENGTH);
+ err = RAND_bytes(finger, NONCE_LENGTH);
+ if (1 != err) {
+ msyslog(LOG_ERR, "ERR: nts_make_cookie - Error from RAND_bytes");
+ exit(1);
+ }
finger += NONCE_LENGTH;
used = finger-cookie;
=====================================
ntpd/nts_extens.c
=====================================
@@ -63,7 +63,7 @@ bool extens_init(void) {
int extens_client_send(struct peer *peer, struct pkt *xpkt) {
struct BufCtl_t buf;
- int used, adlength, idx;
+ int err, used, adlength, idx;
size_t left;
uint8_t *nonce, *packet;
bool ok;
@@ -73,7 +73,11 @@ int extens_client_send(struct peer *peer, struct pkt *xpkt) {
buf.left = MAX_EXT_LEN;
/* UID */
- RAND_bytes(peer->nts_state.UID, NTS_UID_LENGTH);
+ err = RAND_bytes(peer->nts_state.UID, NTS_UID_LENGTH);
+ if (1 != err) {
+ msyslog(LOG_ERR, "ERR: extens_client_send - RAND_bytes failed");
+ exit(1);
+ }
ex_append_record_bytes(&buf, Unique_Identifier,
peer->nts_state.UID, NTS_UID_LENGTH);
@@ -99,7 +103,11 @@ int extens_client_send(struct peer *peer, struct pkt *xpkt) {
append_uint16(&buf, NONCE_LENGTH);
append_uint16(&buf, CMAC_LENGTH);
nonce = buf.next;
- RAND_bytes(nonce, NONCE_LENGTH);
+ err = RAND_bytes(nonce, NONCE_LENGTH);
+ if (1 != err) {
+ msyslog(LOG_ERR, "ERR: extens_client_send - RAND_bytes failed");
+ exit(1);
+ }
buf.next += NONCE_LENGTH;
buf.left -= NONCE_LENGTH;
left = buf.left;
@@ -259,7 +267,7 @@ int extens_server_send(struct ntspacket_t *ntspacket, struct pkt *xpkt) {
uint8_t *nonce, *packet;
uint8_t *plaintext, *ciphertext;;
uint8_t cookie[NTS_MAX_COOKIELEN];
- int cookielen, plainleng, aeadlen;
+ int err, cookielen, plainleng, aeadlen;
bool ok;
/* get first cookie now so we have length */
@@ -286,7 +294,11 @@ int extens_server_send(struct ntspacket_t *ntspacket, struct pkt *xpkt) {
append_uint16(&buf, plainleng+CMAC_LENGTH);
nonce = buf.next;
- RAND_bytes(nonce, NONCE_LENGTH);
+ err = RAND_bytes(nonce, NONCE_LENGTH);
+ if (1 != err) {
+ msyslog(LOG_ERR, "ERR: extens_client_send - RAND_bytes failed");
+ exit(1);
+ }
buf.next += NONCE_LENGTH;
buf.left -= NONCE_LENGTH;
=====================================
tests/ntpd/nts_cookie.c
=====================================
@@ -23,7 +23,6 @@ TEST_TEAR_DOWN(nts_cookie) {}
TEST(nts_cookie, nts_make_cookie_key) {
/* init */
- bool ok;
uint8_t kStart1[NTS_MAX_KEYLEN] = {1, 2, 3, 4, 5};
uint8_t kStart2[NTS_MAX_KEYLEN] = {10, 20, 30, 40, 50};
uint32_t iStart = I;
@@ -31,8 +30,7 @@ TEST(nts_cookie, nts_make_cookie_key) {
memcpy(K, kStart1, sizeof(K));
memcpy(K2, kStart2, sizeof(K2));
/* run test */
- ok = nts_make_cookie_key();
- TEST_ASSERT_EQUAL(true, ok);
+ nts_make_cookie_key();
/* check that K2 now equals former-K */
TEST_ASSERT_EQUAL_UINT8_ARRAY(kStart1, K2, sizeof(K2));
/* check that K does not equal former-K */
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/34d309c0c67b98fbfe730ae3bd7199cf62dc2ecc...94ded26173006e88acee9d5782f060cd2da9e308
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/34d309c0c67b98fbfe730ae3bd7199cf62dc2ecc...94ded26173006e88acee9d5782f060cd2da9e308
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20200214/f43d9724/attachment-0001.htm>
More information about the vc
mailing list