Using file_has_data() to check contents.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -43,7 +43,7 @@ int cmd_derive_asym() {
|
|||||||
file_t *fkey;
|
file_t *fkey;
|
||||||
if (!isUserAuthenticated)
|
if (!isUserAuthenticated)
|
||||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !fkey->data || file_get_size(fkey) == 0)
|
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !file_has_data(fkey))
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
if (key_has_purpose(fkey, ALGO_EC_DERIVE) == false)
|
if (key_has_purpose(fkey, ALGO_EC_DERIVE) == false)
|
||||||
return SW_CONDITIONS_NOT_SATISFIED();
|
return SW_CONDITIONS_NOT_SATISFIED();
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ int cmd_external_authenticate() {
|
|||||||
if (apdu.nc == 0)
|
if (apdu.nc == 0)
|
||||||
return SW_WRONG_LENGTH();
|
return SW_WRONG_LENGTH();
|
||||||
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
||||||
if (!ef_puk || !ef_puk->data || file_get_size(ef_puk) == 0)
|
if (!file_has_data(ef_puk))
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
uint8_t *puk_data = file_get_data(ef_puk);
|
uint8_t *puk_data = file_get_data(ef_puk);
|
||||||
uint8_t *input = (uint8_t *)calloc(dev_name_len+challenge_len, sizeof(uint8_t)), hash[32];
|
uint8_t *input = (uint8_t *)calloc(dev_name_len+challenge_len, sizeof(uint8_t)), hash[32];
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ int cmd_initialize() {
|
|||||||
if (!fdkey)
|
if (!fdkey)
|
||||||
return SW_EXEC_ERROR();
|
return SW_EXEC_ERROR();
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if (ret_mkek != CCID_OK || file_get_size(fdkey) == 0 || file_get_data(fdkey) == NULL) {
|
if (ret_mkek != CCID_OK || !file_has_data(fdkey)) {
|
||||||
mbedtls_ecdsa_context ecdsa;
|
mbedtls_ecdsa_context ecdsa;
|
||||||
mbedtls_ecdsa_init(&ecdsa);
|
mbedtls_ecdsa_init(&ecdsa);
|
||||||
mbedtls_ecp_group_id ec_id = MBEDTLS_ECP_DP_SECP256R1;
|
mbedtls_ecp_group_id ec_id = MBEDTLS_ECP_DP_SECP256R1;
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ int cmd_mse() {
|
|||||||
file_t *ef = search_dynamic_file(EF_PUK+i);
|
file_t *ef = search_dynamic_file(EF_PUK+i);
|
||||||
if (!ef)
|
if (!ef)
|
||||||
break;
|
break;
|
||||||
if (ef->data == NULL || file_get_size(ef) == 0)
|
if (!file_has_data(ef))
|
||||||
break;
|
break;
|
||||||
size_t chr_len = 0;
|
size_t chr_len = 0;
|
||||||
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@
|
|||||||
int cmd_puk_auth() {
|
int cmd_puk_auth() {
|
||||||
uint8_t p1 = P1(apdu), p2 = P2(apdu);
|
uint8_t p1 = P1(apdu), p2 = P2(apdu);
|
||||||
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
file_t *ef_puk = search_by_fid(EF_PUKAUT, NULL, SPECIFY_EF);
|
||||||
if (!ef_puk || !ef_puk->data || file_get_size(ef_puk) == 0)
|
if (!file_has_data(ef_puk))
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
uint8_t *puk_data = file_get_data(ef_puk);
|
uint8_t *puk_data = file_get_data(ef_puk);
|
||||||
if (apdu.nc > 0) {
|
if (apdu.nc > 0) {
|
||||||
@@ -35,7 +35,7 @@ int cmd_puk_auth() {
|
|||||||
ef = search_dynamic_file(EF_PUK+i);
|
ef = search_dynamic_file(EF_PUK+i);
|
||||||
if (!ef) /* Never should not happen */
|
if (!ef) /* Never should not happen */
|
||||||
return SW_MEMORY_FAILURE();
|
return SW_MEMORY_FAILURE();
|
||||||
if (ef->data == NULL || file_get_size(ef) == 0) /* found first empty slot */
|
if (!file_has_data(ef)) /* found first empty slot */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint8_t *tmp = (uint8_t *)calloc(file_get_size(ef_puk), sizeof(uint8_t));
|
uint8_t *tmp = (uint8_t *)calloc(file_get_size(ef_puk), sizeof(uint8_t));
|
||||||
@@ -64,7 +64,7 @@ int cmd_puk_auth() {
|
|||||||
file_t *ef = search_dynamic_file(EF_PUK+p2);
|
file_t *ef = search_dynamic_file(EF_PUK+p2);
|
||||||
if (!ef)
|
if (!ef)
|
||||||
return SW_INCORRECT_P1P2();
|
return SW_INCORRECT_P1P2();
|
||||||
if (ef->data == NULL || file_get_size(ef) == 0)
|
if (!file_has_data(ef))
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
size_t chr_len = 0;
|
size_t chr_len = 0;
|
||||||
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
const uint8_t *chr = cvc_get_chr(file_get_data(ef), file_get_size(ef), &chr_len);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ int cmd_reset_retry() {
|
|||||||
if (!file_sopin || !file_pin1) {
|
if (!file_sopin || !file_pin1) {
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
if (!file_sopin->data) {
|
if (!file_has_data(file_sopin)) {
|
||||||
return SW_REFERENCE_NOT_FOUND();
|
return SW_REFERENCE_NOT_FOUND();
|
||||||
}
|
}
|
||||||
uint16_t opts = get_device_options();
|
uint16_t opts = get_device_options();
|
||||||
|
|||||||
@@ -94,7 +94,7 @@ int cmd_signature() {
|
|||||||
file_t *fkey;
|
file_t *fkey;
|
||||||
if (!isUserAuthenticated)
|
if (!isUserAuthenticated)
|
||||||
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
return SW_SECURITY_STATUS_NOT_SATISFIED();
|
||||||
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !fkey->data || file_get_size(fkey) == 0)
|
if (!(fkey = search_dynamic_file((KEY_PREFIX << 8) | key_id)) || !file_has_data(fkey))
|
||||||
return SW_FILE_NOT_FOUND();
|
return SW_FILE_NOT_FOUND();
|
||||||
if (get_key_counter(fkey) == 0)
|
if (get_key_counter(fkey) == 0)
|
||||||
return SW_FILE_FULL();
|
return SW_FILE_FULL();
|
||||||
|
|||||||
Reference in New Issue
Block a user