Commit 36e30726 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Switch to correct card and app before generating card keys

This fixes the generation of card keys if multiple cards are inserted.
It's only relevant for GnuPG 2.3.0+ (unreleased).

GnuPG-bug-id: 5130
parent 3a6f8bf5
......@@ -1050,4 +1050,16 @@ std::shared_ptr<Card> ReaderStatus::getCard(const std::string &serialNumber, con
return std::shared_ptr<Card>();
}
// static
std::string ReaderStatus::switchCard(std::shared_ptr<Context>& ctx, const std::string& serialNumber, Error& err)
{
return ::switchCard(ctx, serialNumber, err);
}
// static
std::string ReaderStatus::switchApp(std::shared_ptr<Context>& ctx, const std::string& serialNumber, const std::string& appName, Error& err)
{
return ::switchApp(ctx, serialNumber, appName, err);
}
#include "readerstatus.moc"
......@@ -21,6 +21,8 @@
namespace GpgME
{
class AssuanTransaction;
class Context;
class Error;
}
namespace Kleo
......@@ -56,6 +58,10 @@ public:
return std::dynamic_pointer_cast<T>(getCard(serialNumber, T::AppName));
}
static std::string switchCard(std::shared_ptr<GpgME::Context> &ctx, const std::string &serialNumber, GpgME::Error &err);
static std::string switchApp(std::shared_ptr<GpgME::Context> &ctx, const std::string &serialNumber,
const std::string &appName, GpgME::Error &err);
public Q_SLOTS:
void updateStatus();
void startMonitoring();
......
......@@ -249,6 +249,25 @@ void PGPCardWidget::doChangePin(const std::string &keyRef)
void PGPCardWidget::doGenKey(GenCardKeyDialog *dlg)
{
if (!(engineInfo(GpgME::GpgEngine).engineVersion() < "2.3.0")) {
GpgME::Error err;
std::unique_ptr<GpgME::Context> c = GpgME::Context::createForEngine(GpgME::AssuanEngine, &err);
if (err.code() == GPG_ERR_NOT_SUPPORTED) {
return;
}
auto assuanContext = std::shared_ptr<GpgME::Context>(c.release());
const auto serialNumber = ReaderStatus::switchCard(assuanContext, mRealSerial, err);
if (err || serialNumber != mRealSerial) {
qCWarning(KLEOPATRA_LOG) << "Switching to card" << QString::fromStdString(mRealSerial) << "failed";
return;
}
const auto appName = ReaderStatus::switchApp(assuanContext, mRealSerial, OpenPGPCard::AppName, err);
if (err || appName != OpenPGPCard::AppName) {
qCWarning(KLEOPATRA_LOG) << "Switching card to" << QString::fromStdString(OpenPGPCard::AppName) << "app failed";
return;
}
}
const auto params = dlg->getKeyParams();
auto progress = new QProgressDialog(this, Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::Dialog);
......
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