Skip to content

Commit

Permalink
Fix Historical Bytes buffer with correct padding
Browse files Browse the repository at this point in the history
  • Loading branch information
cedelavergne-ledger committed Feb 23, 2024
1 parent 7c38906 commit f279f8d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/gpg_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ int gpg_dispatch() {
/* --- ACTIVATE/TERMINATE FILE --- */
case INS_ACTIVATE_FILE:
gpg_io_discard(0);
if (N_gpg_pstate->histo[7] == STATE_TERMINATE) {
if (N_gpg_pstate->histo[12] == STATE_TERMINATE) {
gpg_install(STATE_ACTIVATE);
}
return SW_OK;
Expand All @@ -272,7 +272,7 @@ int gpg_dispatch() {
}

/* Other commands allowed if not terminated */
if (N_gpg_pstate->histo[7] != STATE_ACTIVATE) {
if (N_gpg_pstate->histo[12] != STATE_ACTIVATE) {
return SW_STATE_TERMINATED;
}

Expand Down
7 changes: 6 additions & 1 deletion src/gpg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,11 @@ const unsigned char C_default_Histo[] = {
0xC0, // select method: by DF/partialDF ,
0x01, // data coding style: ontime/byte
0x80, // chaining
0x00, // Padding zero bytes
0x00,
0x00,
0x00,
0x00,
0x7F, // zero state
0x90,
0x00};
Expand Down Expand Up @@ -409,7 +414,7 @@ void gpg_install(unsigned char app_state) {

// historical bytes
memmove(G_gpg_vstate.work.io_buffer, C_default_Histo, sizeof(C_default_Histo));
G_gpg_vstate.work.io_buffer[7] = app_state;
G_gpg_vstate.work.io_buffer[sizeof(C_default_Histo) - 3] = app_state;
nvm_write((void *) (N_gpg_pstate->histo), G_gpg_vstate.work.io_buffer, sizeof(C_default_Histo));

// AID
Expand Down
2 changes: 1 addition & 1 deletion src/gpg_select.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int gpg_apdu_select() {
}

gpg_io_discard(0);
if (N_gpg_pstate->histo[7] != STATE_ACTIVATE) {
if (N_gpg_pstate->histo[12] != STATE_ACTIVATE) {
sw = SW_STATE_TERMINATED;
} else {
sw = SW_OK;
Expand Down

0 comments on commit f279f8d

Please sign in to comment.