Commit 4bb358ec authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Add explicit reset mode for changing a PIN

Previously, ChangePinCommand implicitly used the reset mode for
OpenPGP v2+ cards if the reset code keyRef was set. Now, the reset mode
has to be set explicitly by the users of ChangePinCommand.

GnuPG-bug-id: 5138
parent 5e480a78
......@@ -48,6 +48,7 @@ private:
private:
std::string appName;
std::string keyRef;
ChangePinMode mode = NormalMode;
};
ChangePinCommand::Private *ChangePinCommand::d_func()
......@@ -93,6 +94,12 @@ void ChangePinCommand::setKeyRef(const std::string &keyRef)
d->keyRef = keyRef;
}
void ChangePinCommand::setMode(ChangePinMode mode)
{
d->mode = mode;
}
void ChangePinCommand::doStart()
{
qCDebug(KLEOPATRA_LOG) << "ChangePinCommand::doStart()";
......@@ -117,8 +124,7 @@ void ChangePinCommand::Private::changePin()
QByteArrayList command;
command << "SCD PASSWD";
if (card->appName() == OpenPGPCard::AppName && card->appVersion() >= 0x0200 && keyRef == OpenPGPCard::resetCodeKeyRef()) {
// special handling for setting/changing the Reset Code of OpenPGP v2 cards
if (mode == ResetMode) {
command << "--reset";
}
command << QByteArray::fromStdString(keyRef);
......
......@@ -25,10 +25,16 @@ class ChangePinCommand : public CardCommand
{
Q_OBJECT
public:
enum ChangePinMode {
NormalMode = 0,
ResetMode = 1
};
explicit ChangePinCommand(const std::string &serialNumber, const std::string &appName, QWidget *parent);
~ChangePinCommand() override;
void setKeyRef(const std::string &keyRef);
void setMode(ChangePinMode mode = NormalMode);
private:
void doStart() override;
......
......@@ -13,7 +13,6 @@
#include "kleopatra_debug.h"
#include "commands/changepincommand.h"
#include "commands/createcsrforcardkeycommand.h"
#include "commands/createopenpgpkeyfromcardkeyscommand.h"
......@@ -215,7 +214,8 @@ PGPCardWidget::PGPCardWidget(QWidget *parent):
auto resetCodeButton = new QPushButton(i18n("Change Reset Code"));
pukButton->setToolTip(i18n("Change the PIN required to reset the smartcard to an empty state."));
actionLayout->addWidget(resetCodeButton);
connect(resetCodeButton, &QPushButton::clicked, this, [this] () { doChangePin(OpenPGPCard::resetCodeKeyRef()); });
connect(resetCodeButton, &QPushButton::clicked,
this, [this] () { doChangePin(OpenPGPCard::resetCodeKeyRef(), ChangePinCommand::ResetMode); });
if (CreateOpenPGPKeyFromCardKeysCommand::isSupported()) {
mKeyForCardKeysButton = new QPushButton(this);
......@@ -283,7 +283,7 @@ void PGPCardWidget::setCard(const OpenPGPCard *card)
}
}
void PGPCardWidget::doChangePin(const std::string &keyRef)
void PGPCardWidget::doChangePin(const std::string &keyRef, ChangePinCommand::ChangePinMode mode)
{
auto cmd = new ChangePinCommand(mRealSerial, OpenPGPCard::AppName, this);
this->setEnabled(false);
......@@ -292,6 +292,7 @@ void PGPCardWidget::doChangePin(const std::string &keyRef)
this->setEnabled(true);
});
cmd->setKeyRef(keyRef);
cmd->setMode(mode);
cmd->start();
}
......
......@@ -11,6 +11,8 @@
#ifndef VIEW_PGPCARDWIDGET_H
#define VIEW_PGPCARDWIDGET_H
#include "commands/changepincommand.h"
#include <QMap>
#include <QWidget>
......@@ -59,7 +61,7 @@ public Q_SLOTS:
private:
KeyWidgets createKeyWidgets(const SmartCard::KeyPairInfo &keyInfo);
void updateKeyWidgets(const std::string &keyRef, const SmartCard::OpenPGPCard *card);
void doChangePin(const std::string &keyRef);
void doChangePin(const std::string &keyRef, Commands::ChangePinCommand::ChangePinMode mode = Commands::ChangePinCommand::NormalMode);
private:
QLabel *mSerialNumber = nullptr,
......
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