]> git.ipfire.org Git - thirdparty/chrony.git/blob - ntp_auth.h
ntp: move auth parsing to ntp_auth
[thirdparty/chrony.git] / ntp_auth.h
1 /*
2 chronyd/chronyc - Programs for keeping computer clocks accurate.
3
4 **********************************************************************
5 * Copyright (C) Miroslav Lichvar 2019
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *
20 **********************************************************************
21
22 =======================================================================
23
24 Header file for NTP authentication
25 */
26
27 #ifndef GOT_NTP_AUTH_H
28 #define GOT_NTP_AUTH_H
29
30 #include "addressing.h"
31 #include "ntp.h"
32
33 typedef struct NAU_Instance_Record *NAU_Instance;
34
35 /* Create an authenticator instance in a specific mode */
36 extern NAU_Instance NAU_CreateNoneInstance(void);
37 extern NAU_Instance NAU_CreateSymmetricInstance(uint32_t key_id);
38
39 /* Destroy an instance */
40 extern void NAU_DestroyInstance(NAU_Instance instance);
41
42 /* Check if an instance is not in the None mode */
43 extern int NAU_IsAuthEnabled(NAU_Instance instance);
44
45 /* Get NTP version recommended for better compatibility */
46 extern int NAU_GetSuggestedNtpVersion(NAU_Instance instance);
47
48 /* Perform operations necessary for NAU_GenerateRequestAuth() */
49 extern int NAU_PrepareRequestAuth(NAU_Instance instance);
50
51 /* Adjust a transmit timestamp for an estimated minimum time it takes to call
52 NAU_GenerateRequestAuth() */
53 extern void NAU_AdjustRequestTimestamp(NAU_Instance instance, struct timespec *ts);
54
55 /* Extend a request with data required by the authentication mode */
56 extern int NAU_GenerateRequestAuth(NAU_Instance instance, NTP_Packet *request,
57 NTP_PacketInfo *info);
58
59 /* Parse a request or response to detect the authentication mode */
60 extern int NAU_ParsePacket(NTP_Packet *packet, NTP_PacketInfo *info);
61
62 /* Verify that a request is authentic */
63 extern int NAU_CheckRequestAuth(NTP_Packet *request, NTP_PacketInfo *info);
64
65 /* Adjust a transmit timestamp for an estimated minimum time it takes to call
66 NAU_GenerateResponseAuth() */
67 extern void NAU_AdjustResponseTimestamp(NTP_Packet *request, NTP_PacketInfo *info,
68 struct timespec *ts);
69
70 /* Extend a response with data required by the authentication mode. This
71 function can be called only if the previous call of NAU_CheckRequestAuth()
72 was on the same request. */
73 extern int NAU_GenerateResponseAuth(NTP_Packet *request, NTP_PacketInfo *request_info,
74 NTP_Packet *response, NTP_PacketInfo *response_info,
75 NTP_Remote_Address *remote_addr,
76 NTP_Local_Address *local_addr);
77
78 /* Verify that a response is authentic */
79 extern int NAU_CheckResponseAuth(NAU_Instance instance, NTP_Packet *response,
80 NTP_PacketInfo *info);
81
82 #endif