Commit 044244a4 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Make SetInitialPinCommand work on a card with given serial number

Previously, the command always worked on the "first" card.

ReaderStatus:
* Remove obsolete pinStates()

GnuPG-bug-id: 5066
parent 6eac9b66
......@@ -10,11 +10,12 @@
#include <config-kleopatra.h>
#include "setinitialpincommand.h"
#include "command_p.h"
#include "cardcommand_p.h"
#include <dialogs/setinitialpindialog.h>
#include "dialogs/setinitialpindialog.h"
#include <smartcard/readerstatus.h>
#include "smartcard/netkeycard.h"
#include "smartcard/readerstatus.h"
#include <KLocalizedString>
......@@ -25,7 +26,7 @@ using namespace Kleo::Dialogs;
using namespace Kleo::SmartCard;
using namespace GpgME;
class SetInitialPinCommand::Private : public Command::Private
class SetInitialPinCommand::Private : public CardCommand::Private
{
friend class ::Kleo::Commands::SetInitialPinCommand;
SetInitialPinCommand *q_func() const
......@@ -33,13 +34,12 @@ class SetInitialPinCommand::Private : public Command::Private
return static_cast<SetInitialPinCommand *>(q);
}
public:
explicit Private(SetInitialPinCommand *qq);
explicit Private(SetInitialPinCommand *qq, const std::string &serialNumber);
~Private();
private:
void init()
{
}
void ensureDialogCreated() const
......@@ -53,11 +53,6 @@ private:
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->setWindowTitle(i18nc("@title:window", "Set Initial Pin"));
const std::vector<Card::PinState> pinStates = ReaderStatus::instance()->pinStates(0);
dlg->setNksPinPresent(pinStates.size() >= 1 && pinStates[0] != Card::NullPin);
dlg->setSigGPinPresent(pinStates.size() >= 3 && pinStates[2] != Card::NullPin);
connect(dlg, SIGNAL(nksPinRequested()), q_func(), SLOT(slotNksPinRequested()));
connect(dlg, SIGNAL(sigGPinRequested()), q_func(), SLOT(slotSigGPinRequested()));
connect(dlg, SIGNAL(rejected()), q_func(), SLOT(slotDialogRejected()));
......@@ -121,17 +116,16 @@ const SetInitialPinCommand::Private *SetInitialPinCommand::d_func() const
#define q q_func()
#define d d_func()
SetInitialPinCommand::Private::Private(SetInitialPinCommand *qq)
: Command::Private(qq),
SetInitialPinCommand::Private::Private(SetInitialPinCommand *qq, const std::string &serialNumber)
: CardCommand::Private(qq, serialNumber, nullptr),
dialog()
{
}
SetInitialPinCommand::Private::~Private() {}
SetInitialPinCommand::SetInitialPinCommand()
: Command(new Private(this))
SetInitialPinCommand::SetInitialPinCommand(const std::string &serialNumber)
: CardCommand(new Private(this, serialNumber))
{
d->init();
}
......@@ -146,6 +140,20 @@ QDialog *SetInitialPinCommand::dialog() const
void SetInitialPinCommand::doStart()
{
d->ensureDialogCreated();
const auto nksCard = ReaderStatus::instance()->getCard<NetKeyCard>(d->serialNumber());
if (!nksCard) {
d->error(i18n("Failed to find the NetKey card with the serial number: %1", QString::fromStdString(d->serialNumber())));
d->dialog->close();
finished();
return;
}
const std::vector<Card::PinState> pinStates = nksCard->pinStates();
d->dialog->setNksPinPresent(pinStates.size() >= 1 && pinStates[0] != Card::NullPin);
d->dialog->setSigGPinPresent(pinStates.size() >= 3 && pinStates[2] != Card::NullPin);
d->ensureDialogVisible();
}
......
......@@ -10,18 +10,18 @@
#ifndef __KLEOPATRA_COMMANDS_SETINITIALPINCOMMAND_H__
#define __KLEOPATRA_COMMANDS_SETINITIALPINCOMMAND_H__
#include <commands/command.h>
#include <commands/cardcommand.h>
namespace Kleo
{
namespace Commands
{
class SetInitialPinCommand : public Command
class SetInitialPinCommand : public CardCommand
{
Q_OBJECT
public:
SetInitialPinCommand();
SetInitialPinCommand(const std::string &serialNumber);
~SetInitialPinCommand() override;
/* reimp */ static Restrictions restrictions()
......
......@@ -813,16 +813,6 @@ bool ReaderStatus::anyCardCanLearnKeys() const
return d->anyCardCanLearnKeysImpl();
}
std::vector<Card::PinState> ReaderStatus::pinStates(unsigned int slot) const
{
const auto ci = d->cardInfos();
if (slot < ci.size()) {
return ci[slot]->pinStates();
} else {
return std::vector<Card::PinState>();
}
}
void ReaderStatus::startSimpleTransaction(const QByteArray &command, QObject *receiver, const char *slot)
{
const Transaction t = { command, receiver, slot, nullptr };
......
......@@ -47,8 +47,6 @@ public:
std::string firstCardWithNullPin() const;
bool anyCardCanLearnKeys() const;
std::vector<Card::PinState> pinStates(unsigned int slot) const;
std::vector<std::shared_ptr<Card> > getCards() const;
template <typename T>
......
......@@ -83,9 +83,11 @@ private:
void slotSetInitialPin()
{
SetInitialPinCommand *cmd = new SetInitialPinCommand;
q->setAttentionWindow(cmd->dialog());
startCommand(cmd);
if (!firstCardWithNullPin.empty()) {
SetInitialPinCommand *cmd = new SetInitialPinCommand(firstCardWithNullPin);
q->setAttentionWindow(cmd->dialog());
startCommand(cmd);
}
}
void slotLearnCertificates()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment