Skip to content

Conversation

@aaronjamt
Copy link
Contributor

(AKA #3031 attempt 2)

Replaces unused nonce value with a new keyslot value. By default, key indexes 0 and 1 use keyslot 1, key index 2 uses keyslot 3, and key index 3 uses keyslot 9 respectively. This means that hf seos adf and hf seos pacs work the same as before, and hf seos gdf was updated to default to key index 3 to also maintain compatibility. Key index 2 is set to keyslot 3 to prepare for future write support.

Replaces unused `nonce` value
@github-actions
Copy link

You are welcome to add an entry to the CHANGELOG.md as well

Comment on lines -1303 to +1311
PrintAndLogEx(INFO, "idx| key");
PrintAndLogEx(INFO, "---+------------------------");
PrintAndLogEx(INFO, "idx|slot| key");
PrintAndLogEx(INFO, "---+----+------------------------");
for (uint8_t i = 0; i < ARRAYLEN(keys); i++) {
if (memcmp(keys[i].privEncKey, zeros, sizeof(zeros)) == 0)
PrintAndLogEx(INFO, " %u |", i);
PrintAndLogEx(INFO, " %u | |", i);
else
PrintAndLogEx(INFO, " %u | " _YELLOW_("%s"), i, sprint_hex(keys[i].nonce, 8));
PrintAndLogEx(INFO, " %u | " _YELLOW_("% 2u") " | " _YELLOW_("%s"), i, keys[i].keyslot, sprint_hex(keys[i].readKey, 8));
}
PrintAndLogEx(INFO, "---+------------------------");
PrintAndLogEx(INFO, "---+----+------------------------");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured also showing an actual key would be useful, rather than just the slot number. Should there be logic here to show a different key based on the selected keyslot, or maybe show one of the privacy keys instead?


size_t i = 0;
for (; i < bytes_read / kn; i++) {
memcpy(keys[i].nonce, dump + (i * kn), 8);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also be done like:
keys[i].nonce = *(dump + (i * kn));
I did it this way to keep it more similar to the rest of the block, but let me know if you'd rather change it.

Comment on lines +1338 to +1343
memcpy(&keys[i].keyslot, dump + (i * kn), 1);
memcpy(keys[i].privEncKey, dump + ((i * kn) + 1), 16);
memcpy(keys[i].privMacKey, dump + ((i * kn) + 17), 16);
memcpy(keys[i].readKey, dump + ((i * kn) + 33), 16);
memcpy(keys[i].writeKey, dump + ((i * kn) + 49), 16);
memcpy(keys[i].adminKey, dump + ((i * kn) + 65), 16);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as relevant to this PR, but maybe it would make sense to have the offsets instead stored as a variable and incremented by each memcpy since these odd numbers look weird?

Alternatively, does it make more sense to move the keyslot to the end of the struct so all the rest of the values are nice even multiples of 8?

Comment on lines +1516 to +1517
"hf seos managekeys --ki 0 --keyslot 1 -> Set keyslot value at key index 0\n"
"hf seos managekeys --ki 1 --read 0102030405060708 -> Set read key value at key index 1\n"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured I'd switch the line over to the read key, since it's more similar to the original message (showing how you can input a hex string) and it applies to more values. I added an additional line for the keyslot, but I'm not sure if this is actually necessary.

if (nonce_len != 0) {
PrintAndLogEx(SUCCESS, "Current value for nonce[%d] " _GREEN_("%s"), key_index, sprint_hex_inrow(keys[key_index].nonce, 8));
if (keyslot != -1) {
PrintAndLogEx(SUCCESS, "Current value for keyslot[%d] " _GREEN_("%u"), key_index, keys[key_index].keyslot);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere the keyslot is used internally, it's fetched with a %02X format string, but I think it's better displayed to the user in decimal. Is this actually true or should I swap it back to hex everywhere?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant