lf keri: refuse values the frame can't carry, print the sim id
clone took negative FC and CN, and MS values above 5 and 22 bits, without a word: MS FC 40 wrote the card of FC 8. sim let ids of 32 bits or more change the fixed bits, so --id 2147483648 simulated id 0, and printed the shifted frame as Internal Id. The sim help example used --cn, the option is --id, and the clone hint named lf keri read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f90d0d0bf9
commit
49e5b502f5
4 files changed
+30
-8
No files matched your search
+26
-6
@@ -248,8 +248,8 @@ static int CmdKeriClone(const char *Cmd) {
|
||||
int typeLen = sizeof(keritype) - 1; // CLIGetStrWithReturn does not guarantee string to be null-terminated
|
||||
CLIGetStrWithReturn(ctx, 1, keritype, &typeLen);
|
||||
|
||||
uint32_t fc = arg_get_int_def(ctx, 2, 0);
|
||||
uint32_t cid = arg_get_int_def(ctx, 3, 0);
|
||||
int fc_arg = arg_get_int_def(ctx, 2, 0);
|
||||
int cn_arg = arg_get_int_def(ctx, 3, 0);
|
||||
bool q5 = arg_get_lit(ctx, 4);
|
||||
bool em = arg_get_lit(ctx, 5);
|
||||
CLIParserFree(ctx);
|
||||
@@ -259,6 +259,20 @@ static int CmdKeriClone(const char *Cmd) {
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (fc_arg < 0 || cn_arg < 0) {
|
||||
PrintAndLogEx(FAILED, "FC and CN can't be negative");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
// the MS scramble carries 5 bits of fc and 22 of cn
|
||||
if (keritype[0] == 'm' && (fc_arg > 31 || cn_arg > 0x3FFFFF)) {
|
||||
PrintAndLogEx(FAILED, "MS FC has a max value of 31 and CN has a max value of 4194303");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint32_t fc = (uint32_t)fc_arg;
|
||||
uint32_t cid = (uint32_t)cn_arg;
|
||||
|
||||
// Setup card data/build internal id
|
||||
uint32_t internalid = 0;
|
||||
switch (keritype[0]) {
|
||||
@@ -310,7 +324,7 @@ static int CmdKeriClone(const char *Cmd) {
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Done!");
|
||||
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf keri read`") " to verify");
|
||||
PrintAndLogEx(HINT, "Hint: Try " _YELLOW_("`lf keri reader`") " to verify");
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -320,7 +334,7 @@ static int CmdKeriSim(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "lf keri sim",
|
||||
"Enables simulation of KERI card with internal ID.\n"
|
||||
"You supply a KERI card id and it will converted to a KERI internal ID.",
|
||||
"lf keri sim --cn 112233"
|
||||
"lf keri sim --id 112233"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
@@ -332,6 +346,14 @@ static int CmdKeriSim(const char *Cmd) {
|
||||
uint64_t internalid = arg_get_u64_def(ctx, 1, 0);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// the frame carries 31 bits of internal id
|
||||
if (internalid > 0x7FFFFFFF) {
|
||||
PrintAndLogEx(FAILED, "Internal Id has a max value of 2147483647");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64) ", Raw: E0000000%08" PRIX64, internalid, internalid | 0x80000000);
|
||||
|
||||
internalid |= 0x80000000;
|
||||
internalid <<= 3;
|
||||
internalid += 7;
|
||||
@@ -343,8 +365,6 @@ static int CmdKeriSim(const char *Cmd) {
|
||||
bs[j++] = ((internalid >> i) & 1);
|
||||
}
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Simulating KERI - Internal Id " _YELLOW_("%" PRIu64), internalid);
|
||||
|
||||
lf_psksim_t *payload = calloc(1, sizeof(lf_psksim_t) + sizeof(bs));
|
||||
if (payload == NULL) {
|
||||
PrintAndLogEx(WARNING, "Failed to allocate memory");
|
||||
|
||||
Reference in new issue
Block a user