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

Show nicer card/app labels for the card/app tabs

Card, PIVCard:
* Add display serial number to the base class Card

ReaderStatus:
* Try to get the display serial number from scdaemon for all supported
  cards/card applications

PIVCardWidget:
* Show only the display serial number; the full serial number is available
  as tooltip

SmartCardWidget:
* Use display serial number and nicer app names for the labels of the
  card application tabs

GnuPG-bug-id: 5066
parent ff3e79e6
Pipeline #36718 passed with stage
in 30 minutes and 21 seconds
......@@ -64,6 +64,16 @@ std::string Card::serialNumber() const
return mSerialNumber;
}
QString Card::displaySerialNumber() const
{
return mDisplaySerialNumber;
}
void Card::setDisplaySerialNumber(const QString &serialNumber)
{
mDisplaySerialNumber = serialNumber;
}
std::string Card::appName() const
{
return mAppName;
......
......@@ -57,6 +57,9 @@ public:
void setSerialNumber(const std::string &sn);
std::string serialNumber() const;
QString displaySerialNumber() const;
void setDisplaySerialNumber(const QString &sn);
std::string appName() const;
void setAppVersion(int version);
......@@ -90,6 +93,7 @@ private:
bool mHasNullPin = false;
Status mStatus = NoCard;
std::string mSerialNumber;
QString mDisplaySerialNumber;
std::string mAppName;
int mAppVersion = -1;
std::string mCardType;
......
......@@ -141,16 +141,6 @@ void PIVCard::setCardInfo(const std::vector< std::pair<std::string, std::string>
}
}
std::string PIVCard::displaySerialNumber() const
{
return mDisplaySerialNumber;
}
void PIVCard::setDisplaySerialNumber(const std::string &serialno)
{
mDisplaySerialNumber = serialno;
}
std::string PIVCard::keyAlgorithm(const std::string &keyRef) const
{
return mMetaInfo.value("KLEO-KEYALGO-" + keyRef);
......
......@@ -41,9 +41,6 @@ public:
void setCardInfo(const std::vector< std::pair<std::string, std::string> > &infos);
std::string displaySerialNumber() const;
void setDisplaySerialNumber(const std::string &sn);
std::string keyAlgorithm(const std::string &keyRef) const;
void setKeyAlgorithm(const std::string &keyRef, const std::string &algorithm);
......@@ -53,7 +50,6 @@ public:
bool operator == (const Card& other) const override;
private:
std::string mDisplaySerialNumber;
QMap <std::string, std::string> mMetaInfo;
};
} // namespace Smartcard
......
......@@ -338,6 +338,23 @@ static const std::string get_manufacturer(std::shared_ptr<Context> &gpgAgent, Er
return manufacturerName;
}
static const std::string getDisplaySerialNumber(std::shared_ptr<Context> &gpgAgent, Error &err)
{
const auto displaySerialnumber = scd_getattr_status(gpgAgent, "$DISPSERIALNO", err);
if (err && err.code() != GPG_ERR_INV_NAME) {
qCWarning(KLEOPATRA_LOG) << "Running SCD GETATTR $DISPSERIALNO failed:" << err;
}
return displaySerialnumber;
}
static bool setDisplaySerialNumber(Card *card, std::shared_ptr<Context> &gpgAgent)
{
Error err;
const std::string displaySerialnumber = getDisplaySerialNumber(gpgAgent, err);
card->setDisplaySerialNumber(err ? QString::fromStdString(card->serialNumber()) : QString::fromStdString(displaySerialnumber));
return !err;
}
static void handle_openpgp_card(std::shared_ptr<Card> &ci, std::shared_ptr<Context> &gpg_agent)
{
Error err;
......@@ -355,6 +372,11 @@ static void handle_openpgp_card(std::shared_ptr<Card> &ci, std::shared_ptr<Conte
return;
}
pgpCard->setCardInfo(info);
if (!setDisplaySerialNumber(pgpCard, gpg_agent)) {
pgpCard->setDisplaySerialNumber(QString::fromStdString(pgpCard->serialNumber()).mid(16, 12));
}
ci.reset(pgpCard);
}
......@@ -404,12 +426,6 @@ static void handle_piv_card(std::shared_ptr<Card> &ci, std::shared_ptr<Context>
Error err;
auto pivCard = new PIVCard(*ci);
const auto displaySerialnumber = scd_getattr_status(gpg_agent, "$DISPSERIALNO", err);
if (err) {
qCWarning(KLEOPATRA_LOG) << "Running SCD GETATTR $DISPSERIALNO failed:" << err;
}
pivCard->setDisplaySerialNumber(err ? ci->serialNumber() : displaySerialnumber);
const auto info = gpgagent_statuslines(gpg_agent, "SCD LEARN --force", err);
if (err) {
ci->setStatus(Card::CardError);
......@@ -417,6 +433,8 @@ static void handle_piv_card(std::shared_ptr<Card> &ci, std::shared_ptr<Context>
}
pivCard->setCardInfo(info);
(void) setDisplaySerialNumber(pivCard, gpg_agent);
for (const std::string &keyRef : PIVCard::supportedKeys()) {
if (!pivCard->keyGrip(keyRef).empty()) {
readKeyPairInfoFromPIVCard(keyRef, pivCard, gpg_agent);
......@@ -446,6 +464,9 @@ static void handle_netkey_card(std::shared_ptr<Card> &ci, std::shared_ptr<Contex
ci->setErrorMsg(QStringLiteral("NetKey v%1 cards are not supported.").arg(ci->appVersion()));
return;
}
(void) setDisplaySerialNumber(nkCard, gpg_agent);
// the following only works for NKS v3...
const auto chvStatus = QString::fromStdString(
scd_getattr_status(gpg_agent, "CHV-STATUS", err)).split(QLatin1Char(' '));
......
......@@ -214,13 +214,8 @@ void PIVCardWidget::setCard(const PIVCard *card)
mCardSerialNumber = card->serialNumber();
mVersionLabel->setText(i18nc("%1 version number", "PIV v%1 card", card->displayAppVersion()));
if (card->displaySerialNumber() != card->serialNumber()) {
mSerialNumber->setText(i18nc("%1 nice serial number, %2 real serial number", "%1 (%2)",
QString::fromStdString(card->displaySerialNumber()),
QString::fromStdString(card->serialNumber())));
} else {
mSerialNumber->setText(QString::fromStdString(card->serialNumber()));
}
mSerialNumber->setText(card->displaySerialNumber());
mSerialNumber->setToolTip(QString::fromStdString(card->serialNumber()));
updateKeyWidgets(PIVCard::pivAuthenticationKeyRef(), card);
updateKeyWidgets(PIVCard::cardAuthenticationKeyRef(), card);
......
......@@ -140,6 +140,22 @@ void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumbe
}
}
namespace
{
QString displayAppName(const std::string &appName)
{
if (appName == SmartCard::NetKeyCard::AppName) {
return i18nc("proper name of a type of smartcard", "NetKey");
} else if (appName == SmartCard::OpenPGPCard::AppName) {
return i18nc("proper name of a type of smartcard", "OpenPGP");
} else if (appName == SmartCard::PIVCard::AppName) {
return i18nc("proper name of a type of smartcard", "PIV");
} else {
return QString::fromStdString(appName);
}
}
}
template <typename C, typename W>
void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumber)
{
......@@ -153,8 +169,8 @@ void SmartCardWidget::Private::cardAddedOrChanged(const std::string &serialNumbe
if (!cardWidget) {
cardWidget = new W;
mCardWidgets.insert({serialNumber, C::AppName}, cardWidget);
const QString cardLabel = i18nc("@title:tab serial number of smartcard - smartcard application", "%1 - %2",
QString::fromStdString(serialNumber), QString::fromStdString(C::AppName));
const QString cardLabel = i18nc("@title:tab smartcard application - serial number of smartcard", "%1 - %2",
displayAppName(C::AppName), card->displaySerialNumber());
mTabWidget->addTab(cardWidget, cardLabel);
if (mCardWidgets.size() == 1) {
mStack->setCurrentWidget(mTabWidget);
......
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