mirror of
https://github.com/LedgerHQ/openpgp-card-app
synced 2024-11-09 07:10:30 +00:00
Fix Historical Bytes buffer with correct padding
This commit is contained in:
parent
2969c0e150
commit
7d68daf254
@ -80,7 +80,7 @@ int gpg_apdu_get_data(unsigned int ref) {
|
|||||||
break;
|
break;
|
||||||
case 0x5F52:
|
case 0x5F52:
|
||||||
/* Historical bytes */
|
/* Historical bytes */
|
||||||
gpg_io_insert((const unsigned char *) N_gpg_pstate->histo, 15);
|
gpg_io_insert((const unsigned char *) N_gpg_pstate->histo, HISTO_LENGTH);
|
||||||
break;
|
break;
|
||||||
case 0x7F66:
|
case 0x7F66:
|
||||||
/* Extended length information */
|
/* Extended length information */
|
||||||
@ -115,7 +115,7 @@ int gpg_apdu_get_data(unsigned int ref) {
|
|||||||
memmove(G_gpg_vstate.work.io_buffer + G_gpg_vstate.io_offset - 6,
|
memmove(G_gpg_vstate.work.io_buffer + G_gpg_vstate.io_offset - 6,
|
||||||
G_gpg_vstate.kslot->serial,
|
G_gpg_vstate.kslot->serial,
|
||||||
4);
|
4);
|
||||||
gpg_io_insert_tlv(0x5F52, 15, (const unsigned char *) N_gpg_pstate->histo);
|
gpg_io_insert_tlv(0x5F52, HISTO_LENGTH, (const unsigned char *) N_gpg_pstate->histo);
|
||||||
gpg_io_insert_tlv(0x7F66, sizeof(C_ext_length), C_ext_length);
|
gpg_io_insert_tlv(0x7F66, sizeof(C_ext_length), C_ext_length);
|
||||||
|
|
||||||
gpg_io_mark();
|
gpg_io_mark();
|
||||||
|
@ -254,7 +254,7 @@ int gpg_dispatch() {
|
|||||||
/* --- ACTIVATE/TERMINATE FILE --- */
|
/* --- ACTIVATE/TERMINATE FILE --- */
|
||||||
case INS_ACTIVATE_FILE:
|
case INS_ACTIVATE_FILE:
|
||||||
gpg_io_discard(0);
|
gpg_io_discard(0);
|
||||||
if (N_gpg_pstate->histo[7] == STATE_TERMINATE) {
|
if (N_gpg_pstate->histo[HISTO_OFFSET_STATE] == STATE_TERMINATE) {
|
||||||
gpg_install(STATE_ACTIVATE);
|
gpg_install(STATE_ACTIVATE);
|
||||||
}
|
}
|
||||||
return SW_OK;
|
return SW_OK;
|
||||||
@ -272,7 +272,7 @@ int gpg_dispatch() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Other commands allowed if not terminated */
|
/* Other commands allowed if not terminated */
|
||||||
if (N_gpg_pstate->histo[7] != STATE_ACTIVATE) {
|
if (N_gpg_pstate->histo[HISTO_OFFSET_STATE] != STATE_ACTIVATE) {
|
||||||
return SW_STATE_TERMINATED;
|
return SW_STATE_TERMINATED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +261,7 @@ const unsigned char C_default_AID[] = {
|
|||||||
0x00,
|
0x00,
|
||||||
0x00};
|
0x00};
|
||||||
|
|
||||||
const unsigned char C_default_Histo[] = {
|
const unsigned char C_default_Histo[HISTO_LENGTH] = {
|
||||||
0x00,
|
0x00,
|
||||||
0x31,
|
0x31,
|
||||||
0xC5, // select method: by DF/partialDF; IO-file:readbinary; RFU???
|
0xC5, // select method: by DF/partialDF; IO-file:readbinary; RFU???
|
||||||
@ -269,6 +269,11 @@ const unsigned char C_default_Histo[] = {
|
|||||||
0xC0, // select method: by DF/partialDF ,
|
0xC0, // select method: by DF/partialDF ,
|
||||||
0x01, // data coding style: ontime/byte
|
0x01, // data coding style: ontime/byte
|
||||||
0x80, // chaining
|
0x80, // chaining
|
||||||
|
0x00, // Padding zero bytes
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
|
0x00,
|
||||||
0x7F, // zero state
|
0x7F, // zero state
|
||||||
0x90,
|
0x90,
|
||||||
0x00};
|
0x00};
|
||||||
@ -408,9 +413,9 @@ void gpg_install(unsigned char app_state) {
|
|||||||
nvm_write((void *) (N_gpg_pstate), NULL, sizeof(gpg_nv_state_t));
|
nvm_write((void *) (N_gpg_pstate), NULL, sizeof(gpg_nv_state_t));
|
||||||
|
|
||||||
// historical bytes
|
// historical bytes
|
||||||
memmove(G_gpg_vstate.work.io_buffer, C_default_Histo, sizeof(C_default_Histo));
|
memmove(G_gpg_vstate.work.io_buffer, C_default_Histo, HISTO_LENGTH);
|
||||||
G_gpg_vstate.work.io_buffer[7] = app_state;
|
G_gpg_vstate.work.io_buffer[HISTO_OFFSET_STATE] = app_state;
|
||||||
nvm_write((void *) (N_gpg_pstate->histo), G_gpg_vstate.work.io_buffer, sizeof(C_default_Histo));
|
nvm_write((void *) (N_gpg_pstate->histo), G_gpg_vstate.work.io_buffer, HISTO_LENGTH);
|
||||||
|
|
||||||
// AID
|
// AID
|
||||||
memmove(G_gpg_vstate.work.io_buffer, C_default_AID, sizeof(C_default_AID));
|
memmove(G_gpg_vstate.work.io_buffer, C_default_AID, sizeof(C_default_AID));
|
||||||
|
@ -51,7 +51,7 @@ int gpg_apdu_select() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gpg_io_discard(0);
|
gpg_io_discard(0);
|
||||||
if (N_gpg_pstate->histo[7] != STATE_ACTIVATE) {
|
if (N_gpg_pstate->histo[HISTO_OFFSET_STATE] != STATE_ACTIVATE) {
|
||||||
sw = SW_STATE_TERMINATED;
|
sw = SW_STATE_TERMINATED;
|
||||||
} else {
|
} else {
|
||||||
sw = SW_OK;
|
sw = SW_OK;
|
||||||
|
@ -41,6 +41,8 @@
|
|||||||
#define GPG_MIN_PW1_LENGTH 6
|
#define GPG_MIN_PW1_LENGTH 6
|
||||||
#define GPG_MIN_PW3_LENGTH 8
|
#define GPG_MIN_PW3_LENGTH 8
|
||||||
|
|
||||||
|
#define HISTO_LENGTH 15
|
||||||
|
#define HISTO_OFFSET_STATE 12 // 3rd byte from last (buffer size is 15)
|
||||||
#ifdef TARGET_NANOS
|
#ifdef TARGET_NANOS
|
||||||
#define GPG_KEYS_SLOTS 1
|
#define GPG_KEYS_SLOTS 1
|
||||||
#else
|
#else
|
||||||
@ -159,7 +161,7 @@ struct gpg_nv_state_s {
|
|||||||
/* 4F */
|
/* 4F */
|
||||||
unsigned char AID[16];
|
unsigned char AID[16];
|
||||||
/* 5F52 */
|
/* 5F52 */
|
||||||
unsigned char histo[15];
|
unsigned char histo[HISTO_LENGTH];
|
||||||
|
|
||||||
/* C4 */
|
/* C4 */
|
||||||
unsigned char PW_status[4];
|
unsigned char PW_status[4];
|
||||||
|
Loading…
Reference in New Issue
Block a user