mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2026-08-23 13:07:11 +01:00
Reject truncated data object responses
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -66,6 +66,9 @@ int cmd_get_data(void) {
|
||||
else {
|
||||
select_file(ef);
|
||||
}
|
||||
if ((file_get_type(ef) & FILE_DATA_FLASH) && file_get_size(ef) > OPENPGP_MAX_DO_SIZE) {
|
||||
return SW_MEMORY_FAILURE();
|
||||
}
|
||||
if (ef->data) {
|
||||
if (requested_fid == EF_PW_STATUS || requested_fid == EF_HIST_BYTES ||
|
||||
requested_fid == EF_FULL_AID || requested_fid == EF_SEC_TPL) {
|
||||
@@ -73,7 +76,6 @@ int cmd_get_data(void) {
|
||||
}
|
||||
uint16_t fids[] = { 1, ef->fid };
|
||||
uint16_t data_len = parse_do(fids, 1);
|
||||
data_len = MIN(data_len, res_APDU_size);
|
||||
if (!(file_get_type(ef) & FILE_DATA_FLASH)) {
|
||||
uint8_t *p = NULL;
|
||||
tlv_item_t item;
|
||||
@@ -105,7 +107,10 @@ int cmd_get_data(void) {
|
||||
if (data_len >= 256) {
|
||||
off++;
|
||||
}
|
||||
data_len = MIN(data_len, OPENPGP_MAX_RESPONSE_SIZE - off);
|
||||
if (data_len > OPENPGP_MAX_RESPONSE_SIZE - off) {
|
||||
res_APDU_size = 0;
|
||||
return SW_MEMORY_FAILURE();
|
||||
}
|
||||
res_APDU_size = data_len;
|
||||
memmove(res_APDU + off, res_APDU, data_len);
|
||||
off = 0;
|
||||
|
||||
@@ -51,6 +51,9 @@ int cmd_put_data(void) {
|
||||
if (!put_data_authorized(requested_fid)) {
|
||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||
}
|
||||
if (apdu.nc > OPENPGP_MAX_DO_SIZE) {
|
||||
return SW_WRONG_DATA();
|
||||
}
|
||||
|
||||
uint16_t max_size = fixed_do_max_size(requested_fid);
|
||||
if (max_size != 0 && apdu.nc > max_size) {
|
||||
|
||||
+2
-2
@@ -60,8 +60,8 @@ uint8_t extended_capabilities[] = {
|
||||
*/
|
||||
0, /* Secure Messaging Algorithm: N/A (TDES=0, AES=1) */
|
||||
(uint8_t)(OPENPGP_MAX_CHALLENGE_SIZE >> 8), (uint8_t)OPENPGP_MAX_CHALLENGE_SIZE, /* Max size of GET CHALLENGE */
|
||||
0x08, 0x00, /* max. length of cardholder certificate (2KiB) */
|
||||
0x08, 0x00, /* max. length of private DO (2KiB) */
|
||||
(uint8_t)(OPENPGP_MAX_DO_SIZE >> 8), (uint8_t)OPENPGP_MAX_DO_SIZE,
|
||||
(uint8_t)(OPENPGP_MAX_DO_SIZE >> 8), (uint8_t)OPENPGP_MAX_DO_SIZE,
|
||||
0x00, 0x1
|
||||
};
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@
|
||||
#define EF_GFM 0x7f74 //C
|
||||
|
||||
#define OPENPGP_MAX_CHALLENGE_SIZE 1024u
|
||||
#define OPENPGP_MAX_DO_SIZE 2036u
|
||||
|
||||
// PIV
|
||||
|
||||
|
||||
@@ -201,7 +201,7 @@ def test_extended_capabilities(card):
|
||||
pytest.skip("Yubikey returns 6B00 when no key")
|
||||
else:
|
||||
a = get_data_object(card, 0xc0)
|
||||
assert a == None or match(b'[\x70\x7F\x75\x77]\x00(?:\x00.|\x04\x00)[\x00\x08]\x00\x08\x00[\x00\x01][\x00\x01]', a)
|
||||
assert a == None or match(b'[\x70\x7F\x75\x77]\x00(?:\x00.|\x04\x00)(?:[\x00\x08]\x00|\x07\xf4)(?:\x08\x00|\x07\xf4)[\x00\x01][\x00\x01]', a)
|
||||
|
||||
def test_key_attributes_1(card):
|
||||
if card.is_yubikey:
|
||||
|
||||
Reference in New Issue
Block a user