Debian Codegraph @

runtime/nsd_mbedtls.h

raw
1 /* An implementation of the nsd interface for Mbed TLS.
2 *
3 * Copyright 2008-2021 Adiscon GmbH.
4 * Copyright (C) 2023 CS Group.
5 *
6 * This file is part of the rsyslog runtime library.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 * -or-
14 * see COPYING.ASL20 in the source distribution
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22
23 #ifndef INCLUDED_NSD_MBEDTLS_H
24 #define INCLUDED_NSD_MBEDTLS_H
25
26 #include <mbedtls/net_sockets.h>
27 #include <mbedtls/entropy.h>
28 #include <mbedtls/ctr_drbg.h>
29 #include <mbedtls/ssl.h>
30 #include <mbedtls/x509_crt.h>
31
32 #include "nsd.h"
33
34 typedef nsd_if_t nsd_mbedtls_if_t; /* we just *implement* this interface */
35
36 /* the nsd_mbedtls object */
37 struct nsd_mbedtls_s {
38 BEGINobjInstance
39 ; /* Data to implement generic object - MUST be the first data element! */
40 nsd_t *pTcp; /**< our aggregated nsd_ptcp data */
41 uchar *pszConnectHost; /**< hostname used for connect - may be used to
42 authenticate peer if no other name given */
43 const uchar *pszCAFile;
44 const uchar *pszCRLFile;
45 const uchar *pszKeyFile;
46 const uchar *pszCertFile;
47 int iMode; /* 0 - plain tcp, 1 - TLS */
48 int bAbortConn; /* if set, abort conncection (fatal error had happened) */
49 enum {
50 MBEDTLS_AUTH_CERTNAME = 0,
51 MBEDTLS_AUTH_CERTFINGERPRINT = 1,
52 MBEDTLS_AUTH_CERTVALID = 2,
53 MBEDTLS_AUTH_CERTANON = 3
54 } authMode;
55 enum {
56 MBEDTLS_EXPIRED_PERMIT = 0,
57 MBEDTLS_EXPIRED_DENY = 1,
58 MBEDTLS_EXPIRED_WARN = 2,
59 } permitExpiredCerts;
60 enum { MBEDTLS_NONE = 0, MBEDTLS_PURPOSE = 1 } dataTypeCheck;
61 int bHaveSess; /* true if a tls session is active */
62 int DrvrVerifyDepth; /* Verify Depth for certificate chains */
63 int DrvrTlsRevocationCheck; /**< Enable TLS revocation checking (OCSP/CRL) */
64 permittedPeers_t *pPermPeers; /* permitted peers */
65 int *anzCipherSuites; /* array of cipher suites (IANA ids) in decreasing priority order (0-terminated) */
66 int bSANpriority; /* if true, we do stricter checking (if any SAN present we do not check CN) */
67 int bReportAuthErr; /* only the first auth error is to be reported, this var triggers it. Initially, it is
68 * set to 1 and changed to 0 after the first report. It is changed back to 1 after
69 * one successful authentication. */
70 int sock;
71
72 mbedtls_entropy_context entropy;
73 mbedtls_ctr_drbg_context ctr_drbg;
74 mbedtls_ssl_context ssl;
75 mbedtls_ssl_config conf;
76 int bHaveCaCert;
77 mbedtls_x509_crt cacert;
78 int bHaveCrl;
79 mbedtls_x509_crl crl;
80 int bHaveKey;
81 mbedtls_pk_context pkey;
82 int bHaveCert;
83 mbedtls_x509_crt srvcert;
84 };
85
86 /* interface is defined in nsd.h, we just implement it! */
87 #define nsd_mbedtlsCURR_IF_VERSION nsdCURR_IF_VERSION
88
89 /* prototypes */
90 PROTOTYPEObjFull(nsd_mbedtls);
91
92 /* the name of our library binary */
93 #define LM_NSD_MBEDTLS_FILENAME "lmnsd_mbedtls"
94
95 #endif /* #ifndef INCLUDED_NSD_MBEDTLS_H */