added hexact parser
This commit is contained in:
1 parent
72f48c8a02
commit
7142ddc9bd
10 files changed
+467
-248
No files matched your search
+19
-2
@@ -45,6 +45,7 @@
|
||||
#include "mifare/gen4.h"
|
||||
#include "parsers/parsehid.h"
|
||||
#include "parsers/parsevigik.h"
|
||||
#include "parsers/parsehexact.h"
|
||||
#include "generator.h" // keygens.
|
||||
#include "fpga.h"
|
||||
#include "mifare/mifarehost.h"
|
||||
@@ -885,6 +886,10 @@ static int mf_view_dump(uint8_t *dump, size_t bytes_read, uint16_t block_cnt, bo
|
||||
(void)vigik_parser_parse(dump, bytes_read);
|
||||
}
|
||||
|
||||
if (is_valid_hexact_card(dump, bytes_read)) {
|
||||
(void)hexact_parser_parse(dump, bytes_read);
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -8466,13 +8471,15 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mf view",
|
||||
"Print a MIFARE Classic dump file (bin/eml/json)",
|
||||
"hf mf view -f hf-mf-01020304-dump.bin"
|
||||
"hf mf view -f hf-mf-01020304-dump.bin\n"
|
||||
"hf mf view --selftest"
|
||||
);
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
|
||||
arg_str0("f", "file", "<fn>", "Specify a filename for dump file"),
|
||||
arg_lit0("v", "verbose", "verbose output"),
|
||||
arg_lit0(NULL, "sk", "Save extracted keys to binary file"),
|
||||
arg_lit0(NULL, "selftest", "Run the dump parsers self tests and exit"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
@@ -8481,8 +8488,18 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool save_keys = arg_get_lit(ctx, 3);
|
||||
bool selftest = arg_get_lit(ctx, 4);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (selftest) {
|
||||
return vigik_selftest();
|
||||
}
|
||||
|
||||
if (fnlen == 0) {
|
||||
PrintAndLogEx(ERR, "Specify a filename with `-f` or run `--selftest`");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
// read dump file
|
||||
uint8_t *dump = NULL;
|
||||
size_t bytes_read = 0;
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// See LICENSE.txt for the text of the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hexact / COGELEC / Intratone parser for MIFARE Classic dumps
|
||||
//
|
||||
// A VIGIK based residential access system, but one that carries no MAD, so the
|
||||
// VIGIK structure parser cannot find anything on it. What the layout is, as far
|
||||
// as it has been worked out against cards:
|
||||
//
|
||||
// sector 0 block 2 8 byte per card identifier, then a constant tail
|
||||
// sector 9 48 bytes, differs completely between cards
|
||||
// sector 11 32 bytes, differs completely between cards
|
||||
// sector 15 the system identifier, the same on every card
|
||||
// sector 16, 17 MIFARE Classic EV1 signature, not application data
|
||||
//
|
||||
// The sector 9 and 11 payload is not decoded. It carries no structure in common
|
||||
// between two cards, so it is enciphered with something not held here, and
|
||||
// printing a guess at fields would be inventing them.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#include "parsehexact.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "commonutil.h"
|
||||
#include "ui.h" // PrintAndLogEx
|
||||
#include "util.h" // sprint_hex
|
||||
#include "mifare/mifaredefault.h" // MFBLOCK_SIZE
|
||||
#include "mifare/mifare4.h" // mfFirstBlockOfSector
|
||||
|
||||
#define HEXACT_ID_SECTOR 15
|
||||
#define HEXACT_DATA_SECTOR_A 9
|
||||
#define HEXACT_DATA_SECTOR_B 11
|
||||
|
||||
// Sector 15 block 0 spells the system out and is identical on every card seen
|
||||
static const uint8_t hexact_marker[] = {
|
||||
'h', 'E', 'x', 'a', 'c', 't', ' ', '-', ' ', 'C', 'O', 'G', 'E', 'L', 'E', 'C'
|
||||
};
|
||||
|
||||
// Block 0 of these cards advertises SAK 0x88 while the tag itself answers 0x08.
|
||||
// A magic card written with that block 0 answers 0x88 in anticollision too,
|
||||
// which is how the readers spot a clone.
|
||||
#define HEXACT_BLOCK0_SAK 0x88
|
||||
|
||||
static const uint8_t *hexact_sector(const uint8_t *dump, size_t dumplen, uint8_t sector, uint8_t block) {
|
||||
size_t off = (mfFirstBlockOfSector(sector) + block) * MFBLOCK_SIZE;
|
||||
if (off + MFBLOCK_SIZE > dumplen) {
|
||||
return NULL;
|
||||
}
|
||||
return dump + off;
|
||||
}
|
||||
|
||||
bool is_valid_hexact_card(const uint8_t *dump, size_t dumplen) {
|
||||
const uint8_t *p = hexact_sector(dump, dumplen, HEXACT_ID_SECTOR, 0);
|
||||
if (p == NULL) {
|
||||
return false;
|
||||
}
|
||||
return (memcmp(p, hexact_marker, sizeof(hexact_marker)) == 0);
|
||||
}
|
||||
|
||||
int hexact_parser_parse(const uint8_t *dump, size_t dumplen) {
|
||||
|
||||
if (is_valid_hexact_card(dump, dumplen) == false) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, _CYAN_("Hexact / COGELEC / Intratone") " detected");
|
||||
|
||||
const uint8_t *id0 = hexact_sector(dump, dumplen, HEXACT_ID_SECTOR, 0);
|
||||
const uint8_t *id1 = hexact_sector(dump, dumplen, HEXACT_ID_SECTOR, 1);
|
||||
const uint8_t *id2 = hexact_sector(dump, dumplen, HEXACT_ID_SECTOR, 2);
|
||||
|
||||
PrintAndLogEx(INFO, "System............. %.16s", (const char *)id0);
|
||||
if (id1) {
|
||||
PrintAndLogEx(INFO, " %.16s", (const char *)id1);
|
||||
}
|
||||
if (id2) {
|
||||
PrintAndLogEx(INFO, " %.12s", (const char *)(id2 + 4));
|
||||
}
|
||||
|
||||
// sector 0 block 2 holds a per card value followed by a tail that is the
|
||||
// same on every card
|
||||
const uint8_t *s0b2 = hexact_sector(dump, dumplen, 0, 2);
|
||||
if (s0b2) {
|
||||
PrintAndLogEx(INFO, "Card identifier.... %s", sprint_hex_inrow(s0b2, 8));
|
||||
}
|
||||
|
||||
if (dumplen > 5 && dump[5] == HEXACT_BLOCK0_SAK) {
|
||||
PrintAndLogEx(INFO, "Block 0 SAK........ 0x%02X ( " _YELLOW_("anti clone marker") " )", dump[5]);
|
||||
PrintAndLogEx(INFO, " the tag answers 0x08, a clone written with this block 0 answers 0x88");
|
||||
}
|
||||
|
||||
const uint8_t *a = hexact_sector(dump, dumplen, HEXACT_DATA_SECTOR_A, 0);
|
||||
const uint8_t *b = hexact_sector(dump, dumplen, HEXACT_DATA_SECTOR_B, 0);
|
||||
if (a == NULL || b == NULL) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Payload............ sector %u and %u, " _YELLOW_("not decoded"),
|
||||
HEXACT_DATA_SECTOR_A, HEXACT_DATA_SECTOR_B);
|
||||
for (uint8_t blk = 0; blk < 3; blk++) {
|
||||
PrintAndLogEx(INFO, " sector %2u blk %u.. %s", HEXACT_DATA_SECTOR_A, blk, sprint_hex_inrow(a + (blk * MFBLOCK_SIZE), MFBLOCK_SIZE));
|
||||
}
|
||||
for (uint8_t blk = 0; blk < 3; blk++) {
|
||||
PrintAndLogEx(INFO, " sector %2u blk %u.. %s", HEXACT_DATA_SECTOR_B, blk, sprint_hex_inrow(b + (blk * MFBLOCK_SIZE), MFBLOCK_SIZE));
|
||||
}
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// Copyright (C) Proxmark3 contributors. See AUTHORS.md for details.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// See LICENSE.txt for the text of the license.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Hexact / COGELEC / Intratone parser for MIFARE Classic dumps
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef PARSEHEXACT_H__
|
||||
#define PARSEHEXACT_H__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
// True when sector 15 carries the Hexact system identifier
|
||||
bool is_valid_hexact_card(const uint8_t *dump, size_t dumplen);
|
||||
|
||||
// Print what is known about the layout of a Hexact card
|
||||
int hexact_parser_parse(const uint8_t *dump, size_t dumplen);
|
||||
|
||||
#endif
|
||||
+288
-244
@@ -30,6 +30,11 @@
|
||||
#include "mifare/mifaredefault.h" // MIFARE_KEY_SIZE
|
||||
#include "mbedtls/bignum.h"
|
||||
|
||||
#define VIGIK_SIG_LEN 128 // RSA 1024, the signature on the card
|
||||
#define VIGIK_MSG_SLOTS 64 // message byte slots in an ISO 9796-1 block
|
||||
#define VIGIK_MSG_PAD 8 // leading zero bytes of the signed message
|
||||
|
||||
|
||||
static const vigik_pk_t vigik_rsa_pk[] = {
|
||||
{"La Poste Service Universel", 0x07AA, "AB9953CBFCCD9375B6C028ADBAB7584BED15B9CA037FADED9765996F9EA1AB983F3041C90DA3A198804FF90D5D872A96A4988F91F2243B821E01C5021E3ED4E1BA83B7CFECAB0E766D8563164DE0B2412AE4E6EA63804DF5C19C7AA78DC14F608294D732D7C8C67A88C6F84C0F2E3FAFAE34084349E11AB5953AC68729D07715"},
|
||||
{"La Poste Service Universel", 0x07AA, "1577D02987C63A95B51AE149430834AEAF3F2E0F4CF8C6887AC6C8D732D79482604FC18DA77A9CC1F54D8063EAE6E42A41B2E04D1663856D760EABECCFB783BAE1D43E1E02C5011E823B24F2918F98A4962A875D0DF94F8098A1A30DC941303F98ABA19E6F996597EDAD7F03CAB915ED4B58B7BAAD28C0B67593CDFCCB5399AB"},
|
||||
@@ -37,11 +42,11 @@ static const vigik_pk_t vigik_rsa_pk[] = {
|
||||
{"La Poste Autres Services", 0x07AB, "A6D99B8D902893B04F3F8DE56CB6BF24338FEE897C1BCE6DFD4EBD05B7B1A07FD2EB564BB4F7D35DBFE0A42966C2C137AD156E3DAB62904592BCA20C0BC7B8B1E261EF82D53F52D203843566305A49A22062DECC38C2FE3864CAD08E79219487651E2F79F1C9392B48CAFE1BFFAFF4802AE451E7A283E55A4026AD1E82DF1A15"},
|
||||
{"La Poste Autres Services", 0x07AB, "151adf821ead26405ae583a2e751e42a80f4afff1bfeca482b39c9f1792f1e65879421798ed0ca6438fec238ccde6220a2495a3066358403d2523fd582ef61e2b1b8c70b0ca2bc92459062ab3d6e15ad37c1c26629a4e0bf5dd3f7b44b56ebd27fa0b1b705bd4efd6dce1b7c89ee8f3324bfb66ce58d3f4fb09328908d9bd9a6"},
|
||||
|
||||
{"France Telecom", 0x07AC, "C44DBCD92F9DCF42F4902A87335DBB35D2FF530CDB09814CFA1F4B95A1BD018D099BC6AB69F667B4922AE1ED826E72951AA3E0EAAA7D49A695F04F8CDAAE2D18D10D25BD529CBB05ABF070DC7C041EC35C2BA7F58CC4C349983CC6E11A5CBE828FB8ECBC26F08E1094A6B44C8953C8E1BAFD214DF3E69F430A98CCC75C03669D"},
|
||||
{"France Telecom", 0x07AC, "9d66035cc7cc980a439fe6f34d21fdbae1c853894cb4a694108ef026bcecb88f82be5c1ae1c63c9849c3c48cf5a72b5cc31e047cdc70f0ab05bb9c52bd250dd1182daeda8c4ff095a6497daaeae0a31a95726e82ede12a92b467f669abc69b098d01bda1954b1ffa4c8109db0c53ffd235bb5d33872a90f442cf9d2fd9bc4dc4"},
|
||||
{"France Telecom", 0x07AC, "B35193DBD2F88A21CDCFFF4BF84F7FC036A991A363DCB3E802407A5E5879DC2127EECFC520779E79E911394882482C87D09A88B0711CBC2973B77FFDAE40EA0001F595072708C558B484AB89D02BCBCB971FF1B80371C0BE30CB13661078078BB68EBCCA524B9DD55EBF7D47D9355AFC95511350CC1103A5DEE847868848B235"},
|
||||
{"France Telecom", 0x07AC, "35b248888647e8dea50311cc50135195fc5a35d9477dbf5ed59d4b52cabc8eb68b0778106613cb30bec07103b8f11f97cbcb2bd089ab84b458c508270795f50100ea40aefd7fb77329bc1c71b0889ad0872c4882483911e9799e7720c5cfee2721dc79585e7a4002e8b3dc63a391a936c07f4ff84bffcfcd218af8d2db9351b3"},
|
||||
|
||||
{"EDF-GDF", 0x07AD, "B35193DBD2F88A21CDCFFF4BF84F7FC036A991A363DCB3E802407A5E5879DC2127EECFC520779E79E911394882482C87D09A88B0711CBC2973B77FFDAE40EA0001F595072708C558B484AB89D02BCBCB971FF1B80371C0BE30CB13661078078BB68EBCCA524B9DD55EBF7D47D9355AFC95511350CC1103A5DEE847868848B235"},
|
||||
{"EDF-GDF", 0x07AD, "35b248888647e8dea50311cc50135195fc5a35d9477dbf5ed59d4b52cabc8eb68b0778106613cb30bec07103b8f11f97cbcb2bd089ab84b458c508270795f50100ea40aefd7fb77329bc1c71b0889ad0872c4882483911e9799e7720c5cfee2721dc79585e7a4002e8b3dc63a391a936c07f4ff84bffcfcd218af8d2db9351b3"},
|
||||
{"EDF-GDF", 0x07AD, "C44DBCD92F9DCF42F4902A87335DBB35D2FF530CDB09814CFA1F4B95A1BD018D099BC6AB69F667B4922AE1ED826E72951AA3E0EAAA7D49A695F04F8CDAAE2D18D10D25BD529CBB05ABF070DC7C041EC35C2BA7F58CC4C349983CC6E11A5CBE828FB8ECBC26F08E1094A6B44C8953C8E1BAFD214DF3E69F430A98CCC75C03669D"},
|
||||
{"EDF-GDF", 0x07AD, "9d66035cc7cc980a439fe6f34d21fdbae1c853894cb4a694108ef026bcecb88f82be5c1ae1c63c9849c3c48cf5a72b5cc31e047cdc70f0ab05bb9c52bd250dd1182daeda8c4ff095a6497daaeae0a31a95726e82ede12a92b467f669abc69b098d01bda1954b1ffa4c8109db0c53ffd235bb5d33872a90f442cf9d2fd9bc4dc4"},
|
||||
{NULL, 0, NULL}
|
||||
};
|
||||
|
||||
@@ -55,256 +60,311 @@ const char *vigik_get_service(uint16_t service_code) {
|
||||
}
|
||||
|
||||
|
||||
int vigik_verify(mfc_vigik_t *d) {
|
||||
#define PUBLIC_VIGIK_KEYLEN 128
|
||||
// ISO 9796-1 shadow permutation. Each message byte is stored next to its shadow,
|
||||
// which is what gives the scheme its redundancy.
|
||||
static const uint8_t vigik_iso9796_pi[16] = {
|
||||
0x0E, 0x03, 0x05, 0x08, 0x09, 0x04, 0x02, 0x0F,
|
||||
0x00, 0x0D, 0x0B, 0x06, 0x07, 0x0A, 0x0C, 0x01
|
||||
};
|
||||
|
||||
// iso9796
|
||||
// Exponent V = 2
|
||||
// n = The public modulus n is the product of the secret prime factors p and q. Its length is 1024 bits.
|
||||
static uint8_t vigik_shadow(uint8_t b) {
|
||||
return (uint8_t)((vigik_iso9796_pi[b >> 4] << 4) | vigik_iso9796_pi[b & 0x0F]);
|
||||
}
|
||||
|
||||
if (g_debugMode == DEBUG) {
|
||||
PrintAndLogEx(INFO, "Raw");
|
||||
print_hex_noascii_break((uint8_t *)d, sizeof(*d) - sizeof(d->rsa_signature), MFBLOCK_SIZE * 2);
|
||||
// Recover the message an ISO 9796-1 signature carries, checking the redundancy on
|
||||
// the way. `sig` is the signature as it sits on the card, `modulus` the public key
|
||||
// to try. On success msg holds msglen bytes.
|
||||
//
|
||||
// Rabin, so v = 2 and squaring the signature gives the block back. Which of the
|
||||
// four candidates is the block is decided by the format itself: an ISO 9796-1
|
||||
// block always ends in the nibble 6.
|
||||
static int vigik_iso9796_recover(const uint8_t *sig, const char *modulus, uint8_t *msg, size_t *msglen) {
|
||||
|
||||
PrintAndLogEx(INFO, "Raw signature");
|
||||
print_hex_noascii_break(d->rsa_signature, sizeof(d->rsa_signature), MFBLOCK_SIZE * 2);
|
||||
uint8_t n[VIGIK_SIG_LEN] = {0};
|
||||
int dl = 0;
|
||||
param_gethex_to_eol(modulus, 0, n, sizeof(n), &dl);
|
||||
if (dl != VIGIK_SIG_LEN) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
/*
|
||||
int dl = 0;
|
||||
uint8_t rev[VIGIK_SIG_LEN] = {0};
|
||||
reverse_array_copy(sig, VIGIK_SIG_LEN, rev);
|
||||
|
||||
param_gethex_to_eol("1C07D46DA3849326D24B3468BD76673F4F3C41827DC413E81E4F3C7804FAC727213059B21D047510D6432448643A92EBFC67FBEDDAB468D13D948B172F5EBC79A0E3FEFDFAF4E81FC7108E070F1E3CD0", 0, signature, PUBLIC_VIGIK_KEYLEN, &dl);
|
||||
mbedtls_mpi N, S, E, J, cand, tmp;
|
||||
mbedtls_mpi_init(&N);
|
||||
mbedtls_mpi_init(&S);
|
||||
mbedtls_mpi_init(&E);
|
||||
mbedtls_mpi_init(&J);
|
||||
mbedtls_mpi_init(&cand);
|
||||
mbedtls_mpi_init(&tmp);
|
||||
|
||||
param_gethex_to_eol("1AB86FE0C17FFFFE4379D5E15A4B2FAFFEFCFA0F1F3F7FA03E7DDDF1E3C78FFFB1F0E23F7FFF51584771C5C18307FEA36CA74E60AA6B0409ACA66A9EC155F4E9112345708A2B8457E722608EE1157408", 0, signature, PUBLIC_VIGIK_KEYLEN, &dl);
|
||||
signature_len = dl;
|
||||
*/
|
||||
mbedtls_mpi_read_binary(&N, n, sizeof(n));
|
||||
mbedtls_mpi_read_binary(&S, rev, sizeof(rev));
|
||||
mbedtls_mpi_add_int(&E, &E, 2);
|
||||
|
||||
uint8_t rev_sig[128];
|
||||
reverse_array_copy(d->rsa_signature, sizeof(d->rsa_signature), rev_sig);
|
||||
uint8_t f[VIGIK_SIG_LEN] = {0};
|
||||
bool got_block = false;
|
||||
|
||||
PrintAndLogEx(INFO, "Raw signature reverse");
|
||||
print_hex_noascii_break(rev_sig, sizeof(d->rsa_signature), MFBLOCK_SIZE * 2);
|
||||
if (mbedtls_mpi_cmp_mpi(&S, &N) < 0) {
|
||||
|
||||
// t = 0xBC = Implicitly known
|
||||
// t = 0xCC = look at byte before to determine hash function
|
||||
// uint8_t T[] = {0x33, 0xCC};
|
||||
mbedtls_mpi_exp_mod(&J, &S, &E, &N, NULL);
|
||||
|
||||
// Success decrypt would mean 0x4b BB ... BB BA padding
|
||||
// padding, message, hash, 8 bits or 16 bits
|
||||
for (uint8_t c = 0; c < 4 && got_block == false; c++) {
|
||||
|
||||
// signature = h( C || M1 || h(M2) )
|
||||
// 1024 - 786 - 160 - 16 -1
|
||||
// salt C
|
||||
// message M = 96 bytes, 768 bits
|
||||
// sha1 hash H = 20 bytes, 160 bits
|
||||
// padding = 20 bytes, 96 bits
|
||||
switch (c) {
|
||||
case 0:
|
||||
mbedtls_mpi_copy(&cand, &J);
|
||||
break;
|
||||
case 1:
|
||||
mbedtls_mpi_sub_mpi(&cand, &N, &J);
|
||||
break;
|
||||
case 2:
|
||||
mbedtls_mpi_mul_int(&cand, &J, 2);
|
||||
break;
|
||||
default:
|
||||
mbedtls_mpi_sub_mpi(&tmp, &N, &J);
|
||||
mbedtls_mpi_mul_int(&cand, &tmp, 2);
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t i;
|
||||
bool is_valid = false;
|
||||
if (mbedtls_mpi_bitlen(&cand) > (VIGIK_SIG_LEN * 8)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t low = 0;
|
||||
for (uint8_t b = 0; b < 4; b++) {
|
||||
low |= (uint8_t)(mbedtls_mpi_get_bit(&cand, b) << b);
|
||||
}
|
||||
|
||||
if (low != 0x06) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mbedtls_mpi_write_binary(&cand, f, sizeof(f)) == 0) {
|
||||
got_block = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_mpi_free(&N);
|
||||
mbedtls_mpi_free(&S);
|
||||
mbedtls_mpi_free(&E);
|
||||
mbedtls_mpi_free(&J);
|
||||
mbedtls_mpi_free(&cand);
|
||||
mbedtls_mpi_free(&tmp);
|
||||
|
||||
if (got_block == false) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
// Every byte pair has to be a message byte next to its shadow. Exactly three
|
||||
// are allowed not to be: the leading pair carries the bit that keeps the block
|
||||
// below n, one marks how long the message is, and the last holds the forced 6.
|
||||
size_t broken[4] = {0};
|
||||
size_t brokencnt = 0;
|
||||
for (size_t i = 0; i < VIGIK_SIG_LEN; i += 2) {
|
||||
if (vigik_shadow(f[i + 1]) != f[i]) {
|
||||
if (brokencnt < ARRAYLEN(broken)) {
|
||||
broken[brokencnt] = i;
|
||||
}
|
||||
brokencnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (brokencnt != 3 || broken[0] != 0 || broken[2] != (VIGIK_SIG_LEN - 2)) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
size_t z = VIGIK_MSG_SLOTS - (broken[1] / 2);
|
||||
if (z == 0 || z > (VIGIK_MSG_SLOTS - 1)) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
uint8_t stream[VIGIK_MSG_SLOTS] = {0};
|
||||
for (size_t i = 0; i < VIGIK_SIG_LEN; i += 2) {
|
||||
stream[i / 2] = f[i + 1];
|
||||
}
|
||||
|
||||
// The message is repeated to fill the block, the first slot belonging to the
|
||||
// truncated tail of the run before it. Where a second copy fits, it has to
|
||||
// agree with the first.
|
||||
if (((1 + (2 * z)) <= VIGIK_MSG_SLOTS) && (memcmp(stream + 1, stream + 1 + z, z) != 0)) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
reverse_array_copy(stream + 1, (int)z, msg);
|
||||
*msglen = z;
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// The five byte dates are year since 1900, then month, day, hour, minute.
|
||||
// Print the raw bytes with the date spelled out beside them, and leave the
|
||||
// decoded form off when the bytes cannot be a date at all.
|
||||
static void vigik_print_date(const char *label, const uint8_t *v) {
|
||||
|
||||
bool sane = ((v[1] >= 1) && (v[1] <= 12) &&
|
||||
(v[2] >= 1) && (v[2] <= 31) &&
|
||||
(v[3] <= 23) && (v[4] <= 59));
|
||||
|
||||
if (sane) {
|
||||
PrintAndLogEx(INFO, "%s %s ( " _YELLOW_("%04u-%02u-%02u %02u:%02u") " )",
|
||||
label, sprint_hex_inrow(v, 5),
|
||||
1900 + v[0], v[1], v[2], v[3], v[4]);
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "%s %s", label, sprint_hex_inrow(v, 5));
|
||||
}
|
||||
}
|
||||
|
||||
// What a VIGIK signature covers: the UID the card has to keep, the service it
|
||||
// belongs to, and the window it is good for.
|
||||
static size_t vigik_expected_msg(const mfc_vigik_t *d, uint8_t *out) {
|
||||
|
||||
size_t len = 0;
|
||||
memset(out, 0, VIGIK_MSG_PAD);
|
||||
len += VIGIK_MSG_PAD;
|
||||
|
||||
memcpy(out + len, d->b0, 4); // UID
|
||||
len += 4;
|
||||
|
||||
Uint4byteToMemLe(out + len, d->service_code);
|
||||
len += 4;
|
||||
|
||||
out[len++] = d->key_version;
|
||||
out[len++] = d->services_counter;
|
||||
|
||||
memcpy(out + len, d->slot_access_date, sizeof(d->slot_access_date));
|
||||
len += sizeof(d->slot_access_date);
|
||||
|
||||
Uint2byteToMemLe(out + len, d->slot_dst_duration);
|
||||
len += 2;
|
||||
return len;
|
||||
}
|
||||
|
||||
int vigik_verify(mfc_vigik_t *d) {
|
||||
|
||||
if (d == NULL) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint8_t expected[VIGIK_MSG_SLOTS] = {0};
|
||||
size_t expectedlen = vigik_expected_msg(d, expected);
|
||||
|
||||
for (uint8_t i = 0; i < ARRAYLEN(vigik_rsa_pk); i++) {
|
||||
|
||||
for (i = 0; i < ARRAYLEN(vigik_rsa_pk); i++) {
|
||||
if (vigik_rsa_pk[i].desc == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
mbedtls_mpi RN, E;
|
||||
mbedtls_mpi_init(&RN);
|
||||
|
||||
// exponent 2 = even
|
||||
mbedtls_mpi_init(&E);
|
||||
mbedtls_mpi_add_int(&E, &E, 2);
|
||||
|
||||
int dl = 0;
|
||||
uint8_t n[PUBLIC_VIGIK_KEYLEN];
|
||||
memset(n, 0, sizeof(n));
|
||||
param_gethex_to_eol(vigik_rsa_pk[i].n, 0, n, PUBLIC_VIGIK_KEYLEN, &dl);
|
||||
|
||||
// convert
|
||||
mbedtls_mpi N, s, sqr, res;
|
||||
mbedtls_mpi_init(&N);
|
||||
mbedtls_mpi_init(&s);
|
||||
mbedtls_mpi_init(&sqr);
|
||||
mbedtls_mpi_init(&res);
|
||||
|
||||
mbedtls_mpi_read_binary(&N, (const unsigned char *)n, PUBLIC_VIGIK_KEYLEN);
|
||||
|
||||
//mbedtls_mpi_read_binary(&s, (const unsigned char*)signature, signature_len);
|
||||
mbedtls_mpi_read_binary(&s, (const unsigned char *)rev_sig, sizeof(d->rsa_signature));
|
||||
|
||||
// check is sign < (N/2)
|
||||
|
||||
mbedtls_mpi n_2;
|
||||
mbedtls_mpi_init(&n_2);
|
||||
mbedtls_mpi_copy(&n_2, &N);
|
||||
mbedtls_mpi_shift_r(&n_2, 1);
|
||||
bool is_less = (mbedtls_mpi_cmp_mpi(&s, &n_2) > 0) ? false : true;
|
||||
PrintAndLogEx(DEBUG, "z < (N/2) ..... %s", (is_less) ? _GREEN_("YES") : _RED_("NO"));
|
||||
mbedtls_mpi_free(&n_2);
|
||||
|
||||
|
||||
if (is_less) {
|
||||
mbedtls_mpi_exp_mod(&sqr, &s, &E, &N, &RN);
|
||||
} else {
|
||||
uint8_t msg[VIGIK_MSG_SLOTS] = {0};
|
||||
size_t msglen = 0;
|
||||
if (vigik_iso9796_recover(d->rsa_signature, vigik_rsa_pk[i].n, msg, &msglen) != PM3_SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
if v is even and
|
||||
⎯ if J* mod 8 = 1, then f* = n–J*.
|
||||
⎯ if J* mod 8 = 4, then f* = J*,
|
||||
⎯ if J* mod 8 = 6, then f* = 2J*,
|
||||
⎯ if J* mod 8 = 7, then f* = 2(n–J*),
|
||||
*/
|
||||
uint8_t b2 = mbedtls_mpi_get_bit(&sqr, 2);
|
||||
uint8_t b1 = mbedtls_mpi_get_bit(&sqr, 1);
|
||||
uint8_t b0 = mbedtls_mpi_get_bit(&sqr, 0);
|
||||
uint8_t lsb = (b2 << 2) | (b1 << 1) | b0;
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Signature") " ------------------------------");
|
||||
PrintAndLogEx(INFO, "Signed by.......... " _YELLOW_("%s"), vigik_rsa_pk[i].desc);
|
||||
PrintAndLogEx(INFO, "Scheme............. ISO 9796-1, RSA 1024, v=2");
|
||||
PrintAndLogEx(INFO, "Recovered.......... %s", sprint_hex_inrow(msg, msglen));
|
||||
|
||||
/*
|
||||
//1
|
||||
mbedtls_mpi_sub_mpi(&res, &N, &sqr);
|
||||
mbedtls_mpi_write_file( "[=] 1... ", &res, 16, NULL );
|
||||
// 4
|
||||
mbedtls_mpi_copy(&res, &sqr);
|
||||
mbedtls_mpi_write_file( "[=] 4... ", &res, 16, NULL );
|
||||
// 6
|
||||
mbedtls_mpi_mul_int(&res, &sqr, 2);
|
||||
mbedtls_mpi_write_file( "[=] 6... ", &res, 16, NULL );
|
||||
// 7
|
||||
mbedtls_mpi foo;
|
||||
mbedtls_mpi_init(&foo);
|
||||
mbedtls_mpi_sub_mpi(&foo, &N, &sqr);
|
||||
mbedtls_mpi_mul_int(&res, &foo, 2);
|
||||
mbedtls_mpi_free(&foo);
|
||||
mbedtls_mpi_write_file( "[=] 7... ", &res, 16, NULL );
|
||||
*/
|
||||
|
||||
switch (lsb) {
|
||||
case 1: {
|
||||
mbedtls_mpi_sub_mpi(&res, &N, &sqr);
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
mbedtls_mpi_copy(&res, &sqr);
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
mbedtls_mpi_mul_int(&res, &sqr, 2);
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
mbedtls_mpi foo2;
|
||||
mbedtls_mpi_init(&foo2);
|
||||
mbedtls_mpi_sub_mpi(&foo2, &N, &sqr);
|
||||
mbedtls_mpi_mul_int(&res, &foo2, 2);
|
||||
mbedtls_mpi_free(&foo2);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
continue;
|
||||
}
|
||||
if ((msglen != expectedlen) || (memcmp(msg, expected, msglen) != 0)) {
|
||||
PrintAndLogEx(INFO, "Card fields........ %s", sprint_hex_inrow(expected, expectedlen));
|
||||
PrintAndLogEx(FAILED, "Signature verification: " _RED_("card data does not match the signature"));
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
PrintAndLogEx(DEBUG, "LSB............ " _GREEN_("%u"), lsb);
|
||||
if (g_debugMode == DEBUG) {
|
||||
mbedtls_mpi_write_file("[=] N.............. ", &N, 16, NULL);
|
||||
mbedtls_mpi_write_file("[=] signature...... ", &s, 16, NULL);
|
||||
mbedtls_mpi_write_file("[=] square mod n... ", &sqr, 16, NULL);
|
||||
mbedtls_mpi_write_file("[=] n-fs........... ", &res, 16, NULL);
|
||||
PrintAndLogEx(INFO, " UID.............. %s", sprint_hex_inrow(msg + VIGIK_MSG_PAD, 4));
|
||||
PrintAndLogEx(INFO, " Service code..... 0x%04X", (uint16_t)d->service_code);
|
||||
PrintAndLogEx(INFO, " Key version...... %u", d->key_version);
|
||||
PrintAndLogEx(INFO, " Services counter. %u", d->services_counter);
|
||||
vigik_print_date(" Access date......", d->slot_access_date);
|
||||
PrintAndLogEx(INFO, " DST duration..... %u", d->slot_dst_duration);
|
||||
|
||||
// The service code on the card says which service issued it, so it should
|
||||
// name the key that just verified. Where it does not, the table pairs a
|
||||
// description with the wrong modulus - say so rather than quietly
|
||||
// reporting the wrong issuer.
|
||||
if (vigik_rsa_pk[i].code != (uint16_t)d->service_code) {
|
||||
PrintAndLogEx(WARNING, "Card says service 0x%04X but the key that verified is listed as 0x%04X ( %s )",
|
||||
(uint16_t)d->service_code, vigik_rsa_pk[i].code, vigik_rsa_pk[i].desc);
|
||||
}
|
||||
|
||||
|
||||
uint8_t nfs[128] = {0};
|
||||
mbedtls_mpi_write_binary(&res, nfs, sizeof(nfs));
|
||||
|
||||
// xor 0xDC01
|
||||
int count_zero = 0;
|
||||
for (int x = 0; x < sizeof(nfs); x += 2) {
|
||||
nfs[x] ^= 0xDC;
|
||||
nfs[x + 1] ^= 0x01;
|
||||
|
||||
if (nfs[x] == 0x00)
|
||||
count_zero++;
|
||||
if (nfs[x + 1] == 0x00)
|
||||
count_zero++;
|
||||
}
|
||||
|
||||
if (count_zero > 10) {
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, "Message XORED");
|
||||
print_hex_noascii_break(nfs, sizeof(nfs), 32);
|
||||
PrintAndLogEx(INFO, "\n");
|
||||
is_valid = true;
|
||||
break;
|
||||
}
|
||||
|
||||
/*
|
||||
if (bar == 0) {
|
||||
typedef struct vigik_rsa_s {
|
||||
uint8_t rsa[127];
|
||||
uint8_t hash;
|
||||
} vigik_rsa_t;
|
||||
|
||||
vigik_rsa_t ts;
|
||||
memcpy(&ts, nfs, sizeof(ts));
|
||||
|
||||
if ( ts.hash == 0xCC ) {
|
||||
PrintAndLogEx(INFO, "Hash byte... 0x%02X", ts.hash);
|
||||
switch(ts.rsa[126]) {
|
||||
case 0x11:
|
||||
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1");
|
||||
break;
|
||||
case 0x22:
|
||||
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - RIPEMD");
|
||||
break;
|
||||
case 0x33:
|
||||
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - SHA1");
|
||||
break;
|
||||
default:
|
||||
PrintAndLogEx(INFO, "Hash algo ( 0x%02X ) - " _RED_("err"));
|
||||
break;
|
||||
}
|
||||
} else if ( ts.hash == 0xBC) {
|
||||
PrintAndLogEx(INFO, "Hash byte... 0x%02X - " _GREEN_("implict"), ts.hash);
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "Hash byte... 0x%02x - " _RED_("err"), ts.hash);
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Message w padding");
|
||||
print_hex_noascii_break(ts.rsa, sizeof(ts.rsa) - 20, 32);
|
||||
}
|
||||
*/
|
||||
|
||||
mbedtls_mpi_free(&N);
|
||||
mbedtls_mpi_free(&s);
|
||||
mbedtls_mpi_free(&res);
|
||||
mbedtls_mpi_free(&RN);
|
||||
mbedtls_mpi_free(&E);
|
||||
PrintAndLogEx(SUCCESS, "Signature verification: " _GREEN_("successful"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("Tag Signature"));
|
||||
PrintAndLogEx(INFO, "RSA: 1024bit");
|
||||
PrintAndLogEx(FAILED, "Signature verification: " _RED_("no public key recovered a valid block"));
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
if (is_valid == false || i == ARRAYLEN(vigik_rsa_pk)) {
|
||||
PrintAndLogEx(INFO, "Signature:");
|
||||
print_hex_noascii_break(d->rsa_signature, sizeof(d->rsa_signature), MFBLOCK_SIZE * 2);
|
||||
PrintAndLogEx(SUCCESS, "Signature verification: " _RED_("failed"));
|
||||
// An expired VIGIK service badge, published for study in
|
||||
// armsrc/Standalone/hf_colin.c. Signed by La Poste Service Universel.
|
||||
static const uint8_t vigik_selftest_card[] = {
|
||||
0x12, 0x1C, 0x7F, 0x73, 0x02, 0x08, 0x04, 0x00, 0x01, 0xFA, 0x33, 0xF5,
|
||||
0xCB, 0x2D, 0x02, 0x1D, 0x44, 0x00, 0x10, 0x49, 0x16, 0x49, 0x16, 0x49,
|
||||
0x16, 0x49, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xAA, 0x07, 0x00, 0x00, 0x21, 0x02, 0x08, 0x00,
|
||||
0x00, 0x74, 0x0C, 0x11, 0x06, 0x00, 0xAF, 0x13, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x74, 0x0C, 0x11, 0x08, 0x22, 0x00, 0x00,
|
||||
0x24, 0xE5, 0x72, 0xB9, 0x23, 0xA3, 0xD2, 0x43, 0xB4, 0x02, 0xD6, 0x0C,
|
||||
0xAB, 0x57, 0x69, 0x56, 0x21, 0x6D, 0x65, 0x01, 0xFC, 0x86, 0x18, 0xB6,
|
||||
0xC4, 0x26, 0x76, 0x25, 0x11, 0xAC, 0x2D, 0xEE, 0x25, 0xBF, 0x4C, 0xEC,
|
||||
0x36, 0x18, 0xD0, 0xBA, 0xB3, 0xA6, 0xE9, 0x21, 0x0D, 0x88, 0x77, 0x46,
|
||||
0x0F, 0xBC, 0x41, 0xA5, 0xD9, 0x53, 0x98, 0xE7, 0x6A, 0x1B, 0x20, 0x29,
|
||||
0xE8, 0xEA, 0x97, 0x35, 0x08, 0x8B, 0xA2, 0xCE, 0x73, 0x26, 0x53, 0xD0,
|
||||
0xC1, 0x14, 0x75, 0x96, 0xAF, 0xCF, 0x94, 0xD7, 0x77, 0xB4, 0xD9, 0x1F,
|
||||
0x04, 0x42, 0x18, 0x22, 0x73, 0xA2, 0x9D, 0xEA, 0xF7, 0xA2, 0xD0, 0x95,
|
||||
0x4C, 0xEE, 0x71, 0x58, 0x66, 0xE5, 0x08, 0xCD, 0xBC, 0x95, 0xC6, 0x40,
|
||||
0xEC, 0x9D, 0x1E, 0x58, 0xE8, 0x00, 0x45, 0x7C, 0xF8, 0xB0, 0x79, 0x41,
|
||||
0x4E, 0x1B, 0x45, 0xDD, 0x3E, 0x6C, 0x93, 0x17,
|
||||
};
|
||||
|
||||
int vigik_selftest(void) {
|
||||
|
||||
PrintAndLogEx(INFO, "Testing VIGIK ISO 9796-1 signature recovery");
|
||||
|
||||
if (sizeof(vigik_selftest_card) != sizeof(mfc_vigik_t)) {
|
||||
PrintAndLogEx(FAILED, " vector is %zu bytes, struct is %zu ( " _RED_("fail") " )",
|
||||
sizeof(vigik_selftest_card), sizeof(mfc_vigik_t));
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Signature public key name: " _YELLOW_("%s"), vigik_rsa_pk[i].desc);
|
||||
PrintAndLogEx(INFO, "Signature public key value:");
|
||||
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n);
|
||||
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 64);
|
||||
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 128);
|
||||
PrintAndLogEx(INFO, "%.64s", vigik_rsa_pk[i].n + 192);
|
||||
mfc_vigik_t card;
|
||||
memcpy(&card, vigik_selftest_card, sizeof(card));
|
||||
|
||||
PrintAndLogEx(INFO, "Signature:");
|
||||
print_hex_noascii_break(d->rsa_signature, sizeof(d->rsa_signature), MFBLOCK_SIZE * 2);
|
||||
uint8_t expected[VIGIK_MSG_SLOTS] = {0};
|
||||
size_t expectedlen = vigik_expected_msg(&card, expected);
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Signature verification: " _GREEN_("successful"));
|
||||
uint8_t msg[VIGIK_MSG_SLOTS] = {0};
|
||||
size_t msglen = 0;
|
||||
int res = PM3_ESOFT;
|
||||
|
||||
for (uint8_t i = 0; i < ARRAYLEN(vigik_rsa_pk); i++) {
|
||||
if (vigik_rsa_pk[i].desc == NULL) {
|
||||
break;
|
||||
}
|
||||
if (vigik_iso9796_recover(card.rsa_signature, vigik_rsa_pk[i].n, msg, &msglen) == PM3_SUCCESS) {
|
||||
PrintAndLogEx(INFO, " recovered against.. %s", vigik_rsa_pk[i].desc);
|
||||
res = PM3_SUCCESS;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(FAILED, " no public key recovered a valid block ( " _RED_("fail") " )");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, " recovered.......... %s", sprint_hex_inrow(msg, msglen));
|
||||
PrintAndLogEx(INFO, " card fields........ %s", sprint_hex_inrow(expected, expectedlen));
|
||||
|
||||
if ((msglen != expectedlen) || (memcmp(msg, expected, msglen) != 0)) {
|
||||
PrintAndLogEx(FAILED, " recovered message does not match the card ( " _RED_("fail") " )");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "VIGIK signature selftest ( " _GREEN_("ok") " )");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -312,20 +372,20 @@ int vigik_annotate(mfc_vigik_t *d) {
|
||||
if (d == NULL)
|
||||
return PM3_EINVARG;
|
||||
|
||||
PrintAndLogEx(INFO, "Manufacture......... %s", sprint_hex(d->b0, sizeof(d->b0)));
|
||||
PrintAndLogEx(INFO, "MAD................. %s", sprint_hex(d->mad, sizeof(d->mad)));
|
||||
PrintAndLogEx(INFO, "Manufacture......... %s", sprint_hex_inrow(d->b0, sizeof(d->b0)));
|
||||
PrintAndLogEx(INFO, "MAD................. %s", sprint_hex_inrow(d->mad, sizeof(d->mad)));
|
||||
PrintAndLogEx(INFO, "Counters............ %u", d->counters);
|
||||
PrintAndLogEx(INFO, "rtf................. %s", sprint_hex(d->rtf, sizeof(d->rtf)));
|
||||
PrintAndLogEx(INFO, "rtf................. %s", sprint_hex_inrow(d->rtf, sizeof(d->rtf)));
|
||||
PrintAndLogEx(INFO, "Service code........ 0x%08x / %u - " _YELLOW_("%s"), d->service_code, d->service_code, vigik_get_service(d->service_code));
|
||||
PrintAndLogEx(INFO, "Info flag........... %u -", d->info_flag); // , sprint_bin(d->info_flag, 1));
|
||||
PrintAndLogEx(INFO, "Key version......... %u", d->key_version);
|
||||
PrintAndLogEx(INFO, "PTR Counter......... %u", d->ptr_counter);
|
||||
PrintAndLogEx(INFO, "Counter num......... %u", d->counter_num);
|
||||
PrintAndLogEx(INFO, "Slot access date.... %s", sprint_hex(d->slot_access_date, sizeof(d->slot_access_date)));
|
||||
vigik_print_date("Slot access date....", d->slot_access_date);
|
||||
PrintAndLogEx(INFO, "Slot dst duration... %u", d->slot_dst_duration);
|
||||
PrintAndLogEx(INFO, "Other Slots......... %s", sprint_hex(d->other_slots, sizeof(d->other_slots)));
|
||||
PrintAndLogEx(INFO, "Other Slots......... %s", sprint_hex_inrow(d->other_slots, sizeof(d->other_slots)));
|
||||
PrintAndLogEx(INFO, "Services counter.... %u", d->services_counter);
|
||||
PrintAndLogEx(INFO, "Loading date........ %s", sprint_hex(d->loading_date, sizeof(d->loading_date)));
|
||||
vigik_print_date("Loading date........", d->loading_date);
|
||||
PrintAndLogEx(INFO, "Reserved null....... %u", d->reserved_null);
|
||||
PrintAndLogEx(INFO, "----------------------------------------------------------------");
|
||||
PrintAndLogEx(INFO, "");
|
||||
@@ -339,8 +399,7 @@ int vigik_annotate(mfc_vigik_t *d) {
|
||||
// Key layouts of the VIGIK family building access systems. Every one of these
|
||||
// ships the same keys on every card, so matching the whole set identifies the
|
||||
// system outright - no guessing from the payload. Sourced from the schemas in
|
||||
// armsrc/Standalone/hf_colin.c, with the Hexact sector 15 key B measured on a
|
||||
// card here; hf_colin.c leaves that slot empty.
|
||||
// armsrc/Standalone/hf_colin.c. Hexact is not here; it has its own parser.
|
||||
typedef struct {
|
||||
const char *name;
|
||||
uint64_t key_a[16];
|
||||
@@ -348,21 +407,6 @@ typedef struct {
|
||||
} vigik_schema_t;
|
||||
|
||||
static const vigik_schema_t vigik_schemas[] = {
|
||||
{
|
||||
"Infineon / Hexact / COGELEC / Intratone",
|
||||
{
|
||||
0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL,
|
||||
0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL,
|
||||
0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL,
|
||||
0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL
|
||||
},
|
||||
{
|
||||
0xa22ae129c013ULL, 0x49fae4e3849fULL, 0x38fcf33072e0ULL, 0x8ad5517b4b18ULL,
|
||||
0x509359f131b1ULL, 0x6c78928e1317ULL, 0xaa0720018738ULL, 0xa6cac2886412ULL,
|
||||
0x62d0c424ed8eULL, 0xe64a986a5d94ULL, 0x8fa1d601d0a2ULL, 0x89347350bd36ULL,
|
||||
0x66d2b7dc39efULL, 0x6bc1e1ae547dULL, 0x22729a9bd40fULL, 0x484558414354ULL
|
||||
}
|
||||
},
|
||||
{
|
||||
"Noralsy",
|
||||
{
|
||||
@@ -402,8 +446,8 @@ static const vigik_schema_t vigik_schemas[] = {
|
||||
VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY
|
||||
},
|
||||
{
|
||||
0x010203040506ULL, 0x010203040506ULL, 0x010203040506ULL, 0x010203040506ULL,
|
||||
0x010203040506ULL, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY,
|
||||
VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY,
|
||||
VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY,
|
||||
VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY,
|
||||
VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY
|
||||
}
|
||||
|
||||
@@ -47,4 +47,7 @@ const char *vigik_get_service(uint16_t service_code);
|
||||
int vigik_verify(mfc_vigik_t *d);
|
||||
int vigik_annotate(mfc_vigik_t *d);
|
||||
|
||||
// Recover and check the signature of a known good expired card
|
||||
int vigik_selftest(void);
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user