1 #pragma once 2 /* smartcard/card.h 3 4 This file is part of Kleopatra, the KDE keymanager 5 SPDX-FileCopyrightText: 2017 Bundesamt für Sicherheit in der Informationstechnik 6 SPDX-FileContributor: Intevation GmbH 7 8 SPDX-License-Identifier: GPL-2.0-or-later 9 */ 10 11 #include "keypairinfo.h" 12 13 #include <map> 14 #include <string> 15 #include <vector> 16 17 #include <QString> 18 19 namespace Kleo 20 { 21 namespace SmartCard 22 { 23 24 /** Class representing an application on a smartcard or similar hardware token. */ 25 class Card 26 { 27 public: 28 enum PinState { 29 UnknownPinState, 30 NullPin, 31 PinBlocked, 32 NoPin, 33 PinOk, 34 35 NumPinStates 36 }; 37 38 enum Status { 39 NoCard, 40 CardPresent, 41 CardActive, 42 CardUsable, 43 44 _NumScdStates, 45 46 CardError = _NumScdStates, 47 48 NumStates 49 }; 50 51 Card(); 52 virtual ~Card(); 53 54 virtual bool operator == (const Card &other) const; 55 bool operator != (const Card &other) const; 56 57 void setStatus(Status s); 58 Status status() const; 59 60 void setSerialNumber(const std::string &sn); 61 std::string serialNumber() const; 62 63 void setCardInfo(const std::vector<std::pair<std::string, std::string>> &infos); 64 65 QString displaySerialNumber() const; 66 void setDisplaySerialNumber(const QString &sn); 67 68 std::string appName() const; 69 70 void setAppVersion(int version); 71 int appVersion() const; 72 QString displayAppVersion() const; 73 74 void setManufacturer(const std::string &manufacturer); 75 std::string manufacturer() const; 76 77 std::string cardType() const; 78 79 int cardVersion() const; 80 QString displayCardVersion() const; 81 82 QString cardHolder() const; 83 84 void setSigningKeyRef(const std::string &keyRef); 85 std::string signingKeyRef() const; 86 bool hasSigningKey() const; 87 88 void setEncryptionKeyRef(const std::string &keyRef); 89 std::string encryptionKeyRef() const; 90 bool hasEncryptionKey() const; 91 92 void setAuthenticationKeyRef(const std::string &keyRef); 93 std::string authenticationKeyRef() const; 94 bool hasAuthenticationKey() const; 95 96 std::vector<PinState> pinStates() const; 97 void setPinStates(const std::vector<PinState> &pinStates); 98 99 bool hasNullPin() const; 100 void setHasNullPin(bool value); 101 102 bool canLearnKeys() const; 103 void setCanLearnKeys(bool value); 104 105 QString errorMsg() const; 106 void setErrorMsg(const QString &msg); 107 108 const std::vector<KeyPairInfo> & keyInfos() const; 109 const KeyPairInfo & keyInfo(const std::string &keyRef) const; 110 111 std::string keyFingerprint(const std::string &keyRef) const; 112 113 protected: 114 void setAppName(const std::string &name); 115 void setInitialKeyInfos(const std::vector<KeyPairInfo> &infos); 116 117 virtual void processCardInfo(); 118 119 void addCardInfo(const std::string &name, const std::string &value); 120 std::string cardInfo(const std::string &name) const; 121 122 private: 123 void parseCardInfo(const std::string &name, const std::string &value); 124 125 void updateKeyInfo(const KeyPairInfo &keyPairInfo); 126 127 private: 128 bool mCanLearn = false; 129 bool mHasNullPin = false; 130 Status mStatus = NoCard; 131 std::string mSerialNumber; 132 QString mDisplaySerialNumber; 133 std::string mAppName; 134 int mAppVersion = -1; 135 std::string mCardType; 136 int mCardVersion = -1; 137 QString mCardHolder; 138 std::string mSigningKeyRef; 139 std::string mEncryptionKeyRef; 140 std::string mAuthenticationKeyRef; 141 std::vector<PinState> mPinStates; 142 QString mErrMsg; 143 std::vector<KeyPairInfo> mKeyInfos; 144 std::multimap<std::string, std::string> mCardInfo; 145 }; 146 } // namespace Smartcard 147 } // namespace Kleopatra 148 149