Debian Codegraph @

runtime/nsd_ossl.h

raw
1 /* An implementation of the nsd interface for OpenSSL.
2 *
3 * Copyright 2018-2026 Adiscon GmbH.
4 * Author: Andre Lorbach
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_OSSL_H
24 #define INCLUDED_NSD_OSSL_H
25
26 #include "nsd.h"
27
28 #define NSD_OSSL_MAX_RCVBUF 16 * 1024 + 1 /* TLS RFC 8449: max size of buffer for message reception */
29
30 typedef enum {
31 osslRtry_None = 0, /**< no call needs to be retried */
32 osslRtry_handshake = 1,
33 osslRtry_recv = 2
34 } osslRtryCall_t; /**< IDs of calls that needs to be retried */
35
36 typedef nsd_if_t nsd_ossl_if_t; /* we just *implement* this interface */
37
38 /* the nsd_ossl object */
39 struct nsd_ossl_s {
40 BEGINobjInstance
41 ; /* Data to implement generic object - MUST be the first data element! */
42 nsd_t *pTcp; /**< our aggregated nsd_ptcp data */
43 uchar *pszConnectHost; /**< hostname used for connect - may be used to
44 authenticate peer if no other name given */
45 int iMode; /* 0 - plain tcp, 1 - TLS */
46 int bAbortConn; /* if set, abort conncection (fatal error had happened) */
47 PermitExpiredCerts permitExpiredCerts;
48 osslRtryCall_t rtryCall; /**< what must we retry? */
49 int rtryOsslErr; /**< store ssl error code into like SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE */
50 int bIsInitiator; /**< 0 if socket is the server end (listener), 1 if it is the initiator */
51 int bHaveSess; /* as we don't know exactly which gnutls_session values
52 are invalid, we use this one to flag whether or
53 not we are in a session (same as -1 for a socket
54 meaning no sess) */
55 uchar *gnutlsPriorityString; /* gnutls priority string */
56 int DrvrVerifyDepth; /* Verify Depth for certificate chains */
57 int DrvrTlsRevocationCheck; /* Enable TLS revocation checking (OCSP/CRL) */
58 uchar *remoteSNI; /**< Remote SNI to use instead of the server hostname */
59 short bOurCertIsInit; /**< 1 if our certificate is initialized and must be deinit on destruction */
60 short bOurKeyIsInit; /**< 1 if our private key is initialized and must be deinit on destruction */
61 char *pszRcvBuf;
62 int lenRcvBuf;
63 /**< -1: empty, 0: connection closed, 1..NSD_OSSL_MAX_RCVBUF-1: data of that size present */
64 int ptrRcvBuf; /**< offset for next recv operation if 0 < lenRcvBuf < NSD_OSSL_MAX_RCVBUF */
65
66 /* OpenSSL and Config Cert vars inside net_ossl_t now */
67 net_ossl_t *pNetOssl; /* OSSL shared Config and object vars are here */
68 };
69
70 /* interface is defined in nsd.h, we just implement it! */
71 #define nsd_osslCURR_IF_VERSION nsdCURR_IF_VERSION
72
73 /* prototypes */
74 PROTOTYPEObjFull(nsd_ossl);
75 /* some prototypes for things used by our nsdsel_ossl helper class */
76 uchar *osslStrerror(int error);
77 rsRetVal osslChkPeerAuth(nsd_ossl_t *pThis);
78 rsRetVal osslRecordRecv(nsd_ossl_t *pThis, unsigned *);
79 rsRetVal osslHandshakeCheck(nsd_ossl_t *pNsd);
80 void nsd_ossl_lastOpenSSLErrorMsg(
81 nsd_ossl_t const *pThis, const int ret, SSL *ssl, int severity, const char *pszCallSource, const char *pszOsslApi);
82 rsRetVal osslPostHandshakeCheck(nsd_ossl_t *pNsd);
83
84 /* the name of our library binary */
85 #define LM_NSD_OSSL_FILENAME "lmnsd_ossl"
86
87 #endif /* #ifndef INCLUDED_NSD_OSSL_H */