From 7de7ebd0e558a0982469998e7188449346110b97 Mon Sep 17 00:00:00 2001 From: Raul Metsma Date: Fri, 7 Feb 2025 09:07:40 +0200 Subject: [PATCH] Remove CardInfo Signed-off-by: Raul Metsma --- lib/libelectronic-id | 2 +- src/app/main.cpp | 2 ++ src/controller/application.cpp | 4 ++-- src/controller/certandpininfo.hpp | 2 +- .../command-handlers/authenticate.cpp | 8 ++++---- .../command-handlers/certificatereader.cpp | 18 +++++++++--------- .../command-handlers/certificatereader.hpp | 2 +- .../command-handlers/getcertificate.cpp | 2 +- src/controller/command-handlers/sign.cpp | 13 ++++++------- src/controller/commandhandler.hpp | 2 +- src/controller/controller.cpp | 9 +++++---- src/controller/controller.hpp | 4 ++-- src/controller/inputoutputmode.cpp | 2 ++ src/controller/qeid.hpp | 4 ++-- .../threads/cardeventmonitorthread.hpp | 17 ++++++++--------- .../threads/commandhandlerconfirmthread.hpp | 2 +- .../threads/commandhandlerrunthread.hpp | 4 ++-- src/controller/threads/waitforcardthread.hpp | 2 +- src/controller/writeresponse.cpp | 2 ++ src/mac/main.mm | 2 ++ src/ui/webeiddialog.cpp | 4 ++-- 21 files changed, 57 insertions(+), 50 deletions(-) diff --git a/lib/libelectronic-id b/lib/libelectronic-id index f47fc152..2b92f7ed 160000 --- a/lib/libelectronic-id +++ b/lib/libelectronic-id @@ -1 +1 @@ -Subproject commit f47fc15265f9864eececcde85d0b246bac240aa3 +Subproject commit 2b92f7ed13c6db00636a0d6dc886f28ee43e2fb7 diff --git a/src/app/main.cpp b/src/app/main.cpp index 3658f4c7..f7a8f31c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -26,6 +26,8 @@ #include +#include + int main(int argc, char* argv[]) { Q_INIT_RESOURCE(web_eid_resources); diff --git a/src/controller/application.cpp b/src/controller/application.cpp index 2832cdf9..e454cc19 100644 --- a/src/controller/application.cpp +++ b/src/controller/application.cpp @@ -185,8 +185,8 @@ CommandWithArgumentsPtr Application::parseArgs() void Application::registerMetatypes() { qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType>(); + qRegisterMetaType(); + qRegisterMetaType>(); qRegisterMetaType(); qRegisterMetaType(); diff --git a/src/controller/certandpininfo.hpp b/src/controller/certandpininfo.hpp index e3a659a5..257fb490 100644 --- a/src/controller/certandpininfo.hpp +++ b/src/controller/certandpininfo.hpp @@ -50,7 +50,7 @@ struct PinInfo struct CardCertificateAndPinInfo { - electronic_id::CardInfo::ptr cardInfo; + electronic_id::ElectronicID::ptr cardInfo; QByteArray certificateBytesInDer; QSslCertificate certificate {}; CertificateInfo certInfo; diff --git a/src/controller/command-handlers/authenticate.cpp b/src/controller/command-handlers/authenticate.cpp index 904d30d1..589ba12c 100644 --- a/src/controller/command-handlers/authenticate.cpp +++ b/src/controller/command-handlers/authenticate.cpp @@ -122,15 +122,15 @@ QVariantMap Authenticate::onConfirm(WebEidUI* window, { try { const auto signatureAlgorithm = - QString::fromStdString(cardCertAndPin.cardInfo->eid().authSignatureAlgorithm()); + QString::fromStdString(cardCertAndPin.cardInfo->authSignatureAlgorithm()); pcsc_cpp::byte_vector pin; // Reserve space for APDU overhead (5 bytes) + PIN padding (16 bytes) to prevent PIN memory // reallocation. The 16-byte limit comes from the max PIN length of 12 bytes across all card // implementations in lib/libelectronic-id/src/electronic-ids/pcsc/. pin.reserve(5 + 16); - getPin(pin, cardCertAndPin.cardInfo->eid(), window); - const auto signature = createSignature(origin.url(), challengeNonce, - cardCertAndPin.cardInfo->eid(), std::move(pin)); + getPin(pin, *cardCertAndPin.cardInfo, window); + const auto signature = + createSignature(origin.url(), challengeNonce, *cardCertAndPin.cardInfo, std::move(pin)); return createAuthenticationToken(signatureAlgorithm, cardCertAndPin.certificateBytesInDer, signature); diff --git a/src/controller/command-handlers/certificatereader.cpp b/src/controller/command-handlers/certificatereader.cpp index e48f2722..4f423285 100644 --- a/src/controller/command-handlers/certificatereader.cpp +++ b/src/controller/command-handlers/certificatereader.cpp @@ -31,17 +31,17 @@ using namespace electronic_id; namespace { -CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const CardInfo::ptr& card, +CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const ElectronicID::ptr& card, const CertificateType certificateType) { - const auto certificateBytes = card->eid().getCertificate(certificateType); + const auto certificateBytes = card->getCertificate(certificateType); QByteArray certificateDer(reinterpret_cast(certificateBytes.data()), int(certificateBytes.size())); QSslCertificate certificate(certificateDer, QSsl::Der); if (certificate.isNull()) { THROW(SmartCardChangeRequiredError, - "Invalid certificate returned by electronic ID " + card->eid().name()); + "Invalid certificate returned by electronic ID " + card->name()); } auto subject = certificate.subjectInfo(QSslCertificate::CommonName).join(' '); @@ -61,11 +61,11 @@ CardCertificateAndPinInfo getCertificateWithStatusAndInfo(const CardInfo::ptr& c CertificateInfo certInfo { certificateType, certificate.expiryDate() < QDateTime::currentDateTimeUtc(), certificate.effectiveDate() > QDateTime::currentDateTimeUtc(), std::move(subject)}; - PinInfo pinInfo {certificateType.isAuthentication() ? card->eid().authPinMinMaxLength() - : card->eid().signingPinMinMaxLength(), - certificateType.isAuthentication() ? card->eid().authPinRetriesLeft() - : card->eid().signingPinRetriesLeft(), - card->eid().smartcard().readerHasPinPad()}; + PinInfo pinInfo {certificateType.isAuthentication() ? card->authPinMinMaxLength() + : card->signingPinMinMaxLength(), + certificateType.isAuthentication() ? card->authPinRetriesLeft() + : card->signingPinRetriesLeft(), + card->smartcard().readerHasPinPad()}; if (pinInfo.pinRetriesCount.first == 0) { pinInfo.pinIsBlocked = true; } @@ -83,7 +83,7 @@ CertificateReader::CertificateReader(const CommandWithArguments& cmd) : CommandH } } -void CertificateReader::run(const std::vector& cards) +void CertificateReader::run(const std::vector& cards) { REQUIRE_NOT_EMPTY_CONTAINS_NON_NULL_PTRS(cards) diff --git a/src/controller/command-handlers/certificatereader.hpp b/src/controller/command-handlers/certificatereader.hpp index 8d006c8c..0ba5ffd8 100644 --- a/src/controller/command-handlers/certificatereader.hpp +++ b/src/controller/command-handlers/certificatereader.hpp @@ -33,7 +33,7 @@ class CertificateReader : public CommandHandler public: explicit CertificateReader(const CommandWithArguments& cmd); - void run(const std::vector& cards) override; + void run(const std::vector& cards) override; void connectSignals(const WebEidUI* window) override; protected: diff --git a/src/controller/command-handlers/getcertificate.cpp b/src/controller/command-handlers/getcertificate.cpp index f51a168a..461bb2de 100644 --- a/src/controller/command-handlers/getcertificate.cpp +++ b/src/controller/command-handlers/getcertificate.cpp @@ -53,6 +53,6 @@ QVariantMap GetCertificate::onConfirm(WebEidUI* /* window */, // Each string in the array is a Base64-encoded (Section 4 of [RFC4648] -- not // Base64url-encoded) DER [ITU.X690.2008] PKIX certificate value. auto certPem = cardCertAndPin.certificateBytesInDer.toBase64(); - auto algos = supportedSigningAlgos(cardCertAndPin.cardInfo->eid()); + auto algos = supportedSigningAlgos(*cardCertAndPin.cardInfo); return {{"certificate", QString(certPem)}, {"supportedSignatureAlgorithms", algos}}; } diff --git a/src/controller/command-handlers/sign.cpp b/src/controller/command-handlers/sign.cpp index 28736cfd..c703d98e 100644 --- a/src/controller/command-handlers/sign.cpp +++ b/src/controller/command-handlers/sign.cpp @@ -86,9 +86,9 @@ void Sign::emitCertificatesReady(const std::vector& c return; } - if (!cardWithCertificateFromArgs->cardInfo->eid().isSupportedSigningHashAlgorithm(hashAlgo)) { + if (!cardWithCertificateFromArgs->cardInfo->isSupportedSigningHashAlgorithm(hashAlgo)) { THROW(ArgumentFatalError, - "Electronic ID " + cardWithCertificateFromArgs->cardInfo->eid().name() + "Electronic ID " + cardWithCertificateFromArgs->cardInfo->name() + " does not support hash algorithm " + std::string(hashAlgo)); } @@ -103,11 +103,10 @@ QVariantMap Sign::onConfirm(WebEidUI* window, const CardCertificateAndPinInfo& c // reallocation. The 16-byte limit comes from the max PIN length of 12 bytes across all card // implementations in lib/libelectronic-id/src/electronic-ids/pcsc/. pin.reserve(5 + 16); - getPin(pin, cardCertAndPin.cardInfo->eid(), window); - const auto signature = - signHash(cardCertAndPin.cardInfo->eid(), std::move(pin), docHash, hashAlgo); - return {{QStringLiteral("signature"), signature.first}, - {QStringLiteral("signatureAlgorithm"), signature.second}}; + getPin(pin, *cardCertAndPin.cardInfo, window); + auto signature = signHash(*cardCertAndPin.cardInfo, std::move(pin), docHash, hashAlgo); + return {{QStringLiteral("signature"), std::move(signature.first)}, + {QStringLiteral("signatureAlgorithm"), std::move(signature.second)}}; } catch (const VerifyPinFailed& failure) { switch (failure.status()) { diff --git a/src/controller/commandhandler.hpp b/src/controller/commandhandler.hpp index b1b04608..d7b80513 100644 --- a/src/controller/commandhandler.hpp +++ b/src/controller/commandhandler.hpp @@ -33,7 +33,7 @@ class CommandHandler : public QObject public: using ptr = std::unique_ptr; - virtual void run(const std::vector& cards) = 0; + virtual void run(const std::vector& cards) = 0; virtual void connectSignals(const WebEidUI* window) = 0; virtual QVariantMap onConfirm(WebEidUI* window, const CardCertificateAndPinInfo& cardCertAndPin) = 0; diff --git a/src/controller/controller.cpp b/src/controller/controller.cpp index 5894e103..e5d1694e 100644 --- a/src/controller/controller.cpp +++ b/src/controller/controller.cpp @@ -163,7 +163,8 @@ void Controller::connectOkCancelWaitingForPinPad() connect(window, &WebEidUI::waitingForPinPad, this, &Controller::onConfirmCommandHandler); } -void Controller::onCardsAvailable(const std::vector& availableCards) +void Controller::onCardsAvailable( + const std::vector& availableCards) { try { REQUIRE_NON_NULL(commandHandler) @@ -172,8 +173,8 @@ void Controller::onCardsAvailable(const std::vectoreid().smartcard().protocol() == SmartCard::Protocol::T0 ? "T=0" : "T=1"; - qInfo() << "Card" << card->eid().name() << "in reader" << card->reader().name + card->smartcard().protocol() == SmartCard::Protocol::T0 ? "T=0" : "T=1"; + qInfo() << "Card" << card->name() << "in reader" << card->smartcard().name() << "using protocol" << protocol; } @@ -188,7 +189,7 @@ void Controller::onCardsAvailable(const std::vector& availableCards) +void Controller::runCommandHandler(const std::vector& availableCards) { try { CommandHandlerRunThread* commandHandlerRunThread = diff --git a/src/controller/controller.hpp b/src/controller/controller.hpp index e4af4828..91a9296b 100644 --- a/src/controller/controller.hpp +++ b/src/controller/controller.hpp @@ -47,7 +47,7 @@ class Controller : public QObject void run(); // Called either directly from run() or from the monitor thread when cards are available. - void onCardsAvailable(const std::vector& availableCards); + void onCardsAvailable(const std::vector& availableCards); // Called when CommandHandlerRunThread finishes execution. void onCertificatesLoaded(); @@ -73,7 +73,7 @@ class Controller : public QObject private: void startCommandExecution(); - void runCommandHandler(const std::vector& availableCards); + void runCommandHandler(const std::vector& availableCards); void connectOkCancelWaitingForPinPad(); void connectRetry(const ControllerChildThread* childThread); void saveChildThreadPtrAndConnectFailureFinish(ControllerChildThread* childThread); diff --git a/src/controller/inputoutputmode.cpp b/src/controller/inputoutputmode.cpp index f9d57e59..e84041ad 100644 --- a/src/controller/inputoutputmode.cpp +++ b/src/controller/inputoutputmode.cpp @@ -25,6 +25,8 @@ #include #include +#include + #ifdef Q_OS_WIN #include #include diff --git a/src/controller/qeid.hpp b/src/controller/qeid.hpp index 06c22093..8ee76fa0 100644 --- a/src/controller/qeid.hpp +++ b/src/controller/qeid.hpp @@ -27,6 +27,6 @@ #include Q_DECLARE_METATYPE(electronic_id::AutoSelectFailed::Reason) -Q_DECLARE_METATYPE(electronic_id::CardInfo::ptr) -Q_DECLARE_METATYPE(std::vector) +Q_DECLARE_METATYPE(electronic_id::ElectronicID::ptr) +Q_DECLARE_METATYPE(std::vector) Q_DECLARE_METATYPE(electronic_id::VerifyPinFailed::Status) diff --git a/src/controller/threads/cardeventmonitorthread.hpp b/src/controller/threads/cardeventmonitorthread.hpp index f1087030..607c6978 100644 --- a/src/controller/threads/cardeventmonitorthread.hpp +++ b/src/controller/threads/cardeventmonitorthread.hpp @@ -29,8 +29,8 @@ class CardEventMonitorThread : public ControllerChildThread Q_OBJECT public: - using card_ptr = electronic_id::CardInfo::ptr; - using card_ptr_vector = std::vector; + using card_ptr = electronic_id::ElectronicID::ptr; + using card_ptr_vector = std::vector; CardEventMonitorThread(QObject* parent, const std::string& commandType) : ControllerChildThread(parent), cmdType(commandType) @@ -101,21 +101,20 @@ class CardEventMonitorThread : public ControllerChildThread void sortByReaderNameAndAtr(card_ptr_vector& a) { std::sort(a.begin(), a.end(), [](const card_ptr& c1, const card_ptr& c2) { - if (c1->reader().name != c2->reader().name) { - return c1->reader().name < c2->reader().name; + if (c1->smartcard().name() != c2->smartcard().name()) { + return c1->smartcard().name() < c2->smartcard().name(); } - return c1->reader().cardAtr < c2->reader().cardAtr; + return c1->smartcard().atr() < c2->smartcard().atr(); }); } bool areEqualByReaderNameAndAtr(const card_ptr_vector& a, const card_ptr_vector& b) { // std::equal requires that second range is not shorter than first, so compare size first. - return a.size() == b.size() - && std::equal(a.cbegin(), a.cend(), b.cbegin(), + return std::equal(a.cbegin(), a.cend(), b.cbegin(), b.end(), [](const card_ptr& c1, const card_ptr& c2) { - return c1->reader().name == c2->reader().name - && c1->reader().cardAtr == c2->reader().cardAtr; + return c1->smartcard().name() == c2->smartcard().name() + && c1->smartcard().atr() == c2->smartcard().atr(); }); } diff --git a/src/controller/threads/commandhandlerconfirmthread.hpp b/src/controller/threads/commandhandlerconfirmthread.hpp index f1621546..cb2aae82 100644 --- a/src/controller/threads/commandhandlerconfirmthread.hpp +++ b/src/controller/threads/commandhandlerconfirmthread.hpp @@ -43,7 +43,7 @@ class CommandHandlerConfirmThread : public ControllerChildThread void doRun() override { const auto result = commandHandler.onConfirm(window, cardCertAndPinInfo); - cardCertAndPinInfo.cardInfo->eid().release(); + cardCertAndPinInfo.cardInfo->release(); emit completed(result); } diff --git a/src/controller/threads/commandhandlerrunthread.hpp b/src/controller/threads/commandhandlerrunthread.hpp index 898a5a0a..cd12ada0 100644 --- a/src/controller/threads/commandhandlerrunthread.hpp +++ b/src/controller/threads/commandhandlerrunthread.hpp @@ -30,7 +30,7 @@ class CommandHandlerRunThread : public ControllerChildThread public: CommandHandlerRunThread(QObject* parent, CommandHandler& handler, - const std::vector& cs) : + const std::vector& cs) : ControllerChildThread(parent), commandHandler(handler), cmdType(commandHandler.commandType()), cards(cs) { @@ -45,5 +45,5 @@ class CommandHandlerRunThread : public ControllerChildThread CommandHandler& commandHandler; const std::string cmdType; - std::vector cards; + std::vector cards; }; diff --git a/src/controller/threads/waitforcardthread.hpp b/src/controller/threads/waitforcardthread.hpp index 81458903..2a97acfa 100644 --- a/src/controller/threads/waitforcardthread.hpp +++ b/src/controller/threads/waitforcardthread.hpp @@ -32,7 +32,7 @@ class WaitForCardThread : public ControllerChildThread explicit WaitForCardThread(QObject* parent) : ControllerChildThread(parent) {} signals: - void cardsAvailable(const std::vector& cardInfo); + void cardsAvailable(const std::vector& cardInfo); void statusUpdate(const RetriableError status); private: diff --git a/src/controller/writeresponse.cpp b/src/controller/writeresponse.cpp index 270f5e57..3e6db83a 100644 --- a/src/controller/writeresponse.cpp +++ b/src/controller/writeresponse.cpp @@ -27,6 +27,8 @@ #include #include +#include + namespace { diff --git a/src/mac/main.mm b/src/mac/main.mm index df68a653..6f3bec48 100644 --- a/src/mac/main.mm +++ b/src/mac/main.mm @@ -34,6 +34,8 @@ #include "shared.hpp" +#include + @implementation NSApplication (MacController) + (QVariant)toQVariant:(id)data diff --git a/src/ui/webeiddialog.cpp b/src/ui/webeiddialog.cpp index dd30e2d0..e33cc791 100644 --- a/src/ui/webeiddialog.cpp +++ b/src/ui/webeiddialog.cpp @@ -376,7 +376,7 @@ void WebEidDialog::onSingleCertificateReady(const QUrl& origin, { ui->selectCertificateOriginLabel->setText(fromPunycode(origin)); ui->pinInputOriginLabel->setText(ui->selectCertificateOriginLabel->text()); - const bool useExternalPinDialog = certAndPin.cardInfo->eid().providesExternalPinDialog(); + const bool useExternalPinDialog = certAndPin.cardInfo->providesExternalPinDialog(); switch (currentCommand) { case CommandType::GET_SIGNING_CERTIFICATE: @@ -652,7 +652,7 @@ void WebEidDialog::setupPinInput(const CardCertificateAndPinInfo& certAndPin) // (ASCII 0x20...0x2F, space../ + 0x3A...0x40, :..@ + 0x5B...0x60, [..` + 0x7B...0x7F, {..~). // 5. We additionally allow uppercase and lowercase Unicode letters. const auto& regexpWithOrWithoutLetters = - certAndPin.cardInfo->eid().allowsUsingLettersAndSpecialCharactersInPin() + certAndPin.cardInfo->allowsUsingLettersAndSpecialCharactersInPin() ? QStringLiteral("[0-9 -/:-@[-`{-~\\p{L}]{%1,%2}") : QStringLiteral("[0-9]{%1,%2}"); const QRegularExpression numericMinMaxRegexp(