1771 Commits

Author SHA1 Message Date
Julian Brost
9b2c05d0cc VerifyCertificate: Work around issue in OpenSSL < 1.1.0 causing invalid certifcates being treated as valid
Old versions of OpenSSL stored a valid flag in the certificate (see inline code
comment for details) that if already set, causes parts of the verification to
be skipped and return that the certificate is valid, even if it's not actually
signed by the CA in the trust store.

This issue was assigned CVE-2025-48057.
2025-05-22 12:17:38 +02:00
Julian Brost
8cc83c0d6e VerifyCertificate: fix use after free
`X509_STORE_CTX_get_error(csc)` was called after `X509_STORE_CTX_free(csc)`.
This is fixed by automatically freeing variables at the end of the function
using `std::unique_ptr`.
2025-05-22 12:17:38 +02:00
Alexander A. Klimov
34c93a2542 CertificateToString(): allow raw pointer input 2025-05-22 12:17:38 +02:00
Julian Brost
0419a2c36d Security: fix TLS certificate validation bypass
The previous validation in set_verify_callback() could be bypassed, tricking
Icinga 2 into treating invalid certificates as valid. To fix this, the
validation checks were moved into the IsVerifyOK() function.

This is tracked as CVE-2024-49369, more details will be published at a later time.
2024-10-22 10:42:57 +02:00
Alexander A. Klimov
21bc188f59 Handle boost::beast::http::basic_fields#set() signature change (v1.81)
Make String convertible to boost::beast::string_view (always working),
not boost::string_view (broken).
2023-02-15 13:36:58 +01:00
Julian Brost
33a52d8655 Replace EventuallyAtomic with AtomicOrLocked which falls back to a mutex
Apparently there was a reason for making the members of generated classes
atomic. However, this was only done for some types, others were still accessed
using non-atomic operations. For members of type T::Ptr (i.e.  intrusive_ptr<T>),
this can result in a double free when multiple threads access the same variable
and at least one of them writes to the variable.

This commit makes use of std::atomic<T> for more T (it removes the additional
constraint sizeof(T) <= sizeof(void*)) and uses a type including a mutex for
load and store operations as a fallback.
2022-06-14 12:23:04 +02:00
Alexander A. Klimov
dba78f73da mkclass: make .ti class members atomic if possible
... not to have to lock the objects while setting attributes.
2022-06-14 12:23:04 +02:00
Julian Brost
372f8f3599
Merge pull request #9338 from Icinga/Al2Klimov-patch-3-212
Let new cluster certificates expire after 397 days, not 15 years
2022-04-12 09:50:37 +02:00
Alexander A. Klimov
97dce39699 Renew certificates also periodically 2022-04-11 12:45:58 +02:00
Alexander A. Klimov
913373fc38 Introduce IsCertUptodate() 2022-04-11 12:44:52 +02:00
Alexander A. Klimov
19ecb241f5 Let new cluster certificates expire after 397 days, not 15 years
https://cabforum.org/wp-content/uploads/CA-Browser-Forum-BR-1.7.3.pdf, section 6.3.2:

"Subscriber Certificates issued on or after 1 September 2020 SHOULD NOT have a Validity Period greater than 397 days and MUST NOT have a Validity Period greater than 398 days."
2022-04-11 12:44:52 +02:00
Julian Brost
c402baf088
Merge pull request #9326 from Icinga/bugfix/parallel-api-package-calls-do-not-finish-while-reload
Worker process doesn't let parallel API package stage updates to complete when terminated
2022-04-08 12:28:11 +02:00
Yonas Habteab
e3f14883e9 Defer: Allow to cancel the callback before going out of scope 2022-04-07 11:30:50 +02:00
Alexander Aleksandrovič Klimov
92e688b94a
Merge pull request #9320 from Icinga/boost1.78
Make compatible with Boost 1.78 (for Windows)
2022-04-06 16:38:33 +02:00
Alexander A. Klimov
1e0a0f7f9d Fix missing include 2022-04-06 12:44:49 +02:00
Yonas Habteab
7f9cbc8707 ConfigObject: Initialize local static var at declaration to ensure thread safety 2022-03-29 16:36:50 +02:00
Julian Brost
8910abc588 Enable hostname verification in UnbufferedAsioTlsStream 2021-08-17 16:33:18 +02:00
Julian Brost
d8ab328c33 Add comments to stack trace formatter and test case 2021-07-08 14:53:15 +02:00
Julian Brost
f5873a8e75 Use backtrace_symbols() when printing stack traces on FreeBSD
Unfortunately, the symbol resolution of boost::stacktrace is broken on
FreeBSD, therefore fall back to using backtrace_symbols() to print the
stack trace saved by Boost.

Additionally, -D_GNU_SOURCE is required on FreeBSD for the
_Unwind_Backtrace function used by boost::stacktrace.
2021-07-08 14:53:15 +02:00
Julian Brost
a2e5cfd34f Crash handlers: use more compact string representation 2021-07-08 14:53:15 +02:00
Julian Brost
2310cdb4fa Begin crash log for SIGABRT with error message and timestamp
This makes the format more similar to what the uncaught C++ and SEH
exception handlers write. Previously there was no indication in the
crash log that a SIGABRT happened.
2021-07-08 14:53:15 +02:00
Julian Brost
2330ab59f8 Add some comments to __cxa_throw
Maybe this will save the next person who has to look at this code some
time. Please don't blame me for the implementation, I'm just trying to
reconstruct what it does.
2021-07-08 14:53:15 +02:00
Julian Brost
9fcc781172 Restructure stack and context trace selection in DiagnosticInformation and document behavior
The logic for selecting the traces to print stays the same, but there
are fewer nested ifs now. This changes the format of the returned string
a bit by adding a heading for both traces.
2021-07-08 14:53:15 +02:00
Julian Brost
df59aa0087 Add documentation for cast_exception function 2021-07-08 14:53:15 +02:00
Julian Brost
996f280bfc Pass fallback stacktrace to DiagnosticInformation in terminate handler
By default, DiagnosticInformation uses the stack trace saved when the
exception was thrown, but this mechanism is not in use on Windows.
Gathering a stacktrace in the terminate handler serves as a fallback.
2021-07-08 14:53:15 +02:00
Julian Brost
8b2f4636db Replace icinga::StackTrace with boost::stacktrace::stacktrace
Provides roughly the same functionality but works better on certain
platforms (especially Windows) and is less code to maintain.
2021-07-08 14:53:15 +02:00
Julian Brost
4a29c39eba Print details in uncaught SEH exception handler 2021-07-08 14:53:15 +02:00
Julian Brost
8b67e4a637 Move error message and time to the beginning of the SEH crash log
This is more similar to the normal exception crashlog which also states
the problem and time at the beginning of the file.
2021-07-08 14:53:15 +02:00
Julian Brost
9ebd812da5 Use boost::stacktrace instead of custom implementation in Windows SEH filter 2021-07-08 14:53:15 +02:00
Julian Brost
b5017b78d7 Run termination handler for uncaught C++ exceptions on Windows
On Windows, the termination handler is executed for uncaught C++
exceptions unless a SEH unhandled exception filter is also set. In this
case, this filter has to explicitly chain the default filter to keep
this behavior.
2021-07-08 14:53:15 +02:00
Julian Brost
bdbe35b42d Utility: add a function to truncate strings while avoiding collisions 2021-07-05 16:18:57 +02:00
Julian Brost
d109dfcb78 Retry file rename operations on Windows for some errors 2021-05-25 15:57:41 +02:00
Julian Brost
cf4dd94b97 Provide a conversion function from icinga::String to boost::string_view
Boost.Beast changed the signature of
boost::beast::http::basic_fields::set in version 1.74 so that no longer
allows passing an icinga::String instance as value. This adds a
conversion function so that it works again.
2021-05-20 16:27:51 +02:00
Louis Sautier
04f4c132ff Fix ‘fs::copy_option’ has not been declared with boost 1.74.0
It was deprecated in
f199152b7d
2021-05-20 16:27:51 +02:00
Noah Hilverling
2cb995e937
Merge pull request from GHSA-pcmr-2p2f-r7j6
Verify certificates against CRL before renewing them (2.12)
2020-12-15 12:30:19 +01:00
Julian Brost
cae22a89da Verify certificates against CRL before renewing them
When a CRL is specified in the ApiListener configuration, Icinga 2 only
used it when connections were established so far, but not when a
certificate is requested. This allows a node to automatically renew a
revoked certificate if it meets the other conditions for auto-renewal
(issued before 2017 or expires in less than 30 days).
2020-12-15 10:33:38 +01:00
Julian Brost
c868010884 Use ERR_error_string_n() instead of ERR_error_string()
Explicitly pass the actual length of the buffer to avoid overflows.
2020-12-15 08:29:37 +01:00
Julian Brost
1f945add50 Increase size of buffer for OpenSSL error messages
According to man 3 ERR_error_string, "buf must be at least 256 bytes
long", therefore increase the buffer size to 256 everywhere.
2020-12-15 08:29:37 +01:00
Julian Brost
159ccced65 Remove std::string to_string(const errinfo_openssl_error& e)
The function was never used and it's implementation contains a bug where
a buffer of too small size is used as a paramter to ERR_error_string.
According to the `man 3 ERR_error_info`, the buffer has to be at least
256 bytes in size.

Also the function seems of limited use as it allows to output the tag
object used with additional error information for exceptions in Boost.
However, you boost::get_error_info<>() just returns the value type but
not the full tag object from the exception.
2020-12-15 08:29:37 +01:00
Julian Brost
e7d9c5138b Remove SpinLock
No longer needed as its only user now uses std::mutex.
2020-11-27 11:32:11 +01:00
Julian Brost
867a3c0216 Add Process::WaitForResult to allow waiting for the process to finish 2020-11-27 11:32:10 +01:00
Noah Hilverling
47a6daf341
Merge pull request #8293 from Icinga/bugfix/icinga2-doesn-t-close-connections-7203
Add timeout for boost::asio::ssl::stream#async_shutdown()
2020-10-14 09:44:12 +02:00
Alexander A. Klimov
639c426cf3 Introduce SpinLock 2020-10-13 17:45:37 +02:00
Henrik Triem
38eb2b6bc8 WorkQueue: Allow choosing stats log level 2020-09-22 14:41:11 +02:00
Alexander A. Klimov
d69c6879fa Application#RunEventLoop(): don't wait for the thread pool to stop on shutdown
refs #8173
2020-09-03 14:04:42 +02:00
Noah Hilverling
97fc70ccb2
Merge pull request #7836 from Icinga/bugfix/jsonrpcconnection-m_seen
Consider a JsonRpcConnection being seen on a single byte of TLS payload, not only a whole message
2020-07-29 15:02:48 +02:00
Alexander A. Klimov
647f1547a9 Generalize I/O timeout emulation 2020-06-17 10:31:40 +02:00
Noah Hilverling
df43cf573c
Merge pull request #8053 from Icinga/bugfix/segfault-map-reduce-filter-null-8047
Ensure the custom function is not null in Array#{sort,map,reduce,filter,any,all}()
2020-06-16 15:25:11 +02:00
Alexander A. Klimov
9c85401914 Ensure the custom function is not null in Array#{sort,map,reduce,filter,any,all}()
refs #8047
2020-06-09 12:35:04 +02:00
Alexander A. Klimov
f21b60e390 StreamLogger#Flush(): lock self
... just to be sure.
2020-05-15 15:33:37 +02:00