]> git.ipfire.org Git - thirdparty/chrony.git/log
thirdparty/chrony.git
4 years agodoc: improve NEWS 4.0-pre2
Miroslav Lichvar [Mon, 20 Apr 2020 13:49:58 +0000 (15:49 +0200)] 
doc: improve NEWS

Add a notable enhancement from 4.0-pre1 and make the description of
another enhancement less ambiguous.

4 years agodoc: update README
Miroslav Lichvar [Mon, 20 Apr 2020 09:17:35 +0000 (11:17 +0200)] 
doc: update README

4 years agocheck return value of SCK_OpenUnixSocketPair()
Miroslav Lichvar [Mon, 20 Apr 2020 13:42:45 +0000 (15:42 +0200)] 
check return value of SCK_OpenUnixSocketPair()

4 years agosamplefilt: remove useless assignment
Miroslav Lichvar [Mon, 20 Apr 2020 13:41:25 +0000 (15:41 +0200)] 
samplefilt: remove useless assignment

4 years agodoc: update documentation for recent NTS changes
Miroslav Lichvar [Thu, 16 Apr 2020 15:26:25 +0000 (17:26 +0200)] 
doc: update documentation for recent NTS changes

4 years agonts: allow disabling certificate time checks
Miroslav Lichvar [Thu, 16 Apr 2020 14:08:43 +0000 (16:08 +0200)] 
nts: allow disabling certificate time checks

Add "nocerttimecheck" directive to specify the number of clock updates
that need to be made before the time validation of certificates is
enabled. This makes NTS usable on machines that don't have a RTC.

4 years agonts: provide time function to gnutls
Miroslav Lichvar [Thu, 16 Apr 2020 10:06:55 +0000 (12:06 +0200)] 
nts: provide time function to gnutls

Use the internal time instead of system time for validation checks in
gnutls.

4 years agonts: add server support for NTP server negotiation
Miroslav Lichvar [Wed, 15 Apr 2020 13:41:22 +0000 (15:41 +0200)] 
nts: add server support for NTP server negotiation

Add ntsntpserver directive to specify the hostname of the NTP server
provided in NTS-KE response to clients.

4 years agocmdmon: reload NTS server keys on rekey command
Miroslav Lichvar [Wed, 15 Apr 2020 09:52:49 +0000 (11:52 +0200)] 
cmdmon: reload NTS server keys on rekey command

When ntsrotate is set to 0, allow the keys to be reloaded with the rekey
command of chronyc.

4 years agonts: enable external management of server keys
Miroslav Lichvar [Wed, 15 Apr 2020 09:43:59 +0000 (11:43 +0200)] 
nts: enable external management of server keys

If ntsrotate is set to 0, don't generate new server keys and don't save
them to ntsdumpdir. This allows the keys to be managed externally and
shared with other servers.

4 years agonts: generate cookies from second newest key
Miroslav Lichvar [Wed, 15 Apr 2020 08:48:29 +0000 (10:48 +0200)] 
nts: generate cookies from second newest key

Generate one server key in advance to give it time to be distributed to
other servers before it is actually used.

4 years agonts: encode key ID in cookie in network order
Miroslav Lichvar [Wed, 15 Apr 2020 08:44:20 +0000 (10:44 +0200)] 
nts: encode key ID in cookie in network order

This allows the server cookie to be decoded on different platforms.

4 years agocmdmon: save NTS cookies and server keys on dump command
Miroslav Lichvar [Wed, 15 Apr 2020 08:12:55 +0000 (10:12 +0200)] 
cmdmon: save NTS cookies and server keys on dump command

Extend the dump command to save also the server NTS keys and client NTS
cookies. Remove the warning for unset dumpdir.

4 years agontp: update auth-specific address sooner
Miroslav Lichvar [Wed, 15 Apr 2020 14:26:43 +0000 (16:26 +0200)] 
ntp: update auth-specific address sooner

When replacing an NTP source, update the NTS address before the NTP
address to save cookies with the old NTP address instead of the newly
resolved address (which may immediately change to an address provided by
NTS-KE).

4 years agonts: update TLS exporter label
Miroslav Lichvar [Thu, 26 Mar 2020 14:37:08 +0000 (15:37 +0100)] 
nts: update TLS exporter label

Change the string to "EXPORTER-network-time-security" as specified in
the latest NTS draft.

4 years agotest: extend 139-nts test
Miroslav Lichvar [Thu, 9 Apr 2020 14:51:10 +0000 (16:51 +0200)] 
test: extend 139-nts test

4 years agonts: extend server key file format
Miroslav Lichvar [Thu, 9 Apr 2020 13:07:07 +0000 (15:07 +0200)] 
nts: extend server key file format

Include in the key dump file an identifier, the AEAD number, and the
age of the last key to improve robustness and avoid generating a new key
immediately on start.

Also, improve the code that saves and loads the file.

4 years agonts: save and load cookies on client
Miroslav Lichvar [Thu, 9 Apr 2020 08:33:55 +0000 (10:33 +0200)] 
nts: save and load cookies on client

Save the NTS context and cookies to files in the NTS dumpdir when the
client NTS instances are destroyed or the address is changed, and reload
the data to avoid unnecessary NTS-KE requests when chronyd is restarted
or it is switching between different addresses resolved from the NTS-KE
or NTP name.

4 years agonts: rename ntscachedir directive to ntsdumpdir
Miroslav Lichvar [Wed, 8 Apr 2020 13:51:41 +0000 (15:51 +0200)] 
nts: rename ntscachedir directive to ntsdumpdir

This makes the naming consistent with the existing dumpdir directive and
the dump command.

4 years agonts: refactor NTS context
Miroslav Lichvar [Mon, 30 Mar 2020 16:06:57 +0000 (18:06 +0200)] 
nts: refactor NTS context

Add a context structure for the algorithm and keys established by
NTS-KE. Modify the client to save the context and reset the SIV key to
the C2S/S2C key before each request/response instead of keeping two SIV
instances.

This will make it easier for the server to support different algorithms
and allow the client to save the context with cookies to disk.

4 years agonts: drop unused constant
Miroslav Lichvar [Thu, 26 Mar 2020 16:14:06 +0000 (17:14 +0100)] 
nts: drop unused constant

4 years agoutil: add function to split string into words
Miroslav Lichvar [Thu, 9 Apr 2020 07:59:39 +0000 (09:59 +0200)] 
util: add function to split string into words

4 years agoutil: constify input parameters
Miroslav Lichvar [Wed, 8 Apr 2020 13:16:18 +0000 (15:16 +0200)] 
util: constify input parameters

4 years agosources: constify parameters of log_selection_message()
Miroslav Lichvar [Wed, 8 Apr 2020 13:15:50 +0000 (15:15 +0200)] 
sources: constify parameters of log_selection_message()

4 years agodoc: add sourcename to list of remote commands
Miroslav Lichvar [Mon, 30 Mar 2020 08:37:17 +0000 (10:37 +0200)] 
doc: add sourcename to list of remote commands

4 years agonts: zero cookie placeholder
Miroslav Lichvar [Thu, 26 Mar 2020 14:30:28 +0000 (15:30 +0100)] 
nts: zero cookie placeholder

Zero the body of the cookie placeholder in client requests as
recommended by the latest NTS draft.

4 years agonts: disable TLS version 1.2
Miroslav Lichvar [Thu, 26 Mar 2020 14:18:08 +0000 (15:18 +0100)] 
nts: disable TLS version 1.2

Require TLS version 1.3 or later as specified in the latest NTS draft.

4 years agonts: rework NTS-KE retry interval
Miroslav Lichvar [Wed, 25 Mar 2020 16:01:27 +0000 (17:01 +0100)] 
nts: rework NTS-KE retry interval

Make the NTS-KE retry interval exponentially increasing, using a factor
provided by the NKE session. Use shorter intervals when the server is
refusing TCP connections or the connection is closed or timing out
before the TLS handshake.

4 years agonts: include server address in client NTS-KE log messages
Miroslav Lichvar [Mon, 23 Mar 2020 14:39:58 +0000 (15:39 +0100)] 
nts: include server address in client NTS-KE log messages

4 years agonts: fix address in server NTS-KE log messages
Miroslav Lichvar [Mon, 23 Mar 2020 14:34:08 +0000 (15:34 +0100)] 
nts: fix address in server NTS-KE log messages

The server session instances are reused for different clients. Separate
the server name from the label used in log messages and set it on each
start of the session.

4 years agontp: fix log message for replaced source
Miroslav Lichvar [Thu, 26 Mar 2020 10:51:17 +0000 (11:51 +0100)] 
ntp: fix log message for replaced source

When a source was replaced and the new source had the same slot as the
old source, a wrong message was logged. Fix the condition to distinguish
correctly between changed address and port.

Fixes: 9468fd4aa680 ("ntp: allow changing port of source")
4 years agoreference: improve check for close leap second
Miroslav Lichvar [Wed, 25 Mar 2020 08:12:35 +0000 (09:12 +0100)] 
reference: improve check for close leap second

Improve the check to work with the actual timestamp of the leap second
instead of the closest midnight and don't turn it off on the leap
timeout. Also allow sample times to be checked in addition to the system
time and NTP time to avoid accumulation of samples mixing pre-leap and
post-leap timestamps (causing error of +/-0.5 or +/-1.0 seconds).

4 years agosocket: remove obsolete comment
Miroslav Lichvar [Tue, 24 Mar 2020 14:46:34 +0000 (15:46 +0100)] 
socket: remove obsolete comment

4 years agosocket: fix severity check in debug logging
Miroslav Lichvar [Tue, 24 Mar 2020 14:29:21 +0000 (15:29 +0100)] 
socket: fix severity check in debug logging

Don't waste time formatting the debug message in log_message() when
debug output is disabled.

Fixes: 86a3ef9ed192 ("socket: add new socket support")
4 years agosocket: increase maximum number of received messages
Miroslav Lichvar [Tue, 24 Mar 2020 14:26:35 +0000 (15:26 +0100)] 
socket: increase maximum number of received messages

The buffers are no longer on stack. Increase their number for better
performance on heavily loaded servers.

4 years agosocket: simplify receiving messages
Miroslav Lichvar [Tue, 24 Mar 2020 14:22:31 +0000 (15:22 +0100)] 
socket: simplify receiving messages

Don't require the caller to provide a SCK_Message (on stack). Modify the
SCK_ReceiveMessage*() functions to return a pointer to static buffers,
as the message buffer which SCK_Message points to already is.

4 years agosocket: enable port sharing on Linux
Miroslav Lichvar [Mon, 23 Mar 2020 10:34:02 +0000 (11:34 +0100)] 
socket: enable port sharing on Linux

On Linux, enable the SO_REUSEPORT option on sockets bound to a port in
order to support load balancing with multiple chronyd instances
(configured to not adjust the system clock).

The IP_FREEBIND option already allowed different instances to bind to
the same address and port, but only one was actually receiving packets.

As the instances don't share their state, sharing the NTP port doesn't
work well with the interleaved mode, symmetric mode, and rate limiting.

Sharing the NTS-KE port will not work until the server keys can be
derived from a shared key.

4 years agodoc: fix typo in smoothtime description
Miroslav Lichvar [Thu, 19 Mar 2020 16:03:25 +0000 (17:03 +0100)] 
doc: fix typo in smoothtime description

4 years agosys_macosx: fix build issue on Sierra and presumably earlier
David Bohman [Tue, 17 Mar 2020 15:24:33 +0000 (08:24 -0700)] 
sys_macosx: fix build issue on Sierra and presumably earlier

4 years agotest: make 139-nts more reliable
Miroslav Lichvar [Tue, 17 Mar 2020 14:56:31 +0000 (15:56 +0100)] 
test: make 139-nts more reliable

4 years agodoc: fix typo in NEWS
Miroslav Lichvar [Mon, 16 Mar 2020 17:34:03 +0000 (18:34 +0100)] 
doc: fix typo in NEWS

4 years agodoc: update NEWS 4.0-pre1
Miroslav Lichvar [Mon, 16 Mar 2020 12:16:14 +0000 (13:16 +0100)] 
doc: update NEWS

4 years agosys_macosx: don't require clock_gettime()
Bryan Christianson [Thu, 12 Mar 2020 19:33:00 +0000 (08:33 +1300)] 
sys_macosx: don't require clock_gettime()

Earlier versions of macOS do not provide clock_gettime(). This patch
checks for clock_gettime() at run-time and falls back to gettimeofday()
if the symbol is not present.

4 years agomain: accept zero timeout
Miroslav Lichvar [Thu, 12 Mar 2020 13:25:21 +0000 (14:25 +0100)] 
main: accept zero timeout

Allow -t to specify zero timeout to exit immediately. It might be
useful for testing.

4 years agoreference: update synchronization status more frequently
Miroslav Lichvar [Thu, 12 Mar 2020 09:49:38 +0000 (10:49 +0100)] 
reference: update synchronization status more frequently

Update the local clock errors with each update of the leap status to
avoid the kernel marking the clock as unsynchronized when a large
number of NTP samples is dropped.

4 years agosources: update reference leap status early
Miroslav Lichvar [Wed, 11 Mar 2020 16:03:00 +0000 (17:03 +0100)] 
sources: update reference leap status early

When a leap second status is updated by a source, don't wait for the
next source selection and full update of the reference. Count votes from
sources that passed the previous selection and update the reference leap
status directly.

This should allow leap seconds to spread quickly even when the
samples are dropped or delayed by the filters.

4 years agosources: separate update of leap status
Miroslav Lichvar [Wed, 11 Mar 2020 14:48:00 +0000 (15:48 +0100)] 
sources: separate update of leap status

Remove leap status from the NTP sample and set it independently from
the sample accumulation in order to accept a leap second sooner when
samples are filtered.

4 years agosourcestats: move leap status to sources
Miroslav Lichvar [Wed, 11 Mar 2020 14:21:57 +0000 (15:21 +0100)] 
sourcestats: move leap status to sources

4 years agocmdmon: add reset command
Miroslav Lichvar [Wed, 11 Mar 2020 11:20:51 +0000 (12:20 +0100)] 
cmdmon: add reset command

The reset command drops all measurements and switches the reference to
the unsynchronised state. This command can help chronyd with recovery
when the measurements are known to be no longer valid or accurate, e.g.
due to moving the computer to a different network, or resuming the
computer from a low-power state (which resets the system clock).

4 years agodoc: fix tag in chronyc man page
Miroslav Lichvar [Wed, 11 Mar 2020 10:56:29 +0000 (11:56 +0100)] 
doc: fix tag in chronyc man page

4 years agoreference: don't report synchronized status after unknown step
Miroslav Lichvar [Wed, 11 Mar 2020 10:38:24 +0000 (11:38 +0100)] 
reference: don't report synchronized status after unknown step

The source handler resets SST instances on an unknown step, which
makes the sources unselectable, but SRC_SelectSource() doesn't call
REF_SetUnsynchronised() when no source is selectable.

Handle the step in the reference handler.

Fixes: 049eae661ae3 ("sources: keep synchronized status with unreachable/unselectable sources")
4 years agoreference: convert to monotonic time
Miroslav Lichvar [Wed, 11 Mar 2020 08:54:49 +0000 (09:54 +0100)] 
reference: convert to monotonic time

Calculate the update interval and drift file age from increments in the
monotonic time instead of real time.

4 years agonts: convert to monotonic time
Miroslav Lichvar [Wed, 11 Mar 2020 08:22:53 +0000 (09:22 +0100)] 
nts: convert to monotonic time

Use the monotonic timestamp provided by the scheduler for NTS-KE rate
limiting and refresh.

4 years agosched: provide low-precision monotonic time
Miroslav Lichvar [Wed, 11 Mar 2020 07:56:17 +0000 (08:56 +0100)] 
sched: provide low-precision monotonic time

Measure the interval since the start in order to provide a monotonic
time for periodical tasks not using timers like driftfile updates, key
refresh, etc. Return the interval in the double format, but keep an
integer remainder limiting the precision to 0.01 second to avoid issues
with very small increments in a long-running process.

4 years agoconfigure: improve nettle and gnutls check
Miroslav Lichvar [Tue, 10 Mar 2020 13:02:08 +0000 (14:02 +0100)] 
configure: improve nettle and gnutls check

Before enabling NTS, check for more gnutls functions (some added in
3.6.3) to avoid build failures with older gnutls versions. Also, make
sure that nettle supports the new AES interface (added in 3.0).

4 years agodoc: add missing dependencies to installation document
Miroslav Lichvar [Tue, 10 Mar 2020 10:02:59 +0000 (11:02 +0100)] 
doc: add missing dependencies to installation document

4 years agoconfigure: improve pkg-config support
Miroslav Lichvar [Tue, 10 Mar 2020 09:50:56 +0000 (10:50 +0100)] 
configure: improve pkg-config support

4 years agodoc: update description of on/offline commands
Miroslav Lichvar [Mon, 9 Mar 2020 12:00:47 +0000 (13:00 +0100)] 
doc: update description of on/offline commands

4 years agontp: ignore onoffline command for unresolved sources
Miroslav Lichvar [Mon, 9 Mar 2020 11:26:51 +0000 (12:26 +0100)] 
ntp: ignore onoffline command for unresolved sources

The onoffline command switches an unresolved source to the offline
status, even when the network is already up.

Ignore the onoffline command for unresolved sources to prevent sources
unexpectedly staying in the offline status, e.g. when the command is
issued from a network dispatcher script (and no other call is expected
later when the name is resolved).

4 years agodoc: update installation document
Miroslav Lichvar [Tue, 4 Feb 2020 13:34:47 +0000 (14:34 +0100)] 
doc: update installation document

4 years agodoc: describe NTS directives and options
Miroslav Lichvar [Wed, 19 Jun 2019 10:44:20 +0000 (12:44 +0200)] 
doc: describe NTS directives and options

4 years agotest: add nts unit tests
Miroslav Lichvar [Wed, 26 Feb 2020 13:14:49 +0000 (14:14 +0100)] 
test: add nts unit tests

4 years agotest: update compilation tests
Miroslav Lichvar [Thu, 9 Jan 2020 11:25:20 +0000 (12:25 +0100)] 
test: update compilation tests

4 years agotest: add 139-nts test
Miroslav Lichvar [Thu, 12 Sep 2019 14:42:53 +0000 (16:42 +0200)] 
test: add 139-nts test

4 years agocmdmon: add NTS support
Miroslav Lichvar [Thu, 7 Mar 2019 10:52:16 +0000 (11:52 +0100)] 
cmdmon: add NTS support

Allow the nts and ntsport options to be specified for sources added from
chronyc. This is an incompatible change in the request, but there was no
release using the new REQ_ADD_SOURCE command yet.

4 years agontp: enable NTS support
Miroslav Lichvar [Tue, 4 Feb 2020 14:27:24 +0000 (15:27 +0100)] 
ntp: enable NTS support

Add an option to enable NTS for an NTP source. Check for NTS-specific
extension fields and pass the packets to the NTS-NTP code in order to
enable the NTS client and server.

4 years agonts: add NTS-NTP server and client
Miroslav Lichvar [Tue, 4 Feb 2020 14:15:03 +0000 (15:15 +0100)] 
nts: add NTS-NTP server and client

Add support for the NTS NTP extension fields.

4 years agonts: add NTS-KE server and client
Miroslav Lichvar [Tue, 4 Feb 2020 14:10:14 +0000 (15:10 +0100)] 
nts: add NTS-KE server and client

Add a client and server implementing the Network Time Security (NTS) Key
Establishment. Use the GnuTLS library for TLS.

4 years agotest: add siv unit test
Miroslav Lichvar [Wed, 21 Aug 2019 15:51:23 +0000 (17:51 +0200)] 
test: add siv unit test

4 years agosiv: add internal implementation based on Nettle
Miroslav Lichvar [Wed, 21 Aug 2019 12:09:37 +0000 (14:09 +0200)] 
siv: add internal implementation based on Nettle

This adds an internal implementation of the AES-SIV-CMAC-256 cipher
based on GNU Nettle and the following patch (which was later reworked
and included in Nettle):

https://gitlab.com/gnutls/gnutls/uploads/1ab02c51e317264f9dba07ddfbc01d9a/0001-Added-support-for-AES_SIV_CMAC_256-and-AES_SIV_CMAC_.patch

This implementation will be dropped when the cipher is widely supported
by gnutls or Nettle.

4 years agosiv: add support for Nettle
Miroslav Lichvar [Wed, 21 Aug 2019 12:02:49 +0000 (14:02 +0200)] 
siv: add support for Nettle

4 years agosiv: introduce API for SIV
Miroslav Lichvar [Mon, 19 Aug 2019 15:33:54 +0000 (17:33 +0200)] 
siv: introduce API for SIV

Add a header file for Synthetic Initialization Vector (SIV) cipher mode,
which will be used by NTS.

4 years agosys_linux: allow getuid() in seccomp filter
Miroslav Lichvar [Mon, 10 Feb 2020 10:57:17 +0000 (11:57 +0100)] 
sys_linux: allow getuid() in seccomp filter

This will be needed by gnutls when loading certificates.

4 years agosys_linux: add syscall filter context for NTS-KE
Miroslav Lichvar [Tue, 26 Nov 2019 13:16:47 +0000 (14:16 +0100)] 
sys_linux: add syscall filter context for NTS-KE

The NTS-KE helper process will use a more restrictive filter than the
main process.

4 years agosys: specify context for syscall filter
Miroslav Lichvar [Tue, 26 Nov 2019 13:10:24 +0000 (14:10 +0100)] 
sys: specify context for syscall filter

Specify a context to enable different processes using different (more
restrictive) syscall filters.

4 years agosched: remove slew handler in finalization
Miroslav Lichvar [Tue, 4 Feb 2020 17:03:30 +0000 (18:03 +0100)] 
sched: remove slew handler in finalization

This allows repeated calls of SCH_Initialise() and SCH_Finalise().

4 years agosched: add function to remove all timers and descriptors
Miroslav Lichvar [Wed, 20 Nov 2019 11:39:32 +0000 (12:39 +0100)] 
sched: add function to remove all timers and descriptors

This allows a helper process to be started in an *_Initialise() call
and use the scheduler (unlike the privops helper, which has its own
loop).

4 years agonameserv: allow concurrent asynchronous requests
Miroslav Lichvar [Mon, 11 Nov 2019 18:02:30 +0000 (19:02 +0100)] 
nameserv: allow concurrent asynchronous requests

Allow multiple resolving threads to be running at the same time in order
to support multiple callers, but use a mutex to avoid sending multiple
requests to the privops helper. This will be needed for the NTS-KE
server negotiation.

4 years agoutil: add functions for printing and parsing hexadecimal data
Miroslav Lichvar [Thu, 31 Oct 2019 11:52:18 +0000 (12:52 +0100)] 
util: add functions for printing and parsing hexadecimal data

4 years agosources: don't reset active status
Miroslav Lichvar [Tue, 12 Nov 2019 17:04:48 +0000 (18:04 +0100)] 
sources: don't reset active status

Avoid resetting the active status when an NTP source changes its
address in NCR_ChangeRemoteAddress().

This will allow an NTP source to update its address with NTS-KE
hostname negotiation and continue in a special reference mode
(e.g. -q/-Q option).

4 years agontp: move definition of invalid stratum to ntp.h
Miroslav Lichvar [Thu, 7 Nov 2019 14:52:34 +0000 (15:52 +0100)] 
ntp: move definition of invalid stratum to ntp.h

4 years agontp: pass server name to ntp_core instances
Miroslav Lichvar [Wed, 13 Mar 2019 16:32:40 +0000 (17:32 +0100)] 
ntp: pass server name to ntp_core instances

The server name will be needed for certificate verification in NTS-KE.

4 years agotest: add ntp_ext unit test
Miroslav Lichvar [Thu, 5 Mar 2020 09:43:43 +0000 (10:43 +0100)] 
test: add ntp_ext unit test

4 years agontp: add functions for adding extension fields
Miroslav Lichvar [Mon, 3 Feb 2020 17:28:00 +0000 (18:28 +0100)] 
ntp: add functions for adding extension fields

4 years agontp: add function to change authentication-specific address
Miroslav Lichvar [Tue, 4 Feb 2020 10:50:29 +0000 (11:50 +0100)] 
ntp: add function to change authentication-specific address

When an NTS source will be replaced, the authentication-specific address
of the NTS-KE server will need to be changed too.

4 years agontp: add function to update source NTP address
Miroslav Lichvar [Sat, 23 Mar 2019 14:49:06 +0000 (15:49 +0100)] 
ntp: add function to update source NTP address

This will allow a source to have its address changed due to NTS-KE
server negotiation, which allows the NTS-KE server to have a different
address than the NTP server.

4 years agontp: allow changing port of source
Miroslav Lichvar [Thu, 13 Feb 2020 12:27:23 +0000 (13:27 +0100)] 
ntp: allow changing port of source

Modify the replace_source() function to not require a different IP
address when replacing a source with the same address but different
port. This will enable the NTS-KE port negotiation.

4 years agontp: don't accept packets with unexpected authentication
Miroslav Lichvar [Mon, 3 Feb 2020 15:04:08 +0000 (16:04 +0100)] 
ntp: don't accept packets with unexpected authentication

If authentication is not enabled in configuration, responses are not
expected to be authenticated. Handle such responses as having failed
authentication.

A case where this could happen is a misconfigured symmetric association
where only one peer has specified the other with a key. Before this
change synchronization would work in one direction and used packets
with an asymmetric length.

4 years agontp: don't allow long MACs in NTPv4 packets with extension fields
Miroslav Lichvar [Mon, 3 Feb 2020 13:03:57 +0000 (14:03 +0100)] 
ntp: don't allow long MACs in NTPv4 packets with extension fields

MAC longer than 24 octets in NTPv4 packet is supported only for
compatibility with some pre-RFC7822 chrony versions. They didn't use
any extension fields.

4 years agontp: add support for sending KoD responses
Miroslav Lichvar [Thu, 7 Nov 2019 13:57:52 +0000 (14:57 +0100)] 
ntp: add support for sending KoD responses

Enable the server to respond with a KoD when authentication fails. This
will be used by NTS to respond with a NAK when a client has expired
cookies.

4 years agontp: prefix NTP_AuthMode enums
Miroslav Lichvar [Thu, 15 Aug 2019 09:23:44 +0000 (11:23 +0200)] 
ntp: prefix NTP_AuthMode enums

4 years agontp: move auth parsing to ntp_auth
Miroslav Lichvar [Thu, 15 Aug 2019 09:20:36 +0000 (11:20 +0200)] 
ntp: move auth parsing to ntp_auth

Move the remaining authentication-specific code to the new file.

4 years agontp: refactor authentication
Miroslav Lichvar [Wed, 14 Aug 2019 16:23:45 +0000 (18:23 +0200)] 
ntp: refactor authentication

Move most of the authentication-specific code to a new file and
introduce authenticator instances in order to support other
authentication mechanisms (e.g. NTS).

4 years agontp: rework packet parsing
Miroslav Lichvar [Wed, 14 Aug 2019 13:53:17 +0000 (15:53 +0200)] 
ntp: rework packet parsing

Rework the code to detect the authentication mode and count extension
fields in the first parsing of the packet and store this information in
the new packet info structure.

4 years agontp: add functions for parsing extension fields
Miroslav Lichvar [Mon, 18 Feb 2019 12:12:49 +0000 (13:12 +0100)] 
ntp: add functions for parsing extension fields

4 years agontp: count packets with invalid format
Miroslav Lichvar [Mon, 19 Aug 2019 11:55:12 +0000 (13:55 +0200)] 
ntp: count packets with invalid format

Include packets that cannot be parsed in the total RX count.

4 years agontp: don't send response longer than request
Miroslav Lichvar [Mon, 15 Apr 2019 10:48:41 +0000 (12:48 +0200)] 
ntp: don't send response longer than request

When sending a response in the server or passive mode, make sure the
response is not longer than the request to prevent amplification
attacks when resposes may contain extension fields (e.g. NTS).

4 years agontp: provide access to request in transmit_packet()
Miroslav Lichvar [Thu, 8 Aug 2019 13:41:09 +0000 (15:41 +0200)] 
ntp: provide access to request in transmit_packet()

This will allow new authentication code (e.g. NTS) to get data from the
request when generating a response.

4 years agontp: rename receive_packet() to process_response()
Miroslav Lichvar [Thu, 15 Aug 2019 14:30:50 +0000 (16:30 +0200)] 
ntp: rename receive_packet() to process_response()

4 years agontp: add structure with packet info
Miroslav Lichvar [Wed, 14 Aug 2019 12:10:28 +0000 (14:10 +0200)] 
ntp: add structure with packet info

Add a structure for length and other information about received and
transmitted NTP packets to minimize the number of parameters and avoid
repeated parsing of the packet.