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

Set initial (static) KeyPairInfo for PIV cards

In particular, this makes the possible usage of the supported keys
statically available.

GnuPG-bug-id: 5127
parent f4b40d89
......@@ -207,6 +207,11 @@ QString Card::errorMsg() const
return mErrMsg;
}
void Card::setInitialKeyInfos(const std::vector<KeyPairInfo> &infos)
{
mKeyInfos = infos;
}
const std::vector<KeyPairInfo> & Card::keyInfos() const
{
return mKeyInfos;
......
......@@ -101,6 +101,7 @@ public:
protected:
void setAppName(const std::string &name);
void setInitialKeyInfos(const std::vector<KeyPairInfo> &infos);
bool parseCardInfo(const std::string &name, const std::string &value);
......
......@@ -38,6 +38,26 @@ KeyPairInfo KeyPairInfo::fromStatusLine(const std::string &s) {
return info;
}
bool KeyPairInfo::canAuthenticate() const
{
return usage.find('a') != std::string::npos;
}
bool KeyPairInfo::canCertify() const
{
return usage.find('c') != std::string::npos;
}
bool KeyPairInfo::canEncrypt() const
{
return usage.find('e') != std::string::npos;
}
bool KeyPairInfo::canSign() const
{
return usage.find('s') != std::string::npos;
}
void KeyPairInfo::update(const KeyPairInfo &other)
{
Q_ASSERT(keyRef == other.keyRef);
......
......@@ -18,10 +18,15 @@ namespace SmartCard
struct KeyPairInfo {
static KeyPairInfo fromStatusLine(const std::string &s);
bool canAuthenticate() const;
bool canCertify() const;
bool canEncrypt() const;
bool canSign() const;
void update(const KeyPairInfo &other);
std::string grip;
std::string keyRef;
std::string grip;
std::string usage;
std::string keyTime;
std::string algorithm;
......
......@@ -25,6 +25,7 @@ PIVCard::PIVCard(const Card &card)
: Card(card)
{
setAppName(AppName);
setInitialKeyInfos(PIVCard::supportedKeys());
}
// static
......@@ -64,16 +65,16 @@ std::string PIVCard::pukKeyRef()
}
// static
const std::vector<std::string> & PIVCard::supportedKeys()
const std::vector<KeyPairInfo> & PIVCard::supportedKeys()
{
static const std::vector<std::string> keyRefs = {
PIVCard::pivAuthenticationKeyRef(),
PIVCard::cardAuthenticationKeyRef(),
PIVCard::digitalSignatureKeyRef(),
PIVCard::keyManagementKeyRef()
static const std::vector<KeyPairInfo> keyInfos = {
{PIVCard::pivAuthenticationKeyRef(), "", "a", "", ""},
{PIVCard::cardAuthenticationKeyRef(), "", "a", "", ""},
{PIVCard::digitalSignatureKeyRef(), "", "sc", "", ""},
{PIVCard::keyManagementKeyRef(), "", "e", "", ""}
};
return keyRefs;
return keyInfos;
}
// static
......
......@@ -17,6 +17,8 @@ namespace Kleo
{
namespace SmartCard
{
struct KeyPairInfo;
/** Class to work with PIV smartcards or compatible tokens */
class PIVCard: public Card
{
......@@ -33,7 +35,7 @@ public:
static std::string pinKeyRef();
static std::string pukKeyRef();
static const std::vector<std::string> & supportedKeys();
static const std::vector<KeyPairInfo> & supportedKeys();
static QString keyDisplayName(const std::string &keyRef);
static std::vector< std::pair<std::string, QString> > supportedAlgorithms(const std::string &keyRef);
......
......@@ -499,10 +499,10 @@ static void handle_piv_card(std::shared_ptr<Card> &ci, std::shared_ptr<Context>
setDisplaySerialNumber(pivCard, gpg_agent);
for (const std::string &keyRef : PIVCard::supportedKeys()) {
if (!pivCard->keyInfo(keyRef).grip.empty()) {
readKeyPairInfoFromPIVCard(keyRef, pivCard, gpg_agent);
readCertificateFromPIVCard(keyRef, pivCard, gpg_agent);
for (const KeyPairInfo &keyInfo : pivCard->keyInfos()) {
if (!keyInfo.grip.empty()) {
readKeyPairInfoFromPIVCard(keyInfo.keyRef, pivCard, gpg_agent);
readCertificateFromPIVCard(keyInfo.keyRef, pivCard, gpg_agent);
}
}
......
......@@ -118,21 +118,9 @@ PIVCardWidget::PIVCardWidget(QWidget *parent)
// The keys
grid->addWidget(new QLabel(QStringLiteral("<b>%1</b>").arg(i18n("Keys:"))), row++, 0);
{
KeyWidgets keyWidgets = createKeyWidgets(PIVCard::pivAuthenticationKeyRef());
layoutKeyWidgets(grid, i18n("PIV authentication:"), keyWidgets);
}
{
KeyWidgets keyWidgets = createKeyWidgets(PIVCard::cardAuthenticationKeyRef());
layoutKeyWidgets(grid, i18n("Card authentication:"), keyWidgets);
}
{
KeyWidgets keyWidgets = createKeyWidgets(PIVCard::digitalSignatureKeyRef());
layoutKeyWidgets(grid, i18n("Digital signature:"), keyWidgets);
}
{
KeyWidgets keyWidgets = createKeyWidgets(PIVCard::keyManagementKeyRef());
layoutKeyWidgets(grid, i18n("Key management:"), keyWidgets);
for (const auto &keyInfo : PIVCard::supportedKeys()) {
KeyWidgets keyWidgets = createKeyWidgets(keyInfo);
layoutKeyWidgets(grid, PIVCard::keyDisplayName(keyInfo.keyRef), keyWidgets);
}
row = grid->rowCount();
......@@ -180,8 +168,9 @@ PIVCardWidget::PIVCardWidget(QWidget *parent)
grid->setColumnStretch(4, -1);
}
PIVCardWidget::KeyWidgets PIVCardWidget::createKeyWidgets(const std::string &keyRef)
PIVCardWidget::KeyWidgets PIVCardWidget::createKeyWidgets(const KeyPairInfo &keyInfo)
{
const std::string keyRef = keyInfo.keyRef;
KeyWidgets keyWidgets;
keyWidgets.keyGrip = new QLabel(this);
keyWidgets.keyGrip->setTextInteractionFlags(Qt::TextBrowserInteraction);
......
......@@ -23,6 +23,7 @@ namespace Kleo
namespace SmartCard
{
class KeyPairInfo;
class PIVCard;
} // namespace SmartCard
......@@ -46,7 +47,7 @@ public:
};
private:
KeyWidgets createKeyWidgets(const std::string &keyRef);
KeyWidgets createKeyWidgets(const SmartCard::KeyPairInfo &keyInfo);
void updateKeyWidgets(const std::string &keyRef, const SmartCard::PIVCard *card);
void generateKey(const std::string &keyref);
void writeCertificateToCard(const std::string &keyref);
......
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