Debian Codegraph @

runtime/nsd_gtls.h

raw
1 /* An implementation of the nsd interface for GnuTLS.
2 *
3 * Copyright 2008-2026 Adiscon GmbH.
4 *
5 * This file is part of the rsyslog runtime library.
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * -or-
13 * see COPYING.ASL20 in the source distribution
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22 #ifndef INCLUDED_NSD_GTLS_H
23 #define INCLUDED_NSD_GTLS_H
24
25 #include "nsd.h"
26
27 #define NSD_GTLS_MAX_RCVBUF 16 * 1024 + 1 /* TLS RFC 8449: max size of buffer for message reception */
28 #define NSD_GTLS_MAX_CERT 10 /* max number of certs in our chain */
29
30 typedef enum {
31 gtlsRtry_None = 0, /**< no call needs to be retried */
32 gtlsRtry_handshake = 1,
33 gtlsRtry_recv = 2
34 } gtlsRtryCall_t; /**< IDs of calls that needs to be retried */
35
36 typedef enum {
37 gtlsDir_READ = 0, /**< GNUTLS wants READ */
38 gtlsDir_WRITE = 1 /**< GNUTLS wants WRITE */
39 } gtlsDirection_t;
40
41 typedef nsd_if_t nsd_gtls_if_t; /* we just *implement* this interface */
42
43 /* the nsd_gtls object */
44 struct nsd_gtls_s {
45 BEGINobjInstance
46 ; /* Data to implement generic object - MUST be the first data element! */
47 nsd_t *pTcp; /**< our aggregated nsd_ptcp data */
48 uchar *pszConnectHost; /**< hostname used for connect - may be used to
49 authenticate peer if no other name given */
50 const uchar *pszCAFile;
51 const uchar *pszCRLFile;
52 const uchar *pszKeyFile;
53 const uchar *pszCertFile;
54 gnutls_certificate_credentials_t xcred;
55 int xcred_is_copy;
56 int iMode; /* 0 - plain tcp, 1 - TLS */
57 int bAbortConn; /* if set, abort conncection (fatal error had happened) */
58 enum {
59 GTLS_AUTH_CERTNAME = 0,
60 GTLS_AUTH_CERTFINGERPRINT = 1,
61 GTLS_AUTH_CERTVALID = 2,
62 GTLS_AUTH_CERTANON = 3
63 } authMode;
64 enum { GTLS_EXPIRED_PERMIT = 0, GTLS_EXPIRED_DENY = 1, GTLS_EXPIRED_WARN = 2 } permitExpiredCerts;
65 enum { GTLS_NONE = 0, GTLS_PURPOSE = 1 } dataTypeCheck;
66 int bSANpriority; /* if true, we do stricter checking (if any SAN present we do not cehck CN) */
67 gtlsRtryCall_t rtryCall; /**< what must we retry? */
68 int bIsInitiator; /**< 0 if socket is the server end (listener), 1 if it is the initiator */
69 gnutls_session_t sess;
70 int bHaveSess; /* as we don't know exactly which gnutls_session values
71 are invalid, we use this one to flag whether or
72 not we are in a session (same as -1 for a socket
73 meaning no sess) */
74 int bReportAuthErr; /* only the first auth error is to be reported, this var triggers it. Initially, it is
75 * set to 1 and changed to 0 after the first report. It is changed back to 1 after
76 * one successful authentication. */
77 permittedPeers_t *pPermPeers; /* permitted peers */
78 uchar *gnutlsPriorityString; /* gnutls priority string */
79 uchar *remoteSNI; /**< Remote SNI to use instead of the server hostname */
80 int DrvrVerifyDepth; /* Verify Depth for certificate chains */
81 int DrvrTlsRevocationCheck; /**< Enable TLS revocation checking (OCSP/CRL) */
82 time_t crlNextUpdate; /**< cached CRL nextUpdate for per-connection expiration check (0 = not set) */
83 gnutls_x509_crt_t pOurCerts[NSD_GTLS_MAX_CERT]; /**< our certificate, if in client mode
84 (unused in server mode) */
85 unsigned int nOurCerts; /* number of certificates in our chain */
86 gnutls_x509_privkey_t ourKey; /**< our private key, if in client mode (unused in server mode) */
87 short bOurCertIsInit; /**< 1 if our certificate is initialized and must be deinit on destruction */
88 short bOurKeyIsInit; /**< 1 if our private key is initialized and must be deinit on destruction */
89 char *pszRcvBuf;
90 int lenRcvBuf;
91 /**< -1: empty, 0: connection closed, 1..NSD_GTLS_MAX_RCVBUF-1: data of that size present */
92 int ptrRcvBuf; /**< offset for next recv operation if 0 < lenRcvBuf < NSD_GTLS_MAX_RCVBUF */
93 };
94
95 /* interface is defined in nsd.h, we just implement it! */
96 #define nsd_gtlsCURR_IF_VERSION nsdCURR_IF_VERSION
97
98 /* prototypes */
99 PROTOTYPEObjFull(nsd_gtls);
100 /* some prototypes for things used by our nsdsel_gtls helper class */
101 uchar *gtlsStrerror(int error);
102 rsRetVal gtlsChkPeerAuth(nsd_gtls_t *pThis);
103 rsRetVal gtlsRecordRecv(nsd_gtls_t *pThis, unsigned *);
104
105 /* the name of our library binary */
106 #define LM_NSD_GTLS_FILENAME "lmnsd_gtls"
107
108 #if GNUTLS_VERSION_NUMBER <= 0x00030000
109 #define GTLS_ANON_PRIO_NOTLSV13 "NORMAL:-VERS-TLS1.3:+ANON-DH:+COMP-ALL"
110 #define GTLS_ANON_PRIO "NORMAL:+ANON-DH:+COMP-ALL"
111 #else
112 #define GTLS_ANON_PRIO_NOTLSV13 "NORMAL:-VERS-TLS1.3:+ANON-DH:+ANON-ECDH:+COMP-ALL"
113 #define GTLS_ANON_PRIO "NORMAL:+ANON-DH:+ANON-ECDH:+COMP-ALL"
114 #endif
115
116 #if GNUTLS_VERSION_MAJOR > 3 || (GNUTLS_VERSION_MAJOR == 3 && GNUTLS_VERSION_MINOR >= 4)
117 #define EXTENDED_CERT_CHECK_AVAILABLE
118 #endif
119
120 #endif /* #ifndef INCLUDED_NSD_GTLS_H */