Add ROCA vulnerability test (RRG repository PR 76 by @merlokk) (#762)
[proxmark3-svn] / client / emv / emvcore.h
CommitLineData
a2bb2735 1//-----------------------------------------------------------------------------
2// Copyright (C) 2017 Merlok
3//
4// This code is licensed to you under the terms of the GNU GPL, version 2 or,
5// at your option, any later version. See the LICENSE.txt file for the text of
6// the license.
7//-----------------------------------------------------------------------------
3c5fce2b 8// EMV core functionality
a2bb2735 9//-----------------------------------------------------------------------------
10
11#ifndef EMVCORE_H__
12#define EMVCORE_H__
13
14#include <stdio.h>
15#include <stdint.h>
16#include <stdlib.h>
17#include <inttypes.h>
3c5fce2b 18#include <string.h>
95b697f0 19#include <jansson.h>
a2bb2735 20#include "util.h"
21#include "common.h"
22#include "ui.h"
3c5fce2b 23#include "cmdhf14a.h"
d03fb293
OM
24#include "apduinfo.h"
25#include "tlv.h"
26#include "dol.h"
27#include "dump.h"
28#include "emv_tags.h"
29#include "emv_pk.h"
30#include "emv_pki.h"
a2bb2735 31
3c5fce2b
OM
32#define APDU_RES_LEN 260
33#define APDU_AID_LEN 50
34
8d7d7b61 35typedef enum {
36 ECC_CONTACTLESS,
37 ECC_CONTACT
38} EMVCommandChannel;
39
10d4f823 40enum TransactionType {
41 TT_MSD,
42 TT_VSDC, // not standart for contactless!!!!
43 TT_QVSDCMCHIP,
44 TT_CDA,
45};
95b697f0 46extern char *TransactionTypeStr[];
10d4f823 47
66efdc1f 48typedef struct {
49 uint8_t CLA;
50 uint8_t INS;
51 uint8_t P1;
52 uint8_t P2;
53 uint8_t Lc;
54 uint8_t *data;
55} sAPDU;
56
57enum CardPSVendor {
58 CV_NA,
59 CV_VISA,
60 CV_MASTERCARD,
61 CV_AMERICANEXPRESS,
62 CV_JCB,
63 CV_CB,
64 CV_OTHER,
65};
66extern enum CardPSVendor GetCardPSVendor(uint8_t * AID, size_t AIDlen);
67
1511ea28 68extern bool TLVPrintFromBuffer(uint8_t *data, int datalen);
3c5fce2b 69extern void TLVPrintFromTLV(struct tlvdb *tlv);
66efdc1f 70extern void TLVPrintFromTLVLev(struct tlvdb *tlv, int level);
3c5fce2b
OM
71extern void TLVPrintAIDlistFromSelectTLV(struct tlvdb *tlv);
72
66efdc1f 73extern struct tlvdb *GetPANFromTrack2(const struct tlv *track2);
74extern struct tlvdb *GetdCVVRawFromTrack2(const struct tlv *track2);
75
3c5fce2b
OM
76extern void SetAPDULogging(bool logging);
77
39cc1c87 78// exchange
8d7d7b61 79extern int EMVExchange(EMVCommandChannel channel, bool LeaveFieldON, sAPDU apdu, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
39cc1c87 80
3c5fce2b 81// search application
1511ea28 82extern int EMVSearchPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, bool decodeTLV, struct tlvdb *tlv);
8d7d7b61 83extern int EMVSearch(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, bool decodeTLV, struct tlvdb *tlv);
84extern int EMVSelectPSE(EMVCommandChannel channel, bool ActivateField, bool LeaveFieldON, uint8_t PSENum, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw);
85extern 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);
3c5fce2b
OM
86// select application
87extern int EMVSelectApplication(struct tlvdb *tlv, uint8_t *AID, size_t *AIDlen);
88// Get Processing Options
8d7d7b61 89extern 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);
90extern 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);
10d4f823 91// AC
8d7d7b61 92extern int EMVGenerateChallenge(EMVCommandChannel channel, bool LeaveFieldON, uint8_t *Result, size_t MaxResultLen, size_t *ResultLen, uint16_t *sw, struct tlvdb *tlv);
93extern 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);
d03fb293 94// DDA
8d7d7b61 95extern 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);
66efdc1f 96// Mastercard
8d7d7b61 97int 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);
10d4f823 98// Auth
d03fb293 99extern int trSDA(struct tlvdb *tlv);
8d7d7b61 100extern int trDDA(EMVCommandChannel channel, bool decodeTLV, struct tlvdb *tlv);
d03fb293 101extern int trCDA(struct tlvdb *tlv, struct tlvdb *ac_tlv, struct tlv *pdol_data_tlv, struct tlv *ac_data_tlv);
a2bb2735 102
95b697f0
OM
103extern int RecoveryCertificates(struct tlvdb *tlvRoot, json_t *root);
104
1511ea28 105extern struct emv_pk *get_ca_pk(struct tlvdb *db);
a2bb2735 106#endif
107
108
109
110
Impressum, Datenschutz