Commit graph

2240 commits

Author SHA1 Message Date
Miroslav Lichvar
27c8a64977 reference: don't clone file attributes of drift file
When replacing an existing drift file with the temporary file, don't
change the ownership or permissions of the temporary file to match the
old drift file, as if it didn't exist.
2019-10-24 11:03:47 +02:00
Miroslav Lichvar
2fc8edacb8 use PATH_MAX
Include <limits.h> and use the PATH_MAX macro to define the length of
buffers containing paths to make it constistent. (It's not supposed to
fit all possible paths.)
2019-10-24 11:03:47 +02:00
Miroslav Lichvar
903fa247f8 logging: include <syslog.h>
Move the inclusion of <syslog.h> from sysincl.h to logging.c to avoid
accidentally using the LOG_* constants from the header.
2019-10-24 11:03:47 +02:00
Miroslav Lichvar
96771d6857 logging: make banner printing safer
Don't rely on the buffer filled with '=' characters to be always at
least as long as the log-specific banner string.
2019-10-24 11:03:41 +02:00
Miroslav Lichvar
f4c6a00b2a logging: call exit() in LOG_Message()
Call exit() in LOG_Message() after printing a fatal message to allow the
LOG macro or LOG_Message() to be used directly instead of the LOG_FATAL
macro.
2019-10-10 18:05:00 +02:00
Miroslav Lichvar
990f8cd89b test: extend 110-chronyc test 2019-09-24 16:39:49 +02:00
Miroslav Lichvar
813ea71b50 test: extend 105-ntpauth test 2019-09-24 16:39:49 +02:00
Miroslav Lichvar
e8be384cdf test: extend keys unit test 2019-09-24 16:39:49 +02:00
Miroslav Lichvar
61773a2c07 test: add cmac unit test 2019-09-24 16:39:49 +02:00
Miroslav Lichvar
510aa8b050 client: add CMAC support to keygen command
Allow a CMAC cipher to be specified in the keygen command. Ignore the
specified length as the key length is determined by the cipher.
2019-09-24 16:39:01 +02:00
Miroslav Lichvar
57957ab6cf keys: add support for CMAC keys
Allow a cipher (AES128 or AES256) to be specified as the type of a key
in the key file to authenticate NTP packets with a CMAC instead of the
NTPv4 (RFC 5905) MAC using a hash function. This follows RFC 8573.
2019-09-24 16:38:12 +02:00
Miroslav Lichvar
e8069a0179 cmac: add support for Nettle
Add support for AES128 and AES256 CMAC in Nettle.
2019-09-24 14:04:44 +02:00
Miroslav Lichvar
f3f840551a cmac: add CMAC interface
Add cmac.h and stubs for cipher-based message authentication code
(CMAC).
2019-09-24 11:56:05 +02:00
Miroslav Lichvar
10a42c1e04 keys: don't fudge authentication delay
Remove the magic constant compensating for copying, conversions, etc.
It cannot possibly be accurate on all hardware. The delay is supposed to
be a minimum delay.
2019-09-24 11:35:51 +02:00
Miroslav Lichvar
4a219ecbf1 hash: drop support for RIPEMD hash functions
An analysis by Tim Ruffing [1] shows that a length extension attack
adding valid extension fields to NTPv4 packets is possible with some
specific key lengths and hash functions using little-endian length like
MD5 and RIPEMD160.

chronyd currently doesn't process or generate any extension fields, but
it could be a problem in future when a non-authentication extension
field is supported.

Drop support for all RIPEMD functions as they don't seem to be secure in
the context of the NTPv4 MAC. MD5 is kept only for compatibility.

[1] https://mailarchive.ietf.org/arch/msg/ntp/gvibuB6bTbDRBumfHNdJ84Kq4kA
2019-09-24 11:32:31 +02:00
Miroslav Lichvar
0d298bfc4c makefile: improve coding style 2019-09-19 17:30:28 +02:00
Miroslav Lichvar
792c241e3a makefile: refactor to support extra client-specific objects 2019-09-19 17:30:28 +02:00
Miroslav Lichvar
6336a87855 configure: move duplicated libraries to LIBS 2019-09-19 17:30:28 +02:00
Miroslav Lichvar
f5721b1212 configure: remove unused variables 2019-09-19 17:30:28 +02:00
Miroslav Lichvar
7d3e9180c6 test: disable server on client-only nodes by default 2019-09-12 14:51:12 +02:00
Miroslav Lichvar
03b8ca186a test: add 138-syncloop test 2019-09-12 14:51:12 +02:00
Miroslav Lichvar
435cbef31a test: allow nodes to poll themselves 2019-09-12 14:51:12 +02:00
Miroslav Lichvar
4adcf58368 test: remove subdirectories in tmp directory 2019-09-12 14:50:58 +02:00
Miroslav Lichvar
004986310d ntp: skip loop test if no server socket is open
If there is no socket that could receive a request from a client or
peer, we know that nothing can be synchronized to us and no loop is
possible.
2019-09-12 13:01:18 +02:00
Miroslav Lichvar
7a88e0a87b ntp: prevent synchronization to itself
Improve the client's test D to compare the stratum, reference ID,
reference timestamp, and root delay from the received packet with its
own reference data in order to prevent it from synchronizing to itself,
e.g. due to a misconfiguration.
2019-09-12 13:01:18 +02:00
Miroslav Lichvar
64e21d6281 reference: make local reference timestamp consistent
In the local reference mode, instead of returning the adjusted current
time as the reference time, return the same timestamp updated only once
per about 62.5 seconds.

This will enable chronyd to detect polling of itself even when the local
reference mode is active.
2019-09-12 13:01:06 +02:00
Miroslav Lichvar
9ef7ea2bcb reference: rework adjustment of reference timestamp
Instead of converting the reference timestamp to the NTP format and
back, add a negative double value to the timestamp directly. Move the
code to a separate function. This will allow the timestamp to stay
outside the compiled-in NTP era, which is useful for testing of the
cmdmon protocol.
2019-09-11 17:33:57 +02:00
Miroslav Lichvar
6d1796d6be test: extend 110-chronyc test 2019-09-03 13:17:44 +02:00
Miroslav Lichvar
fcaba98101 test: add 137-pool test 2019-09-03 12:41:01 +02:00
Miroslav Lichvar
9bbda5c964 test: add 013-nameserv test 2019-09-02 16:32:58 +02:00
Miroslav Lichvar
2c81d38861 test: add option to enable name/address resolving 2019-09-02 16:27:05 +02:00
Miroslav Lichvar
78fec3f05a test: add copyright header to util unit test 2019-08-27 17:11:49 +02:00
Miroslav Lichvar
392a1a5ff6 test: extend 105-ntpauth test 2019-08-27 17:11:49 +02:00
Miroslav Lichvar
219a414cb7 test: add debug message to ntp unit test 2019-08-27 17:11:49 +02:00
Miroslav Lichvar
58fc81441b ntp: update setting of socket option 2019-08-27 17:11:49 +02:00
Miroslav Lichvar
02ada36838 socket: add support for TCP sockets
TCP sockets will be needed for NTS key establishment.
2019-08-27 17:10:13 +02:00
Miroslav Lichvar
81978f0ba0 socket: fix typo in union declaration 2019-08-08 17:32:48 +02:00
Miroslav Lichvar
622769cdfd util: add debug messages to UTI_FdSetCloexec() 2019-08-08 17:32:48 +02:00
Miroslav Lichvar
3038047f9b makefile: clean unit tests in clean target 2019-08-06 16:11:07 +02:00
Miroslav Lichvar
3e3f045ab7 doc: improve ntpdate answer in FAQ 2019-08-06 16:11:07 +02:00
Miroslav Lichvar
a6d9f41eda sourcestats: report offset even with single sample 2019-08-06 16:11:07 +02:00
Miroslav Lichvar
bf6a4e1a81 sourcestats: simplify SST_DoSourcestatsReport() 2019-08-06 16:11:07 +02:00
Miroslav Lichvar
5982d96b75 test: extend 130-quit test 2019-08-06 16:11:07 +02:00
Miroslav Lichvar
28e3e4cdca sourcestats: enable selection with maxsamples < 3
Setting maxsamples to 1 or 2 prevented the source from being selected as
the regression would always fail. Handle this as a special case with
disabled frequency tracking in order to enable a fast reference update
with the -q/-Q option.
2019-08-06 16:11:07 +02:00
Miroslav Lichvar
24134c78e8 sourcestats: update offset estimate when regression fails
If there are too few samples to make a regression, at least update the
offset estimate from the last sample and keep the previous frequency
offset unchanged. Also, reset the error estimates.
2019-08-06 13:04:59 +02:00
Miroslav Lichvar
5e8ed72b89 socket: fix compiler warning
Don't define check_socket_flag() if no supported socket flag is defined.
2019-07-25 09:52:33 +02:00
Miroslav Lichvar
45e41b7ac1 socket: avoid unnecessary bind() call
Don't call bind() if the specified local address of a socket has port 0
and the "any" address. It will be bound automatically on connect() or
sendmsg().
2019-07-24 16:27:07 +02:00
Miroslav Lichvar
27fd751915 socket: add support for socket() flags
On start, check if the SOCK_CLOEXEC and SOCK_NONBLOCK flags are
supported in the socket() call and use them instead of fcntl() in order
to reduce the number of system calls required to send a client request.
2019-07-24 15:35:00 +02:00
Miroslav Lichvar
4d26cfc92b socket: make all sockets non-blocking
All networking code in chronyd (NTP server/client, signd client, cmdmon
server) assumes sending a message will not block, but only the signd
client actually checks for a write event and only the NTP server
requests a non-blocking socket. The cmdmon server and NTP client
(if using one socket for all servers) might be blocked.

chronyc doesn't need a non-blocking socket, but it is not expected to
block as it sends only one message at a time.

Prefer dropped messages over blocking in all cases. Remove the
SCK_FLAG_NONBLOCK flag and make all sockets non-blocking.
2019-07-24 10:21:14 +02:00
Miroslav Lichvar
d78680912e ntp: improve debug messages with port number 2019-07-18 17:29:44 +02:00