Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cmake-linux-fedora.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
container: fedora:${{ matrix.container }}
strategy:
matrix:
container: [41, 42, 43]
container: [42, 43]

steps:
- name: Install Deps
run: dnf install -y --setopt=install_weak_deps=False git gcc-c++ cmake rpm-build openssl-devel pcsc-lite-devel qt6-qtsvg-devel qt6-qttools-devel gtest-devel

- uses: actions/checkout@v4
- uses: actions/checkout@v5
with:
submodules: recursive

Expand Down
1 change: 0 additions & 1 deletion src/controller/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ add_library(controller STATIC
logging.cpp
logging.hpp
qeid.hpp
retriableerror.cpp
retriableerror.hpp
threads/cardeventmonitorthread.hpp
threads/commandhandlerconfirmthread.hpp
Expand Down
4 changes: 2 additions & 2 deletions src/controller/commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "commands.hpp"

#include "magic_enum/magic_enum.hpp"
#include <QMetaEnum>

#include <stdexcept>
#include <map>
Expand Down Expand Up @@ -51,5 +51,5 @@ CommandType commandNameToCommandType(const QString& cmdName)

CommandType::operator std::string() const
{
return std::string(magic_enum::enum_name(value));
return QMetaEnum::fromType<CommandType::CommandTypeEnum>().valueToKey(value);
}
16 changes: 8 additions & 8 deletions src/controller/commands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@

class CommandType
{
Q_GADGET
public:
enum CommandTypeEnum {
enum CommandTypeEnum : quint8 {
NONE,
INSERT_CARD,
GET_SIGNING_CERTIFICATE,
AUTHENTICATE,
SIGN,
QUIT,
ABOUT,
NONE = -1
};
Q_ENUM(CommandTypeEnum)

CommandType() = default;
constexpr CommandType(const CommandTypeEnum _value) : value(_value) {}
constexpr CommandType(CommandTypeEnum _value = NONE) noexcept : value(_value) {}

constexpr bool operator==(CommandTypeEnum other) const { return value == other; }
constexpr bool operator!=(CommandTypeEnum other) const { return value != other; }
constexpr operator CommandTypeEnum() const { return value; }
constexpr bool operator==(CommandTypeEnum other) const noexcept { return value == other; }
constexpr operator CommandTypeEnum() const noexcept { return value; }

operator std::string() const;

private:
CommandTypeEnum value = NONE;
CommandTypeEnum value;
};

extern const QString CMDLINE_GET_SIGNING_CERTIFICATE;
Expand Down
5 changes: 2 additions & 3 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ void Controller::onCommandHandlerConfirmCompleted(const QVariantMap& res)
_result = res;
writeResponseToStdOut(isInStdinMode, res, commandHandler->commandType());
} catch (const std::exception& error) {
qCritical() << "Command" << std::string(commandType())
qCritical() << "Command" << commandType()
<< "fatal error while writing response to stdout:" << error;
}

Expand Down Expand Up @@ -288,8 +288,7 @@ void Controller::onDialogCancel()
void Controller::onCriticalFailure(const QString& error)
{
emit stopCardEventMonitorThread();
qCritical() << "Exiting due to command" << std::string(commandType())
<< "fatal error:" << error;
qCritical() << "Exiting due to command" << commandType() << "fatal error:" << error;
_result =
makeErrorObject(RESP_TECH_ERROR, QStringLiteral("Technical error, see application logs"));
disposeUI();
Expand Down
14 changes: 5 additions & 9 deletions src/controller/logging.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@

void setupLogging();

inline QDebug operator<<(QDebug out, const std::string& s)
#if QT_VERSION < QT_VERSION_CHECK(6, 5, 0)
template <typename...Args>
inline QDebug operator<<(QDebug out, const std::basic_string<char, Args...> &s)
{
out << QString::fromStdString(s);
return out;
}

inline QDebug operator<<(QDebug out, const std::wstring& s)
{
out << QString::fromStdWString(s);
return out;
return out << QUtf8StringView(s);
}
#endif

inline QDebug operator<<(QDebug out, const std::exception& e)
{
Expand Down
50 changes: 0 additions & 50 deletions src/controller/retriableerror.cpp

This file was deleted.

167 changes: 88 additions & 79 deletions src/controller/retriableerror.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,92 +26,101 @@
#include "pcsc-cpp/pcsc-cpp-utils.hpp"

#include <QMetaType>
#include <QDebug>

enum class RetriableError {
// libpcsc-cpp
SMART_CARD_SERVICE_IS_NOT_RUNNING,
NO_SMART_CARD_READERS_FOUND,
NO_SMART_CARDS_FOUND,
FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER,
SMART_CARD_WAS_REMOVED,
SMART_CARD_TRANSACTION_FAILED,
SCARD_ERROR,
// libelectronic-id
SMART_CARD_CHANGE_REQUIRED,
SMART_CARD_COMMAND_ERROR,
PKCS11_TOKEN_NOT_PRESENT,
PKCS11_TOKEN_REMOVED,
PKCS11_ERROR,
// AutoSelectFailed::Reason
UNSUPPORTED_CARD,
// CertificateReader::run
NO_VALID_CERTIFICATE_AVAILABLE,
PIN_VERIFY_DISABLED,
// default
UNKNOWN_ERROR
};

Q_DECLARE_METATYPE(RetriableError)
class RetriableError
{
Q_GADGET
public:
enum Error : quint8 {
// default
UNKNOWN_ERROR,
// libpcsc-cpp
SMART_CARD_SERVICE_IS_NOT_RUNNING,
NO_SMART_CARD_READERS_FOUND,
NO_SMART_CARDS_FOUND,
FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER,
SMART_CARD_WAS_REMOVED,
SMART_CARD_TRANSACTION_FAILED,
SCARD_ERROR,
// libelectronic-id
SMART_CARD_CHANGE_REQUIRED,
SMART_CARD_COMMAND_ERROR,
PKCS11_TOKEN_NOT_PRESENT,
PKCS11_TOKEN_REMOVED,
PKCS11_ERROR,
// AutoSelectFailed::Reason
UNSUPPORTED_CARD,
// CertificateReader::run
NO_VALID_CERTIFICATE_AVAILABLE,
PIN_VERIFY_DISABLED,
};
Q_ENUM(Error)

QDebug& operator<<(QDebug& d, const RetriableError);

RetriableError toRetriableError(const electronic_id::AutoSelectFailed::Reason reason);
constexpr RetriableError(Error error = UNKNOWN_ERROR) : value(error) {}
constexpr explicit RetriableError(const electronic_id::AutoSelectFailed::Reason reason)
{
switch (reason) {
using enum electronic_id::AutoSelectFailed::Reason;
case SERVICE_NOT_RUNNING:
value = SMART_CARD_SERVICE_IS_NOT_RUNNING;
break;
case NO_READERS:
value = NO_SMART_CARD_READERS_FOUND;
break;
case SINGLE_READER_NO_CARD:
case MULTIPLE_READERS_NO_CARD:
value = NO_SMART_CARDS_FOUND;
break;
case SINGLE_READER_UNSUPPORTED_CARD:
case MULTIPLE_READERS_NO_SUPPORTED_CARD:
value = UNSUPPORTED_CARD;
break;
default:
value = UNKNOWN_ERROR;
}
}

// Define retriable error handling in one place so that it can be reused.
constexpr operator Error() const { return value; }

#define CATCH_PCSC_CPP_RETRIABLE_ERRORS(ERROR_HANDLER) \
catch (const pcsc_cpp::ScardServiceNotRunningError& error) \
{ \
ERROR_HANDLER(RetriableError::SMART_CARD_SERVICE_IS_NOT_RUNNING, error); \
} \
catch (const pcsc_cpp::ScardNoReadersError& error) \
{ \
ERROR_HANDLER(RetriableError::NO_SMART_CARD_READERS_FOUND, error); \
} \
catch (const pcsc_cpp::ScardNoCardError& error) \
{ \
ERROR_HANDLER(RetriableError::NO_SMART_CARDS_FOUND, error); \
} \
catch (const pcsc_cpp::ScardCardCommunicationFailedError& error) \
{ \
ERROR_HANDLER(RetriableError::FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER, error); \
} \
catch (const pcsc_cpp::ScardCardRemovedError& error) \
{ \
ERROR_HANDLER(RetriableError::SMART_CARD_WAS_REMOVED, error); \
} \
catch (const pcsc_cpp::ScardTransactionFailedError& error) \
{ \
ERROR_HANDLER(RetriableError::SMART_CARD_TRANSACTION_FAILED, error); \
} \
catch (const pcsc_cpp::ScardError& error) \
{ \
ERROR_HANDLER(RetriableError::SCARD_ERROR, error); \
static RetriableError catchRetriableError()
{
try {
throw;
} catch (const pcsc_cpp::ScardServiceNotRunningError& /*error*/) {
return SMART_CARD_SERVICE_IS_NOT_RUNNING;
} catch (const pcsc_cpp::ScardNoReadersError& /*error*/) {
return NO_SMART_CARD_READERS_FOUND;
} catch (const pcsc_cpp::ScardNoCardError& /*error*/) {
return NO_SMART_CARDS_FOUND;
} catch (const pcsc_cpp::ScardCardCommunicationFailedError& /*error*/) {
return FAILED_TO_COMMUNICATE_WITH_CARD_OR_READER;
} catch (const pcsc_cpp::ScardCardRemovedError& /*error*/) {
return SMART_CARD_WAS_REMOVED;
} catch (const pcsc_cpp::ScardTransactionFailedError& /*error*/) {
return SMART_CARD_TRANSACTION_FAILED;
} catch (const pcsc_cpp::ScardError& /*error*/) {
return SCARD_ERROR;
} catch (const electronic_id::SmartCardChangeRequiredError& /*error*/) {
return SMART_CARD_CHANGE_REQUIRED;
} catch (const electronic_id::SmartCardError& /*error*/) {
return SMART_CARD_COMMAND_ERROR;
} catch (const electronic_id::Pkcs11TokenNotPresent& /*error*/) {
return PKCS11_TOKEN_NOT_PRESENT;
} catch (const electronic_id::Pkcs11TokenRemoved& /*error*/) {
return PKCS11_TOKEN_REMOVED;
} catch (const electronic_id::Pkcs11Error& /*error*/) {
return PKCS11_ERROR;
} catch (...) {
return UNKNOWN_ERROR;
}
}

#define CATCH_LIBELECTRONIC_ID_RETRIABLE_ERRORS(ERROR_HANDLER) \
catch (const electronic_id::SmartCardChangeRequiredError& error) \
{ \
ERROR_HANDLER(RetriableError::SMART_CARD_CHANGE_REQUIRED, error); \
} \
catch (const electronic_id::SmartCardError& error) \
{ \
ERROR_HANDLER(RetriableError::SMART_CARD_COMMAND_ERROR, error); \
} \
catch (const electronic_id::Pkcs11TokenNotPresent& error) \
{ \
ERROR_HANDLER(RetriableError::PKCS11_TOKEN_NOT_PRESENT, error); \
} \
catch (const electronic_id::Pkcs11TokenRemoved& error) \
{ \
ERROR_HANDLER(RetriableError::PKCS11_TOKEN_REMOVED, error); \
} \
catch (const electronic_id::Pkcs11Error& error) \
{ \
ERROR_HANDLER(RetriableError::PKCS11_ERROR, error); \
}
private:
Error value;
};

#define WARN_RETRIABLE_ERROR(commandType, errorCode, error) \
qWarning().nospace() << "Command " << commandType << " retriable error " << errorCode << ": " \
<< error

Q_DECLARE_METATYPE(RetriableError)
Loading