Commit 02b63bb5 authored by Ingo Klöcker's avatar Ingo Klöcker
Browse files

Replace card-specific logic with info about signing/encryption key

GnuPG-bug-id: 5125, 5126
parent d2bf514e
......@@ -91,26 +91,21 @@ CreateOpenPGPKeyFromCardKeysCommand::Private::~Private()
void CreateOpenPGPKeyFromCardKeysCommand::Private::start()
{
const auto card = ReaderStatus::instance()->getCard(serialNumber(), appName);
if (!card) {
error(i18n("Failed to find the smartcard with the serial number: %1", QString::fromStdString(serialNumber())));
if (appName != OpenPGPCard::AppName && appName != PIVCard::AppName) {
qCWarning(KLEOPATRA_LOG) << "CreateOpenPGPKeyFromCardKeysCommand does not support card application" << QString::fromStdString(appName);
finished();
return;
}
Key signingKey;
if (card->appName() == OpenPGPCard::AppName) {
const auto pgpCard = std::dynamic_pointer_cast<OpenPGPCard>(card);
signingKey = KeyCache::instance()->findByKeyIDOrFingerprint(pgpCard->sigFpr());
} else if (appName == PIVCard::AppName) {
const auto pivCard = std::dynamic_pointer_cast<PIVCard>(card);
signingKey = KeyCache::instance()->findSubkeyByKeyGrip(pivCard->keyGrip(PIVCard::digitalSignatureKeyRef()), OpenPGP).parent();
} else {
qCWarning(KLEOPATRA_LOG) << "CreateOpenPGPKeyFromCardKeysCommand does not support card application" << QString::fromStdString(appName);
const auto card = ReaderStatus::instance()->getCard(serialNumber(), appName);
if (!card) {
error(i18n("Failed to find the smartcard with the serial number: %1", QString::fromStdString(serialNumber())));
finished();
return;
}
const auto signingKeyGrip = card->keyInfo(card->signingKeyRef()).grip;
const Key signingKey = KeyCache::instance()->findSubkeyByKeyGrip(signingKeyGrip, OpenPGP).parent();
if (!signingKey.isNull()) {
const QString message = i18nc("@info",
"<p>There is already an OpenPGP key corresponding to the signing key on this card:</p><p>%1</p>"
......
......@@ -131,6 +131,11 @@ std::string Card::signingKeyRef() const
return mSigningKeyRef;
}
bool Card::hasSigningKey() const
{
return !keyInfo(mSigningKeyRef).grip.empty();
}
void Card::setEncryptionKeyRef(const std::string &keyRef)
{
mEncryptionKeyRef = keyRef;
......@@ -141,6 +146,11 @@ std::string Card::encryptionKeyRef() const
return mEncryptionKeyRef;
}
bool Card::hasEncryptionKey() const
{
return !keyInfo(mEncryptionKeyRef).grip.empty();
}
std::vector<Card::PinState> Card::pinStates() const
{
return mPinStates;
......
......@@ -78,9 +78,11 @@ public:
void setSigningKeyRef(const std::string &keyRef);
std::string signingKeyRef() const;
bool hasSigningKey() const;
void setEncryptionKeyRef(const std::string &keyRef);
std::string encryptionKeyRef() const;
bool hasEncryptionKey() const;
std::vector<PinState> pinStates() const;
void setPinStates(const std::vector<PinState> &pinStates);
......
......@@ -240,7 +240,7 @@ void PGPCardWidget::setCard(const OpenPGPCard *card)
updateKey(mAuthKey, card->authFpr());
mCardIsEmpty = card->authFpr().empty() && card->sigFpr().empty() && card->encFpr().empty();
mKeyForCardKeysButton->setEnabled(!mCardIsEmpty);
mKeyForCardKeysButton->setEnabled(card->hasSigningKey() && card->hasEncryptionKey());
}
void PGPCardWidget::doChangePin(const std::string &keyRef)
......
......@@ -228,9 +228,7 @@ void PIVCardWidget::setCard(const PIVCard *card)
updateKeyWidgets(PIVCard::digitalSignatureKeyRef(), card);
updateKeyWidgets(PIVCard::keyManagementKeyRef(), card);
const bool signingKeyAvailable = !card->keyGrip(PIVCard::digitalSignatureKeyRef()).empty();
const bool encryptionKeyAvailable = !card->keyGrip(PIVCard::keyManagementKeyRef()).empty();
mKeyForCardKeysButton->setEnabled(signingKeyAvailable && encryptionKeyAvailable);
mKeyForCardKeysButton->setEnabled(card->hasSigningKey() && card->hasEncryptionKey());
}
void PIVCardWidget::updateKeyWidgets(const std::string &keyRef, const PIVCard *card)
......
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