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 //-----------------------------------------------------------------------------
17 //-----------------------------------------------------------------------------
18 #include "cmdhfseos.h"
21 #include <ctype.h> // tolower
22 #include "cliparser.h"
23 #include "cmdparser.h" // command_t
24 #include "comms.h" // clearCommandBuffer
28 #include "cmdhf14a.h" // manufacture
29 #include "protocols.h" // definitions of ISO14A/7816 protocol
30 #include "iso7816/apduinfo.h" // GetAPDUCodeDescription
31 #include "crypto/asn1utils.h" // ASN1 decode / print
32 #include "commonutil.h" // get_sw
33 #include "protocols.h" // ISO7816 APDU return codes
35 static int CmdHelp(const char *Cmd
);
37 static int seos_select(void) {
38 bool activate_field
= true;
39 bool keep_field_on
= true;
40 uint8_t response
[PM3_CMD_DATA_SIZE
];
43 // --------------- Select SEOS applet ----------------
44 uint8_t aSELECT_AID
[80];
45 int aSELECT_AID_n
= 0;
46 param_gethex_to_eol("00a404000aa000000440000101000100", 0, aSELECT_AID
, sizeof(aSELECT_AID
), &aSELECT_AID_n
);
47 int res
= ExchangeAPDU14a(aSELECT_AID
, aSELECT_AID_n
, activate_field
, keep_field_on
, response
, sizeof(response
), &resplen
);
48 if (res
!= PM3_SUCCESS
) {
58 uint16_t sw
= get_sw(response
, resplen
);
59 if (sw
!= ISO7816_OK
) {
60 PrintAndLogEx(ERR
, "Selecting SEOS applet aid failed (%04x - %s).", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
65 activate_field
= false;
66 keep_field_on
= false;
67 // --------------- CC file reading ----------------
69 uint8_t aSELECT_FILE_ADF
[30];
70 int aSELECT_FILE_ADF_n
= 0;
71 param_gethex_to_eol("80a504001306112b0601040181e43801010201180101020200", 0, aSELECT_FILE_ADF
, sizeof(aSELECT_FILE_ADF
), &aSELECT_FILE_ADF_n
);
72 res
= ExchangeAPDU14a(aSELECT_FILE_ADF
, aSELECT_FILE_ADF_n
, activate_field
, keep_field_on
, response
, sizeof(response
), &resplen
);
73 if (res
!= PM3_SUCCESS
) {
78 sw
= get_sw(response
, resplen
);
79 if (sw
!= ISO7816_OK
) {
80 PrintAndLogEx(ERR
, "Selecting ADF file failed (%04x - %s).", sw
, GetAPDUCodeDescription(sw
>> 8, sw
& 0xff));
85 // remove the 2byte SW
86 asn1_print(response
, resplen
- 2, " ");
90 int infoSeos(bool verbose
) {
91 int res
= seos_select();
92 if (res
== PM3_SUCCESS
) {
93 PrintAndLogEx(NORMAL
, "");
94 PrintAndLogEx(INFO
, "--- " _CYAN_("Tag Information") " ---------------------------");
99 static int CmdHfSeosInfo(const char *Cmd
) {
100 CLIParserContext
*ctx
;
101 CLIParserInit(&ctx
, "hf seos info",
102 "Get info from SEOS tags",
109 CLIExecWithReturn(ctx
, Cmd
, argtable
, true);
111 return infoSeos(true);
114 static int CmdHfSeosList(const char *Cmd
) {
115 return CmdTraceListAlias(Cmd
, "hf seos", "seos -c");
118 static command_t CommandTable
[] = {
119 {"help", CmdHelp
, AlwaysAvailable
, "This help"},
120 {"info", CmdHfSeosInfo
, IfPm3NfcBarcode
, "Tag information"},
121 {"list", CmdHfSeosList
, AlwaysAvailable
, "List SEOS history"},
122 {NULL
, NULL
, NULL
, NULL
}
125 static int CmdHelp(const char *Cmd
) {
126 (void)Cmd
; // Cmd is not used so far
127 CmdsHelp(CommandTable
);
131 int CmdHFSeos(const char *Cmd
) {
132 clearCommandBuffer();
133 return CmdsParse(CommandTable
, Cmd
);