File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed
Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ add_library(tcp-input MODULE
1515 src/IpxPlugin.cpp
1616 src/tls/Ssl.cpp
1717 src/tls/TlsDecoder.cpp
18+ src/tls/DecoderFactory.cpp
1819)
1920
2021if (CMAKE_HOST_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_HOST_SYSTEM_NAME STREQUAL "OpenBSD" )
Original file line number Diff line number Diff line change 1+ /* *
2+ * \file
3+ * \author Jakub Antonín Štigler <[email protected] > 4+ * \brief Factory for tls connections. (source file)
5+ * \date 2025
6+ *
7+ * Copyright: (C) 2023 CESNET, z.s.p.o.
8+ * SPDX-License-Identifier: BSD-3-Clause
9+ */
10+
11+ #include " DecoderFactory.hpp"
12+
13+ #include " TlsDecoder.hpp"
14+
15+ namespace tcp_in {
16+ namespace tls {
17+
18+ DecoderFactory::DecoderFactory (const std::string &cert_path) : m_ctx(TLS_server_method()) {
19+ // Cache configuration
20+ constexpr std::chrono::seconds CACHE_TIMEOUT (3600 );
21+ const std::string cache_id = " ipfixcol2" ;
22+ constexpr std::size_t CACHE_SIZE = 1024 ;
23+
24+ m_ctx.set_min_proto_version (TLS1_2_VERSION);
25+ m_ctx.set_options (
26+ SSL_OP_IGNORE_UNEXPECTED_EOF | SSL_OP_NO_RENEGOTIATION | SSL_OP_CIPHER_SERVER_PREFERENCE
27+ );
28+
29+ m_ctx.use_certificate_chain_file (cert_path.c_str ());
30+ m_ctx.use_private_key_file (cert_path.c_str (), SSL_FILETYPE_PEM);
31+
32+ m_ctx.set_session_id_context (cache_id.data (), unsigned (cache_id.size ()));
33+ m_ctx.set_session_cache_mode (SSL_SESS_CACHE_SERVER);
34+ m_ctx.sess_set_cache_size (CACHE_SIZE);
35+ m_ctx.sess_set_timeout (CACHE_TIMEOUT);
36+
37+ // Don't verify peer. Servers usually don't verify clients, but maybe we want to verify clients?
38+ m_ctx.set_verify (SSL_VERIFY_NONE);
39+ }
40+
41+ std::unique_ptr<Decoder> DecoderFactory::create (int fd) {
42+ return std::unique_ptr<Decoder>(new TlsDecoder (m_ctx, fd));
43+ }
44+
45+ } // namespace tls
46+ } // namespace tcp_in
Original file line number Diff line number Diff line change 1+ /* *
2+ * \file
3+ * \author Jakub Antonín Štigler <[email protected] > 4+ * \brief Factory for tls connections. (header file)
5+ * \date 2025
6+ *
7+ * Copyright: (C) 2023 CESNET, z.s.p.o.
8+ * SPDX-License-Identifier: BSD-3-Clause
9+ */
10+
11+ #pragma once
12+
13+ #include " ../Decoder.hpp"
14+ #include " SslCtx.hpp"
15+
16+ namespace tcp_in {
17+ namespace tls {
18+
19+ /* * Factory for `TlsDecoder`s. Holds shared data. */
20+ class DecoderFactory {
21+ public:
22+ /* *
23+ * @brief Create new tls decoder factory using certificate and private key in the given file.
24+ * Note that this may prompt the user for password.
25+ */
26+ DecoderFactory (const std::string &cert_path);
27+
28+ /* * Create new tls decoder. */
29+ std::unique_ptr<Decoder> create (int fd);
30+
31+ private:
32+ SslCtx m_ctx;
33+ };
34+
35+ } // namespace tls
36+ } // namespace tcp_in
37+
You can’t perform that action at this time.
0 commit comments