Fix Botan 3 build (#9388)

* SymmetricCipher: Fix Botan 3 build

Botan commit 819cf8fe6278a19b8266f449228f02fc28a4f784 changed
Botan::Cipher_Dir to be a scoped enumeration, so the users
must be adapted.

This change causes no issues with Botan 2 because normal
enumeration values can also be referred to the same way
scoped enumeration values are accessed.

* Auto detect Botan3

* AsyncTask: Do not use `std::result_of`

`std::result_of` was deprecated in C++17 and then it was
subsequently removed in C++20. One could use `std::invoke_result_t`,
but let Qt figure out the return type instead.

* Collapse Botan2 and Botan3 find package into one

* Update COPYING

---------

Co-authored-by: Jonathan White <support@dmapps.us>
This commit is contained in:
Barnabás Pőcze 2023-05-07 14:48:58 +02:00 committed by GitHub
parent cf819e0a3f
commit 16b3d32ca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 94 additions and 259 deletions

View file

@ -14,7 +14,6 @@
#cmakedefine WITH_XC_AUTOTYPE
#cmakedefine WITH_XC_NETWORKING
#cmakedefine KPXC_DEV_BOTAN3
#cmakedefine WITH_XC_BROWSER
#cmakedefine WITH_XC_YUBIKEY
#cmakedefine WITH_XC_SSHAGENT
@ -23,6 +22,7 @@
#cmakedefine WITH_XC_FDOSECRETS
#cmakedefine WITH_XC_DOCS
#cmakedefine WITH_XC_X11
#cmakedefine WITH_XC_BOTAN3
#cmakedefine KEEPASSXC_BUILD_TYPE "@KEEPASSXC_BUILD_TYPE@"
#cmakedefine KEEPASSXC_BUILD_TYPE_RELEASE

View file

@ -33,12 +33,10 @@ namespace AsyncTask
* @param future future to wait for
* @return async task result
*/
template <typename FunctionObject>
typename std::result_of<FunctionObject()>::type
waitForFuture(QFuture<typename std::result_of<FunctionObject()>::type> future)
template <typename T> T waitForFuture(QFuture<T> future)
{
QEventLoop loop;
QFutureWatcher<typename std::result_of<FunctionObject()>::type> watcher;
QFutureWatcher<T> watcher;
QObject::connect(&watcher, SIGNAL(finished()), &loop, SLOT(quit()));
watcher.setFuture(future);
loop.exec();
@ -51,10 +49,9 @@ namespace AsyncTask
* @param task std::function object to run
* @return async task result
*/
template <typename FunctionObject>
typename std::result_of<FunctionObject()>::type runAndWaitForFuture(FunctionObject task)
template <typename FunctionObject> decltype(auto) runAndWaitForFuture(FunctionObject task)
{
return waitForFuture<FunctionObject>(QtConcurrent::run(task));
return waitForFuture(QtConcurrent::run(task));
}
/**
@ -69,9 +66,8 @@ namespace AsyncTask
template <typename FunctionObject, typename FunctionObject2>
void runThenCallback(FunctionObject task, QObject* context, FunctionObject2 callback)
{
typedef QFutureWatcher<typename std::result_of<FunctionObject()>::type> FutureWatcher;
auto future = QtConcurrent::run(task);
auto watcher = new FutureWatcher(context);
auto watcher = new QFutureWatcher<decltype(future.result())>(context);
QObject::connect(watcher, &QFutureWatcherBase::finished, context, [=]() {
watcher->deleteLater();
callback(future.result());

View file

@ -239,7 +239,7 @@ namespace Crypto
{
bool init()
{
#ifdef KPXC_DEV_BOTAN3
#ifdef WITH_XC_BOTAN3
unsigned int version_major = 3, min_version_minor = 0;
QString versionString = "3.x";
#else

View file

@ -33,7 +33,8 @@ bool SymmetricCipher::init(Mode mode, Direction direction, const QByteArray& key
try {
auto botanMode = modeToString(mode);
auto botanDirection = (direction == SymmetricCipher::Encrypt ? Botan::ENCRYPTION : Botan::DECRYPTION);
auto botanDirection =
(direction == SymmetricCipher::Encrypt ? Botan::Cipher_Dir::ENCRYPTION : Botan::Cipher_Dir::DECRYPTION);
auto cipher = Botan::Cipher_Mode::create_or_throw(botanMode.toStdString(), botanDirection);
m_cipher.reset(cipher.release());

View file

@ -25,7 +25,7 @@
#include <QDebug>
#include <botan/dh.h>
#ifdef KPXC_DEV_BOTAN3
#ifdef WITH_XC_BOTAN3
#include <botan/pubkey.h>
#else
#include <botan/pk_ops.h>
@ -57,7 +57,7 @@ namespace FdoSecrets
try {
Botan::secure_vector<uint8_t> salt(32, '\0');
#ifdef KPXC_DEV_BOTAN3
#ifdef WITH_XC_BOTAN3
Botan::PK_Key_Agreement dhka(*m_privateKey, *randomGen()->getRng(), "HKDF(SHA-256)", "");
auto aesKey = dhka.derive_key(16,
reinterpret_cast<const uint8_t*>(clientPublicKey.constData()),