Commit 2b5f5b4b authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Use ChangePinCommand also for setting the initial NetKey PINs

parent f5d3e324
......@@ -11,6 +11,7 @@
#include "cardcommand_p.h"
#include "smartcard/netkeycard.h"
#include "smartcard/openpgpcard.h"
#include "smartcard/pivcard.h"
#include "smartcard/readerstatus.h"
......@@ -149,6 +150,20 @@ static QString errorMessage(const std::string &keyRef, ChangePinCommand::ChangeP
if (keyRef == OpenPGPCard::resetCodeKeyRef() && mode == ChangePinCommand::ResetMode) {
return i18nc("@info", "Changing the Reset Code failed: %1", errorText);
}
if (keyRef == NetKeyCard::nksPinKeyRef()) {
if (mode == ChangePinCommand::NullPinMode) {
return i18nc("@info", "Setting the NKS PIN failed: %1", errorText);
} else {
return i18nc("@info", "Changing the NKS PIN failed: %1", errorText);
}
}
if (keyRef == NetKeyCard::sigGPinKeyRef()) {
if (mode == ChangePinCommand::NullPinMode) {
return i18nc("@info", "Setting the SigG PIN failed: %1", errorText);
} else {
return i18nc("@info", "Changing the SigG PIN failed: %1", errorText);
}
}
return i18nc("@info", "Changing the PIN failed: %1", errorText);
}
......@@ -167,6 +182,20 @@ static QString successMessage(const std::string &keyRef, ChangePinCommand::Chang
if (keyRef == OpenPGPCard::resetCodeKeyRef() && mode == ChangePinCommand::ResetMode) {
return i18nc("@info", "Reset Code changed successfully.");
}
if (keyRef == NetKeyCard::nksPinKeyRef()) {
if (mode == ChangePinCommand::NullPinMode) {
return i18nc("@info", "NKS PIN set successfully.");
} else {
return i18nc("@info", "NKS PIN changed successfully.");
}
}
if (keyRef == NetKeyCard::sigGPinKeyRef()) {
if (mode == ChangePinCommand::NullPinMode) {
return i18nc("@info", "SigG PIN set successfully.");
} else {
return i18nc("@info", "SigG PIN changed successfully.");
}
}
return i18nc("@info", "PIN changed successfully.");
}
}
......
......@@ -11,9 +11,8 @@
#include "kleopatra_debug.h"
#include "smartcard/netkeycard.h"
#include "smartcard/readerstatus.h"
#include <gpgme++/error.h>
#include "commands/changepincommand.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
......@@ -24,6 +23,7 @@
#include <KMessageBox>
using namespace Kleo;
using namespace Kleo::Commands;
using namespace Kleo::SmartCard;
NullPinWidget::NullPinWidget(QWidget *parent)
......@@ -42,10 +42,10 @@ NullPinWidget::NullPinWidget(QWidget *parent)
mSigGBtn = new QPushButton(i18nc("SigG is an identifier for a type of keys on a NetKey card", "Set SigG PIN"));
connect(mNKSBtn, &QPushButton::clicked, this, [this] () {
doChangePin(false);
doChangePin(NetKeyCard::nksPinKeyRef());
});
connect(mSigGBtn, &QPushButton::clicked, this, [this] () {
doChangePin(true);
doChangePin(NetKeyCard::sigGPinKeyRef());
});
auto hLayBtn = new QHBoxLayout;
......@@ -62,7 +62,7 @@ void NullPinWidget::setSerialNumber(const std::string &serialNumber)
mSerialNumber = serialNumber;
}
void NullPinWidget::doChangePin(bool sigG)
void NullPinWidget::doChangePin(const std::string &keyRef)
{
parentWidget()->setEnabled(false);
auto ret = KMessageBox::warningContinueCancel(this,
......@@ -81,32 +81,14 @@ void NullPinWidget::doChangePin(bool sigG)
return;
}
const auto nksCard = ReaderStatus::instance()->getCard<NetKeyCard>(mSerialNumber);
if (!nksCard) {
KMessageBox::error(this, i18n("Failed to find the NetKey card with the serial number: %1", QString::fromStdString(mSerialNumber)));
parentWidget()->setEnabled(true);
return;
}
if (sigG) {
ReaderStatus::mutableInstance()->startSimpleTransaction(
nksCard, "SCD PASSWD --nullpin PW1.CH.SIG", this, "setSigGPinSettingResult");
} else {
ReaderStatus::mutableInstance()->startSimpleTransaction(
nksCard, "SCD PASSWD --nullpin PW1.CH", this, "setNksPinSettingResult");
}
}
void NullPinWidget::handleResult(const GpgME::Error &err)
{
if (err) {
KMessageBox::error(this, i18nc("@info",
"Failed to set PIN: %1", QString::fromLatin1(err.asString())),
i18nc("@title", "Error"));
} else if (!err.isCanceled()) {
ReaderStatus::mutableInstance()->updateStatus();
}
parentWidget()->setEnabled(true);
auto cmd = new ChangePinCommand(mSerialNumber, NetKeyCard::AppName, this);
connect(cmd, &ChangePinCommand::finished,
this, [this]() {
this->parentWidget()->setEnabled(true);
});
cmd->setKeyRef(keyRef);
cmd->setMode(ChangePinCommand::NullPinMode);
cmd->start();
}
void NullPinWidget::setSigGVisible(bool val)
......@@ -118,13 +100,3 @@ void NullPinWidget::setNKSVisible(bool val)
{
mNKSBtn->setVisible(val);
}
void NullPinWidget::setSigGPinSettingResult(const GpgME::Error &err)
{
handleResult(err);
}
void NullPinWidget::setNksPinSettingResult(const GpgME::Error &err)
{
handleResult(err);
}
......@@ -31,12 +31,7 @@ public:
void setNKSVisible(bool val);
private:
void doChangePin(bool sigG);
void handleResult(const GpgME::Error &err);
private Q_SLOTS:
void setSigGPinSettingResult(const GpgME::Error &err);
void setNksPinSettingResult(const GpgME::Error &err);
void doChangePin(const std::string &keyRef);
private:
std::string mSerialNumber;
......
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