proxmark3/client/emv/emvcore.h

95 lines
3.9 KiB
C
Raw Normal View History

2017-11-11 03:08:28 +08:00
//-----------------------------------------------------------------------------
// Copyright (C) 2017 Merlok
//
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
// at your option, any later version. See the LICENSE.txt file for the text of
// the license.
//-----------------------------------------------------------------------------
2017-11-25 10:28:02 +08:00
// EMV core functionality
2017-11-11 03:08:28 +08:00
//-----------------------------------------------------------------------------
#ifndef EMVCORE_H__
#define EMVCORE_H__
#include "common.h"
2017-11-11 03:08:28 +08:00
#include <inttypes.h>
2018-11-20 22:26:35 +08:00
#include <jansson.h>
#include "apduinfo.h"
#include "emv_pki.h"
2017-11-11 03:08:28 +08:00
2017-11-25 10:28:02 +08:00
#define APDU_RES_LEN 260
#define APDU_AID_LEN 50
2018-12-04 01:29:31 +08:00
typedef enum {
2019-03-10 06:35:06 +08:00
ECC_CONTACTLESS,
ECC_CONTACT
2018-12-04 01:29:31 +08:00
} EMVCommandChannel;
enum TransactionType {
2019-03-10 06:35:06 +08:00
TT_MSD,
TT_VSDC, // contact only. not standard for contactless
2019-03-10 06:35:06 +08:00
TT_QVSDCMCHIP,
TT_CDA,
};
extern const char *TransactionTypeStr[];
enum CardPSVendor {
2019-03-10 06:35:06 +08:00
CV_NA,
CV_VISA,
CV_MASTERCARD,
CV_AMERICANEXPRESS,
CV_JCB,
CV_CB,
2019-04-10 15:37:46 +08:00
CV_SWITCH,
CV_DINERS,
2019-03-10 06:35:06 +08:00
CV_OTHER,
};
2019-04-06 06:52:55 +08:00
enum CardPSVendor GetCardPSVendor(uint8_t *AID, size_t AIDlen);
2019-04-06 06:52:55 +08:00
bool TLVPrintFromBuffer(uint8_t *data, int datalen);
void TLVPrintFromTLV(struct tlvdb *tlv);
void TLVPrintFromTLVLev(struct tlvdb *tlv, int level);
void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv);
2017-11-25 10:28:02 +08:00
2019-04-06 06:52:55 +08:00
struct tlvdb *GetPANFromTrack2(const struct tlv *track2);
struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2);
2019-04-06 06:52:55 +08:00
void SetAPDULogging(bool logging);
bool GetAPDULogging(void);
2017-11-25 10:28:02 +08:00
// exchange
2019-04-06 06:52:55 +08:00
int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
2017-11-25 10:28:02 +08:00
// search application
2019-04-06 06:52:55 +08:00
int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, bool decodeTLV, struct tlvdb *tlv);
int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv);
int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw);
int EMVSelect(EMVCommandChannel 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);
2017-11-25 10:28:02 +08:00
// select application
2019-04-06 06:52:55 +08:00
int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen);
2017-11-25 10:28:02 +08:00
// Get Processing Options
2019-04-06 06:52:55 +08:00
int EMVGPO(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *PDOL, size_t PDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
int EMVReadRecord(EMVCommandChannel channel, bool LeaveFieldON, uint8_t SFI, uint8_t SFIrec, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// AC
2019-04-06 06:52:55 +08:00
int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
int EMVAC(EMVCommandChannel 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);
// DDA
2019-04-06 06:52:55 +08:00
int EMVInternalAuthenticate(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *DDOL, size_t DDOLLen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// Mastercard
2018-12-04 01:29:31 +08:00
int MSCComputeCryptoChecksum(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *UDOL, uint8_t UDOLlen, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
// Auth
2019-04-06 06:52:55 +08:00
int trSDA(struct tlvdb *tlv);
int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv);
int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, struct tlv *ac_data_tlv);
2017-11-11 03:08:28 +08:00
2019-04-06 06:52:55 +08:00
int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root);
2018-11-20 22:26:35 +08:00
2019-04-06 06:52:55 +08:00
struct emv_pk *get_ca_pk(struct tlvdb *db);
2017-11-11 03:08:28 +08:00
#endif