1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // See LICENSE.txt for the text of the license.
15 //-----------------------------------------------------------------------------
16 // EMV core functionality
17 //-----------------------------------------------------------------------------
27 #include "iso7816/apduinfo.h"
28 #include "iso7816/iso7816core.h"
31 typedef enum TransactionType
{
33 TT_VSDC
, // contact only. not standard for contactless
38 extern const char *TransactionTypeStr
[];
51 enum CardPSVendor
GetCardPSVendor(uint8_t *AID
, size_t AIDlen
);
53 bool TLVPrintFromBuffer(uint8_t *data
, int datalen
);
54 void TLVPrintFromTLV(struct tlvdb
*tlv
);
55 void TLVPrintFromTLVLev(struct tlvdb
*tlv
, int level
);
56 void TLVPrintAIDlistFromSelectTLV(struct tlvdb
*tlv
);
58 struct tlvdb
*GetPANFromTrack2(const struct tlv
*track2
);
59 struct tlvdb
*GetdCVVRawFromTrack2(const struct tlv
*track2
);
62 int EMVExchange(Iso7816CommandChannel channel
, bool LeaveFieldON
, sAPDU_t apdu
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
65 int EMVSearchPSE(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, bool decodeTLV
, struct tlvdb
*tlv
);
66 int EMVSearch(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, bool decodeTLV
, struct tlvdb
*tlv
, bool verbose
);
67 int EMVSelectPSE(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t PSENum
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
);
68 int EMVSelect(Iso7816CommandChannel channel
, bool ActivateField
, bool LeaveFieldON
, uint8_t *AID
, size_t AIDLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
70 int EMVSelectApplication(struct tlvdb
*tlv
, uint8_t *AID
, size_t *AIDlen
);
71 // Get Processing Options
72 int EMVGPO(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *PDOL
, size_t PDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
73 int EMVReadRecord(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t SFI
, uint8_t SFIrec
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
75 // Emv override get data
76 int EMVGetData(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint16_t foo
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
78 int EMVGenerateChallenge(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
79 int EMVAC(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t RefControl
, uint8_t *CDOL
, size_t CDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
81 int EMVInternalAuthenticate(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *DDOL
, size_t DDOLLen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
83 int MSCComputeCryptoChecksum(Iso7816CommandChannel channel
, bool LeaveFieldON
, uint8_t *UDOL
, uint8_t UDOLlen
, uint8_t *Result
, size_t MaxResultLen
, size_t *ResultLen
, uint16_t *sw
, struct tlvdb
*tlv
);
85 int trSDA(struct tlvdb
*tlv
);
86 int trDDA(Iso7816CommandChannel channel
, bool decodeTLV
, struct tlvdb
*tlv
);
87 int trCDA(struct tlvdb
*tlv
, struct tlvdb
*ac_tlv
, struct tlv
*pdol_data_tlv
, struct tlv
*ac_data_tlv
);
89 int RecoveryCertificates(struct tlvdb
*tlvRoot
, json_t
*root
);
91 struct emv_pk
*get_ca_pk(struct tlvdb
*db
);