File indexing completed on 2024-06-16 04:56:17

0001 /*  view/pivcardwiget.h
0002 
0003     This file is part of Kleopatra, the KDE keymanager
0004     SPDX-FileCopyrightText: 2020 g10 Code GmbH
0005     SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
0006 
0007     SPDX-License-Identifier: GPL-2.0-or-later
0008 */
0009 #pragma once
0010 
0011 #include <smartcard/keypairinfo.h>
0012 
0013 #include <QMap>
0014 #include <QWidget>
0015 
0016 #include <gpgme++/error.h>
0017 
0018 class QLabel;
0019 class QPushButton;
0020 
0021 namespace Kleo
0022 {
0023 
0024 namespace SmartCard
0025 {
0026 class PIVCard;
0027 } // namespace SmartCard
0028 
0029 class PIVCardWidget : public QWidget
0030 {
0031     Q_OBJECT
0032 public:
0033     explicit PIVCardWidget(QWidget *parent = nullptr);
0034     ~PIVCardWidget() override;
0035 
0036     void setCard(const SmartCard::PIVCard *card);
0037 
0038     struct KeyWidgets {
0039         SmartCard::KeyPairInfo keyInfo;
0040         std::string certificateData;
0041         QLabel *keyGrip = nullptr;
0042         QLabel *keyAlgorithm = nullptr;
0043         QLabel *certificateInfo = nullptr;
0044         QPushButton *generateButton = nullptr;
0045         QPushButton *createCSRButton = nullptr;
0046         QPushButton *writeCertificateButton = nullptr;
0047         QPushButton *importCertificateButton = nullptr;
0048         QPushButton *writeKeyButton = nullptr;
0049     };
0050 
0051 private:
0052     KeyWidgets createKeyWidgets(const SmartCard::KeyPairInfo &keyInfo);
0053     void updateCachedValues(const std::string &keyRef, const SmartCard::PIVCard *card);
0054     void updateKeyWidgets(const std::string &keyRef);
0055     void generateKey(const std::string &keyref);
0056     void createCSR(const std::string &keyref);
0057     void writeCertificateToCard(const std::string &keyref);
0058     void importCertificateFromCard(const std::string &keyref);
0059     void writeKeyToCard(const std::string &keyref);
0060     void createKeyFromCardKeys();
0061     void changePin(const std::string &keyRef);
0062     void setAdminKey();
0063 
0064 private:
0065     std::string mCardSerialNumber;
0066     QLabel *mSerialNumber = nullptr;
0067     QLabel *mVersionLabel = nullptr;
0068     QPushButton *mKeyForCardKeysButton = nullptr;
0069     std::map<std::string, KeyWidgets> mKeyWidgets;
0070 };
0071 } // namespace Kleo