Skip to content

Commit

Permalink
Remove CardInfo
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma committed Feb 7, 2025
1 parent 9fd7a8b commit 7de7ebd
Show file tree
Hide file tree
Showing 21 changed files with 57 additions and 50 deletions.
2 changes: 2 additions & 0 deletions src/app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

#include <QTimer>

#include <iostream>

int main(int argc, char* argv[])
{
Q_INIT_RESOURCE(web_eid_resources);
Expand Down
4 changes: 2 additions & 2 deletions src/controller/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,8 @@ CommandWithArgumentsPtr Application::parseArgs()
void Application::registerMetatypes()
{
qRegisterMetaType<electronic_id::AutoSelectFailed::Reason>();
qRegisterMetaType<electronic_id::CardInfo::ptr>();
qRegisterMetaType<std::vector<electronic_id::CardInfo::ptr>>();
qRegisterMetaType<electronic_id::ElectronicID::ptr>();
qRegisterMetaType<std::vector<electronic_id::ElectronicID::ptr>>();
qRegisterMetaType<electronic_id::VerifyPinFailed::Status>();

qRegisterMetaType<CardCertificateAndPinInfo>();
Expand Down
2 changes: 1 addition & 1 deletion src/controller/certandpininfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct PinInfo

struct CardCertificateAndPinInfo
{
electronic_id::CardInfo::ptr cardInfo;
electronic_id::ElectronicID::ptr cardInfo;
QByteArray certificateBytesInDer;
QSslCertificate certificate {};
CertificateInfo certInfo;
Expand Down
8 changes: 4 additions & 4 deletions src/controller/command-handlers/authenticate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 9 additions & 9 deletions src/controller/command-handlers/certificatereader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*>(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(' ');
Expand All @@ -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;
}
Expand All @@ -83,7 +83,7 @@ CertificateReader::CertificateReader(const CommandWithArguments& cmd) : CommandH
}
}

void CertificateReader::run(const std::vector<CardInfo::ptr>& cards)
void CertificateReader::run(const std::vector<ElectronicID::ptr>& cards)
{
REQUIRE_NOT_EMPTY_CONTAINS_NON_NULL_PTRS(cards)

Expand Down
2 changes: 1 addition & 1 deletion src/controller/command-handlers/certificatereader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CertificateReader : public CommandHandler
public:
explicit CertificateReader(const CommandWithArguments& cmd);

void run(const std::vector<electronic_id::CardInfo::ptr>& cards) override;
void run(const std::vector<electronic_id::ElectronicID::ptr>& cards) override;
void connectSignals(const WebEidUI* window) override;

protected:
Expand Down
2 changes: 1 addition & 1 deletion src/controller/command-handlers/getcertificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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}};
}
13 changes: 6 additions & 7 deletions src/controller/command-handlers/sign.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ void Sign::emitCertificatesReady(const std::vector<CardCertificateAndPinInfo>& 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));
}

Expand All @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion src/controller/commandhandler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CommandHandler : public QObject
public:
using ptr = std::unique_ptr<CommandHandler>;

virtual void run(const std::vector<electronic_id::CardInfo::ptr>& cards) = 0;
virtual void run(const std::vector<electronic_id::ElectronicID::ptr>& cards) = 0;
virtual void connectSignals(const WebEidUI* window) = 0;
virtual QVariantMap onConfirm(WebEidUI* window,
const CardCertificateAndPinInfo& cardCertAndPin) = 0;
Expand Down
9 changes: 5 additions & 4 deletions src/controller/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ void Controller::connectOkCancelWaitingForPinPad()
connect(window, &WebEidUI::waitingForPinPad, this, &Controller::onConfirmCommandHandler);
}

void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr>& availableCards)
void Controller::onCardsAvailable(
const std::vector<electronic_id::ElectronicID::ptr>& availableCards)
{
try {
REQUIRE_NON_NULL(commandHandler)
Expand All @@ -172,8 +173,8 @@ void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr

for (const auto& card : availableCards) {
const auto protocol =
card->eid().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;
}

Expand All @@ -188,7 +189,7 @@ void Controller::onCardsAvailable(const std::vector<electronic_id::CardInfo::ptr
}
}

void Controller::runCommandHandler(const std::vector<electronic_id::CardInfo::ptr>& availableCards)
void Controller::runCommandHandler(const std::vector<ElectronicID::ptr>& availableCards)
{
try {
CommandHandlerRunThread* commandHandlerRunThread =
Expand Down
4 changes: 2 additions & 2 deletions src/controller/controller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<electronic_id::CardInfo::ptr>& availableCards);
void onCardsAvailable(const std::vector<electronic_id::ElectronicID::ptr>& availableCards);

// Called when CommandHandlerRunThread finishes execution.
void onCertificatesLoaded();
Expand All @@ -73,7 +73,7 @@ class Controller : public QObject

private:
void startCommandExecution();
void runCommandHandler(const std::vector<electronic_id::CardInfo::ptr>& availableCards);
void runCommandHandler(const std::vector<electronic_id::ElectronicID::ptr>& availableCards);
void connectOkCancelWaitingForPinPad();
void connectRetry(const ControllerChildThread* childThread);
void saveChildThreadPtrAndConnectFailureFinish(ControllerChildThread* childThread);
Expand Down
2 changes: 2 additions & 0 deletions src/controller/inputoutputmode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include <QJsonDocument>
#include <QJsonObject>

#include <iostream>

#ifdef Q_OS_WIN
#include <stdio.h>
#include <io.h>
Expand Down
4 changes: 2 additions & 2 deletions src/controller/qeid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
#include <QMetaType>

Q_DECLARE_METATYPE(electronic_id::AutoSelectFailed::Reason)
Q_DECLARE_METATYPE(electronic_id::CardInfo::ptr)
Q_DECLARE_METATYPE(std::vector<electronic_id::CardInfo::ptr>)
Q_DECLARE_METATYPE(electronic_id::ElectronicID::ptr)
Q_DECLARE_METATYPE(std::vector<electronic_id::ElectronicID::ptr>)
Q_DECLARE_METATYPE(electronic_id::VerifyPinFailed::Status)
17 changes: 8 additions & 9 deletions src/controller/threads/cardeventmonitorthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class CardEventMonitorThread : public ControllerChildThread
Q_OBJECT

public:
using card_ptr = electronic_id::CardInfo::ptr;
using card_ptr_vector = std::vector<electronic_id::CardInfo::ptr>;
using card_ptr = electronic_id::ElectronicID::ptr;
using card_ptr_vector = std::vector<electronic_id::ElectronicID::ptr>;

CardEventMonitorThread(QObject* parent, const std::string& commandType) :
ControllerChildThread(parent), cmdType(commandType)
Expand Down Expand Up @@ -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();
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/controller/threads/commandhandlerconfirmthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
4 changes: 2 additions & 2 deletions src/controller/threads/commandhandlerrunthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CommandHandlerRunThread : public ControllerChildThread

public:
CommandHandlerRunThread(QObject* parent, CommandHandler& handler,
const std::vector<electronic_id::CardInfo::ptr>& cs) :
const std::vector<electronic_id::ElectronicID::ptr>& cs) :
ControllerChildThread(parent), commandHandler(handler),
cmdType(commandHandler.commandType()), cards(cs)
{
Expand All @@ -45,5 +45,5 @@ class CommandHandlerRunThread : public ControllerChildThread

CommandHandler& commandHandler;
const std::string cmdType;
std::vector<electronic_id::CardInfo::ptr> cards;
std::vector<electronic_id::ElectronicID::ptr> cards;
};
2 changes: 1 addition & 1 deletion src/controller/threads/waitforcardthread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class WaitForCardThread : public ControllerChildThread
explicit WaitForCardThread(QObject* parent) : ControllerChildThread(parent) {}

signals:
void cardsAvailable(const std::vector<electronic_id::CardInfo::ptr>& cardInfo);
void cardsAvailable(const std::vector<electronic_id::ElectronicID::ptr>& cardInfo);
void statusUpdate(const RetriableError status);

private:
Expand Down
2 changes: 2 additions & 0 deletions src/controller/writeresponse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
#include <QJsonDocument>
#include <QJsonObject>

#include <iostream>

namespace
{

Expand Down
2 changes: 2 additions & 0 deletions src/mac/main.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@

#include "shared.hpp"

#include <iostream>

@implementation NSApplication (MacController)

+ (QVariant)toQVariant:(id)data
Expand Down
4 changes: 2 additions & 2 deletions src/ui/webeiddialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7de7ebd

Please sign in to comment.