Merge pull request #97 from merlokk/contact_scan

Contact scan
This commit is contained in:
Oleg Moiseenko 2019-02-20 16:13:48 +02:00 committed by GitHub
commit d1bbab7dc4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 54 additions and 27 deletions

View file

@ -292,7 +292,10 @@ static int PrintATR(uint8_t *atr, size_t atrlen) {
return 0; return 0;
} }
static bool smart_select(bool silent) { bool smart_select(bool silent, smart_card_atr_t *atr) {
if (atr)
memset(atr, 0, sizeof(smart_card_atr_t));
UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}}; UsbCommand c = {CMD_SMART_ATR, {0, 0, 0}};
clearCommandBuffer(); clearCommandBuffer();
SendCommand(&c); SendCommand(&c);
@ -308,12 +311,14 @@ static bool smart_select(bool silent) {
return false; return false;
} }
if (!silent) { smart_card_atr_t card;
smart_card_atr_t card; memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
memcpy(&card, (smart_card_atr_t *)resp.d.asBytes, sizeof(smart_card_atr_t));
if (atr)
memcpy(atr, &card, sizeof(smart_card_atr_t));
if (!silent)
PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len)); PrintAndLogEx(INFO, "ISO7816-3 ATR : %s", sprint_hex(card.atr, card.atr_len));
}
return true; return true;
} }
@ -518,7 +523,7 @@ int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leave
*dataoutlen = 0; *dataoutlen = 0;
if (activateCard) if (activateCard)
smart_select(false); smart_select(false, NULL);
PrintAndLogEx(DEBUG, "APDU SC"); PrintAndLogEx(DEBUG, "APDU SC");
@ -1017,7 +1022,7 @@ int CmdSmartBruteforceSFI(const char *Cmd) {
return 1; return 1;
PrintAndLogEx(INFO, "Selecting card"); PrintAndLogEx(INFO, "Selecting card");
if ( !smart_select(false) ) if ( !smart_select(false, NULL) )
return 1; return 1;
char* caid = NULL; char* caid = NULL;

View file

@ -33,6 +33,7 @@ extern int CmdSmartUpgrade(const char* cmd);
extern int CmdSmartInfo(const char* cmd); extern int CmdSmartInfo(const char* cmd);
extern int CmdSmartReader(const char *Cmd); extern int CmdSmartReader(const char *Cmd);
extern bool smart_select(bool silent, smart_card_atr_t *atr);
extern int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen); extern int ExchangeAPDUSC(uint8_t *datain, int datainlen, bool activateCard, bool leaveSignalON, uint8_t *dataout, int maxdataoutlen, int *dataoutlen);
extern int usage_sm_raw(void); extern int usage_sm_raw(void);

View file

@ -792,6 +792,14 @@ int CmdEMVExec(const char *cmd) {
uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2; uint8_t psenum = (channel == ECC_CONTACT) ? 1 : 2;
CLIParserFree(); CLIParserFree();
#ifndef WITH_SMARTCARD
// not compiled with smartcard functionality, we need to exit
if ( channel == ECC_CONTACT ) {
PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting.");
return 0;
}
#endif
SetAPDULogging(showAPDU); SetAPDULogging(showAPDU);
// init applets list tree // init applets list tree
@ -1380,13 +1388,15 @@ int CmdEMVScan(const char *cmd) {
CLIGetStrWithReturn(12, relfname, &relfnamelen); CLIGetStrWithReturn(12, relfname, &relfnamelen);
CLIParserFree(); CLIParserFree();
SetAPDULogging(showAPDU); #ifndef WITH_SMARTCARD
// not compiled with smartcard functionality, we need to exit
// TODO if ( channel == ECC_CONTACT ) {
if (channel == ECC_CONTACT) { PrintAndLogEx(WARNING, "PM3 Client is not compiled with support for SMARTCARD. Exiting.");
PrintAndLogEx(ERR, "Do not use contact interface. Exit."); return 0;
return 1;
} }
#endif
SetAPDULogging(showAPDU);
// current path + file name // current path + file name
if (!strstr(crelfname, ".json")) if (!strstr(crelfname, ".json"))
@ -1413,21 +1423,31 @@ int CmdEMVScan(const char *cmd) {
// drop field at start // drop field at start
DropFieldEx( channel ); DropFieldEx( channel );
// iso 14443 select
PrintAndLogEx(NORMAL, "--> GET UID, ATS.");
iso14a_card_select_t card;
if (Hf14443_4aGetCardData(&card)) {
return 2;
}
JsonSaveStr(root, "$.File.Created", "proxmark3 `emv scan`"); JsonSaveStr(root, "$.File.Created", "proxmark3 `emv scan`");
JsonSaveStr(root, "$.Card.Communication", "iso14443-4a"); if (channel == ECC_CONTACTLESS) {
JsonSaveBufAsHex(root, "$.Card.UID", (uint8_t *)&card.uid, card.uidlen); // iso 14443 select
JsonSaveHex(root, "$.Card.ATQA", card.atqa[0] + (card.atqa[1] << 2), 2); PrintAndLogEx(NORMAL, "--> GET UID, ATS.");
JsonSaveHex(root, "$.Card.SAK", card.sak, 0);
JsonSaveBufAsHex(root, "$.Card.ATS", (uint8_t *)card.ats, card.ats_len); iso14a_card_select_t card;
if (Hf14443_4aGetCardData(&card)) {
return 2;
}
JsonSaveStr(root, "$.Card.Contactless.Communication", "iso14443-4a");
JsonSaveBufAsHex(root, "$.Card.Contactless.UID", (uint8_t *)&card.uid, card.uidlen);
JsonSaveHex(root, "$.Card.Contactless.ATQA", card.atqa[0] + (card.atqa[1] << 2), 2);
JsonSaveHex(root, "$.Card.Contactless.SAK", card.sak, 0);
JsonSaveBufAsHex(root, "$.Card.Contactless.ATS", (uint8_t *)card.ats, card.ats_len);
} else {
PrintAndLogEx(NORMAL, "--> GET ATR.");
smart_card_atr_t card;
smart_select(true, &card);
JsonSaveStr(root, "$.Card.Contact.Communication", "iso7816");
JsonSaveBufAsHex(root, "$.Card.Contact.ATR", (uint8_t *)card.atr, card.atr_len);
}
// init applets list tree // init applets list tree
const char *al = "Applets list"; const char *al = "Applets list";
@ -1695,6 +1715,7 @@ int CmdEMVRoca(const char *cmd) {
if (arg_get_lit(2)) if (arg_get_lit(2))
channel = ECC_CONTACT; channel = ECC_CONTACT;
PrintChannel(channel); PrintChannel(channel);
CLIParserFree();
#ifndef WITH_SMARTCARD #ifndef WITH_SMARTCARD
// not compiled with smartcard functionality, we need to exit // not compiled with smartcard functionality, we need to exit