recover_pk.py: replace secp192r1 by prime192v1
[RRG-proxmark3.git] / client / src / emv / emvcore.h
blob6ff2b6ef94aaf67a991c4c65674b9a7e2de547dc
1 //-----------------------------------------------------------------------------
2 // Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
3 //
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.
8 //
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 //-----------------------------------------------------------------------------
19 #ifndef EMVCORE_H__
20 #define EMVCORE_H__
22 #include "common.h"
24 #include <inttypes.h>
25 #include <jansson.h>
27 #include "iso7816/apduinfo.h"
28 #include "iso7816/iso7816core.h"
29 #include "emv_pki.h"
31 typedef enum TransactionType {
32 TT_MSD,
33 TT_VSDC, // contact only. not standard for contactless
34 TT_QVSDCMCHIP,
35 TT_CDA,
36 TT_END,
37 } TransactionType_t;
38 extern const char *TransactionTypeStr[];
40 enum CardPSVendor {
41 CV_NA,
42 CV_VISA,
43 CV_MASTERCARD,
44 CV_AMERICANEXPRESS,
45 CV_JCB,
46 CV_CB,
47 CV_SWITCH,
48 CV_DINERS,
49 CV_OTHER,
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);
61 // exchange
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);
64 // search application
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);
69 // select application
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);
77 // AC
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);
80 // DDA
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);
82 // Mastercard
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);
84 // Auth
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);
92 #endif