Skip to content

Commit

Permalink
Return counter in text for backward compatibility. Allow to request n…
Browse files Browse the repository at this point in the history
…ew format.

Signed-off-by: Szczepan Zalega <[email protected]>
  • Loading branch information
szszszsz committed Jun 18, 2019
1 parent acfc516 commit 52625ec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/OTP/report_protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,9 @@ u8 slot_no = report[1];
u8 cmd_read_slot (u8 * report, u8 * output)
{
u8 slot_no = report[CMD_RS_SLOT_NUMBER_OFFSET];
u8 format_version = report[CMD_RS_VERSION_OFFSET];
u64 counter;
char buf[20] = {};

if (is_HOTP_slot_number(slot_no)) // HOTP slot
{
Expand All @@ -1587,9 +1589,16 @@ u64 counter;
memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 16, slot->token_id, 13);
output[OUTPUT_CMD_RESULT_OFFSET +15] = slot->config;

counter = get_counter_value (hotp_slot_counters[slot_no]);
counter = endian_swap(counter);
memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, &counter, sizeof(u64));
counter = get_counter_value(hotp_slot_counters[slot_no]);
if (format_version == 1) {
counter = endian_swap(counter);
memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, &counter, sizeof(u64));
} else {
itoa(counter, buf);
buf[7] = 0;
memcpy (output + OUTPUT_CMD_RESULT_OFFSET + 29, buf, 8);
}


{
u8 text[20];
Expand Down
1 change: 1 addition & 0 deletions src/OTP/report_protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ typedef struct {
*/

#define CMD_RS_SLOT_NUMBER_OFFSET 1
#define CMD_RS_VERSION_OFFSET 2
#define CMD_RS_OUTPUT_COUNTER_OFFSET 34

/*
Expand Down

0 comments on commit 52625ec

Please sign in to comment.