From 034b64f4153550cbe5849bcbfc27e187377cc512 Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Thu, 29 Jun 2023 00:06:20 +0200 Subject: EMV keyfile support: Overall code improvements and bug fixes --- src/Common/EMVCard.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/Common/EMVCard.h (limited to 'src/Common/EMVCard.h') diff --git a/src/Common/EMVCard.h b/src/Common/EMVCard.h new file mode 100644 index 00000000..116de705 --- /dev/null +++ b/src/Common/EMVCard.h @@ -0,0 +1,69 @@ +#ifndef TC_HEADER_Common_EMVCard +#define TC_HEADER_Common_EMVCard + +#include "Platform/PlatformBase.h" +#if defined (TC_WINDOWS) && !defined (TC_PROTOTYPE) +# include "Exception.h" +#else +# include "Platform/Exception.h" +#endif + +#include "Token.h" +#include "SCard.h" + +namespace VeraCrypt +{ + typedef enum EMVCardType + { + NONE = 0, + AMEX, + MASTERCARD, + VISA + } EMVCardType; + + class EMVCard : public SCard + { + protected: + + // The following fields will only be empty if the card has not been read yet. + // After the card has been read, and if some or all fields cannot be read, the EMVCard + // object will be considered invalid and will not be included in the list of available cards + // of EMVToken. + vector m_aid; + vector> m_supportedAids; + vector m_iccCert; + vector m_issuerCert; + vector m_cplcData; + wstring m_lastPANDigits; + + public: + + // Add other AIDS + // https://gist.github.com/pvieito/6224eed92c99b069f6401996c548d0e4 + // https://ambimat.com/developer-resources/list-of-application-identifiers-aid/ + const static byte AMEX_AID[7]; + const static byte MASTERCARD_AID[7]; + const static byte VISA_AID[7]; + const static map> SUPPORTED_AIDS; + + EMVCard(); + EMVCard(size_t slotId); + EMVCard(const EMVCard& other); + EMVCard(EMVCard&& other); + EMVCard& operator = (const EMVCard& other); + EMVCard& operator = (EMVCard&& other); + virtual ~EMVCard(); + + void Clear(void); + + // Retrieves the card's AID. + // It first checks the card against a list of supported AIDs. + // If that fails, it tries getting the AID from the card using PSE + vector GetCardAID(bool forceContactless = false); + + void GetCardContent(vector& iccCert, vector& issuerCert, vector& cplcData); + void GetCardPAN(wstring& lastPANDigits); + }; +} + +#endif // TC_HEADER_Common_EMVCard -- cgit v1.2.3