replaced SC_TEST_RET with LOG_TEST_RET
This commit is contained in:
parent
907c9479e2
commit
a899a46b09
|
@ -136,7 +136,7 @@ static int acos5_get_serialnr(sc_card_t * card, sc_serial_number_t * serial)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 6;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
||||
|
@ -186,7 +186,7 @@ static int acos5_list_files(sc_card_t * card, u8 * buf, size_t buflen)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x14, 0x01, 0x00);
|
||||
apdu.cla |= 0x80;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90)
|
||||
return SC_ERROR_INTERNAL;
|
||||
count = apdu.sw2;
|
||||
|
@ -207,7 +207,7 @@ static int acos5_list_files(sc_card_t * card, u8 * buf, size_t buflen)
|
|||
apdu.resplen = sizeof(info);
|
||||
apdu.le = sizeof(info);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
||||
|
|
|
@ -93,9 +93,9 @@ select_file(sc_card_t *card, sc_apdu_t *apdu, const sc_path_t *path,
|
|||
apdu->le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu->sw1, apdu->sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (file_out == NULL)
|
||||
return 0;
|
||||
|
@ -126,7 +126,7 @@ akis_select_file(sc_card_t *card, const sc_path_t *path,
|
|||
*/
|
||||
r = select_file(card, &apdu, path, path->len == 2 ? 0 : 8, file_out);
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select DF");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select DF");
|
||||
return 0;
|
||||
} else if (path->type == SC_PATH_TYPE_FILE_ID) {
|
||||
/* AKIS differentiates between EF and DF files
|
||||
|
@ -136,7 +136,7 @@ akis_select_file(sc_card_t *card, const sc_path_t *path,
|
|||
if (r)
|
||||
r = select_file(card, &apdu, path, 0, file_out);
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select DF");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select DF");
|
||||
return 0;
|
||||
} else {
|
||||
return iso_ops->select_file(card, path, file_out);
|
||||
|
@ -161,9 +161,9 @@ akis_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "DIRECTORY command returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "DIRECTORY command returned error");
|
||||
|
||||
left = apdu.resplen;
|
||||
p = rbuf;
|
||||
|
@ -291,7 +291,7 @@ akis_create_file(sc_card_t *card, sc_file_t *file)
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -329,7 +329,7 @@ akis_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
apdu.data = buf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -368,7 +368,7 @@ akis_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data, int *tries_left
|
|||
apdu.lc = apdu.datalen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return r;
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ akis_get_data(sc_card_t *card, unsigned int dataid, u8 *buf, size_t len)
|
|||
apdu.le = len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return r;
|
||||
}
|
||||
|
@ -408,7 +408,7 @@ akis_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
|
||||
/* read serial number */
|
||||
r = akis_get_data(card, 6, system_buffer, 0x4D);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GET_DATA failed");
|
||||
LOG_TEST_RET(card->ctx, r, "GET_DATA failed");
|
||||
|
||||
card->serialnr.len = 12;
|
||||
memcpy(card->serialnr.value, system_buffer+55, 12);
|
||||
|
@ -425,7 +425,7 @@ akis_lifecycle_get(sc_card_t *card, int *mode)
|
|||
u8 memory[10];
|
||||
|
||||
r = akis_get_data(card, 4, memory, 10);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GET_DATA failed");
|
||||
LOG_TEST_RET(card->ctx, r, "GET_DATA failed");
|
||||
|
||||
switch(memory[6]) {
|
||||
case 0xA0:
|
||||
|
@ -462,7 +462,7 @@ akis_lifecycle_set(sc_card_t *card, int *mode)
|
|||
apdu.cla = 0x80;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return r;
|
||||
}
|
||||
|
@ -496,7 +496,7 @@ akis_set_security_env(sc_card_t *card,
|
|||
ref = env->key_ref[0];
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xC3, ref);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return r;
|
||||
}
|
||||
|
@ -512,7 +512,7 @@ akis_logout(sc_card_t *card)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x1A, 0, 0);
|
||||
apdu.cla = 0x80;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return r;
|
||||
}
|
||||
|
|
|
@ -252,7 +252,7 @@ static int asepcos_get_current_df_path(sc_card_t *card, sc_path_t *path)
|
|||
apdu.le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return asepcos_tlvpath_to_scpath(path, apdu.resp, apdu.resplen);
|
||||
|
@ -340,7 +340,7 @@ static int asepcos_akn_to_fileid(sc_card_t *card, sc_cardctl_asepcos_akn2fileid_
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.resplen != 4)
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
@ -364,7 +364,7 @@ static int asepcos_set_sec_attributes(sc_card_t *card, const u8 *data, size_t le
|
|||
apdu.datalen = len;
|
||||
apdu.data = data;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -452,7 +452,7 @@ static int asepcos_decipher(sc_card_t *card, const u8 * crgram, size_t crgram_le
|
|||
apdu.lc = crgram_len;
|
||||
apdu.datalen = crgram_len;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
return apdu.resplen;
|
||||
|
@ -485,7 +485,7 @@ static int asepcos_compute_signature(sc_card_t *card, const u8 *data, size_t dat
|
|||
apdu.le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00) {
|
||||
sc_log(card->ctx, "error creating signature");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
|
@ -513,7 +513,7 @@ static int asepcos_activate_file(sc_card_t *card, int fileid, int is_ef)
|
|||
apdu.datalen = 2;
|
||||
apdu.data = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -555,7 +555,7 @@ static int asepcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
|
||||
|
@ -604,7 +604,7 @@ static int asepcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.datalen = p - sbuf;
|
||||
apdu.data = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
|
||||
|
@ -632,7 +632,7 @@ static int asepcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.data = file->prop_attr;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
/* set security attributes */
|
||||
|
@ -738,7 +738,7 @@ static int asepcos_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
apdu.resplen = sizeof(buf);
|
||||
apdu.resp = buf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
/* looks like a EF */
|
||||
atype = SC_APDU_CASE_3_SHORT;
|
||||
|
@ -759,7 +759,7 @@ static int asepcos_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -790,7 +790,7 @@ static int asepcos_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
if (apdu.resplen != 8) {
|
||||
|
@ -821,7 +821,7 @@ static int asepcos_change_key(sc_card_t *card, sc_cardctl_asepcos_change_key_t *
|
|||
apdu.data = p->data;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
|
|
@ -249,7 +249,7 @@ static int atrust_acos_select_aid(struct sc_card *card,
|
|||
apdu.resplen = 0;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
/* check return value */
|
||||
if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61 )
|
||||
|
@ -300,7 +300,7 @@ static int atrust_acos_select_fid(struct sc_card *card,
|
|||
apdu.datalen = 2;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
|
||||
/* no FCI => we have a DF (see comment in process_fci()) */
|
||||
|
@ -310,7 +310,7 @@ static int atrust_acos_select_fid(struct sc_card *card,
|
|||
apdu.resplen = 0;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU re-transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
|
||||
} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)) {
|
||||
/* SELECT returned some data (possible FCI) =>
|
||||
* try a READ BINARY to see if a EF is selected */
|
||||
|
@ -322,7 +322,7 @@ static int atrust_acos_select_fid(struct sc_card *card,
|
|||
apdu2.le = 1;
|
||||
apdu2.lc = 0;
|
||||
r = sc_transmit_apdu(card, &apdu2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86)
|
||||
/* no current EF is selected => we have a DF */
|
||||
bIsDF = 1;
|
||||
|
@ -476,7 +476,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
|
||||
/* first step: change directory */
|
||||
r = atrust_acos_select_fid(card, path[bMatch], path[bMatch+1], NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
|
||||
memset(&new_path, 0, sizeof(sc_path_t));
|
||||
new_path.type = SC_PATH_TYPE_PATH;
|
||||
|
@ -515,7 +515,7 @@ static int atrust_acos_select_file(struct sc_card *card,
|
|||
for ( i=0; i<pathlen-2; i+=2 )
|
||||
{
|
||||
r = atrust_acos_select_fid(card, path[i], path[i+1], NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
}
|
||||
return atrust_acos_select_fid(card, path[pathlen-2], path[pathlen-1], file_out);
|
||||
}
|
||||
|
@ -574,7 +574,7 @@ static int atrust_acos_set_security_env(struct sc_card *card,
|
|||
apdu.lc = p - sbuf;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
return SC_SUCCESS;
|
||||
|
@ -624,7 +624,7 @@ static int atrust_acos_set_security_env(struct sc_card *card,
|
|||
/* we don't know whether to use
|
||||
* COMPUTE SIGNATURE or INTERNAL AUTHENTICATE */
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
ex_data->fix_digestInfo = 0;
|
||||
ex_data->sec_ops = SC_SEC_OPERATION_SIGN;
|
||||
|
@ -649,7 +649,7 @@ try_authenticate:
|
|||
apdu.lc = p - sbuf;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
ex_data->fix_digestInfo = env->algorithm_flags;
|
||||
|
@ -689,7 +689,7 @@ static int atrust_acos_compute_signature(struct sc_card *card,
|
|||
apdu.lc = datalen;
|
||||
apdu.datalen = datalen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,
|
||||
sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
|
@ -704,7 +704,7 @@ static int atrust_acos_compute_signature(struct sc_card *card,
|
|||
apdu.lc = 0;
|
||||
apdu.datalen = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
memcpy(out, apdu.resp, len);
|
||||
|
@ -736,7 +736,7 @@ static int atrust_acos_compute_signature(struct sc_card *card,
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
{
|
||||
|
@ -785,7 +785,7 @@ static int atrust_acos_decipher(struct sc_card *card,
|
|||
apdu.datalen = crgram_len + 1;
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
@ -841,7 +841,7 @@ static int acos_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.lc = 0;
|
||||
apdu.datalen = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
/* cache serial number */
|
||||
|
@ -882,7 +882,7 @@ static int atrust_acos_logout(struct sc_card *card)
|
|||
apdu.resplen = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU re-transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
|
||||
|
||||
if (apdu.sw1 == 0x69 && apdu.sw2 == 0x85)
|
||||
/* the only possible reason for this error here is, afaik,
|
||||
|
|
|
@ -1867,7 +1867,7 @@ authentic_manage_sdo_generate(struct sc_card *card, struct sc_authentic_sdo *sdo
|
|||
LOG_TEST_RET(ctx, rv, "authentic_sdo_create() SDO put data error");
|
||||
|
||||
rv = authentic_decode_pubkey_rsa(ctx, apdu.resp, apdu.resplen, &sdo->data.prvkey);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "cannot decode public key");
|
||||
LOG_TEST_RET(card->ctx, rv, "cannot decode public key");
|
||||
|
||||
free(data);
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
|
|
@ -268,7 +268,7 @@ static int belpic_select_file(sc_card_t *card,
|
|||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Select File APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Select File APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (r)
|
||||
|
@ -374,10 +374,10 @@ static int belpic_set_security_env(sc_card_t *card,
|
|||
apdu.resplen = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Set Security Env APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Set Security Env APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card's Set Security Env command returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card's Set Security Env command returned error");
|
||||
|
||||
/* If a NonRep signature will be done, ask to enter a PIN. It would be more
|
||||
* logical to put the code below into the compute signature function because
|
||||
|
|
|
@ -103,7 +103,7 @@ static int cardos_match_card(sc_card_t *card)
|
|||
apdu.le = 256;
|
||||
apdu.lc = 0;
|
||||
rv = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return 0;
|
||||
if (apdu.resp[0] != atr[10] ||
|
||||
|
@ -143,7 +143,7 @@ static int cardos_have_2048bit_package(sc_card_t *card)
|
|||
apdu.lc = 0;
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if ((len = apdu.resplen) == 0)
|
||||
/* looks like no package has been installed */
|
||||
|
@ -211,12 +211,12 @@ static int cardos_init(sc_card_t *card)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
if (r < 0)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
LOG_TEST_RET(card->ctx,
|
||||
SC_ERROR_INVALID_CARD,
|
||||
"APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (r < 0)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
LOG_TEST_RET(card->ctx,
|
||||
SC_ERROR_INVALID_CARD,
|
||||
"GET DATA command returned error");
|
||||
if (apdu.resplen != 2)
|
||||
|
@ -346,9 +346,9 @@ get_next_part:
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "DIRECTORY command returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "DIRECTORY command returned error");
|
||||
|
||||
if (apdu.resplen > 256) {
|
||||
sc_log(card->ctx, "directory listing > 256 bytes, cutting");
|
||||
|
@ -730,7 +730,7 @@ static int cardos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
} else
|
||||
|
@ -752,10 +752,10 @@ cardos_restore_security_env(sc_card_t *card, int se_num)
|
|||
apdu.p1 = (card->type == SC_CARD_TYPE_CARDOS_CIE_V1 ? 0xF3 : 0x03);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -812,10 +812,10 @@ cardos_set_security_env(sc_card_t *card,
|
|||
apdu.data = data;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
do {
|
||||
const struct sc_supported_algo_info* algorithm_info = env->supported_algos;
|
||||
|
@ -865,7 +865,7 @@ do_compute_signature(sc_card_t *card, const u8 *data, size_t datalen,
|
|||
apdu.lc = datalen;
|
||||
apdu.datalen = datalen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, apdu.resplen);
|
||||
|
@ -1024,13 +1024,13 @@ cardos_lifecycle_get(sc_card_t *card, int *mode)
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (apdu.resplen < 1) {
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Lifecycle byte not in response");
|
||||
LOG_TEST_RET(card->ctx, r, "Lifecycle byte not in response");
|
||||
}
|
||||
|
||||
r = SC_SUCCESS;
|
||||
|
@ -1080,10 +1080,10 @@ cardos_lifecycle_set(sc_card_t *card, int *mode)
|
|||
apdu.resp = NULL;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1108,10 +1108,10 @@ cardos_put_data_oci(sc_card_t *card,
|
|||
apdu.datalen = args->len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1134,10 +1134,10 @@ cardos_put_data_seci(sc_card_t *card,
|
|||
apdu.datalen = args->len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1169,9 +1169,9 @@ cardos_generate_key(sc_card_t *card,
|
|||
apdu.datalen = apdu.lc = sizeof(data);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GENERATE_KEY failed");
|
||||
LOG_TEST_RET(card->ctx, r, "GENERATE_KEY failed");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1187,7 +1187,7 @@ static int cardos_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
if (apdu.resplen != 32) {
|
||||
|
@ -1290,7 +1290,7 @@ cardos_logout(sc_card_t *card)
|
|||
apdu.cla = 0x80;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
} else
|
||||
|
|
|
@ -185,7 +185,7 @@ static int entersafe_gen_random(sc_card_t *card,u8 *buff,size_t size)
|
|||
apdu.resplen=sizeof(rbuf);
|
||||
|
||||
r=sc_transmit_apdu(card,&apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "entersafe gen random failed");
|
||||
LOG_TEST_RET(card->ctx, r, "entersafe gen random failed");
|
||||
|
||||
if(apdu.resplen!=size)
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INTERNAL);
|
||||
|
@ -272,7 +272,7 @@ static int entersafe_mac_apdu(sc_card_t *card, sc_apdu_t *apdu,
|
|||
return SC_ERROR_INTERNAL;
|
||||
|
||||
r=entersafe_gen_random(card,iv,sizeof(iv));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,r,"entersafe gen random failed");
|
||||
LOG_TEST_RET(card->ctx,r,"entersafe gen random failed");
|
||||
|
||||
/* encode the APDU in the buffer */
|
||||
if ((r=sc_apdu_get_octets(card->ctx, apdu, &tmp, &tmpsize,SC_PROTO_RAW)) != SC_SUCCESS)
|
||||
|
@ -428,7 +428,7 @@ static int entersafe_read_binary(sc_card_t *card,
|
|||
apdu.resp = recvbuf;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.resplen == 0)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
memcpy(buf, recvbuf, apdu.resplen);
|
||||
|
@ -455,8 +455,8 @@ static int entersafe_update_binary(sc_card_t *card,
|
|||
apdu.data = buf;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),
|
||||
"Card returned error");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, count);
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ static int entersafe_process_fci(struct sc_card *card, struct sc_file *file,
|
|||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
|
||||
r = iso_ops->process_fci(card,file,buf,buflen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Process fci failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Process fci failed");
|
||||
|
||||
if(file->namelen)
|
||||
{
|
||||
|
@ -505,7 +505,7 @@ static int entersafe_select_fid(sc_card_t *card,
|
|||
r = iso_ops->select_file(card,&path,&file);
|
||||
if (r < 0)
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
/* update cache */
|
||||
if (file->type == SC_FILE_TYPE_DF) {
|
||||
|
@ -550,7 +550,7 @@ static int entersafe_select_aid(sc_card_t *card,
|
|||
else
|
||||
{
|
||||
r = iso_ops->select_file(card,in_path,file_out);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
/* update cache */
|
||||
card->cache.current_path.type = SC_PATH_TYPE_DF_NAME;
|
||||
|
@ -629,7 +629,7 @@ static int entersafe_select_path(sc_card_t *card,
|
|||
|
||||
/* first step: change directory */
|
||||
r = entersafe_select_fid(card, path[bMatch], path[bMatch+1], NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
|
||||
memset(&new_path, 0, sizeof(sc_path_t));
|
||||
|
||||
|
@ -670,7 +670,7 @@ static int entersafe_select_path(sc_card_t *card,
|
|||
for ( i=0; i<pathlen-2; i+=2 )
|
||||
{
|
||||
r = entersafe_select_fid(card, path[i], path[i+1], NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
}
|
||||
return entersafe_select_fid(card, path[pathlen-2], path[pathlen-1], file_out);
|
||||
}
|
||||
|
@ -750,7 +750,7 @@ static int entersafe_create_mf(sc_card_t *card, sc_entersafe_create_data * data)
|
|||
}break;
|
||||
}
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
static int entersafe_create_df(sc_card_t *card, sc_entersafe_create_data * data)
|
||||
|
@ -768,7 +768,7 @@ static int entersafe_create_df(sc_card_t *card, sc_entersafe_create_data * data)
|
|||
apdu.lc=apdu.datalen=sizeof(data->data.df);
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -785,7 +785,7 @@ static int entersafe_create_ef(sc_card_t *card, sc_entersafe_create_data * data)
|
|||
apdu.lc = apdu.datalen = sizeof(data->data.ef);
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -889,7 +889,7 @@ static int entersafe_internal_set_security_env(sc_card_t *card,
|
|||
apdu.resplen = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -949,7 +949,7 @@ static int entersafe_compute_with_prkey(sc_card_t *card,
|
|||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_ERROR_INTERNAL);
|
||||
|
||||
r = entersafe_internal_set_security_env(card,card->drv_data,&p,&size);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "internal set security env failed");
|
||||
LOG_TEST_RET(card->ctx, r, "internal set security env failed");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A, 0x86,0x80);
|
||||
apdu.data=p;
|
||||
|
@ -960,7 +960,7 @@ static int entersafe_compute_with_prkey(sc_card_t *card,
|
|||
apdu.le = 256;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
@ -1022,7 +1022,7 @@ static int entersafe_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data,
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
}
|
||||
|
||||
{/*change*/
|
||||
|
@ -1038,7 +1038,7 @@ static int entersafe_pin_cmd(sc_card_t *card, struct sc_pin_cmd_data *data,
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,key_maintain,sizeof(key_maintain),1,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
}
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
@ -1060,7 +1060,7 @@ static int entersafe_erase_card(sc_card_t *card)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
sc_invalidate_cache(card);
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xEE, 0x00, 0x00);
|
||||
|
@ -1092,7 +1092,7 @@ static int entersafe_erase_card(sc_card_t *card)
|
|||
}break;
|
||||
}
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
||||
|
@ -1149,8 +1149,8 @@ static int entersafe_write_small_rsa_key(sc_card_t *card,u8 key_id,struct sc_pkc
|
|||
apdu.lc=apdu.datalen=p-sbuff;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,key_maintain,sizeof(key_maintain),1,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey failed");
|
||||
}
|
||||
|
||||
p=sbuff;
|
||||
|
@ -1166,8 +1166,8 @@ static int entersafe_write_small_rsa_key(sc_card_t *card,u8 key_id,struct sc_pkc
|
|||
apdu.lc=apdu.datalen=p-sbuff;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,key_maintain,sizeof(key_maintain),1,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey failed");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
|
||||
|
@ -1195,8 +1195,8 @@ static int entersafe_write_rsa_key_factor(sc_card_t *card,
|
|||
apdu.lc=apdu.datalen=4;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey factor failed(MSE)");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey factor failed(MSE)");
|
||||
}
|
||||
|
||||
{/* Write 'x'; */
|
||||
|
@ -1238,8 +1238,8 @@ static int entersafe_write_rsa_key_factor(sc_card_t *card,
|
|||
apdu.lc=apdu.datalen=data.len;
|
||||
|
||||
r = entersafe_transmit_apdu(card,&apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey factor failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey factor failed");
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
|
||||
}
|
||||
|
@ -1252,15 +1252,15 @@ static int entersafe_write_large_rsa_key(sc_card_t *card,u8 key_id,struct sc_pkc
|
|||
|
||||
{/* write prkey */
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x22,0x01,rsa->p);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write p failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write p failed");
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x22,0x02,rsa->q);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write q failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write q failed");
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x22,0x03,rsa->dmp1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write dmp1 failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write dmp1 failed");
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x22,0x04,rsa->dmq1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write dmq1 failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write dmq1 failed");
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x22,0x05,rsa->iqmp);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write iqmp failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write iqmp failed");
|
||||
}
|
||||
|
||||
{/* write pukey */
|
||||
|
@ -1281,8 +1281,8 @@ static int entersafe_write_large_rsa_key(sc_card_t *card,u8 key_id,struct sc_pkc
|
|||
apdu.lc=apdu.datalen=0x46;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey N(1) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey N(1) failed");
|
||||
|
||||
/* left 192(0xC0) bytes of N */
|
||||
sc_format_apdu(card,&apdu,SC_APDU_CASE_3_SHORT,0x46,0x0B,0x00);
|
||||
|
@ -1290,12 +1290,12 @@ static int entersafe_write_large_rsa_key(sc_card_t *card,u8 key_id,struct sc_pkc
|
|||
apdu.lc=apdu.datalen=0xC0;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey N(2) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write pukey N(2) failed");
|
||||
|
||||
/* E */
|
||||
r = entersafe_write_rsa_key_factor(card,key_id,0x2A,0x0D,rsa->exponent);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "write exponent failed");
|
||||
LOG_TEST_RET(card->ctx, r, "write exponent failed");
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
|
||||
}
|
||||
|
@ -1324,8 +1324,8 @@ static int entersafe_write_symmetric_key(sc_card_t *card,
|
|||
apdu.lc=apdu.datalen=len+2;
|
||||
|
||||
r=entersafe_transmit_apdu(card,&apdu,key_maintain,sizeof(key_maintain),1,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2),"Write prkey failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
|
||||
}
|
||||
|
||||
|
@ -1380,8 +1380,8 @@ static int entersafe_gen_key(sc_card_t *card, sc_entersafe_gen_key_data *data)
|
|||
apdu.le=0;
|
||||
|
||||
r=entersafe_transmit_apdu(card, &apdu, 0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe set MSE failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe set MSE failed");
|
||||
|
||||
/* generate key */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x46, 0x00, 0x00);
|
||||
|
@ -1393,8 +1393,8 @@ static int entersafe_gen_key(sc_card_t *card, sc_entersafe_gen_key_data *data)
|
|||
apdu.datalen = 2;
|
||||
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe generate keypair failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe generate keypair failed");
|
||||
|
||||
/* read public key via READ PUBLIC KEY */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_2_SHORT, 0xE6, 0x2A, data->key_id);
|
||||
|
@ -1403,8 +1403,8 @@ static int entersafe_gen_key(sc_card_t *card, sc_entersafe_gen_key_data *data)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get pukey failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get pukey failed");
|
||||
|
||||
data->modulus = malloc(len);
|
||||
if (!data->modulus)
|
||||
|
@ -1452,8 +1452,8 @@ static int entersafe_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.le=0x08;
|
||||
|
||||
r=entersafe_transmit_apdu(card, &apdu,0,0,0,0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get SN failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card,apdu.sw1,apdu.sw2),"EnterSafe get SN failed");
|
||||
|
||||
card->serialnr.len=serial->len=8;
|
||||
memcpy(card->serialnr.value,rbuf,8);
|
||||
|
@ -1496,7 +1496,7 @@ static int entersafe_preinstall_rsa_2048(sc_card_t *card,u8 key_id)
|
|||
apdu.lc=apdu.datalen=9 + sizeof(rsa_key_e) + 4;
|
||||
|
||||
ret = entersafe_transmit_apdu(card,&apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Preinstall rsa failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "Preinstall rsa failed");
|
||||
|
||||
/* create rsa item in PKF */
|
||||
sbuf[0] = 0x01; /* key len extern */
|
||||
|
@ -1520,7 +1520,7 @@ static int entersafe_preinstall_rsa_2048(sc_card_t *card,u8 key_id)
|
|||
apdu.lc=apdu.datalen=9 + sizeof(rsa_key_e) + 4;
|
||||
|
||||
ret=entersafe_transmit_apdu(card,&apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Preinstall rsa failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "Preinstall rsa failed");
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
|
||||
}
|
||||
|
@ -1540,7 +1540,7 @@ static int entersafe_preinstall_keys(sc_card_t *card,int (*install_rsa)(sc_card_
|
|||
++rsa_index)
|
||||
{
|
||||
r=install_rsa(card,rsa_index);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Preinstall rsa key failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Preinstall rsa key failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1563,7 +1563,7 @@ static int entersafe_preinstall_keys(sc_card_t *card,int (*install_rsa)(sc_card_
|
|||
apdu.lc=apdu.datalen=0x19;
|
||||
|
||||
r = entersafe_transmit_apdu(card,&apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Preinstall key maintain failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Preinstall key maintain failed");
|
||||
}
|
||||
|
||||
{/* user PIN */
|
||||
|
@ -1584,7 +1584,7 @@ static int entersafe_preinstall_keys(sc_card_t *card,int (*install_rsa)(sc_card_
|
|||
apdu.lc=apdu.datalen=0x19;
|
||||
|
||||
r = entersafe_transmit_apdu(card,&apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Preinstall user PIN failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Preinstall user PIN failed");
|
||||
}
|
||||
|
||||
{/* user PUK */
|
||||
|
@ -1605,7 +1605,7 @@ static int entersafe_preinstall_keys(sc_card_t *card,int (*install_rsa)(sc_card_
|
|||
apdu.lc=apdu.datalen=0x19;
|
||||
|
||||
r = entersafe_transmit_apdu(card,&apdu,init_key,sizeof(init_key),0,1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Preinstall user PUK failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Preinstall user PUK failed");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -532,9 +532,9 @@ static int select_file_id(sc_card_t *card, const u8 *buf, size_t buflen,
|
|||
apdu.le = 0;
|
||||
}
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (file_out == NULL)
|
||||
return 0;
|
||||
|
@ -587,18 +587,18 @@ static int flex_select_file(sc_card_t *card, const sc_path_t *path,
|
|||
if (pathlen != 2 || memcmp(pathptr, "\x3F\x00", 2) != 0) {
|
||||
locked = 1;
|
||||
r = sc_lock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
|
||||
if (!magic_done && memcmp(pathptr, "\x3F\x00", 2) != 0) {
|
||||
r = select_file_id(card, (const u8 *) "\x3F\x00", 2, 0, NULL);
|
||||
if (r)
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select Master File (MF)");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select Master File (MF)");
|
||||
}
|
||||
while (pathlen > 2) {
|
||||
r = select_file_id(card, pathptr, 2, 0, NULL);
|
||||
if (r)
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select DF");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select DF");
|
||||
pathptr += 2;
|
||||
pathlen -= 2;
|
||||
}
|
||||
|
@ -709,7 +709,7 @@ static int flex_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
apdu.datalen = 2;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -809,7 +809,7 @@ cryptoflex_construct_file_attrs(sc_card_t *card, const sc_file_t *file,
|
|||
continue;
|
||||
entry = sc_file_get_acl_entry(file, ops[i]);
|
||||
r = acl_to_ac_nibble(entry);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Invalid ACL value");
|
||||
LOG_TEST_RET(card->ctx, r, "Invalid ACL value");
|
||||
/* Do some magic to get the nibbles right */
|
||||
p[8 + i/2] |= (r & 0x0F) << (((i+1) % 2) * 4);
|
||||
r = acl_to_keynum_nibble(entry);
|
||||
|
@ -918,9 +918,9 @@ static int flex_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.lc = sendlen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
if (card->cache.valid) {
|
||||
u8 file_id[2];
|
||||
|
||||
|
@ -1010,9 +1010,9 @@ cryptoflex_compute_signature(sc_card_t *card, const u8 *data,
|
|||
for (i2 = 0; i2 < 10; i2++)
|
||||
sbuf[i2]=data[data_len-1-i2];
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
data_len -= 10;
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x88, 0x00, prv->rsa_key_ref);
|
||||
apdu.cla=0x0;
|
||||
|
@ -1027,9 +1027,9 @@ cryptoflex_compute_signature(sc_card_t *card, const u8 *data,
|
|||
apdu.le = apdu.resplen > 256 ? 256 : apdu.resplen;
|
||||
apdu.resp = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
for (i = 0; i < apdu.resplen; i++)
|
||||
out[i] = sbuf[apdu.resplen-1-i];
|
||||
return apdu.resplen;
|
||||
|
@ -1068,9 +1068,9 @@ cyberflex_compute_signature(sc_card_t *card, const u8 *data,
|
|||
apdu.resplen = outlen;
|
||||
apdu.resp = out;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
return apdu.resplen;
|
||||
}
|
||||
|
||||
|
@ -1143,9 +1143,9 @@ static int flex_generate_key(sc_card_t *card, struct sc_cardctl_cryptoflex_genke
|
|||
sbuf[3] = (data->exponent >> 24) & 0xFF;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
data->pubkey_len = apdu.resplen;
|
||||
return 0;
|
||||
|
@ -1296,10 +1296,10 @@ static int flex_logout(sc_card_t *card)
|
|||
apdu.cla = 0xF0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
|
|
@ -135,7 +135,7 @@ static int gp_select_applet(sc_card_t *card, const u8 *aid, size_t aid_len)
|
|||
apdu.resplen = sizeof(buf);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (r)
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
@ -418,7 +418,7 @@ static int gemsafe_restore_security_env(struct sc_card *card, int se_num)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0x73, (u8) se_num);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
@ -489,7 +489,7 @@ static int gemsafe_compute_signature(struct sc_card *card, const u8 * data,
|
|||
apdu.datalen = data_len + 2;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
if(card->type == SC_CARD_TYPE_GEMSAFEV1_PTEID ||
|
||||
card->type == SC_CARD_TYPE_GEMSAFEV1_SEEID) {
|
||||
|
@ -503,7 +503,7 @@ static int gemsafe_compute_signature(struct sc_card *card, const u8 * data,
|
|||
apdu.cla = 0x00;
|
||||
}
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
@ -537,7 +537,7 @@ static int gemsafe_decipher(struct sc_card *card, const u8 * crgram,
|
|||
apdu.lc = crgram_len;
|
||||
apdu.datalen = crgram_len;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
int len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
|
|
@ -229,8 +229,8 @@ static int gids_get_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdenti
|
|||
apdu.le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids get data failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "gids get data failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
p = sc_asn1_find_tag(card->ctx, buffer, sizeof(buffer), dataObjectIdentifier, &datasize);
|
||||
if (!p) {
|
||||
|
@ -266,8 +266,8 @@ static int gids_put_DO(sc_card_t* card, int fileIdentifier, int dataObjectIdenti
|
|||
apdu.flags |= SC_APDU_FLAGS_CHAINING;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids put data failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "gids put data failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
@ -295,7 +295,7 @@ static int gids_select_aid(sc_card_t* card, u8* aid, size_t aidlen, u8* response
|
|||
r = sc_transmit_apdu(card, &apdu);
|
||||
if (responselen)
|
||||
*responselen = apdu.resplen;
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids select failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids select failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
||||
|
@ -310,9 +310,9 @@ static int gids_read_gidsfile_without_cache(sc_card_t* card, u8* masterfile, siz
|
|||
|
||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the identifier for the gids file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
|
||||
r = gids_get_DO(card, fileIdentifier, dataObjectIdentifier, response, responselen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the data from the file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the data from the file");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -328,9 +328,9 @@ static int gids_write_gidsfile_without_cache(sc_card_t* card, u8* masterfile, si
|
|||
}
|
||||
|
||||
r = gids_get_identifiers(card, masterfile, masterfilesize, directory, filename, &fileIdentifier, &dataObjectIdentifier);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the identifier for the gids file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the identifier for the gids file");
|
||||
r = gids_put_DO(card, fileIdentifier, dataObjectIdentifier, data, datalen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the data from the file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the data from the file");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -360,7 +360,7 @@ static int gids_update_cardcf(sc_card_t* card, int file, int container) {
|
|||
int r;
|
||||
size_t cardcfsize = sizeof(cardcf);
|
||||
r = gids_read_gidsfile_without_cache(card, data->masterfile, data->masterfilesize, "", "cardcf", cardcf, &cardcfsize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the cardcf");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the cardcf");
|
||||
|
||||
if (file) {
|
||||
short filefreshness = cardcf[4] + cardcf[5] * 0x100;
|
||||
|
@ -375,7 +375,7 @@ static int gids_update_cardcf(sc_card_t* card, int file, int container) {
|
|||
cardcf[3] = (containerfreshness>>8) & 0xFF;
|
||||
}
|
||||
r = gids_write_gidsfile_without_cache(card, data->masterfile, data->masterfilesize, "", "cardcf", cardcf, 6);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cardcf file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cardcf file");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -386,11 +386,11 @@ static int gids_read_gidsfile(sc_card_t* card, char *directory, char *filename,
|
|||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (privatedata->masterfilesize == sizeof(privatedata->masterfile)) {
|
||||
r = gids_read_masterfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the masterfile");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the masterfile");
|
||||
}
|
||||
r = gids_read_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
|
||||
directory, filename, response, responselen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to read the file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to read the file");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,r);
|
||||
}
|
||||
|
||||
|
@ -408,11 +408,11 @@ static int gids_write_gidsfile(sc_card_t* card, char *directory, char *filename,
|
|||
int r;
|
||||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
r = gids_update_cardcf(card, 1, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cache file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cache file");
|
||||
|
||||
r = gids_write_gidsfile_without_cache(card, privatedata->masterfile, privatedata->masterfilesize,
|
||||
directory, filename, data, datalen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to write the file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to write the file");
|
||||
if (strcmp(directory, "mscp") == 0 && strcmp(filename, "cmapfile") == 0) {
|
||||
// update the cmapfile cache
|
||||
privatedata->cmapfilesize = datalen;
|
||||
|
@ -432,7 +432,7 @@ static int gids_read_cmapfile(sc_card_t* card) {
|
|||
if (r<0) {
|
||||
data->cmapfilesize = sizeof(data->cmapfile);
|
||||
}
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the cmapfile");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the cmapfile");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -448,7 +448,7 @@ static int gids_create_file(sc_card_t *card, char* directory, char* filename) {
|
|||
gids_mf_record_t* record;
|
||||
|
||||
r = gids_find_available_DO(card, privatedata->masterfile, privatedata->masterfilesize, &fileIdentifier, &dataObjectIdentifier);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to find an empty DO");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to find an empty DO");
|
||||
|
||||
memcpy(masterfilebuffer, privatedata->masterfile, privatedata->masterfilesize);
|
||||
masterfilebuffersize = privatedata->masterfilesize + sizeof(gids_mf_record_t);
|
||||
|
@ -468,10 +468,10 @@ static int gids_create_file(sc_card_t *card, char* directory, char* filename) {
|
|||
record->dataObjectIdentifier = dataObjectIdentifier;
|
||||
|
||||
r = gids_update_cardcf(card, 1, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cardcf");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cardcf");
|
||||
|
||||
r = gids_put_DO(card, MF_FI, MF_DO, masterfilebuffer, masterfilebuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the masterfile");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the masterfile");
|
||||
|
||||
memcpy(privatedata->masterfile, masterfilebuffer, masterfilebuffersize);
|
||||
privatedata->masterfilesize = masterfilebuffersize;
|
||||
|
@ -532,7 +532,7 @@ static int gids_get_pin_status(sc_card_t *card, int pinreference, int *tries_lef
|
|||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OBJECT_NOT_FOUND);
|
||||
}
|
||||
r = gids_get_DO(card, GIDS_APPLET_EFID, dataObjectIdentifier, buffer, &buffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the masterfile");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the masterfile");
|
||||
|
||||
buffersize = buffersize > sizeof(buffer) ? sizeof(buffer) : buffersize;
|
||||
|
||||
|
@ -606,7 +606,7 @@ static int gids_get_serialnr(sc_card_t * card, sc_serial_number_t * serial)
|
|||
|
||||
buffersize = sizeof(buffer);
|
||||
r = gids_read_gidsfile(card, "", "cardid", buffer, &buffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to read cardid");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to read cardid");
|
||||
|
||||
if (SC_MAX_SERIALNR < buffersize)
|
||||
{
|
||||
|
@ -870,8 +870,8 @@ static int gids_read_public_key (struct sc_card *card , unsigned int algorithm,
|
|||
apdu.le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read public key failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read public key failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
buffersize = apdu.resplen;
|
||||
|
||||
keytemplate = sc_asn1_find_tag(card->ctx, buffer, buffersize, GIDS_PUBKEY_TAG, &tlen);
|
||||
|
@ -1098,9 +1098,9 @@ gids_select_key_reference(sc_card_t *card, sc_pkcs15_prkey_info_t* key_info) {
|
|||
|
||||
// refresh the cached data in case some thing has been modified
|
||||
r = gids_read_masterfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read masterfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read masterfile failed");
|
||||
r = gids_read_cmapfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read cmapfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read cmapfile failed");
|
||||
|
||||
recordsnum = (data->cmapfilesize / sizeof(CONTAINER_MAP_RECORD));
|
||||
|
||||
|
@ -1209,10 +1209,10 @@ static int gids_perform_create_keyfile(sc_card_t *card, u8 keytype, u8 kid, u8 a
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, INS_ACTIVATE_FILE, 0x00, 0x00);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "ACTIVATE_FILE returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "ACTIVATE_FILE returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1335,15 +1335,15 @@ static int gids_create_keyfile(sc_card_t *card, sc_pkcs15_object_t *object) {
|
|||
keymaprecord->unknownWithFFFF = (unsigned short) (-1);
|
||||
keymaprecord->keyref = 0xB000 + kid;
|
||||
r = gids_perform_create_keyfile(card, keytype, kid, algid);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to create the key file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to create the key file");
|
||||
|
||||
r = gids_update_cardcf(card, 0, 1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cardcf file regarding container");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cardcf file regarding container");
|
||||
r = gids_put_DO(card, KEYMAP_FI, KEYMAP_DO, keymapbuffer, keymapbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to write the keymap file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to write the keymap file");
|
||||
|
||||
r = gids_write_gidsfile(card, "mscp", "cmapfile", cmapbuffer, cmapbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to write the cmap file after the container creation");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to write the cmap file after the container creation");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1376,13 +1376,13 @@ static int gids_generate_key(sc_card_t *card, sc_pkcs15_object_t *object, struct
|
|||
apdu.data = generatekey;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "generate key returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "generate key returned error");
|
||||
|
||||
r = gids_read_public_key(card, 0, NULL, kid, 0, &buffer, &buffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "read public key returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "read public key returned error");
|
||||
r = sc_pkcs15_decode_pubkey(card->ctx, pubkey, buffer, buffersize);
|
||||
if (buffer)
|
||||
free(buffer);
|
||||
|
@ -1480,11 +1480,11 @@ static int gids_delete_key_file(sc_card_t *card, int containernum) {
|
|||
snprintf(ch_tmp, sizeof(ch_tmp), "3FFFB0%02X", (u8) (0xFF & (containernum + GIDS_FIRST_KEY_IDENTIFIER)));
|
||||
sc_format_path(ch_tmp, &cpath);
|
||||
r = gids_select_file(card, &cpath, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select the key file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select the key file");
|
||||
// delete current selected file
|
||||
memset(&cpath, 0, sizeof(cpath));
|
||||
r = iso_ops->delete_file(card, &cpath);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to delete the key file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to delete the key file");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -1508,7 +1508,7 @@ static int gids_encode_certificate(sc_card_t *card, u8* source, size_t sourcesiz
|
|||
destination[3] = (sourcesize & 0xFF00) >> 8;
|
||||
outlen = *destinationsize - 4;
|
||||
r = sc_compress(destination + 4, &outlen, source, sourcesize, COMPRESSION_ZLIB);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to compress the certificate");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to compress the certificate");
|
||||
*destinationsize = outlen + 4;
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
@ -1528,13 +1528,13 @@ static int gids_save_certificate(sc_card_t *card, sc_pkcs15_object_t *certobject
|
|||
|
||||
// refresh the cached data in case some thing has been modified
|
||||
r = gids_read_masterfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read masterfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read masterfile failed");
|
||||
r= gids_read_cmapfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read cmapfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read cmapfile failed");
|
||||
|
||||
// compress the certificate according to the minidriver specification
|
||||
r = gids_encode_certificate(card, cert_info->value.value, cert_info->value.len, certbuffer, &certbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to encode the certificate");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to encode the certificate");
|
||||
|
||||
// save it to a minidriver file
|
||||
containernum = prkey_info->key_reference - GIDS_FIRST_KEY_IDENTIFIER;
|
||||
|
@ -1547,14 +1547,14 @@ static int gids_save_certificate(sc_card_t *card, sc_pkcs15_object_t *certobject
|
|||
r = gids_does_file_exists(card, "mscp", filename);
|
||||
if (r == SC_ERROR_FILE_NOT_FOUND) {
|
||||
r = gids_create_file(card, "mscp", filename);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to create the certificate file");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to create the certificate file");
|
||||
}
|
||||
r = gids_write_gidsfile(card, "mscp", filename, certbuffer, certbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to write the certificate data");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to write the certificate data");
|
||||
|
||||
// return the path to the DO
|
||||
r = gids_build_certificate_path(card, containernum, !(prkey_info->usage & SC_PKCS15_PRKEY_USAGE_DECRYPT), path);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to build the certificate path");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to build the certificate path");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
|
||||
}
|
||||
|
@ -1606,14 +1606,14 @@ static int gids_delete_container_num(sc_card_t *card, size_t containernum) {
|
|||
|
||||
// remove the key, update the key map & cmap file and signal the change
|
||||
r = gids_delete_key_file(card, (int) containernum);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to delete the key file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to delete the key file");
|
||||
r = gids_update_cardcf(card, 0, 1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cardcf file regarding container");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cardcf file regarding container");
|
||||
r = gids_put_DO(card, KEYMAP_FI, KEYMAP_DO, keymapbuffer, keymapbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to write the keymap file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to write the keymap file");
|
||||
|
||||
r = gids_write_gidsfile(card, "mscp", "cmapfile", cmapbuffer, cmapbuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to write the cmap file after the container creation");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to write the cmap file after the container creation");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
|
||||
}
|
||||
|
@ -1634,9 +1634,9 @@ static int gids_delete_cert(sc_card_t *card, sc_pkcs15_object_t* object) {
|
|||
assert((object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_CERT);
|
||||
// refresh the cached data in case some thing has been modified
|
||||
r = gids_read_masterfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read masterfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read masterfile failed");
|
||||
r= gids_read_cmapfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read cmapfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read cmapfile failed");
|
||||
|
||||
// remove the file reference from the masterfile
|
||||
if (cert_info->path.len != 4) {
|
||||
|
@ -1666,13 +1666,13 @@ static int gids_delete_cert(sc_card_t *card, sc_pkcs15_object_t* object) {
|
|||
|
||||
// remove the DO, update the masterfile, and signal the change
|
||||
r = gids_update_cardcf(card, 1, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to update the cache file");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to update the cache file");
|
||||
|
||||
r = gids_put_DO(card, fileIdentifier, DO, NULL, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to delete the certificate DO");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to delete the certificate DO");
|
||||
|
||||
r = gids_put_DO(card, MF_FI, MF_DO, masterfilebuffer, masterfilebuffersize);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to update the masterfile");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to update the masterfile");
|
||||
|
||||
memcpy(privatedata->masterfile, masterfilebuffer, masterfilebuffersize);
|
||||
privatedata->masterfilesize = masterfilebuffersize;
|
||||
|
@ -1688,13 +1688,13 @@ static int gids_delete_key(sc_card_t *card, sc_pkcs15_object_t* object) {
|
|||
assert((object->type & SC_PKCS15_TYPE_CLASS_MASK) == SC_PKCS15_TYPE_PRKEY);
|
||||
// refresh the cached data in case some thing has been modified
|
||||
r = gids_read_masterfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read masterfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read masterfile failed");
|
||||
r = gids_read_cmapfile(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids read cmapfile failed");
|
||||
LOG_TEST_RET(card->ctx, r, "gids read cmapfile failed");
|
||||
containernum = key_info->key_reference - GIDS_FIRST_KEY_IDENTIFIER;
|
||||
|
||||
r = gids_delete_container_num(card, containernum);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to delete the container");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to delete the container");
|
||||
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
|
||||
}
|
||||
|
||||
|
@ -1708,15 +1708,15 @@ static int gids_initialize_create_file(sc_card_t *card, u8* command, size_t comm
|
|||
apdu.datalen = commandsize;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU1 transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU1 transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
// activate file
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, INS_ACTIVATE_FILE, 0x00, 0x00);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU2 transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU2 transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
||||
|
@ -1736,7 +1736,7 @@ static int gids_set_administrator_key(sc_card_t *card, u8* key) {
|
|||
memcpy(adminKeyData+7, key, 24);
|
||||
r = gids_put_DO(card, GIDS_APPLET_EFID, GIDS_PUT_KEY_DO, adminKeyData, sizeof(adminKeyData));
|
||||
sc_mem_clear(adminKeyData, sizeof(adminKeyData));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to set the admin key");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to set the admin key");
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -1791,7 +1791,7 @@ static int gids_initialize(sc_card_t *card, sc_cardctl_gids_init_param_t* param)
|
|||
|
||||
// avoid multiple initialization
|
||||
r = gids_check_that_card_is_new(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "card seems to have been already initialized");
|
||||
LOG_TEST_RET(card->ctx, r, "card seems to have been already initialized");
|
||||
|
||||
memset(&pindata, 0, sizeof(pindata));
|
||||
// create PIN & PUK
|
||||
|
@ -1802,38 +1802,38 @@ static int gids_initialize(sc_card_t *card, sc_cardctl_gids_init_param_t* param)
|
|||
pindata.pin_reference = 0x80;
|
||||
|
||||
r = sc_pin_cmd(card, &pindata, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids set pin");
|
||||
LOG_TEST_RET(card->ctx, r, "gids set pin");
|
||||
|
||||
// create file
|
||||
r = gids_initialize_create_file(card, UserCreateDeleteDirAc, sizeof(UserCreateDeleteDirAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file UserCreateDeleteDirAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file UserCreateDeleteDirAc");
|
||||
r = gids_initialize_create_file(card, EveryoneReadUserWriteAc, sizeof(EveryoneReadUserWriteAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file EveryoneReadUserWriteAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file EveryoneReadUserWriteAc");
|
||||
r = gids_initialize_create_file(card, UserWriteExecuteAc, sizeof(UserWriteExecuteAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file UserWriteExecuteAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file UserWriteExecuteAc");
|
||||
r = gids_initialize_create_file(card, EveryoneReadAdminWriteAc, sizeof(EveryoneReadAdminWriteAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file EveryoneReadAdminWriteAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file EveryoneReadAdminWriteAc");
|
||||
r = gids_initialize_create_file(card, UserReadWriteAc, sizeof(UserReadWriteAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file UserReadWriteAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file UserReadWriteAc");
|
||||
r = gids_initialize_create_file(card, AdminReadWriteAc, sizeof(AdminReadWriteAc));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file AdminReadWriteAc");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file AdminReadWriteAc");
|
||||
|
||||
//admin key
|
||||
r = gids_initialize_create_file(card, AdminKey, sizeof(AdminKey));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids to create the file AdminKey");
|
||||
LOG_TEST_RET(card->ctx, r, "gids to create the file AdminKey");
|
||||
|
||||
r = gids_set_administrator_key(card, param->init_code);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to set the admin key");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to set the admin key");
|
||||
|
||||
// create the filesystem
|
||||
r = gids_put_DO(card, MF_FI, MF_DO, masterfile, sizeof(masterfile));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to save the masterfile");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to save the masterfile");
|
||||
r = gids_put_DO(card, CARDAPPS_FI, CARDAPPS_DO, cardapps, sizeof(cardapps));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to save the cardapps");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to save the cardapps");
|
||||
r = gids_put_DO(card, CARDCF_FI, CARDCF_DO, cardcf, sizeof(cardcf));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to save the cardcf");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to save the cardcf");
|
||||
r = gids_put_DO(card, CMAP_FI, CMAP_DO, NULL, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to save the cmapfile");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to save the cmapfile");
|
||||
#ifdef ENABLE_OPENSSL
|
||||
for (i = sizeof(param->cardid) -1; i >= 0; i--) {
|
||||
if (param->cardid[i]) break;
|
||||
|
@ -1841,12 +1841,12 @@ static int gids_initialize(sc_card_t *card, sc_cardctl_gids_init_param_t* param)
|
|||
if (i < 0) {
|
||||
// set a random cardid if not set
|
||||
r = RAND_bytes(param->cardid, sizeof(param->cardid));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to set a random serial number");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to set a random serial number");
|
||||
|
||||
}
|
||||
#endif
|
||||
r = gids_put_DO(card, CARDID_FI, CARDID_DO, param->cardid, sizeof(param->cardid));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "gids unable to save the cardid");
|
||||
LOG_TEST_RET(card->ctx, r, "gids unable to save the cardid");
|
||||
|
||||
//select applet
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3, INS_SELECT, 0x00, 0x0C);
|
||||
|
@ -1855,13 +1855,13 @@ static int gids_initialize(sc_card_t *card, sc_cardctl_gids_init_param_t* param)
|
|||
apdu.datalen = 2;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
// activate file
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, INS_ACTIVATE_FILE, 0x00, 0x00);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
||||
|
@ -1905,12 +1905,12 @@ static int gids_authenticate_admin(sc_card_t *card, u8* key) {
|
|||
apdu.data = (const unsigned char *) "\x83\x01\x80";
|
||||
apdu.datalen = 3;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
// generate a challenge
|
||||
r = RAND_bytes(randomR1, 16);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to set computer random");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to set computer random");
|
||||
|
||||
// send it to the card
|
||||
memcpy(apduSetRandom+4, randomR1, 16);
|
||||
|
@ -1922,12 +1922,12 @@ static int gids_authenticate_admin(sc_card_t *card, u8* key) {
|
|||
apdu.resplen = sizeof(apduSetRandomResponse);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
// compute the half size of the mutual authentication secret
|
||||
r = RAND_bytes(z1, 7);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to set computer random");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to set computer random");
|
||||
// set the padding
|
||||
z1[7] = 0x80;
|
||||
|
||||
|
@ -1966,8 +1966,8 @@ static int gids_authenticate_admin(sc_card_t *card, u8* key) {
|
|||
apdu.resplen = sizeof(apduSendResponseResponse);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2), "invalid return");
|
||||
|
||||
if (apdu.resplen != 44)
|
||||
{
|
||||
|
|
|
@ -504,9 +504,9 @@ gpk_select(sc_card_t *card, int kind,
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
/* Nothing we can say about it... invalidate
|
||||
* path cache */
|
||||
|
@ -623,7 +623,7 @@ try_again:
|
|||
} else {
|
||||
if (!locked++) {
|
||||
r = sc_lock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
|
||||
}
|
||||
|
||||
/* Do we need to select the MF first? */
|
||||
|
@ -631,7 +631,7 @@ try_again:
|
|||
r = gpk_select_id(card, GPK_SEL_MF, GPK_FID_MF, NULL);
|
||||
if (r)
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select MF");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select MF");
|
||||
|
||||
/* Consume the MF FID if it's there */
|
||||
if (pathptr[0] == GPK_FID_MF) {
|
||||
|
@ -649,7 +649,7 @@ try_again:
|
|||
r = gpk_select_id(card, GPK_SEL_DF, pathptr[0], NULL);
|
||||
if (r)
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select DF");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select DF");
|
||||
pathptr++;
|
||||
pathlen--;
|
||||
}
|
||||
|
@ -870,9 +870,9 @@ gpk_create_file(sc_card_t *card, sc_file_t *file)
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
/* verify secure messaging response */
|
||||
if (priv->key_set)
|
||||
|
@ -967,9 +967,9 @@ gpk_select_key(sc_card_t *card, int key_sfi, const u8 *buf, size_t buflen)
|
|||
apdu.le = 12;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (apdu.resplen != 12) {
|
||||
r = SC_ERROR_UNKNOWN_DATA_RECEIVED;
|
||||
|
@ -1086,12 +1086,12 @@ gpk_set_security_env(sc_card_t *card,
|
|||
/* Select the PK file. The caller has already selected
|
||||
* the DF. */
|
||||
r = gpk_select_id(card, GPK_SEL_EF, file_id, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to select PK file");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to select PK file");
|
||||
|
||||
/* Read the sys record of the PK file to find out the key length */
|
||||
r = sc_read_record(card, 1, sysrec, sizeof(sysrec),
|
||||
SC_RECORD_BY_REC_NR);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to read PK sysrec");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to read PK sysrec");
|
||||
if (r != 7 || sysrec[0] != 0) {
|
||||
sc_log(card->ctx, "First record of file is not the sysrec");
|
||||
return SC_ERROR_OBJECT_NOT_VALID;
|
||||
|
@ -1118,9 +1118,9 @@ gpk_set_security_env(sc_card_t *card,
|
|||
apdu.p2 = context;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1184,9 +1184,9 @@ gpk_hash(sc_card_t *card, const u8 *data, size_t datalen)
|
|||
apdu.datalen = len + 2;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
chain = 0;
|
||||
}
|
||||
|
||||
|
@ -1205,7 +1205,7 @@ gpk_init_hashed(sc_card_t *card, const u8 *digest, unsigned int len)
|
|||
int r;
|
||||
|
||||
r = reverse(tsegid, sizeof(tsegid), digest, len);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to reverse buffer");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to reverse buffer");
|
||||
|
||||
memset(&apdu, 0, sizeof(apdu));
|
||||
apdu.cse = SC_APDU_CASE_3_SHORT;
|
||||
|
@ -1216,9 +1216,9 @@ gpk_init_hashed(sc_card_t *card, const u8 *digest, unsigned int len)
|
|||
apdu.datalen = len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1246,7 +1246,7 @@ gpk_compute_signature(sc_card_t *card, const u8 *data,
|
|||
return SC_ERROR_BUFFER_TOO_SMALL;
|
||||
|
||||
r = gpk_init_hashed(card, data, data_len);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to send hash to card");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to send hash to card");
|
||||
|
||||
/* Now sign the hash.
|
||||
* The GPK has Internal Authenticate and PK_Sign. I am not
|
||||
|
@ -1261,14 +1261,14 @@ gpk_compute_signature(sc_card_t *card, const u8 *data,
|
|||
apdu.le = priv->sec_mod_len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
/* The GPK returns the signature as little endian numbers.
|
||||
* Need to revert these */
|
||||
r = reverse(out, outlen, cardsig, apdu.resplen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to reverse signature");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to reverse signature");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1299,7 +1299,7 @@ gpk_decipher(sc_card_t *card, const u8 *in, size_t inlen,
|
|||
|
||||
/* First revert the cryptogram */
|
||||
r = reverse(buffer, sizeof(buffer), in, inlen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Cryptogram too large");
|
||||
LOG_TEST_RET(card->ctx, r, "Cryptogram too large");
|
||||
in = buffer;
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x1C, 0x00, 0x00);
|
||||
|
@ -1312,13 +1312,13 @@ gpk_decipher(sc_card_t *card, const u8 *in, size_t inlen,
|
|||
apdu.resplen = sizeof(buffer);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
/* Reverse the data we got back */
|
||||
r = reverse(out, outlen, buffer, apdu.resplen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to reverse buffer");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to reverse buffer");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1363,9 +1363,9 @@ gpk_erase_card(sc_card_t *card)
|
|||
apdu.p2 = offset;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
priv->key_set = 0;
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
@ -1426,9 +1426,9 @@ gpk_lock(sc_card_t *card, struct sc_cardctl_gpk_lock *args)
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (priv->key_set)
|
||||
r = gpk_verify_crycks(card, &apdu, crycks);
|
||||
|
@ -1456,9 +1456,9 @@ gpk_pkfile_init(sc_card_t *card, struct sc_cardctl_gpk_pkinit *args)
|
|||
apdu.p2 = args->privlen / 4;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1493,16 +1493,16 @@ gpk_generate_key(sc_card_t *card, struct sc_cardctl_gpk_genkey *args)
|
|||
apdu.resplen = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
/* Return the public key, inverted.
|
||||
* The first two bytes must be stripped off. */
|
||||
if (args->pubkey_len && apdu.resplen > 2) {
|
||||
r = reverse(args->pubkey, args->pubkey_len,
|
||||
buffer + 2, apdu.resplen - 2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to reverse buffer");
|
||||
LOG_TEST_RET(card->ctx, r, "Failed to reverse buffer");
|
||||
args->pubkey_len = r;
|
||||
}
|
||||
|
||||
|
@ -1568,9 +1568,9 @@ gpk_pkfile_load(sc_card_t *card, struct sc_cardctl_gpk_pkload *args)
|
|||
priv->key_set = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1610,7 +1610,7 @@ static int gpk_get_info(sc_card_t *card, int p1, int p2, u8 *buf,
|
|||
* without collecting the response :)
|
||||
*/
|
||||
r = sc_lock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
|
||||
|
||||
do {
|
||||
memset(&apdu, 0, sizeof(apdu));
|
||||
|
@ -1633,7 +1633,7 @@ static int gpk_get_info(sc_card_t *card, int p1, int p2, u8 *buf,
|
|||
sc_unlock(card);
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -1663,7 +1663,7 @@ static int gpk_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.lc = 0;
|
||||
apdu.datalen = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
/* cache serial number */
|
||||
|
|
|
@ -191,12 +191,12 @@ get_next_part:
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x6a && apdu.sw2 == 0x82)
|
||||
goto end; /* no more files */
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "DIRECTORY command returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "DIRECTORY command returned error");
|
||||
|
||||
if (apdu.resplen >= 3
|
||||
&& ((rbuf[0] >= 0x01 && rbuf[0] <= 0x07) || 0x38 == rbuf[0])
|
||||
|
@ -419,10 +419,10 @@ static int incrypto34_restore_security_env(sc_card_t *card, int se_num)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -454,7 +454,7 @@ static int incrypto34_set_security_env(sc_card_t *card,
|
|||
key_id = env->key_ref[0];
|
||||
|
||||
r = incrypto34_restore_security_env(card, 1);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF1, 0);
|
||||
switch (env->operation) {
|
||||
|
@ -475,10 +475,10 @@ static int incrypto34_set_security_env(sc_card_t *card,
|
|||
apdu.data = data;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -513,7 +513,7 @@ static int do_compute_signature(sc_card_t *card,
|
|||
apdu.lc = datalen;
|
||||
apdu.datalen = datalen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
memcpy(out, rbuf, outlen);
|
||||
|
@ -594,13 +594,13 @@ incrypto34_lifecycle_get(sc_card_t *card, int *mode)
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
if (apdu.resplen < 1) {
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Lifecycle byte not in response");
|
||||
LOG_TEST_RET(card->ctx, r, "Lifecycle byte not in response");
|
||||
}
|
||||
|
||||
r = SC_SUCCESS;
|
||||
|
@ -642,10 +642,10 @@ incrypto34_put_data_oci(sc_card_t *card,
|
|||
apdu.datalen = args->len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -668,10 +668,10 @@ incrypto34_change_key_data(struct sc_card *card,
|
|||
apdu.datalen = args->len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -694,10 +694,10 @@ incrypto34_put_data_seci(sc_card_t *card,
|
|||
apdu.datalen = args->len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -730,9 +730,9 @@ incrypto34_generate_key(sc_card_t *card,
|
|||
apdu.datalen = apdu.lc = sizeof(data);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GENERATE_KEY failed");
|
||||
LOG_TEST_RET(card->ctx, r, "GENERATE_KEY failed");
|
||||
|
||||
return r;
|
||||
}
|
||||
|
@ -766,10 +766,10 @@ incrypto34_erase_files(sc_card_t *card)
|
|||
apdu.cla = 0xb0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error Erasing Filesystem");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error Erasing Filesystem");
|
||||
|
||||
/* Creating ATR file*/
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xe0, 0, 0);
|
||||
|
@ -777,10 +777,10 @@ incrypto34_erase_files(sc_card_t *card)
|
|||
apdu.datalen = apdu.lc = sizeof(pCreateAtrFile);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error Creating ATR file");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error Creating ATR file");
|
||||
|
||||
/* Filling ATR file*/
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xd6, 0, 0);
|
||||
|
@ -788,10 +788,10 @@ incrypto34_erase_files(sc_card_t *card)
|
|||
apdu.datalen = apdu.lc = sizeof(pWriteAtr);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error Filling ATR file");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error Filling ATR file");
|
||||
|
||||
/* Creating DIR-ADO file*/
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xe0, 0, 0);
|
||||
|
@ -799,10 +799,10 @@ incrypto34_erase_files(sc_card_t *card)
|
|||
apdu.datalen = apdu.lc = sizeof(pCreateEF_DIR_ADOFile);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error Creating DIR-ADO file");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error Creating DIR-ADO file");
|
||||
|
||||
return r;
|
||||
|
||||
|
|
|
@ -260,10 +260,10 @@ static int itacns_restore_security_env(sc_card_t *card, int se_num)
|
|||
apdu.le = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, 1, r);
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ static int itacns_set_security_env(sc_card_t *card,
|
|||
so far want 0x03. */
|
||||
r = itacns_restore_security_env(card,
|
||||
(card->type == SC_CARD_TYPE_ITACNS_CIE_V1 ? 0x30 : 0x03));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF1, 0);
|
||||
switch (env->operation) {
|
||||
|
@ -329,10 +329,10 @@ static int itacns_set_security_env(sc_card_t *card,
|
|||
apdu.data = data;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, 1, r);
|
||||
}
|
||||
|
|
|
@ -733,7 +733,7 @@ static int jcop_compute_signature(sc_card_t *card,
|
|||
|
||||
apdu.data = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
int len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
@ -784,7 +784,7 @@ static int jcop_decipher(sc_card_t *card,
|
|||
|
||||
apdu.data = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
int len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
|
|
@ -193,7 +193,7 @@ static int masktech_decipher(sc_card_t *card,
|
|||
apdu.datalen = crgram_len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
@ -222,7 +222,7 @@ static int masktech_pin_unblock(sc_card_t *card,
|
|||
verify_data.pin1.prompt = data->pin1.prompt;
|
||||
|
||||
rv = iso_ops->pin_cmd(card, &verify_data, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed - verify unblock PIN");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed - verify unblock PIN");
|
||||
|
||||
/* Build a SC_PIN_CMD_UNBLOCK APDU */
|
||||
memset(&reset_data, 0, sizeof(reset_data));
|
||||
|
@ -236,7 +236,7 @@ static int masktech_pin_unblock(sc_card_t *card,
|
|||
reset_data.pin2.prompt = data->pin2.prompt;
|
||||
|
||||
rv = iso_ops->pin_cmd(card, &reset_data, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed - reset unblock PIN");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed - reset unblock PIN");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -259,7 +259,7 @@ static int masktech_pin_change(sc_card_t *card,
|
|||
verify_data.pin1.prompt = data->pin1.prompt;
|
||||
|
||||
rv = iso_ops->pin_cmd(card, &verify_data, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed - verify change PIN");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed - verify change PIN");
|
||||
|
||||
/* Build a SC_PIN_CMD_CHANGE APDU */
|
||||
memset(&change_data, 0, sizeof(change_data));
|
||||
|
@ -273,7 +273,7 @@ static int masktech_pin_change(sc_card_t *card,
|
|||
change_data.pin2.prompt = data->pin2.prompt;
|
||||
|
||||
rv = iso_ops->pin_cmd(card, &change_data, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed - change PIN");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed - change PIN");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -320,7 +320,7 @@ static int masktech_get_serialnr(sc_card_t * card, sc_serial_number_t * serial)
|
|||
rv = sc_transmit_apdu(card, &apdu);
|
||||
card->cla = 0x00;
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, rv, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, rv, "APDU transmit failed");
|
||||
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
|
|
@ -206,7 +206,7 @@ static int mcrd_delete_ref_to_authkey(sc_card_t * card)
|
|||
apdu.lc = 2;
|
||||
apdu.datalen = 2;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
||||
|
@ -226,7 +226,7 @@ static int mcrd_delete_ref_to_signkey(sc_card_t * card)
|
|||
apdu.lc = 2;
|
||||
apdu.datalen = 2;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
|
||||
}
|
||||
|
@ -245,10 +245,10 @@ static int mcrd_set_decipher_key_ref(sc_card_t * card, int key_reference)
|
|||
/* track the active keypair */
|
||||
sc_format_path("0033", &path);
|
||||
r = sc_select_file(card, &path, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Can't select keyref info file 0x0033");
|
||||
LOG_TEST_RET(card->ctx, r, "Can't select keyref info file 0x0033");
|
||||
r = sc_read_record(card, 1, keyref_data,
|
||||
SC_ESTEID_KEYREF_FILE_RECLEN, SC_RECORD_BY_REC_NR);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Can't read keyref info file!");
|
||||
LOG_TEST_RET(card->ctx, r, "Can't read keyref info file!");
|
||||
|
||||
sc_log(card->ctx,
|
||||
"authkey reference 0x%02x%02x\n",
|
||||
|
@ -275,7 +275,7 @@ static int mcrd_set_decipher_key_ref(sc_card_t * card, int key_reference)
|
|||
apdu.lc = 5;
|
||||
apdu.datalen = 5;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ static int load_special_files(sc_card_t * card)
|
|||
|
||||
/* Read rule file. Note that we bypass our cache here. */
|
||||
r = select_part(card, MCRD_SEL_EF, EF_Rule, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "selecting EF_Rule failed");
|
||||
LOG_TEST_RET(ctx, r, "selecting EF_Rule failed");
|
||||
|
||||
for (recno = 1;; recno++) {
|
||||
u8 recbuf[256];
|
||||
|
@ -444,7 +444,7 @@ static int load_special_files(sc_card_t * card)
|
|||
sc_log(ctx, "no EF_KeyD file available\n");
|
||||
return 0; /* That is okay. */
|
||||
}
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "selecting EF_KeyD failed");
|
||||
LOG_TEST_RET(ctx, r, "selecting EF_KeyD failed");
|
||||
|
||||
for (recno = 1;; recno++) {
|
||||
u8 recbuf[256];
|
||||
|
@ -777,7 +777,7 @@ do_select(sc_card_t * card, u8 kind,
|
|||
apdu.le = 256;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (!file) {
|
||||
if (apdu.sw1 == 0x61)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, 0);
|
||||
|
@ -867,7 +867,7 @@ select_down(sc_card_t * card,
|
|||
|
||||
for (; pathlen; pathlen--, pathptr++) {
|
||||
if (priv->curpathlen == MAX_CURPATH)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL,
|
||||
LOG_TEST_RET(card->ctx, SC_ERROR_INTERNAL,
|
||||
"path too long for cache");
|
||||
r = -1; /* force DF select. */
|
||||
if (pathlen == 1 && !df_only) {
|
||||
|
@ -880,7 +880,7 @@ select_down(sc_card_t * card,
|
|||
if (r)
|
||||
r = select_part(card, MCRD_SEL_DF, *pathptr,
|
||||
pathlen == 1 ? file : NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select DF");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select DF");
|
||||
priv->curpath[priv->curpathlen] = *pathptr;
|
||||
priv->curpathlen++;
|
||||
}
|
||||
|
@ -922,7 +922,7 @@ select_file_by_path(sc_card_t * card, unsigned short *pathptr,
|
|||
/* MF requested: clear the cache and select it. */
|
||||
priv->curpathlen = 0;
|
||||
r = select_part(card, MCRD_SEL_MF, pathptr[0], file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select MF");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select MF");
|
||||
priv->curpath[0] = pathptr[0];
|
||||
priv->curpathlen = 1;
|
||||
priv->is_ef = 0;
|
||||
|
@ -970,7 +970,7 @@ select_file_by_path(sc_card_t * card, unsigned short *pathptr,
|
|||
/* Relative addressing without a current path. So we
|
||||
select the MF first. */
|
||||
r = select_part(card, MCRD_SEL_MF, pathptr[0], file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select MF");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select MF");
|
||||
priv->curpath[0] = pathptr[0];
|
||||
priv->curpathlen = 1;
|
||||
priv->is_ef = 0;
|
||||
|
@ -1022,7 +1022,7 @@ select_file_by_fid(sc_card_t * card, unsigned short *pathptr,
|
|||
/* MF requested: clear the cache and select it. */
|
||||
priv->curpathlen = 0;
|
||||
r = select_part(card, MCRD_SEL_MF, MFID, file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select MF");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select MF");
|
||||
priv->curpath[0] = MFID;
|
||||
priv->curpathlen = 1;
|
||||
priv->is_ef = 0;
|
||||
|
@ -1032,7 +1032,7 @@ select_file_by_fid(sc_card_t * card, unsigned short *pathptr,
|
|||
/* Relative addressing without a current path. So we
|
||||
select the MF first. */
|
||||
r = select_part(card, MCRD_SEL_MF, pathptr[0], file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to select MF");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to select MF");
|
||||
priv->curpath[0] = pathptr[0];
|
||||
priv->curpathlen = 1;
|
||||
priv->is_ef = 0;
|
||||
|
@ -1146,7 +1146,7 @@ static int mcrd_restore_se(sc_card_t * card, int se_num)
|
|||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 0xF3, se_num);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -1282,7 +1282,7 @@ static int mcrd_set_security_env(sc_card_t * card,
|
|||
/* Need to restore the security environment. */
|
||||
if (num) {
|
||||
r = mcrd_restore_se(card, num);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"mcrd_enable_se failed");
|
||||
}
|
||||
p += 2;
|
||||
|
@ -1299,7 +1299,7 @@ static int mcrd_set_security_env(sc_card_t * card,
|
|||
apdu.resplen = 0;
|
||||
if (se_num > 0) {
|
||||
r = sc_lock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
|
||||
locked = 1;
|
||||
}
|
||||
if (apdu.datalen != 0) {
|
||||
|
@ -1319,7 +1319,7 @@ static int mcrd_set_security_env(sc_card_t * card,
|
|||
if (se_num <= 0)
|
||||
return 0;
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
err:
|
||||
if (locked)
|
||||
|
@ -1369,9 +1369,9 @@ static int mcrd_compute_signature(sc_card_t * card,
|
|||
apdu.resplen = outlen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, apdu.resplen);
|
||||
}
|
||||
|
|
|
@ -217,11 +217,11 @@ static int miocos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.lc = buflen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x6A && apdu.sw2 == 0x89)
|
||||
return SC_ERROR_FILE_ALREADY_EXISTS;
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "Card returned error");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -330,7 +330,7 @@ static int miocos_get_acl(sc_card_t *card, sc_file_t *file)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = sizeof(rbuf);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.resplen == 0)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
left = apdu.resplen;
|
||||
|
@ -338,7 +338,7 @@ static int miocos_get_acl(sc_card_t *card, sc_file_t *file)
|
|||
SC_ASN1_SEQUENCE | SC_ASN1_CONS, &left);
|
||||
if (seq == NULL)
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to process reply");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to process reply");
|
||||
for (i = 1; i < 15; i++) {
|
||||
int j;
|
||||
const u8 *tag;
|
||||
|
@ -401,7 +401,7 @@ static int miocos_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resplen = buflen;
|
||||
apdu.le = buflen > 256 ? 256 : buflen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.resplen == 0)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
return apdu.resplen;
|
||||
|
@ -418,13 +418,13 @@ static int miocos_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_INVALID_ARGUMENTS);
|
||||
}
|
||||
r = sc_select_file(card, path, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to select file to be deleted");
|
||||
LOG_TEST_RET(card->ctx, r, "Unable to select file to be deleted");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xE4, 0x00, 0x00);
|
||||
apdu.cla = 0xA0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -461,7 +461,7 @@ static int miocos_create_ac(sc_card_t *card,
|
|||
apdu.datalen = sendsize;
|
||||
apdu.data = sbuf;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
|
|
@ -748,7 +748,7 @@ static int muscle_decipher(sc_card_t * card,
|
|||
out,
|
||||
crgram_len,
|
||||
out_len);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card signature failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Card signature failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -774,7 +774,7 @@ static int muscle_compute_signature(sc_card_t *card, const u8 *data,
|
|||
out,
|
||||
data_len,
|
||||
outlen);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Card signature failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Card signature failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -783,7 +783,7 @@ static int muscle_get_challenge(sc_card_t *card, u8 *rnd, size_t len)
|
|||
if (len == 0)
|
||||
return SC_SUCCESS;
|
||||
else {
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
LOG_TEST_RET(card->ctx,
|
||||
msc_get_challenge(card, len, 0, NULL, rnd),
|
||||
"GET CHALLENGE cmd failed");
|
||||
return (int) len;
|
||||
|
|
|
@ -301,11 +301,11 @@ static int rtecp_verify(sc_card_t *card, unsigned int type, int ref_qualifier,
|
|||
apdu.data = data;
|
||||
apdu.datalen = data_len;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (send_logout++ == 0 && apdu.sw1 == 0x6F && apdu.sw2 == 0x86)
|
||||
{
|
||||
r = sc_logout(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Logout failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Logout failed");
|
||||
}
|
||||
else
|
||||
break;
|
||||
|
@ -315,7 +315,7 @@ static int rtecp_verify(sc_card_t *card, unsigned int type, int ref_qualifier,
|
|||
/* Verification failed */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0, ref_qualifier);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
}
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (r == SC_ERROR_PIN_CODE_INCORRECT && tries_left)
|
||||
|
@ -332,7 +332,7 @@ static int rtecp_logout(sc_card_t *card)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x40, 0, 0);
|
||||
apdu.cla = 0x80;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
}
|
||||
|
@ -442,7 +442,7 @@ static int rtecp_change_reference_data(sc_card_t *card, unsigned int type,
|
|||
if (type == SC_AC_CHV && old && oldlen != 0)
|
||||
{
|
||||
r = sc_verify(card, type, ref_qualifier, old, oldlen, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Verify old pin failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Verify old pin failed");
|
||||
}
|
||||
|
||||
max_transmit_length = sc_get_max_send_size(card);
|
||||
|
@ -491,7 +491,7 @@ static int rtecp_change_reference_data(sc_card_t *card, unsigned int type,
|
|||
r = sc_transmit_apdu(card, &apdu);
|
||||
sc_mem_clear(buf, buf_length);
|
||||
free(buf);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
}
|
||||
|
@ -508,9 +508,9 @@ static int rtecp_reset_retry_counter(sc_card_t *card, unsigned int type,
|
|||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x2C, 0x03, ref_qualifier);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Unblock card failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Unblock card failed");
|
||||
|
||||
if (newref && newlen) {
|
||||
u8 tmp[2], buf[SC_MAX_APDU_BUFFER_SIZE];
|
||||
|
@ -520,7 +520,7 @@ static int rtecp_reset_retry_counter(sc_card_t *card, unsigned int type,
|
|||
tmp[1] = newlen & 0xFF;
|
||||
sc_asn1_put_tag(0x80, tmp, sizeof(tmp), p, sizeof(buf) - (p - buf), &p);
|
||||
r = sc_asn1_put_tag(0xA5, newref, newlen, p, sizeof(buf) - (p - buf), &p);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Invalid new PIN length");
|
||||
LOG_TEST_RET(card->ctx, r, "Invalid new PIN length");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 0x01, ref_qualifier);
|
||||
apdu.lc = p - buf;
|
||||
|
@ -528,9 +528,9 @@ static int rtecp_reset_retry_counter(sc_card_t *card, unsigned int type,
|
|||
apdu.datalen = p - buf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Set PIN failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Set PIN failed");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
@ -544,7 +544,7 @@ static int rtecp_create_file(sc_card_t *card, sc_file_t *file)
|
|||
if (file->sec_attr_len == 0)
|
||||
{
|
||||
r = set_sec_attr_from_acl(card, file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Set sec_attr from ACL failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Set sec_attr from ACL failed");
|
||||
}
|
||||
assert(iso_ops && iso_ops->create_file);
|
||||
r = iso_ops->create_file(card, file);
|
||||
|
@ -567,12 +567,12 @@ static int rtecp_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x6A && apdu.sw2 == 0x82)
|
||||
break; /* Next file not found */
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "");
|
||||
LOG_TEST_RET(card->ctx, r, "");
|
||||
|
||||
if (apdu.resplen <= 2)
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
|
||||
|
@ -599,9 +599,9 @@ static int rtecp_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
/* Select parent DF of the current DF */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xA4, 0x03, 0);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "");
|
||||
LOG_TEST_RET(card->ctx, r, "");
|
||||
}
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0x02);
|
||||
apdu.lc = sizeof(previd);
|
||||
|
@ -659,7 +659,7 @@ static int rtecp_card_ctl(sc_card_t *card, unsigned long request, void *data)
|
|||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (!r && request == SC_CARDCTL_RTECP_GENERATE_KEY)
|
||||
{
|
||||
|
|
|
@ -257,12 +257,12 @@ static int rutoken_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x6A && apdu.sw2 == 0x82)
|
||||
break; /* Next file not found */
|
||||
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "");
|
||||
LOG_TEST_RET(card->ctx, ret, "");
|
||||
|
||||
if (apdu.resplen <= 2)
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_WRONG_LENGTH);
|
||||
|
@ -292,9 +292,9 @@ static int rutoken_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "");
|
||||
LOG_TEST_RET(card->ctx, ret, "");
|
||||
}
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0xA4, 0, 0x02);
|
||||
apdu.lc = sizeof(previd);
|
||||
|
@ -406,7 +406,7 @@ static int rutoken_select_file(sc_card_t *card,
|
|||
apdu.le = 256;
|
||||
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
if (file_out == NULL)
|
||||
{
|
||||
if (apdu.sw1 == 0x61)
|
||||
|
@ -414,7 +414,7 @@ static int rutoken_select_file(sc_card_t *card,
|
|||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "");
|
||||
LOG_TEST_RET(card->ctx, ret, "");
|
||||
|
||||
if (apdu.resplen > 0 && apdu.resp[0] != 0x62) /* Tag 0x62 - FCP */
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_UNKNOWN_DATA_RECEIVED);
|
||||
|
@ -605,7 +605,7 @@ static int rutoken_create_file(sc_card_t *card, sc_file_t *file)
|
|||
if (file->sec_attr_len == 0)
|
||||
{
|
||||
ret = set_sec_attr_from_acl(card, file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Set sec_attr from ACL failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "Set sec_attr from ACL failed");
|
||||
}
|
||||
assert(iso_ops && iso_ops->create_file);
|
||||
ret = iso_ops->create_file(card, file);
|
||||
|
@ -634,7 +634,7 @@ static int rutoken_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
}
|
||||
else /* No file ID given: means currently selected file */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0xE4, 0x00, 0x00);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_transmit_apdu(card, &apdu), "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, sc_transmit_apdu(card, &apdu), "APDU transmit failed");
|
||||
LOG_FUNC_RETURN(card->ctx, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
}
|
||||
|
||||
|
@ -658,9 +658,9 @@ static int rutoken_verify(sc_card_t *card, unsigned int type, int ref_qualifier,
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x40, 0x00, 0x00);
|
||||
apdu.cla = 0x80;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Reset access rights failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "Reset access rights failed");
|
||||
}
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x20, 0x00, ref_qualifier);
|
||||
|
@ -668,13 +668,13 @@ static int rutoken_verify(sc_card_t *card, unsigned int type, int ref_qualifier,
|
|||
apdu.datalen = data_len;
|
||||
apdu.data = data;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (ret == SC_ERROR_PIN_CODE_INCORRECT && tries_left)
|
||||
{
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x20, 0x00, ref_qualifier);
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (ret == SC_ERROR_PIN_CODE_INCORRECT)
|
||||
*tries_left = (int)(apdu.sw2 & 0x0f);
|
||||
|
@ -691,12 +691,12 @@ static int rutoken_logout(sc_card_t *card)
|
|||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
sc_format_path("3F00", &path);
|
||||
ret = rutoken_select_file(card, &path, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Select MF failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "Select MF failed");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x40, 0x00, 0x00);
|
||||
apdu.cla = 0x80;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_FUNC_RETURN(card->ctx, ret);
|
||||
}
|
||||
|
@ -712,14 +712,14 @@ static int rutoken_change_reference_data(sc_card_t *card, unsigned int type,
|
|||
if (old && oldlen)
|
||||
{
|
||||
ret = rutoken_verify(card, type, ref_qualifier, old, oldlen, tries_left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Invalid 'old' pass");
|
||||
LOG_TEST_RET(card->ctx, ret, "Invalid 'old' pass");
|
||||
}
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x24, 0x01, ref_qualifier);
|
||||
apdu.lc = newlen;
|
||||
apdu.datalen = newlen;
|
||||
apdu.data = newref;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_FUNC_RETURN(card->ctx, ret);
|
||||
}
|
||||
|
@ -740,12 +740,12 @@ static int rutoken_reset_retry_counter(sc_card_t *card, unsigned int type,
|
|||
{
|
||||
ret = rutoken_verify(card, type, ref_qualifier, puk, puklen, &left);
|
||||
sc_log(card->ctx, "Tries left: %i\n", left);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "Invalid 'puk' pass");
|
||||
LOG_TEST_RET(card->ctx, ret, "Invalid 'puk' pass");
|
||||
}
|
||||
#endif
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x2c, 0x03, ref_qualifier);
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_FUNC_RETURN(card->ctx, ret);
|
||||
}
|
||||
|
@ -758,7 +758,7 @@ static int rutoken_restore_security_env(sc_card_t *card, int se_num)
|
|||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, 0x22, 3, se_num);
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_FUNC_RETURN(card->ctx, ret);
|
||||
}
|
||||
|
@ -808,7 +808,7 @@ static int rutoken_set_security_env(sc_card_t *card,
|
|||
}
|
||||
/* set SE */
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
LOG_FUNC_RETURN(card->ctx, ret);
|
||||
}
|
||||
|
@ -870,7 +870,7 @@ static int rutoken_key_gen(sc_card_t *card, sc_DOHdrV2_t *pHdr)
|
|||
apdu.data = data;
|
||||
apdu.datalen = apdu.lc = data_len;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
|
@ -913,7 +913,7 @@ static int rutoken_create_do(sc_card_t *card, sc_DO_V2_t * pDO)
|
|||
apdu.data = data;
|
||||
apdu.datalen = apdu.lc = data_len;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
|
@ -959,7 +959,7 @@ static int rutoken_get_do_info(sc_card_t *card, sc_DO_INFO_t * pInfo)
|
|||
break;
|
||||
}
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
|
@ -985,7 +985,7 @@ static int rutoken_delete_do(sc_card_t *card, u8 *pId)
|
|||
apdu.datalen = sizeof(data);
|
||||
apdu.lc = sizeof(data);
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
|
@ -1027,7 +1027,7 @@ static int rutoken_cipher_p(sc_card_t *card, const u8 * crgram, size_t crgram_le
|
|||
apdu.resp = buf;
|
||||
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (ret == SC_SUCCESS)
|
||||
{
|
||||
|
@ -1113,7 +1113,7 @@ static int rutoken_compute_mac_gost(sc_card_t *card,
|
|||
else
|
||||
apdu.cla = 0x10;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
} while (ret == SC_SUCCESS && ilen != 0);
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
|
@ -1169,7 +1169,7 @@ static int rutoken_get_serial(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.resplen = sizeof(serial->value);
|
||||
apdu.le = 4;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
serial->len = apdu.resplen;
|
||||
swap_four(serial->value, serial->len);
|
||||
|
@ -1188,7 +1188,7 @@ static int rutoken_get_info(sc_card_t *card, void *buff)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = sizeof(rbuf);
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (ret == SC_SUCCESS)
|
||||
memcpy(buff, apdu.resp, apdu.resplen);
|
||||
|
@ -1204,7 +1204,7 @@ static int rutoken_format(sc_card_t *card, int apdu_ins)
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_1, apdu_ins, 0x00, 0x00);
|
||||
apdu.cla = 0x80;
|
||||
ret = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, ret, "APDU transmit failed");
|
||||
ret = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, ret);
|
||||
}
|
||||
|
|
|
@ -634,7 +634,7 @@ static int setcos_set_security_env2(sc_card_t *card,
|
|||
apdu.resplen = 0;
|
||||
if (se_num > 0) {
|
||||
r = sc_lock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_lock() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_lock() failed");
|
||||
locked = 1;
|
||||
}
|
||||
if (apdu.datalen != 0) {
|
||||
|
@ -656,7 +656,7 @@ static int setcos_set_security_env2(sc_card_t *card,
|
|||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x22, 0xF2, se_num);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
sc_unlock(card);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
err:
|
||||
if (locked)
|
||||
|
@ -952,7 +952,7 @@ static int setcos_list_files(sc_card_t *card, u8 * buf, size_t buflen)
|
|||
apdu.resplen = buflen;
|
||||
apdu.le = buflen > 256 ? 256 : buflen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (card->type == SC_CARD_TYPE_SETCOS_44 && apdu.sw1 == 0x6A && apdu.sw2 == 0x82)
|
||||
return 0; /* no files found */
|
||||
if (apdu.resplen == 0)
|
||||
|
@ -998,10 +998,10 @@ static int setcos_putdata(struct sc_card *card, struct sc_cardctl_setcos_data_ob
|
|||
apdu.data = data_obj->Data;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "PUT_DATA returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "PUT_DATA returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1029,10 +1029,10 @@ static int setcos_getdata(struct sc_card *card, struct sc_cardctl_setcos_data_ob
|
|||
apdu.resplen = data_obj->DataLen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GET_DATA returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
|
||||
|
||||
if (apdu.resplen > data_obj->DataLen)
|
||||
r = SC_ERROR_WRONG_LENGTH;
|
||||
|
@ -1085,10 +1085,10 @@ static int setcos_generate_store_key(sc_card_t *card,
|
|||
apdu.lc = len;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "STORE/GENERATE_KEY returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "STORE/GENERATE_KEY returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
@ -1103,10 +1103,10 @@ static int setcos_activate_file(sc_card_t *card)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "ACTIVATE_FILE returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "ACTIVATE_FILE returned error");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, r);
|
||||
}
|
||||
|
|
|
@ -462,7 +462,7 @@ static int starcos_select_aid(sc_card_t *card,
|
|||
apdu.resplen = 0;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
/* check return value */
|
||||
if (!(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) && apdu.sw1 != 0x61 )
|
||||
|
@ -531,7 +531,7 @@ static int starcos_select_fid(sc_card_t *card,
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.p2 == 0x00 && apdu.sw1 == 0x62 && apdu.sw2 == 0x84 ) {
|
||||
/* no FCI => we have a DF (see comment in process_fci()) */
|
||||
|
@ -541,7 +541,7 @@ static int starcos_select_fid(sc_card_t *card,
|
|||
apdu.resplen = 0;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU re-transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
|
||||
} else if ((card->type == SC_CARD_TYPE_STARCOS_V3_4
|
||||
|| card->type == SC_CARD_TYPE_STARCOS_V3_5)
|
||||
&& apdu.p2 == 0x4 && apdu.sw1 == 0x6a && apdu.sw2 == 0x82) {
|
||||
|
@ -553,7 +553,7 @@ static int starcos_select_fid(sc_card_t *card,
|
|||
apdu.le = 256;
|
||||
apdu.lc = 2;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU re-transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
|
||||
} else if (apdu.sw1 == 0x61 || (apdu.sw1 == 0x90 && apdu.sw2 == 0x00 && !isMF)) {
|
||||
/* SELECT returned some data (possible FCI) =>
|
||||
* try a READ BINARY to see if a EF is selected */
|
||||
|
@ -565,7 +565,7 @@ static int starcos_select_fid(sc_card_t *card,
|
|||
apdu2.le = 1;
|
||||
apdu2.lc = 0;
|
||||
r = sc_transmit_apdu(card, &apdu2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu2.sw1 == 0x69 && apdu2.sw2 == 0x86) {
|
||||
/* no current EF is selected => we have a DF */
|
||||
bIsDF = 1;
|
||||
|
@ -744,7 +744,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
|
||||
/* first step: change directory */
|
||||
r = starcos_select_fid(card, path[bMatch], path[bMatch+1], NULL, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
|
||||
memset(&new_path, 0, sizeof(sc_path_t));
|
||||
new_path.type = SC_PATH_TYPE_PATH;
|
||||
|
@ -784,7 +784,7 @@ static int starcos_select_file(sc_card_t *card,
|
|||
for ( i=0; i<pathlen-2; i+=2 )
|
||||
{
|
||||
r = starcos_select_fid(card, path[i], path[i+1], NULL, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "SELECT FILE (DF-ID) failed");
|
||||
LOG_TEST_RET(card->ctx, r, "SELECT FILE (DF-ID) failed");
|
||||
}
|
||||
return starcos_select_fid(card, path[pathlen-2], path[pathlen-1], file_out, 1);
|
||||
}
|
||||
|
@ -992,7 +992,7 @@ static int starcos_create_mf(sc_card_t *card, sc_starcos_create_data *data)
|
|||
apdu.data = (u8 *) data->data.mf.header;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -1028,7 +1028,7 @@ static int starcos_create_df(sc_card_t *card, sc_starcos_create_data *data)
|
|||
apdu.data = data->data.df.header;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
/* second step: CREATE DF */
|
||||
sc_log(ctx, "calling CREATE DF\n");
|
||||
|
||||
|
@ -1039,7 +1039,7 @@ static int starcos_create_df(sc_card_t *card, sc_starcos_create_data *data)
|
|||
apdu.data = data->data.df.header;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -1069,7 +1069,7 @@ static int starcos_create_ef(sc_card_t *card, sc_starcos_create_data *data)
|
|||
apdu.data = (u8 *) data->data.ef.header;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -1101,7 +1101,7 @@ static int starcos_create_end(sc_card_t *card, sc_file_t *file)
|
|||
apdu.datalen = 2;
|
||||
apdu.data = fid;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -1168,7 +1168,7 @@ static int starcos_erase_card(sc_card_t *card)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
sc_invalidate_cache(card);
|
||||
if (apdu.sw1 == 0x69 && apdu.sw2 == 0x85)
|
||||
/* no MF to delete, ignore error */
|
||||
|
@ -1211,7 +1211,7 @@ static int starcos_write_key(sc_card_t *card, sc_starcos_wkey_data *data)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (data->key == NULL)
|
||||
|
@ -1241,7 +1241,7 @@ static int starcos_write_key(sc_card_t *card, sc_starcos_wkey_data *data)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
offset += clen;
|
||||
|
@ -1280,7 +1280,7 @@ static int starcos_gen_key(sc_card_t *card, sc_starcos_gen_key_data *data)
|
|||
apdu.lc = 2;
|
||||
apdu.datalen = 2;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
/* read public key via READ PUBLIC KEY */
|
||||
|
@ -1294,7 +1294,7 @@ static int starcos_gen_key(sc_card_t *card, sc_starcos_gen_key_data *data)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ static int starcos_set_security_env(sc_card_t *card,
|
|||
apdu.lc = p - sbuf;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
|
||||
|
@ -1427,7 +1427,7 @@ static int starcos_set_security_env(sc_card_t *card,
|
|||
apdu.lc = p - sbuf;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
return SC_SUCCESS;
|
||||
|
@ -1477,7 +1477,7 @@ static int starcos_set_security_env(sc_card_t *card,
|
|||
/* we don't know whether to use
|
||||
* COMPUTE SIGNATURE or INTERNAL AUTHENTICATE */
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
ex_data->fix_digestInfo = 0;
|
||||
ex_data->sec_ops = SC_SEC_OPERATION_SIGN;
|
||||
|
@ -1502,7 +1502,7 @@ try_authenticate:
|
|||
apdu.lc = p - sbuf;
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
ex_data->fix_digestInfo = env->algorithm_flags;
|
||||
|
@ -1546,7 +1546,7 @@ static int starcos_compute_signature(sc_card_t *card,
|
|||
}
|
||||
tmp_len = sizeof(sbuf);
|
||||
r = sc_pkcs1_encode(card->ctx, flags, data, datalen, sbuf, &tmp_len, sizeof(sbuf)*8);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_pkcs1_encode failed");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_pkcs1_encode failed");
|
||||
} else {
|
||||
memcpy(sbuf, data, datalen);
|
||||
tmp_len = datalen;
|
||||
|
@ -1559,7 +1559,7 @@ static int starcos_compute_signature(sc_card_t *card,
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
} else {
|
||||
/* set the hash value */
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x2A,
|
||||
|
@ -1572,7 +1572,7 @@ static int starcos_compute_signature(sc_card_t *card,
|
|||
apdu.lc = datalen;
|
||||
apdu.datalen = datalen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,
|
||||
sc_check_sw(card, apdu.sw1, apdu.sw2));
|
||||
|
@ -1587,7 +1587,7 @@ static int starcos_compute_signature(sc_card_t *card,
|
|||
apdu.lc = 0;
|
||||
apdu.datalen = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
}
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
@ -1621,7 +1621,7 @@ static int starcos_compute_signature(sc_card_t *card,
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
size_t len = apdu.resplen > outlen ? outlen : apdu.resplen;
|
||||
|
||||
|
@ -1778,7 +1778,7 @@ static int starcos_get_serialnr(sc_card_t *card, sc_serial_number_t *serial)
|
|||
apdu.lc = 0;
|
||||
apdu.datalen = 0;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00)
|
||||
return SC_ERROR_INTERNAL;
|
||||
/* cache serial number */
|
||||
|
@ -1838,7 +1838,7 @@ static int starcos_logout(sc_card_t *card)
|
|||
apdu.resplen = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU re-transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU re-transmit failed");
|
||||
|
||||
if (apdu.sw1 == 0x69 && apdu.sw2 == 0x85)
|
||||
/* the only possible reason for this error here is, afaik,
|
||||
|
|
|
@ -221,7 +221,7 @@ static int tcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
|
||||
len = SC_MAX_APDU_BUFFER_SIZE;
|
||||
r = tcos_construct_fci(file, sbuf, &len);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "tcos_construct_fci() failed");
|
||||
LOG_TEST_RET(card->ctx, r, "tcos_construct_fci() failed");
|
||||
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE0, 0x00, 0x00);
|
||||
apdu.cla |= 0x80; /* this is an proprietary extension */
|
||||
|
@ -230,7 +230,7 @@ static int tcos_create_file(sc_card_t *card, sc_file_t *file)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -392,7 +392,7 @@ static int tcos_select_file(sc_card_t *card,
|
|||
}
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
if (r || file_out == NULL) SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, r);
|
||||
|
||||
|
@ -431,10 +431,10 @@ static int tcos_list_files(sc_card_t *card, u8 *buf, size_t buflen)
|
|||
apdu.resplen = sizeof(rbuf);
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1==0x6A && (apdu.sw2==0x82 || apdu.sw2==0x88)) continue;
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "List Dir failed");
|
||||
LOG_TEST_RET(ctx, r, "List Dir failed");
|
||||
if (apdu.resplen > buflen) return SC_ERROR_BUFFER_TOO_SMALL;
|
||||
sc_log(ctx,
|
||||
"got %"SC_FORMAT_LEN_SIZE_T"u %s-FileIDs\n",
|
||||
|
@ -469,7 +469,7 @@ static int tcos_delete_file(sc_card_t *card, const sc_path_t *path)
|
|||
apdu.data = sbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
@ -575,7 +575,7 @@ static int tcos_compute_signature(sc_card_t *card, const u8 * data, size_t datal
|
|||
apdu.lc = apdu.datalen = dlen;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (tcos3 && apdu.p1==0x80 && apdu.sw1==0x6A && apdu.sw2==0x87) {
|
||||
int keylen=128;
|
||||
sc_format_apdu(card, &apdu, SC_APDU_CASE_4_SHORT, 0x2A,0x80,0x86);
|
||||
|
@ -590,7 +590,7 @@ static int tcos_compute_signature(sc_card_t *card, const u8 * data, size_t datal
|
|||
apdu.data = sbuf;
|
||||
apdu.lc = apdu.datalen = dlen;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
}
|
||||
if (apdu.sw1==0x90 && apdu.sw2==0x00) {
|
||||
size_t len = apdu.resplen>outlen ? outlen : apdu.resplen;
|
||||
|
@ -631,7 +631,7 @@ static int tcos_decipher(sc_card_t *card, const u8 * crgram, size_t crgram_len,
|
|||
memcpy(sbuf+1, crgram, crgram_len);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if (apdu.sw1==0x90 && apdu.sw2==0x00) {
|
||||
size_t len= (apdu.resplen>outlen) ? outlen : apdu.resplen;
|
||||
|
@ -663,7 +663,7 @@ static int tcos_setperm(sc_card_t *card, int enable_nullpin)
|
|||
apdu.data = NULL;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
return sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
}
|
||||
|
||||
|
|
|
@ -1507,7 +1507,7 @@ sc_card_sm_check(struct sc_card *card)
|
|||
sc_log(ctx, "module_data '%s'", module_data);
|
||||
|
||||
rv = card->sm_ctx.module.ops.module_init(ctx, module_data);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot initialize SM module");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot initialize SM module");
|
||||
}
|
||||
|
||||
/* initialize SM session in the case of 'APDU TRANSMIT' SM mode */
|
||||
|
|
|
@ -222,7 +222,7 @@ ctbcs_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
|
|||
sc_log(reader->ctx, "unable to destroy mutex\n");
|
||||
return s;
|
||||
}
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
/* Check CTBCS status word */
|
||||
switch (((unsigned int) apdu.sw1 << 8) | apdu.sw2) {
|
||||
|
@ -245,7 +245,7 @@ ctbcs_pin_cmd(sc_reader_t *reader, struct sc_pin_cmd_data *data)
|
|||
r = SC_ERROR_CARD_CMD_FAILED;
|
||||
break;
|
||||
}
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "PIN command failed");
|
||||
LOG_TEST_RET(card->ctx, r, "PIN command failed");
|
||||
|
||||
/* Calling Function may expect SW1/SW2 in data-apdu set... */
|
||||
if (data->apdu) {
|
||||
|
|
|
@ -1207,10 +1207,10 @@ static int iso7816_get_data(struct sc_card *card, unsigned int tag, u8 *buf, si
|
|||
apdu.resp = buf;
|
||||
apdu.resplen = len;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "GET_DATA returned error");
|
||||
LOG_TEST_RET(card->ctx, r, "GET_DATA returned error");
|
||||
|
||||
if (apdu.resplen > len)
|
||||
r = SC_ERROR_WRONG_LENGTH;
|
||||
|
|
|
@ -93,7 +93,7 @@ int msc_partial_read_object(sc_card_t *card, msc_id objectId, int offset, u8 *da
|
|||
apdu.resplen = dataLength;
|
||||
apdu.resp = data;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
return dataLength;
|
||||
if(apdu.sw1 == 0x9C) {
|
||||
|
@ -120,7 +120,7 @@ int msc_read_object(sc_card_t *card, msc_id objectId, int offset, u8 *data, size
|
|||
|
||||
for(i = 0; i < dataLength; i += max_read_unit) {
|
||||
r = msc_partial_read_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_read_unit));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Error in partial object read");
|
||||
LOG_TEST_RET(card->ctx, r, "Error in partial object read");
|
||||
}
|
||||
return dataLength;
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ int msc_zero_object(sc_card_t *card, msc_id objectId, size_t dataLength)
|
|||
memset(zeroBuffer, 0, max_write_unit);
|
||||
for(i = 0; i < dataLength; i += max_write_unit) {
|
||||
int r = msc_partial_update_object(card, objectId, i, zeroBuffer, MIN(dataLength - i, max_write_unit));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Error in zeroing file update");
|
||||
LOG_TEST_RET(card->ctx, r, "Error in zeroing file update");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ int msc_create_object(sc_card_t *card, msc_id objectId, size_t objectSize, unsig
|
|||
ushort2bebytes(buffer + 10, writeAcl);
|
||||
ushort2bebytes(buffer + 12, deleteAcl);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
return objectSize;
|
||||
if(apdu.sw1 == 0x9C) {
|
||||
|
@ -197,7 +197,7 @@ int msc_partial_update_object(sc_card_t *card, msc_id objectId, int offset, cons
|
|||
apdu.data = buffer;
|
||||
apdu.datalen = apdu.lc;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
return dataLength;
|
||||
if(apdu.sw1 == 0x9C) {
|
||||
|
@ -224,7 +224,7 @@ int msc_update_object(sc_card_t *card, msc_id objectId, int offset, const u8 *da
|
|||
size_t max_write_unit = MSC_MAX_SEND - 9;
|
||||
for(i = 0; i < dataLength; i += max_write_unit) {
|
||||
r = msc_partial_update_object(card, objectId, offset + i, data + i, MIN(dataLength - i, max_write_unit));
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Error in partial object update");
|
||||
LOG_TEST_RET(card->ctx, r, "Error in partial object update");
|
||||
}
|
||||
return dataLength;
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ int msc_delete_object(sc_card_t *card, msc_id objectId, int zero)
|
|||
apdu.data = objectId.id;
|
||||
apdu.datalen = 4;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
return 0;
|
||||
if(apdu.sw1 == 0x9C) {
|
||||
|
@ -269,7 +269,7 @@ int msc_select_applet(sc_card_t *card, u8 *appletId, size_t appletIdLength)
|
|||
apdu.le = 0;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00)
|
||||
return 1;
|
||||
|
||||
|
@ -296,7 +296,7 @@ int msc_verify_pin(sc_card_t *card, int pinNumber, const u8 *pinValue, int pinLe
|
|||
if(tries)
|
||||
*tries = -1;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return 0;
|
||||
} else if(apdu.sw1 == 0x63) { /* Invalid auth */
|
||||
|
@ -341,7 +341,7 @@ int msc_unblock_pin(sc_card_t *card, int pinNumber, const u8 *pukValue, int pukL
|
|||
if(tries)
|
||||
*tries = -1;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return 0;
|
||||
} else if(apdu.sw1 == 0x63) { /* Invalid auth */
|
||||
|
@ -383,7 +383,7 @@ int msc_change_pin(sc_card_t *card, int pinNumber, const u8 *pinValue, int pinLe
|
|||
if(tries)
|
||||
*tries = -1;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return 0;
|
||||
} else if(apdu.sw1 == 0x63) { /* Invalid auth */
|
||||
|
@ -468,7 +468,7 @@ int msc_get_challenge(sc_card_t *card, unsigned short dataLength, unsigned short
|
|||
free(apdu.resp);
|
||||
}
|
||||
free(buffer);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(location == 1) {
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return SC_SUCCESS;
|
||||
|
@ -542,7 +542,7 @@ int msc_generate_keypair(sc_card_t *card, int privateKey, int publicKey, int alg
|
|||
apdu.lc = 16;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -569,7 +569,7 @@ int msc_extract_key(sc_card_t *card,
|
|||
apdu.datalen = 1;
|
||||
apdu.lc = 1;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
return 0;
|
||||
}
|
||||
|
@ -670,7 +670,7 @@ int msc_compute_crypt_init(sc_card_t *card,
|
|||
memcpy(ptr, initData, dataLength);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
short receivedData = outputBuffer[0] << 8 | outputBuffer[1];
|
||||
*outputDataLength = receivedData;
|
||||
|
@ -721,7 +721,7 @@ int msc_compute_crypt_final(
|
|||
memcpy(ptr, inputData, dataLength);
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
short receivedData = outputBuffer[0] << 8 | outputBuffer[1];
|
||||
*outputDataLength = receivedData;
|
||||
|
@ -787,7 +787,7 @@ static int msc_compute_crypt_final_object(
|
|||
if(r < 0) return r;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
r = msc_read_object(card, inputId, 2, outputData, dataLength);
|
||||
if (r >= 0)
|
||||
|
@ -959,7 +959,7 @@ int msc_import_key(sc_card_t *card,
|
|||
ushort2bebytes(p, writeAcl); p+=2;
|
||||
ushort2bebytes(p, use);
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if(apdu.sw1 == 0x90 && apdu.sw2 == 0x00) {
|
||||
msc_delete_object(card, outputId, 0);
|
||||
return 0;
|
||||
|
|
|
@ -119,7 +119,7 @@ int sc_pkcs15_decode_dodf_entry(struct sc_pkcs15_card *p15card,
|
|||
r = sc_asn1_decode(ctx, asn1_data, *buf, *buflen, buf, buflen);
|
||||
if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
|
||||
return r;
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "ASN.1 decoding failed");
|
||||
LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
|
||||
|
||||
if (!p15card->app || !p15card->app->ddo.aid.len) {
|
||||
r = sc_pkcs15_make_absolute_path(&p15card->file_app->path, &info.path);
|
||||
|
|
|
@ -55,7 +55,7 @@ select_esteid_df (sc_card_t * card)
|
|||
sc_path_t tmppath;
|
||||
sc_format_path ("3F00EEEE", &tmppath);
|
||||
r = sc_select_file (card, &tmppath, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "esteid select DF failed");
|
||||
LOG_TEST_RET(card->ctx, r, "esteid select DF failed");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
@ -74,11 +74,11 @@ sc_pkcs15emu_esteid_init (sc_pkcs15_card_t * p15card)
|
|||
/* Select application directory */
|
||||
sc_format_path ("3f00eeee5044", &tmppath);
|
||||
r = sc_select_file (card, &tmppath, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "select esteid PD failed");
|
||||
LOG_TEST_RET(card->ctx, r, "select esteid PD failed");
|
||||
|
||||
/* read the serial (document number) */
|
||||
r = sc_read_record (card, SC_ESTEID_PD_DOCUMENT_NR, buff, sizeof(buff), SC_RECORD_BY_REC_NR);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "read document number failed");
|
||||
LOG_TEST_RET(card->ctx, r, "read document number failed");
|
||||
buff[MIN((size_t) r, (sizeof buff)-1)] = '\0';
|
||||
set_string (&p15card->tokeninfo->serial_number, (const char *) buff);
|
||||
|
||||
|
|
|
@ -70,7 +70,7 @@ static int sc_pkcs15emu_gids_add_prkey(sc_pkcs15_card_t * p15card, sc_cardctl_gi
|
|||
prkey_obj.auth_id.value[0] = 0x80;
|
||||
|
||||
r = sc_pkcs15emu_add_rsa_prkey(p15card, &prkey_obj, &prkey_info);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to sc_pkcs15emu_add_rsa_prkey");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to sc_pkcs15emu_add_rsa_prkey");
|
||||
|
||||
memset(&pubkey_info, 0, sizeof(pubkey_info));
|
||||
memset(&pubkey_obj, 0, sizeof(pubkey_obj));
|
||||
|
@ -86,7 +86,7 @@ static int sc_pkcs15emu_gids_add_prkey(sc_pkcs15_card_t * p15card, sc_cardctl_gi
|
|||
pubkey_info.id = prkey_info.id;
|
||||
|
||||
r = sc_pkcs15emu_add_rsa_pubkey(p15card, &pubkey_obj, &pubkey_info);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to sc_pkcs15emu_add_rsa_pubkey");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to sc_pkcs15emu_add_rsa_pubkey");
|
||||
|
||||
if (container->certificatepath.len > 0) {
|
||||
memset(&cert_info, 0, sizeof(cert_info));
|
||||
|
@ -122,10 +122,10 @@ static int sc_pkcs15emu_gids_init (sc_pkcs15_card_t * p15card)
|
|||
int has_puk;
|
||||
|
||||
r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the containers. Uninitialized card ?");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the containers. Uninitialized card ?");
|
||||
|
||||
r = sc_card_ctl(card, SC_CARDCTL_GET_SERIALNR, NULL);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to get the serial number. Uninitialized card ?");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to get the serial number. Uninitialized card ?");
|
||||
|
||||
p15card->tokeninfo->serial_number = (char*) malloc(card->serialnr.len *2 +1);
|
||||
if (!p15card->tokeninfo->serial_number) {
|
||||
|
@ -197,7 +197,7 @@ static int sc_pkcs15emu_gids_init (sc_pkcs15_card_t * p15card)
|
|||
}
|
||||
|
||||
r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to sc_pkcs15emu_add_pin_obj");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj");
|
||||
|
||||
if (has_puk) {
|
||||
pin_info.auth_id.value[0] = 0x81;
|
||||
|
@ -208,11 +208,11 @@ static int sc_pkcs15emu_gids_init (sc_pkcs15_card_t * p15card)
|
|||
strlcpy(pin_obj.label, "PUK", sizeof(pin_obj.label));
|
||||
pin_obj.auth_id.len = 0;
|
||||
r = sc_pkcs15emu_add_pin_obj(p15card, &pin_obj, &pin_info);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to sc_pkcs15emu_add_pin_obj with PUK");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to sc_pkcs15emu_add_pin_obj with PUK");
|
||||
}
|
||||
|
||||
r = sc_card_ctl(card, SC_CARDCTL_GIDS_GET_ALL_CONTAINERS, &recordsnum);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "sc_card_ctl SC_CARDCTL_GIDS_GET_ALL_CONTAINERS");
|
||||
LOG_TEST_RET(card->ctx, r, "sc_card_ctl SC_CARDCTL_GIDS_GET_ALL_CONTAINERS");
|
||||
|
||||
for (i = 0; i < recordsnum; i++) {
|
||||
sc_cardctl_gids_get_container_t container;
|
||||
|
|
|
@ -232,14 +232,14 @@ static int itacns_add_cert(sc_pkcs15_card_t *p15card,
|
|||
obj.flags = obj_flags;
|
||||
|
||||
r = sc_pkcs15emu_add_x509_cert(p15card, &obj, &info);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add X.509 certificate");
|
||||
|
||||
/* If we have OpenSSL, read keyUsage */
|
||||
#ifdef ENABLE_OPENSSL
|
||||
|
||||
r = sc_pkcs15_read_certificate(p15card, &info, &cert);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not read X.509 certificate");
|
||||
|
||||
{
|
||||
|
@ -296,7 +296,7 @@ static int itacns_add_pubkey(sc_pkcs15_card_t *p15card,
|
|||
|
||||
*modulus_len_out = info.modulus_length;
|
||||
r = sc_pkcs15emu_add_rsa_pubkey(p15card, &obj, &info);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add pub key");
|
||||
return r;
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ static int itacns_add_data_files(sc_pkcs15_card_t *p15card)
|
|||
sizeof(obj.label));
|
||||
data.path = path;
|
||||
rv = sc_pkcs15emu_add_data_object(p15card, &obj, &data);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, rv,
|
||||
LOG_TEST_RET(p15card->card->ctx, rv,
|
||||
"Could not add data file");
|
||||
}
|
||||
|
||||
|
@ -590,7 +590,7 @@ static int itacns_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
sc_format_path(pubkey_path, &path);
|
||||
r = itacns_add_pubkey(p15card, &path, cert_id, label,
|
||||
pubkey_usage_flags, sec_env, 0, &modulus_length);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add public key");
|
||||
}
|
||||
|
||||
|
@ -606,7 +606,7 @@ static int itacns_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
modulus_length,
|
||||
prkey_usage_flags,
|
||||
private_path, sec_env, cert_id, SC_PKCS15_CO_FLAG_PRIVATE);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add private key");
|
||||
|
||||
/* PIN and PUK */
|
||||
|
@ -619,7 +619,7 @@ static int itacns_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
| SC_PKCS15_PIN_FLAG_INITIALIZED;
|
||||
r = itacns_add_pin(p15card, pinlabel, sec_env, fake_puk_authid, pin_ref,
|
||||
private_path, pin_flags);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add PIN");
|
||||
|
||||
strlcpy(pinlabel, "PUK ", sizeof(pinlabel));
|
||||
|
@ -633,7 +633,7 @@ static int itacns_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
| SC_PKCS15_PIN_FLAG_UNBLOCK_DISABLED;
|
||||
r = itacns_add_pin(p15card, pinlabel, fake_puk_authid, 0, pin_ref+1,
|
||||
private_path, pin_flags);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add PUK");
|
||||
|
||||
return 0;
|
||||
|
@ -686,7 +686,7 @@ static int itacns_check_and_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
if (cert_offset) {
|
||||
u8 certlen[3];
|
||||
r = loadFile(p15card, &path, certlen, sizeof(certlen));
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not read certificate file");
|
||||
path.index = cert_offset;
|
||||
path.count = (certlen[1] << 8) + certlen[2];
|
||||
|
@ -700,7 +700,7 @@ static int itacns_check_and_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
&path, &cert_id, label, 0, &ext_info_ok, &ku, &xku);
|
||||
if (r == SC_ERROR_INVALID_ASN1_OBJECT)
|
||||
return 0;
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add certificate");
|
||||
(*found_certificates)++;
|
||||
|
||||
|
@ -743,7 +743,7 @@ static int itacns_check_and_add_keyset(sc_pkcs15_card_t *p15card,
|
|||
r = itacns_add_keyset(p15card, label, sec_env, &cert_id,
|
||||
pubkey_path, prkey_path, pubkey_usage_flags, prkey_usage_flags,
|
||||
pin_ref);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add keys for this certificate");
|
||||
|
||||
return r;
|
||||
|
@ -817,7 +817,7 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
|
|||
|
||||
/* Data files */
|
||||
r = itacns_add_data_files(p15card);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add data files");
|
||||
|
||||
/*** Certificate and keys. ***/
|
||||
|
@ -825,7 +825,7 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
|
|||
r = itacns_check_and_add_keyset(p15card, "CNS0", cns0_secenv,
|
||||
0, "3F0011001101", "3F003F01", NULL,
|
||||
0x10, &found_certs);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add CNS0");
|
||||
certificate_count += found_certs;
|
||||
|
||||
|
@ -833,7 +833,7 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
|
|||
r = itacns_check_and_add_keyset(p15card, "CNS01", 0x21,
|
||||
5, "3F002FFF8228", NULL, "3F002FFF0000",
|
||||
0x10, &found_certs);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add CNS01");
|
||||
certificate_count += found_certs;
|
||||
|
||||
|
@ -841,7 +841,7 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
|
|||
r = itacns_check_and_add_keyset(p15card, "CNS1", 0x10,
|
||||
0, "3F0014009010", "3F00140081108010", "3F0014008110",
|
||||
0x1a, &found_certs);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not add CNS1");
|
||||
certificate_count += found_certs;
|
||||
|
||||
|
@ -853,7 +853,7 @@ static int itacns_init(sc_pkcs15_card_t *p15card)
|
|||
/* Back to Master File */
|
||||
sc_format_path("3F00", &path);
|
||||
r = sc_select_file(p15card->card, &path, NULL);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(p15card->card->ctx, r,
|
||||
"Could not select master file again");
|
||||
|
||||
return r;
|
||||
|
|
|
@ -143,7 +143,7 @@ sc_pkcs15_decode_aodf_entry(struct sc_pkcs15_card *p15card, struct sc_pkcs15_obj
|
|||
r = sc_asn1_decode(ctx, asn1_auth_type, *buf, *buflen, buf, buflen);
|
||||
if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
|
||||
return r;
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "ASN.1 decoding failed");
|
||||
LOG_TEST_RET(ctx, r, "ASN.1 decoding failed");
|
||||
|
||||
if (asn1_auth_type_choice[0].flags & SC_ASN1_PRESENT) {
|
||||
sc_log(ctx, "AuthType: PIN");
|
||||
|
@ -183,7 +183,7 @@ sc_pkcs15_decode_aodf_entry(struct sc_pkcs15_card *p15card, struct sc_pkcs15_obj
|
|||
sc_debug(ctx, SC_LOG_DEBUG_ASN1, "decoded PIN(ref:%X,path:%s)", info.attrs.pin.reference, sc_print_path(&info.path));
|
||||
}
|
||||
else if (asn1_auth_type_choice[1].flags & SC_ASN1_PRESENT) {
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "BIO authentication object not yet supported");
|
||||
}
|
||||
else if (asn1_auth_type_choice[2].flags & SC_ASN1_PRESENT) {
|
||||
sc_log(ctx, "AuthType: AuthKey");
|
||||
|
@ -194,7 +194,7 @@ sc_pkcs15_decode_aodf_entry(struct sc_pkcs15_card *p15card, struct sc_pkcs15_obj
|
|||
info.attrs.authkey.derived = 1;
|
||||
}
|
||||
else {
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "unknown authentication type");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "unknown authentication type");
|
||||
}
|
||||
|
||||
obj->data = malloc(sizeof(info));
|
||||
|
|
|
@ -690,7 +690,7 @@ int sc_pkcs15_compute_signature(struct sc_pkcs15_card *p15card,
|
|||
/* XXX Assuming RSA key here */
|
||||
r = sc_pkcs1_encode(ctx, pad_flags, tmp, inlen, tmp, &tmplen,
|
||||
prkey->modulus_length);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Unable to add padding");
|
||||
LOG_TEST_RET(ctx, r, "Unable to add padding");
|
||||
inlen = tmplen;
|
||||
}
|
||||
else if ( senv.algorithm == SC_ALGORITHM_RSA &&
|
||||
|
|
|
@ -80,7 +80,7 @@ static int asepcos_check_verify_tpin(sc_profile_t *profile, sc_pkcs15_card_t *p1
|
|||
r = sc_pkcs15init_authenticate(profile, p15card, tfile, SC_AC_OP_CRYPTO);
|
||||
p15card->card->caps |= SC_CARD_CAP_USE_FCI_AC;
|
||||
sc_file_free(tfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "unable to authenticate for 'CRYPTO' operation");
|
||||
LOG_TEST_RET(ctx, r, "unable to authenticate for 'CRYPTO' operation");
|
||||
}
|
||||
return SC_SUCCESS;
|
||||
}
|
||||
|
@ -780,7 +780,7 @@ static int asepcos_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
|||
apdu.resp = rbuf;
|
||||
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
if (apdu.sw1 != 0x90 || apdu.sw2 != 0x00) {
|
||||
sc_log(card->ctx, "error creating key");
|
||||
return SC_ERROR_INTERNAL;
|
||||
|
|
|
@ -859,7 +859,7 @@ static int cardos_have_verifyrc_package(sc_card_t *card)
|
|||
apdu.lc = 0;
|
||||
apdu.le = 256;
|
||||
r = sc_transmit_apdu(card, &apdu);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "APDU transmit failed");
|
||||
LOG_TEST_RET(card->ctx, r, "APDU transmit failed");
|
||||
|
||||
if ((len = apdu.resplen) == 0)
|
||||
/* looks like no package has been installed */
|
||||
|
|
|
@ -246,11 +246,11 @@ cflex_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *df
|
|||
/* Get file definition from the profile */
|
||||
if (sc_profile_get_file(profile, (pin_attrs->reference == 1)? "CHV1" : "CHV2", &file) < 0
|
||||
&& sc_profile_get_file(profile, "CHV", &file) < 0)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_FILE_NOT_FOUND, "profile does not define pin file ACLs");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_FILE_NOT_FOUND, "profile does not define pin file ACLs");
|
||||
|
||||
ndummies = cflex_create_dummy_chvs(profile, p15card, file, SC_AC_OP_CREATE, dummies);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, ndummies, "Unable to create dummy CHV file");
|
||||
LOG_TEST_RET(ctx, ndummies, "Unable to create dummy CHV file");
|
||||
|
||||
r = cflex_create_pin_file(profile, p15card, &df->path, pin_attrs->reference,
|
||||
pin, pin_len, sc_profile_get_pin_retries(profile, pin_type),
|
||||
|
@ -548,7 +548,7 @@ cflex_create_pin_file(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
if (sc_profile_get_file_by_path(profile, &path, &file) < 0
|
||||
&& sc_profile_get_file(profile, (ref == 1)? "CHV1" : "CHV2", &file) < 0
|
||||
&& sc_profile_get_file(profile, "CHV", &file) < 0)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_FILE_NOT_FOUND, "profile does not define pin file ACLs");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_FILE_NOT_FOUND, "profile does not define pin file ACLs");
|
||||
|
||||
file->path = path;
|
||||
file->size = 23;
|
||||
|
@ -568,7 +568,7 @@ cflex_create_pin_file(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
* necessary */
|
||||
ndummies = cflex_create_dummy_chvs(profile, p15card,
|
||||
file, SC_AC_OP_UPDATE, dummies);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, ndummies, "Unable to create dummy CHV file");
|
||||
LOG_TEST_RET(ctx, ndummies, "Unable to create dummy CHV file");
|
||||
|
||||
if (!unprotected) {
|
||||
struct sc_pin_cmd_data pin_cmd;
|
||||
|
@ -581,7 +581,7 @@ cflex_create_pin_file(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
pin_cmd.pin1.len = sizeof(dummy_pin_value);
|
||||
|
||||
r = sc_pin_cmd(p15card->card, &pin_cmd, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot verify dummy PIN");
|
||||
LOG_TEST_RET(ctx, r, "Cannot verify dummy PIN");
|
||||
|
||||
};
|
||||
|
||||
|
@ -593,10 +593,10 @@ cflex_create_pin_file(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
}
|
||||
|
||||
r = sc_pkcs15init_create_file(profile, p15card, file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to create PIN file");
|
||||
LOG_TEST_RET(ctx, r, "Failed to create PIN file");
|
||||
|
||||
r = sc_update_binary(p15card->card, 0, buffer, 23, 0);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to update PIN file");
|
||||
LOG_TEST_RET(ctx, r, "Failed to update PIN file");
|
||||
|
||||
if (r < 0 || file_ret == NULL)
|
||||
sc_file_free(file);
|
||||
|
|
|
@ -82,7 +82,7 @@ static int entersafe_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
SC_FUNC_CALLED(card->ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
|
||||
ret = sc_profile_get_file(profile, "MF", &mf_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Get MF info failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Get MF info failed");
|
||||
|
||||
mf_data.type = SC_ENTERSAFE_MF_DATA;
|
||||
mf_data.data.df.file_id[0]=0x3F;
|
||||
|
@ -98,7 +98,7 @@ static int entersafe_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
sc_file_free(mf_file);
|
||||
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_CREATE_FILE, &mf_data);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Create MF failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Create MF failed");
|
||||
}
|
||||
|
||||
{/* EF(DIR) */
|
||||
|
@ -109,7 +109,7 @@ static int entersafe_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
|
||||
/* get dir profile */
|
||||
ret = sc_profile_get_file(profile, "dir", &dir_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Get EF(DIR) info failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Get EF(DIR) info failed");
|
||||
fid=dir_file->id;
|
||||
size=dir_file->size;
|
||||
sc_file_free(dir_file);
|
||||
|
@ -126,7 +126,7 @@ static int entersafe_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
memset(ef_data.data.ef.sm,0x00,sizeof(ef_data.data.ef.sm));
|
||||
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_CREATE_FILE, &ef_data);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Create EF(DIR) failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Create EF(DIR) failed");
|
||||
|
||||
|
||||
/* fill file by 0 */
|
||||
|
@ -137,7 +137,7 @@ static int entersafe_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
|
||||
ret = sc_update_binary(card,0,buff,size,0);
|
||||
free(buff);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Initialize EF(DIR) failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Initialize EF(DIR) failed");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,SC_SUCCESS);
|
||||
|
@ -168,7 +168,7 @@ static int entersafe_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
|||
memcpy(df_data.data.df.aid,df->name,df->namelen);
|
||||
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_CREATE_FILE, &df_data);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Crate DF failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Crate DF failed");
|
||||
}
|
||||
|
||||
{/* GPKF */
|
||||
|
@ -177,7 +177,7 @@ static int entersafe_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
|||
|
||||
/* get p15_gpkf profile */
|
||||
ret = sc_profile_get_file(profile, "p15_gpkf", &gpkf_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Get GPKF info failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Get GPKF info failed");
|
||||
|
||||
ef_data.type=SC_ENTERSAFE_EF_DATA;
|
||||
ef_data.data.ef.file_id[0]=(gpkf_file->id>>8)&0xFF;
|
||||
|
@ -193,7 +193,7 @@ static int entersafe_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
|||
sc_file_free(gpkf_file);
|
||||
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_CREATE_FILE, &ef_data);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Create GPKF failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Create GPKF failed");
|
||||
}
|
||||
|
||||
{/* p15 efs */
|
||||
|
@ -234,13 +234,13 @@ static int entersafe_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card
|
|||
sc_file_free(file);
|
||||
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_CREATE_FILE, &tmp);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Create pkcs15 file failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Create pkcs15 file failed");
|
||||
}
|
||||
}
|
||||
|
||||
{/* Preinstall keys */
|
||||
ret = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_PREINSTALL_KEYS, 0);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,ret,"Preinstall keys failed");
|
||||
LOG_TEST_RET(card->ctx,ret,"Preinstall keys failed");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE,ret);
|
||||
|
@ -382,7 +382,7 @@ static int entersafe_store_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
r = SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
|
||||
}
|
||||
sc_file_free(tfile);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "cant verify pin");
|
||||
LOG_TEST_RET(card->ctx, r, "cant verify pin");
|
||||
|
||||
data.key_id = (u8) kinfo->key_reference;
|
||||
data.usage=0x22;
|
||||
|
@ -432,14 +432,14 @@ static int entersafe_generate_key(sc_profile_t *profile, sc_pkcs15_card_t *p15ca
|
|||
r = SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
|
||||
}
|
||||
sc_file_free(tfile);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "cant verify pin");
|
||||
LOG_TEST_RET(card->ctx, r, "cant verify pin");
|
||||
|
||||
/* generate key pair */
|
||||
gendat.key_id = (u8) kinfo->key_reference;
|
||||
gendat.key_length = (size_t) kinfo->modulus_length;
|
||||
gendat.modulus = NULL;
|
||||
r = sc_card_ctl(card, SC_CARDCTL_ENTERSAFE_GENERATE_KEY, &gendat);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "EnterSafe generate RSA key pair failed");
|
||||
LOG_TEST_RET(card->ctx, r, "EnterSafe generate RSA key pair failed");
|
||||
|
||||
/* get the modulus via READ PUBLIC KEY */
|
||||
if (pubkey) {
|
||||
|
@ -478,11 +478,11 @@ static int entersafe_sanity_check(sc_profile_t *profile, sc_pkcs15_card_t *p15ca
|
|||
|
||||
sc_log(ctx, "Check and if needed update PinFlags");
|
||||
rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to get PINs");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to get PINs");
|
||||
nn = rv;
|
||||
|
||||
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PIN, &profile_auth);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to get PIN info");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
|
||||
|
||||
for (ii=0; ii<nn; ii++) {
|
||||
struct sc_pkcs15_auth_info *ainfo = (struct sc_pkcs15_auth_info *) objs[ii]->data;
|
||||
|
@ -506,9 +506,9 @@ static int entersafe_sanity_check(sc_profile_t *profile, sc_pkcs15_card_t *p15ca
|
|||
while (df != NULL && df->type != SC_PKCS15_AODF)
|
||||
df = df->next;
|
||||
if (!df)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OBJECT_NOT_FOUND, "Cannot find AODF");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OBJECT_NOT_FOUND, "Cannot find AODF");
|
||||
rv = sc_pkcs15init_update_any_df(p15card, profile, df, 0);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Update AODF error");
|
||||
LOG_TEST_RET(ctx, rv, "Update AODF error");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, rv);
|
||||
|
|
|
@ -57,19 +57,19 @@ static int epass2003_pkcs15_init_card(struct sc_profile *profile,
|
|||
struct sc_file *skey_file;
|
||||
|
||||
ret = sc_profile_get_file(profile, "MF", &mf_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get MF info failed");
|
||||
ret = sc_create_file(card, mf_file);
|
||||
sc_file_free(mf_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create MF failed");
|
||||
|
||||
ret = sc_profile_get_file(profile, "SKey-MF", &skey_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get SKey info failed");
|
||||
ret = sc_create_file(card, skey_file);
|
||||
sc_file_free(skey_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create SKey failed");
|
||||
|
||||
}
|
||||
|
@ -79,11 +79,11 @@ static int epass2003_pkcs15_init_card(struct sc_profile *profile,
|
|||
|
||||
/* get dir profile */
|
||||
ret = sc_profile_get_file(profile, "DIR", &dir_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get EF(DIR) info failed");
|
||||
ret = sc_create_file(card, dir_file);
|
||||
sc_file_free(dir_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create EF(DIR) failed");
|
||||
|
||||
sc_free_apps(card);
|
||||
|
@ -110,38 +110,38 @@ static int epass2003_pkcs15_create_dir(struct sc_profile *profile,
|
|||
u8 so_maxtries = 0;
|
||||
|
||||
ret = sc_profile_get_file(profile, "PKCS15-AppDF", &df_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get PKCS15-AppDF info failed");
|
||||
ret = sc_create_file(card, df_file);
|
||||
sc_file_free(df_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create PKCS15-AppDF failed");
|
||||
|
||||
ret = sc_profile_get_file(profile, "SKey-AppDF", &skey_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get SKey info failed");
|
||||
ret = sc_create_file(card, skey_file);
|
||||
sc_file_free(skey_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create SKey info failed");
|
||||
|
||||
ret = sc_profile_get_file(profile, "MAXPIN", &ef_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get MAXPIN info failed");
|
||||
ret = sc_create_file(card, ef_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create MAXPIN failed");
|
||||
ret = sc_select_file(card, &(ef_file->path), &ef_file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Select MAXPIN failed");
|
||||
|
||||
ret = sc_profile_get_pin_id(profile, 2, &id);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get User PIN id error!");
|
||||
user_maxtries = (u8) sc_profile_get_pin_retries(profile, id);
|
||||
|
||||
ret = sc_profile_get_pin_id(profile, 1, &id);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Get User PIN id error!");
|
||||
so_maxtries = (u8) sc_profile_get_pin_retries(profile, id);
|
||||
|
||||
|
@ -150,7 +150,7 @@ static int epass2003_pkcs15_create_dir(struct sc_profile *profile,
|
|||
|
||||
ret = sc_update_binary(card, 0, max_counter, 2, 0);
|
||||
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Update MAXPIN failed");
|
||||
sc_file_free(ef_file);
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ static int epass2003_pkcs15_create_dir(struct sc_profile *profile,
|
|||
}
|
||||
ret = sc_create_file(card, file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, ret,
|
||||
LOG_TEST_RET(card->ctx, ret,
|
||||
"Create pkcs15 file failed");
|
||||
}
|
||||
}
|
||||
|
@ -240,7 +240,7 @@ static int epass2003_pkcs15_create_pin(struct sc_profile *profile,
|
|||
EPASS2003_AC_MAC_NOLESS | EPASS2003_AC_USER;
|
||||
|
||||
r = sc_profile_get_pin_id(profile, 2, &id);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"Get User PIN id error!");
|
||||
data.key_data.es_secret.EC =
|
||||
sc_profile_get_pin_retries(profile, id);
|
||||
|
@ -276,7 +276,7 @@ static int epass2003_pkcs15_create_pin(struct sc_profile *profile,
|
|||
EPASS2003_AC_MAC_EQUAL | EPASS2003_AC_SO;
|
||||
|
||||
r = sc_profile_get_pin_id(profile, 1, &id);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"Get User PIN id error!");
|
||||
data.key_data.es_secret.EC =
|
||||
sc_profile_get_pin_retries(profile, id);
|
||||
|
@ -429,7 +429,7 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
|||
sc_pkcs15_print_id(&key_info->id));
|
||||
if (key->algorithm != SC_ALGORITHM_RSA
|
||||
|| key->algorithm != SC_ALGORITHM_RSA)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL,
|
||||
LOG_TEST_RET(card->ctx,
|
||||
SC_ERROR_NOT_SUPPORTED,
|
||||
"store key: only support RSA");
|
||||
|
||||
|
@ -441,7 +441,7 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
|||
/* allocate key object */
|
||||
r = cosm_new_file(profile, card, SC_PKCS15_TYPE_PRKEY_RSA,
|
||||
key_info->key_reference, &file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"create key: failed to allocate new key object");
|
||||
file->size = keybits;
|
||||
sc_log(card->ctx, "private key path: %s",
|
||||
|
@ -451,7 +451,7 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
|||
sc_delete_file(p15card->card, &file->path);
|
||||
/* create */
|
||||
r = sc_pkcs15init_create_file(profile, p15card, file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"create key: failed to create key file");
|
||||
|
||||
sc_log(card->ctx,
|
||||
|
@ -468,11 +468,11 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
|||
path.len -= 2;
|
||||
|
||||
r = sc_select_file(card, &path, &tfile);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"generate key: no private object DF");
|
||||
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"No authorisation to store private key");
|
||||
|
||||
sc_file_free(tfile);
|
||||
|
@ -484,7 +484,7 @@ static int epass2003_pkcs15_store_key(struct sc_profile *profile,
|
|||
data.key_data.es_key.rsa = (void *)&key->u.rsa;
|
||||
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_ENTERSAFE_WRITE_KEY, &data);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r,
|
||||
LOG_TEST_RET(card->ctx, r,
|
||||
"store key: cannot update private key");
|
||||
|
||||
sc_file_free(file);
|
||||
|
@ -693,11 +693,11 @@ static int epass2003_pkcs15_sanity_check(sc_profile_t * profile,
|
|||
sc_log(ctx,
|
||||
"Check and if needed update PinFlags");
|
||||
rv = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, objs, 32);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to get PINs");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to get PINs");
|
||||
nn = rv;
|
||||
|
||||
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PIN, &profile_auth);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to get PIN info");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to get PIN info");
|
||||
|
||||
for (ii = 0; ii < nn; ii++) {
|
||||
struct sc_pkcs15_auth_info *ainfo =
|
||||
|
@ -725,11 +725,11 @@ static int epass2003_pkcs15_sanity_check(sc_profile_t * profile,
|
|||
while (df != NULL && df->type != SC_PKCS15_AODF)
|
||||
df = df->next;
|
||||
if (!df)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL,
|
||||
LOG_TEST_RET(ctx,
|
||||
SC_ERROR_OBJECT_NOT_FOUND,
|
||||
"Cannot find AODF");
|
||||
rv = sc_pkcs15init_update_any_df(p15card, profile, df, 0);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Update AODF error");
|
||||
LOG_TEST_RET(ctx, rv, "Update AODF error");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, rv);
|
||||
|
|
|
@ -123,7 +123,7 @@ static int gids_save_certificate(struct sc_pkcs15_card *p15card, struct sc_pkcs1
|
|||
//TODO save the certificate in the special file
|
||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_NOT_SUPPORTED);
|
||||
}
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "unable to find the private key associated to the certificate");
|
||||
LOG_TEST_RET(card->ctx, r, "unable to find the private key associated to the certificate");
|
||||
|
||||
LOG_FUNC_RETURN(card->ctx, sc_card_ctl(card, SC_CARDCTL_GIDS_SAVE_CERT, &call));
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ miocos_create_pin(struct sc_profile *profile, sc_pkcs15_card_t *p15card, struct
|
|||
puk_len = 8;
|
||||
strncpy((char *) ac_info.unblock_value, (const char *) puk, puk_len);
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_MIOCOS_CREATE_AC, &ac_info);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Miocos create AC failed");
|
||||
LOG_TEST_RET(ctx, r, "Miocos create AC failed");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
}
|
||||
|
@ -205,14 +205,14 @@ miocos_create_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
|
||||
if (key_info->modulus_length != 1024)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
|
||||
sc_log(ctx, "create private key ID:%s\n", sc_pkcs15_print_id(&key_info->id));
|
||||
r = miocos_new_file(profile, p15card->card, SC_PKCS15_TYPE_PRKEY_RSA, key_info->key_reference, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot create key: failed to allocate new key object");
|
||||
LOG_TEST_RET(ctx, r, "Cannot create key: failed to allocate new key object");
|
||||
|
||||
memcpy(&file->path, &key_info->path, sizeof(file->path));
|
||||
file->id = file->path.value[file->path.len - 2] * 0x100
|
||||
|
@ -244,20 +244,20 @@ miocos_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA
|
||||
|| key->algorithm != SC_ALGORITHM_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
|
||||
rsa = &key->u.rsa;
|
||||
if (rsa->modulus.len != 128)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "MioCOS supports only 1024-bit RSA keys.");
|
||||
|
||||
sc_log(ctx, "store key with ID:%s and path:%s\n", sc_pkcs15_print_id(&key_info->id),
|
||||
sc_print_path(&key_info->path));
|
||||
|
||||
r = sc_select_file(p15card->card, &key_info->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot store key: select key file failed");
|
||||
LOG_TEST_RET(ctx, r, "Cannot store key: select key file failed");
|
||||
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "No authorisation to store private key");
|
||||
LOG_TEST_RET(ctx, r, "No authorisation to store private key");
|
||||
|
||||
r = miocos_update_private_key(profile, p15card->card, rsa);
|
||||
|
||||
|
|
|
@ -245,10 +245,10 @@ awp_new_container_entry(struct sc_pkcs15_card *p15card, unsigned char *buff, int
|
|||
|
||||
LOG_FUNC_CALLED(ctx);
|
||||
if (len<0x34)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCORRECT_PARAMETERS, "Invalid container update size");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCORRECT_PARAMETERS, "Invalid container update size");
|
||||
|
||||
rv = sc_get_challenge(p15card->card, rand_buf, sizeof(rand_buf));
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot get challenge");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot get challenge");
|
||||
|
||||
*(buff + 12) = 0x26;
|
||||
*(buff + 13) = '{';
|
||||
|
@ -321,11 +321,11 @@ awp_create_container(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
sc_log(ctx, "create container(%X:%X:%X)", acc->prkey_id, acc->cert_id, acc->pubkey_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, COSM_CONTAINER_LIST, 0, &clist, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Create container failed");
|
||||
LOG_TEST_RET(ctx, rv, "Create container failed");
|
||||
sc_log(ctx, "contaner cfile(rcount:%i,rlength:%i)", clist->record_count, clist->record_length);
|
||||
|
||||
rv = sc_select_file(p15card->card, &clist->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Create container failed: cannot select container's list");
|
||||
LOG_TEST_RET(ctx, rv, "Create container failed: cannot select container's list");
|
||||
file->record_length = clist->record_length;
|
||||
|
||||
sc_log(ctx, "contaner file(rcount:%i,rlength:%i)", file->record_count, file->record_length);
|
||||
|
@ -388,7 +388,7 @@ awp_update_container_entry (struct sc_pkcs15_card *p15card, struct sc_profile *p
|
|||
case COSM_TYPE_PRKEY_RSA:
|
||||
if (*(buff + offs + 2)) {
|
||||
free(buff);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_CARD, "private key exists already");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_CARD, "private key exists already");
|
||||
}
|
||||
|
||||
*(buff + offs + 2) = (file_id >> 8) & 0xFF;
|
||||
|
@ -817,7 +817,7 @@ awp_encode_key_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *obj
|
|||
*/
|
||||
ki->id.value = calloc(1, key_info->id.len);
|
||||
if (!ki->id.value)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: ID allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: ID allocation error");
|
||||
memcpy(ki->id.value, key_info->id.value, key_info->id.len);
|
||||
ki->id.len = key_info->id.len;
|
||||
|
||||
|
@ -851,7 +851,7 @@ awp_set_key_info (struct sc_pkcs15_card *p15card, struct sc_profile *profile, st
|
|||
blob_size = 2;
|
||||
blob = malloc(blob_size);
|
||||
if (!blob)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP set key info failed: blob allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP set key info failed: blob allocation error");
|
||||
|
||||
sc_log(ctx, "label:%s",ki->label.value);
|
||||
|
||||
|
@ -933,7 +933,7 @@ awp_encode_cert_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
ERR_load_crypto_strings();
|
||||
|
||||
if (!obj || !ci)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "AWP encode cert failed: invalid parameters");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "AWP encode cert failed: invalid parameters");
|
||||
|
||||
cert_info = (struct sc_pkcs15_cert_info *)obj->data;
|
||||
|
||||
|
@ -948,22 +948,22 @@ awp_encode_cert_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
|
||||
mem = BIO_new_mem_buf(obj->content.value, obj->content.len);
|
||||
if (!mem)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_DATA, "AWP encode cert failed: invalid data");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "AWP encode cert failed: invalid data");
|
||||
|
||||
x = d2i_X509_bio(mem, NULL);
|
||||
if (!x)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_DATA, "AWP encode cert failed: x509 parse error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_DATA, "AWP encode cert failed: x509 parse error");
|
||||
|
||||
buff = OPENSSL_malloc(i2d_X509(x,NULL) + EVP_MAX_MD_SIZE);
|
||||
if (!buff)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: memory allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: memory allocation error");
|
||||
|
||||
/*
|
||||
* subject commonName.
|
||||
*/
|
||||
ptr = awp_get_commonName(x);
|
||||
if (!ptr)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get CommonName");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get CommonName");
|
||||
ci->cn.value = ptr;
|
||||
ci->cn.len = strlen((char *)ptr);
|
||||
|
||||
|
@ -973,11 +973,11 @@ awp_encode_cert_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
ptr = buff;
|
||||
r = i2d_X509_NAME(X509_get_subject_name(x),&ptr);
|
||||
if (r<=0)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get SubjectName");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get SubjectName");
|
||||
|
||||
ci->subject.value = malloc(r);
|
||||
if (!ci->subject.value)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: subject allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: subject allocation error");
|
||||
memcpy(ci->subject.value, buff, r);
|
||||
ci->subject.len = r;
|
||||
|
||||
|
@ -987,11 +987,11 @@ awp_encode_cert_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
ptr = buff;
|
||||
r = i2d_X509_NAME(X509_get_issuer_name(x),&ptr);
|
||||
if (r <= 0)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get IssuerName");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INTERNAL, "AWP encode cert failed: cannot get IssuerName");
|
||||
|
||||
ci->issuer.value = malloc(r);
|
||||
if (!ci->issuer.value)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: issuer allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: issuer allocation error");
|
||||
memcpy(ci->issuer.value, buff, r);
|
||||
ci->issuer.len = r;
|
||||
|
||||
|
@ -1000,7 +1000,7 @@ awp_encode_cert_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
*/
|
||||
ci->id.value = calloc(1, cert_info->id.len);
|
||||
if (!ci->id.value)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: ID allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode cert failed: ID allocation error");
|
||||
memcpy(ci->id.value, cert_info->id.value, cert_info->id.len);
|
||||
ci->id.len = cert_info->id.len;
|
||||
|
||||
|
@ -1104,7 +1104,7 @@ awp_encode_data_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
LOG_FUNC_CALLED(ctx);
|
||||
|
||||
if (!obj || !di)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "AWP encode data failed: invalid parameters");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "AWP encode data failed: invalid parameters");
|
||||
|
||||
data_info = (struct sc_pkcs15_data_info *)obj->data;
|
||||
|
||||
|
@ -1126,13 +1126,13 @@ awp_encode_data_info(struct sc_pkcs15_card *p15card, struct sc_pkcs15_object *ob
|
|||
}
|
||||
|
||||
r = sc_asn1_encode_object_id(&buf, &buflen, &data_info->app_oid);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "AWP encode data failed: cannot encode OID");
|
||||
LOG_TEST_RET(ctx, r, "AWP encode data failed: cannot encode OID");
|
||||
|
||||
di->oid.len = buflen + 2;
|
||||
di->oid.value = malloc(di->oid.len);
|
||||
if (!di->oid.value) {
|
||||
free(buf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP encode data failed: cannot allocate OID");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP encode data failed: cannot allocate OID");
|
||||
}
|
||||
|
||||
*(di->oid.value + 0) = 0x06;
|
||||
|
@ -1260,14 +1260,14 @@ awp_parse_key_info(struct sc_context *ctx, unsigned char *buf, size_t buf_len,
|
|||
|
||||
/* Label */
|
||||
len = awp_get_lv(ctx, buf, buf_len, offs, 2, &ikey->label);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, len, "AWP parse key info failed: label");
|
||||
LOG_TEST_RET(ctx, len, "AWP parse key info failed: label");
|
||||
if (!len)
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
offs += len;
|
||||
|
||||
/* Ignore Key ID */
|
||||
len = awp_get_lv(ctx, buf, buf_len, offs, 2, &ikey->id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, len, "AWP parse key info failed: ID");
|
||||
LOG_TEST_RET(ctx, len, "AWP parse key info failed: ID");
|
||||
if (!len)
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
offs += len;
|
||||
|
@ -1277,7 +1277,7 @@ awp_parse_key_info(struct sc_context *ctx, unsigned char *buf, size_t buf_len,
|
|||
|
||||
/* Subject */
|
||||
len = awp_get_lv(ctx, buf, buf_len, offs, 2, &ikey->subject);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, len, "AWP parse key info failed: subject");
|
||||
LOG_TEST_RET(ctx, len, "AWP parse key info failed: subject");
|
||||
if (!len)
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
offs += len;
|
||||
|
@ -1289,14 +1289,14 @@ awp_parse_key_info(struct sc_context *ctx, unsigned char *buf, size_t buf_len,
|
|||
len = awp_get_lv(ctx, buf, buf_len, offs, 128, &ikey->modulus);
|
||||
else
|
||||
len = awp_get_lv(ctx, buf, buf_len, offs, 256, &ikey->modulus);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, len, "AWP parse key info failed: modulus");
|
||||
LOG_TEST_RET(ctx, len, "AWP parse key info failed: modulus");
|
||||
if (!len)
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
offs += len;
|
||||
|
||||
/* Exponent */
|
||||
len = awp_get_lv(ctx, buf, buf_len, offs, 1, &ikey->exponent);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, len, "AWP parse key info failed: exponent");
|
||||
LOG_TEST_RET(ctx, len, "AWP parse key info failed: exponent");
|
||||
if (!len)
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
|
||||
|
@ -1318,7 +1318,7 @@ awp_update_key_info(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
LOG_FUNC_CALLED(ctx);
|
||||
|
||||
rv = awp_new_file(p15card, profile, SC_PKCS15_TYPE_PRKEY_RSA, prvkey_id & 0xFF, &info_file, &key_file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update key info failed: instantiation error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update key info failed: instantiation error");
|
||||
sc_log(ctx, "key id %X; info id%X", key_file->id, info_file->id);
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, info_file, SC_AC_OP_READ);
|
||||
|
@ -1335,7 +1335,7 @@ awp_update_key_info(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
|
||||
buf = calloc(1,file->size);
|
||||
if (!buf)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP update key info failed: allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP update key info failed: allocation error");
|
||||
|
||||
rv = sc_read_binary(p15card->card, 0, buf, file->size, 0);
|
||||
if (rv < 0) {
|
||||
|
@ -1353,7 +1353,7 @@ awp_update_key_info(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
free(buf);
|
||||
|
||||
rv = awp_set_key_info(p15card, profile, info_file, &ikey, ci);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update key info failed: set key info error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update key info failed: set key info error");
|
||||
done:
|
||||
sc_file_free(file);
|
||||
sc_file_free(key_file);
|
||||
|
@ -1382,7 +1382,7 @@ awp_update_df_create_cert(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
obj_id = (path.value[path.len-1] & 0xFF) + (path.value[path.len-2] & 0xFF) * 0x100;
|
||||
|
||||
rv = awp_new_file(p15card, profile, SC_PKCS15_TYPE_CERT_X509, obj_id & 0xFF, &info_file, &obj_file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "COSM new file error");
|
||||
LOG_TEST_RET(ctx, rv, "COSM new file error");
|
||||
|
||||
memset(&icert, 0, sizeof(icert));
|
||||
sc_log(ctx,
|
||||
|
@ -1572,19 +1572,19 @@ awp_update_df_create_data(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
obj_id = (path.value[path.len-1] & 0xFF) + (path.value[path.len-2] & 0xFF) * 0x100;
|
||||
|
||||
rv = awp_new_file(p15card, profile, obj_type, obj_id & 0xFF, &info_file, &obj_file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "COSM new file error");
|
||||
LOG_TEST_RET(ctx, rv, "COSM new file error");
|
||||
|
||||
memset(&idata, 0, sizeof(idata));
|
||||
sc_log(ctx,
|
||||
"Data Der(%p,%"SC_FORMAT_LEN_SIZE_T"u)", der.value, der.len);
|
||||
rv = awp_encode_data_info(p15card, obj, &idata);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "'Create Data' update DF failed: cannot encode info");
|
||||
LOG_TEST_RET(ctx, rv, "'Create Data' update DF failed: cannot encode info");
|
||||
|
||||
rv = awp_set_data_info(p15card, profile, info_file, &idata);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "'Create Data' update DF failed: cannot set info");
|
||||
LOG_TEST_RET(ctx, rv, "'Create Data' update DF failed: cannot set info");
|
||||
|
||||
rv = awp_update_object_list(p15card, profile, obj_type, obj_id & 0xFF);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "'Create Data' update DF failed: cannot update list");
|
||||
LOG_TEST_RET(ctx, rv, "'Create Data' update DF failed: cannot update list");
|
||||
|
||||
awp_free_data_info(&idata);
|
||||
|
||||
|
@ -1623,7 +1623,7 @@ awp_update_df_create(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
rv = awp_update_df_create_data(p15card, profile, object);
|
||||
break;
|
||||
default:
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "'Create' update DF failed: unsupported object type");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "'Create' update DF failed: unsupported object type");
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
@ -1644,14 +1644,14 @@ awp_delete_from_container(struct sc_pkcs15_card *p15card,
|
|||
sc_log(ctx, "update container entry (type:%X,file-id:%X)", type, file_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, COSM_CONTAINER_LIST, 0, &clist, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update contaner entry: cannot get allocate AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update contaner entry: cannot get allocate AWP file");
|
||||
|
||||
rv = sc_select_file(p15card->card, &clist->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update contaner entry: cannot select container list file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update contaner entry: cannot select container list file");
|
||||
|
||||
buff = malloc(file->record_length);
|
||||
if (!buff)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP update container entry: allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP update container entry: allocation error");
|
||||
|
||||
for (rec = 1; rec <= (unsigned)file->record_count; rec++) {
|
||||
rv = sc_read_record(p15card->card, rec, buff, file->record_length, SC_RECORD_BY_REC_NR);
|
||||
|
@ -1738,22 +1738,22 @@ awp_remove_from_object_list( struct sc_pkcs15_card *p15card, struct sc_profile *
|
|||
snprintf(lst_name, NAME_MAX_LEN,"%s-public-list", COSM_TITLE);
|
||||
break;
|
||||
default:
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCORRECT_PARAMETERS, "AWP update object list: invalid type");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCORRECT_PARAMETERS, "AWP update object list: invalid type");
|
||||
}
|
||||
|
||||
sc_log(ctx, "AWP update object list: select '%s' file", lst_name);
|
||||
rv = sc_profile_get_file(profile, lst_name, &lst_file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update object list: cannot instantiate list file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update object list: cannot instantiate list file");
|
||||
|
||||
rv = sc_select_file(p15card->card, &lst_file->path, &lst);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update object list: cannot select list file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update object list: cannot select list file");
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, lst, SC_AC_OP_READ);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP update object list: 'read' authentication failed");
|
||||
LOG_TEST_RET(ctx, rv, "AWP update object list: 'read' authentication failed");
|
||||
|
||||
buff = malloc(lst->size);
|
||||
if (!buff)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "AWP update object list: allocation error");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "AWP update object list: allocation error");
|
||||
|
||||
rv = sc_read_binary(p15card->card, 0, buff, lst->size, 0);
|
||||
if (rv != (int)lst->size)
|
||||
|
@ -1803,18 +1803,18 @@ awp_update_df_delete_cert(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
sc_log(ctx, "file-id:%X", file_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, obj->type, file_id & 0xFF, &info_file, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete cert' update DF failed: cannot get allocate new AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete cert' update DF failed: cannot get allocate new AWP file");
|
||||
sc_log(ctx, "info file-id:%X", info_file->id);
|
||||
|
||||
rv = cosm_delete_file(p15card, profile, info_file);
|
||||
if (rv != SC_ERROR_FILE_NOT_FOUND)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete cert' update DF failed: delete info file error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete cert' update DF failed: delete info file error");
|
||||
|
||||
rv = awp_delete_from_container(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete cert' update DF failed: cannot update container");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete cert' update DF failed: cannot update container");
|
||||
|
||||
rv = awp_remove_from_object_list(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete cert' update DF failed: cannot remove object");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete cert' update DF failed: cannot remove object");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
}
|
||||
|
@ -1837,18 +1837,18 @@ awp_update_df_delete_prvkey(struct sc_pkcs15_card *p15card, struct sc_profile *p
|
|||
sc_log(ctx, "file-id:%X", file_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, obj->type, file_id & 0xFF, &info_file, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete prkey' update DF failed: cannot get allocate new AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete prkey' update DF failed: cannot get allocate new AWP file");
|
||||
sc_log(ctx, "info file-id:%X", info_file->id);
|
||||
|
||||
rv = cosm_delete_file(p15card, profile, info_file);
|
||||
if (rv != SC_ERROR_FILE_NOT_FOUND)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete prkey' update DF failed: delete info file error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete prkey' update DF failed: delete info file error");
|
||||
|
||||
rv = awp_delete_from_container(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete prkey' update DF failed: cannot update container");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete prkey' update DF failed: cannot update container");
|
||||
|
||||
rv = awp_remove_from_object_list(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete prkey' update DF failed: cannot remove object");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete prkey' update DF failed: cannot remove object");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
}
|
||||
|
@ -1871,18 +1871,18 @@ awp_update_df_delete_pubkey(struct sc_pkcs15_card *p15card, struct sc_profile *p
|
|||
sc_log(ctx, "file-id:%X", file_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, obj->type, file_id & 0xFF, &info_file, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete pubkey' update DF failed: cannot get allocate new AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete pubkey' update DF failed: cannot get allocate new AWP file");
|
||||
sc_log(ctx, "info file-id:%X", info_file->id);
|
||||
|
||||
rv = cosm_delete_file(p15card, profile, info_file);
|
||||
if (rv != SC_ERROR_FILE_NOT_FOUND)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete pubkey' update DF failed: delete info file error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete pubkey' update DF failed: delete info file error");
|
||||
|
||||
rv = awp_delete_from_container(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete pubkey' update DF failed: cannot update container");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete pubkey' update DF failed: cannot update container");
|
||||
|
||||
rv = awp_remove_from_object_list(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete pubkey' update DF failed: cannot remove object");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete pubkey' update DF failed: cannot remove object");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
}
|
||||
|
@ -1905,15 +1905,15 @@ awp_update_df_delete_data(struct sc_pkcs15_card *p15card, struct sc_profile *pro
|
|||
sc_log(ctx, "file-id:%X", file_id);
|
||||
|
||||
rv = awp_new_file(p15card, profile, obj->type, file_id & 0xFF, &info_file, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete DATA' update DF failed: cannot get allocate new AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete DATA' update DF failed: cannot get allocate new AWP file");
|
||||
sc_log(ctx, "info file-id:%X", info_file->id);
|
||||
|
||||
rv = cosm_delete_file(p15card, profile, info_file);
|
||||
if (rv != SC_ERROR_FILE_NOT_FOUND)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete DATA' update DF failed: delete info file error");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete DATA' update DF failed: delete info file error");
|
||||
|
||||
rv = awp_remove_from_object_list(p15card, profile, obj->type, file_id);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "AWP 'delete DATA' update DF failed: cannot remove object");
|
||||
LOG_TEST_RET(ctx, rv, "AWP 'delete DATA' update DF failed: cannot remove object");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
}
|
||||
|
@ -1944,7 +1944,7 @@ awp_update_df_delete(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
rv = awp_update_df_delete_data(p15card, profile, object);
|
||||
break;
|
||||
default:
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "'Create' update DF failed: unsupported object type");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "'Create' update DF failed: unsupported object type");
|
||||
}
|
||||
|
||||
SC_FUNC_RETURN(ctx, 1, rv);
|
||||
|
|
|
@ -130,7 +130,7 @@ cosm_delete_file(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
sc_log(ctx, "id %04X", df->id);
|
||||
if (df->type==SC_FILE_TYPE_DF) {
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, df, SC_AC_OP_DELETE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot authenticate SC_AC_OP_DELETE");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot authenticate SC_AC_OP_DELETE");
|
||||
}
|
||||
|
||||
/* Select the parent DF */
|
||||
|
@ -138,11 +138,11 @@ cosm_delete_file(struct sc_pkcs15_card *p15card, struct sc_profile *profile,
|
|||
path.len -= 2;
|
||||
|
||||
rv = sc_select_file(p15card->card, &path, &parent);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot select parent");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot select parent");
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, parent, SC_AC_OP_DELETE);
|
||||
sc_file_free(parent);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot authenticate SC_AC_OP_DELETE");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot authenticate SC_AC_OP_DELETE");
|
||||
|
||||
memset(&path, 0, sizeof(path));
|
||||
path.type = SC_PATH_TYPE_FILE_ID;
|
||||
|
@ -245,13 +245,13 @@ cosm_create_dir(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
for (ii = 0; create_dfs[ii]; ii++) {
|
||||
if (sc_profile_get_file(profile, create_dfs[ii], &file)) {
|
||||
sc_log(ctx, "Inconsistent profile: cannot find %s", create_dfs[ii]);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "Profile do not contains Oberthur AWP file");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "Profile do not contains Oberthur AWP file");
|
||||
}
|
||||
|
||||
rv = sc_pkcs15init_create_file(profile, p15card, file);
|
||||
sc_file_free(file);
|
||||
if (rv != SC_ERROR_FILE_ALREADY_EXISTS)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to create Oberthur AWP file");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to create Oberthur AWP file");
|
||||
}
|
||||
|
||||
rv = cosm_write_tokeninfo(p15card, profile, NULL,
|
||||
|
@ -289,7 +289,7 @@ cosm_create_reference_data(struct sc_profile *profile, struct sc_pkcs15_card *p1
|
|||
return SC_ERROR_OBJECT_NOT_VALID;
|
||||
|
||||
rv = sc_select_file(card, &ainfo->path, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot select file");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot select file");
|
||||
|
||||
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PIN, &profile_auth_pin);
|
||||
sc_profile_get_pin_info(profile, SC_PKCS15INIT_USER_PUK, &profile_auth_puk);
|
||||
|
@ -313,17 +313,17 @@ cosm_create_reference_data(struct sc_profile *profile, struct sc_pkcs15_card *p1
|
|||
}
|
||||
|
||||
rv = sc_card_ctl(card, SC_CARDCTL_OBERTHUR_CREATE_PIN, &args);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "'CREATE_PIN' card specific command failed");
|
||||
LOG_TEST_RET(ctx, rv, "'CREATE_PIN' card specific command failed");
|
||||
|
||||
if (!(ainfo->attrs.pin.flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN)
|
||||
&& (profile_auth_puk.tries_left > 0)) {
|
||||
struct sc_file *file = NULL;
|
||||
|
||||
if (sc_profile_get_file(profile, COSM_TITLE"-puk-file", &file))
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "Cannot find PUKFILE");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "Cannot find PUKFILE");
|
||||
|
||||
rv = sc_pkcs15init_update_file(profile, p15card, file, oberthur_puk, sizeof(oberthur_puk));
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to update pukfile");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to update pukfile");
|
||||
|
||||
sc_file_free(file);
|
||||
}
|
||||
|
@ -351,20 +351,20 @@ cosm_update_pin(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
if (ainfo->attrs.pin.flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
|
||||
if (ainfo->attrs.pin.reference != 4)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_PIN_REFERENCE, "cosm_update_pin() invalid SOPIN reference");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_REFERENCE, "cosm_update_pin() invalid SOPIN reference");
|
||||
sc_log(ctx, "Update SOPIN ignored");
|
||||
rv = SC_SUCCESS;
|
||||
}
|
||||
else {
|
||||
rv = cosm_create_reference_data(profile, p15card, ainfo, pin, pin_len, puk, puk_len);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_update_pin() failed to change PIN");
|
||||
LOG_TEST_RET(ctx, rv, "cosm_update_pin() failed to change PIN");
|
||||
|
||||
rv = cosm_write_tokeninfo(p15card, profile, NULL,
|
||||
COSM_TOKEN_FLAG_TOKEN_INITIALIZED
|
||||
| COSM_TOKEN_FLAG_PRN_GENERATION
|
||||
| COSM_TOKEN_FLAG_LOGIN_REQUIRED
|
||||
| COSM_TOKEN_FLAG_USER_PIN_INITIALIZED);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_update_pin() failed to update tokeninfo");
|
||||
LOG_TEST_RET(ctx, rv, "cosm_update_pin() failed to update tokeninfo");
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
@ -435,7 +435,7 @@ cosm_create_pin(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
sc_log(ctx, "create '%.*s'; ref 0x%X; flags %X", (int) sizeof pin_obj->label, pin_obj->label, pin_attrs->reference, pin_attrs->flags);
|
||||
if (sc_profile_get_file(profile, COSM_TITLE "-AppDF", &pin_file) < 0)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "\""COSM_TITLE"-AppDF\" not defined");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "\""COSM_TITLE"-AppDF\" not defined");
|
||||
|
||||
if (pin_attrs->flags & SC_PKCS15_PIN_FLAG_LOCAL)
|
||||
auth_info->path = pin_file->path;
|
||||
|
@ -444,27 +444,27 @@ cosm_create_pin(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
if (pin_attrs->flags & SC_PKCS15_PIN_FLAG_SO_PIN) {
|
||||
if (pin_attrs->flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN) {
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "SOPIN unblocking is not supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "SOPIN unblocking is not supported");
|
||||
}
|
||||
else {
|
||||
if (pin_attrs->reference != 4)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid SOPIN reference");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid SOPIN reference");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (pin_attrs->flags & SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN) {
|
||||
if (pin_attrs->reference != 0x84)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid User PUK reference");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid User PUK reference");
|
||||
}
|
||||
else {
|
||||
if (pin_attrs->reference != 0x81)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid User PIN reference");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_PIN_REFERENCE, "Invalid User PIN reference");
|
||||
}
|
||||
}
|
||||
|
||||
if (pin && pin_len) {
|
||||
rv = cosm_update_pin(profile, p15card, auth_info, pin, pin_len, puk, puk_len);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Update PIN failed");
|
||||
LOG_TEST_RET(ctx, rv, "Update PIN failed");
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN(ctx, rv);
|
||||
|
@ -583,7 +583,7 @@ cosm_get_temporary_public_key_file(struct sc_card *card,
|
|||
rv = sc_file_add_acl_entry(file, SC_AC_OP_EXTERNAL_AUTHENTICATE, SC_AC_NONE, 0);
|
||||
if (rv < 0)
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to add ACL entry to the temporary public key file");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to add ACL entry to the temporary public key file");
|
||||
|
||||
*pubkey_file = file;
|
||||
|
||||
|
@ -606,31 +606,31 @@ cosm_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Generate key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Generate key failed: RSA only supported");
|
||||
|
||||
path = key_info->path;
|
||||
path.len -= 2;
|
||||
|
||||
rv = sc_select_file(p15card->card, &path, &tmpf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot generate key: failed to select private object DF");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot generate key: failed to select private object DF");
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, tmpf, SC_AC_OP_CRYPTO);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot generate key: 'CRYPTO' authentication failed");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot generate key: 'CRYPTO' authentication failed");
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, tmpf, SC_AC_OP_CREATE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot generate key: 'CREATE' authentication failed");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot generate key: 'CREATE' authentication failed");
|
||||
|
||||
sc_file_free(tmpf);
|
||||
|
||||
rv = sc_select_file(p15card->card, &key_info->path, &prkf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Failed to generate key: cannot select private key file");
|
||||
LOG_TEST_RET(ctx, rv, "Failed to generate key: cannot select private key file");
|
||||
|
||||
/* In the private key DF create the temporary public RSA file. */
|
||||
rv = cosm_get_temporary_public_key_file(p15card->card, prkf, &tmpf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Error while getting temporary public key file");
|
||||
LOG_TEST_RET(ctx, rv, "Error while getting temporary public key file");
|
||||
|
||||
rv = sc_pkcs15init_create_file(profile, p15card, tmpf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_generate_key() failed to create temporary public key EF");
|
||||
LOG_TEST_RET(ctx, rv, "cosm_generate_key() failed to create temporary public key EF");
|
||||
|
||||
memset(&args, 0, sizeof(args));
|
||||
args.id_prv = prkf->id;
|
||||
|
@ -640,23 +640,23 @@ cosm_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
args.pubkey_len = key_info->modulus_length / 8;
|
||||
args.pubkey = malloc(key_info->modulus_length / 8);
|
||||
if (!args.pubkey)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate pubkey");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate pubkey");
|
||||
|
||||
rv = sc_card_ctl(p15card->card, SC_CARDCTL_OBERTHUR_GENERATE_KEY, &args);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "cosm_generate_key() CARDCTL_OBERTHUR_GENERATE_KEY failed");
|
||||
LOG_TEST_RET(ctx, rv, "cosm_generate_key() CARDCTL_OBERTHUR_GENERATE_KEY failed");
|
||||
|
||||
/* extract public key */
|
||||
pubkey->algorithm = SC_ALGORITHM_RSA;
|
||||
pubkey->u.rsa.modulus.len = key_info->modulus_length / 8;
|
||||
pubkey->u.rsa.modulus.data = malloc(key_info->modulus_length / 8);
|
||||
if (!pubkey->u.rsa.modulus.data)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate modulus buf");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate modulus buf");
|
||||
|
||||
/* FIXME and if the exponent length is not 3? */
|
||||
pubkey->u.rsa.exponent.len = 3;
|
||||
pubkey->u.rsa.exponent.data = malloc(3);
|
||||
if (!pubkey->u.rsa.exponent.data)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate exponent buf");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_OUT_OF_MEMORY, "cosm_generate_key() cannot allocate exponent buf");
|
||||
memcpy(pubkey->u.rsa.exponent.data, "\x01\x00\x01", 3);
|
||||
memcpy(pubkey->u.rsa.modulus.data, args.pubkey, args.pubkey_len);
|
||||
|
||||
|
@ -687,13 +687,13 @@ cosm_create_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Create key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Create key failed: RSA only supported");
|
||||
|
||||
sc_log(ctx, "create private key ID:%s", sc_pkcs15_print_id(&key_info->id));
|
||||
/* Here, the path of private key file should be defined.
|
||||
* Nevertheless, we need to instantiate private key to get the ACLs. */
|
||||
rv = cosm_new_file(profile, p15card->card, SC_PKCS15_TYPE_PRKEY_RSA, key_info->key_reference, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot create key: failed to allocate new key object");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot create key: failed to allocate new key object");
|
||||
|
||||
file->size = key_info->modulus_length;
|
||||
memcpy(&file->path, &key_info->path, sizeof(file->path));
|
||||
|
@ -739,16 +739,16 @@ cosm_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA || prkey->algorithm != SC_ALGORITHM_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Store key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Store key failed: RSA only supported");
|
||||
|
||||
sc_log(ctx, "store key with ID:%s and path:%s", sc_pkcs15_print_id(&key_info->id),
|
||||
sc_print_path(&key_info->path));
|
||||
|
||||
rv = sc_select_file(p15card->card, &key_info->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot store key: select key file failed");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot store key: select key file failed");
|
||||
|
||||
rv = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "No authorisation to store private key");
|
||||
LOG_TEST_RET(ctx, rv, "No authorisation to store private key");
|
||||
|
||||
if (key_info->id.len > sizeof(update_info.id))
|
||||
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
|
||||
|
@ -761,7 +761,7 @@ cosm_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
memcpy(update_info.id, key_info->id.value, update_info.id_len);
|
||||
|
||||
rv = sc_card_ctl(p15card->card, SC_CARDCTL_OBERTHUR_UPDATE_KEY, &update_info);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, rv, "Cannot update private key");
|
||||
LOG_TEST_RET(ctx, rv, "Cannot update private key");
|
||||
|
||||
sc_file_free(file);
|
||||
|
||||
|
@ -814,7 +814,7 @@ cosm_emu_update_tokeninfo(struct sc_profile *profile, struct sc_pkcs15_card *p15
|
|||
SC_FUNC_CALLED(ctx, 1);
|
||||
|
||||
if (sc_profile_get_file(profile, COSM_TITLE"-token-info", &file))
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INCONSISTENT_PROFILE, "cannot find "COSM_TITLE"-token-info");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INCONSISTENT_PROFILE, "cannot find "COSM_TITLE"-token-info");
|
||||
|
||||
buf = calloc(1, file->size);
|
||||
if (!buf) {
|
||||
|
|
|
@ -95,18 +95,18 @@ static int rtecp_init(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
card = p15card->card;
|
||||
|
||||
r = sc_profile_get_file(profile, "MF", &file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get MF info failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Get MF info failed");
|
||||
assert(file);
|
||||
r = sc_create_file(card, file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create MF failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Create MF failed");
|
||||
|
||||
r = sc_profile_get_file(profile, "DIR", &file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get DIR file info failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Get DIR file info failed");
|
||||
assert(file);
|
||||
r = sc_create_file(card, file);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, r, "Create DIR file failed");
|
||||
LOG_TEST_RET(card->ctx, r, "Create DIR file failed");
|
||||
|
||||
create_sysdf(profile, card, "Sys-DF");
|
||||
create_sysdf(profile, card, "SysKey-DF");
|
||||
|
@ -212,7 +212,7 @@ static int rtecp_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
r = sc_pkcs15init_fixup_file(profile, p15card, file);
|
||||
if (r < 0)
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot fixup the ACLs of PIN file");
|
||||
LOG_TEST_RET(p15card->card->ctx, r, "Cannot fixup the ACLs of PIN file");
|
||||
|
||||
acl = sc_file_get_acl_entry(file, SC_AC_OP_PIN_RESET);
|
||||
if (acl && acl->method == SC_AC_CHV && acl->key_ref == RTECP_SO_PIN_REF) {
|
||||
|
@ -269,7 +269,7 @@ static int rtecp_select_key_reference(sc_profile_t *profile,
|
|||
return SC_ERROR_TOO_MANY_OBJECTS;
|
||||
|
||||
r = sc_profile_get_file(profile, "PrKey-DF", &df);
|
||||
SC_TEST_RET(p15card->card->ctx, SC_LOG_DEBUG_NORMAL, r, "Get PrKey-DF info failed");
|
||||
LOG_TEST_RET(p15card->card->ctx, r, "Get PrKey-DF info failed");
|
||||
assert(df);
|
||||
key_info->path = df->path;
|
||||
sc_file_free(df);
|
||||
|
@ -341,12 +341,12 @@ static int rtecp_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
}
|
||||
|
||||
r = sc_profile_get_file(profile, "PKCS15-AppDF", &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Get PKCS15-AppDF info failed");
|
||||
LOG_TEST_RET(ctx, r, "Get PKCS15-AppDF info failed");
|
||||
r = sc_file_add_acl_entry(file, SC_AC_OP_CREATE, SC_AC_CHV, auth_id);
|
||||
if (r == SC_SUCCESS)
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_CREATE);
|
||||
sc_file_free(file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Authenticate failed");
|
||||
LOG_TEST_RET(ctx, r, "Authenticate failed");
|
||||
|
||||
file = sc_file_new();
|
||||
if (!file)
|
||||
|
|
|
@ -105,17 +105,17 @@ setcos_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
|
||||
/* Fix up the file's ACLs */
|
||||
r = sc_pkcs15init_fixup_file(profile, p15card, mf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "MF fixup failed");
|
||||
LOG_TEST_RET(ctx, r, "MF fixup failed");
|
||||
|
||||
mf->status = SC_FILE_STATUS_CREATION;
|
||||
r = sc_create_file(p15card->card, mf);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "MF creation failed");
|
||||
LOG_TEST_RET(ctx, r, "MF creation failed");
|
||||
}
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot select MF");
|
||||
LOG_TEST_RET(ctx, r, "Cannot select MF");
|
||||
|
||||
/* Create the global pin file if it doesn't exist yet */
|
||||
r = sc_profile_get_file(profile, "pinfile", &pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot get 'pinfile' from profile");
|
||||
LOG_TEST_RET(ctx, r, "Cannot get 'pinfile' from profile");
|
||||
|
||||
r = sc_select_file(p15card->card, &pinfile->path, NULL);
|
||||
if (r == SC_ERROR_FILE_NOT_FOUND) {
|
||||
|
@ -125,7 +125,7 @@ setcos_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
r = sc_pkcs15init_fixup_file(profile, p15card, pinfile);
|
||||
if (r < 0)
|
||||
sc_file_free(pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Pinfile fixup failed");
|
||||
LOG_TEST_RET(ctx, r, "Pinfile fixup failed");
|
||||
|
||||
/* Set life cycle state to SC_FILE_STATUS_CREATION,
|
||||
* which means that all ACs are ignored. */
|
||||
|
@ -133,10 +133,10 @@ setcos_init_card(sc_profile_t *profile, sc_pkcs15_card_t *p15card)
|
|||
r = sc_create_file(p15card->card, pinfile);
|
||||
if (r < 0)
|
||||
sc_file_free(pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Pinfile creation failed");
|
||||
LOG_TEST_RET(ctx, r, "Pinfile creation failed");
|
||||
}
|
||||
sc_file_free(pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Select pinfile failed");
|
||||
LOG_TEST_RET(ctx, r, "Select pinfile failed");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
}
|
||||
|
@ -153,10 +153,10 @@ setcos_create_dir(sc_profile_t *profile, sc_pkcs15_card_t *p15card, sc_file_t *d
|
|||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
|
||||
r = sc_pkcs15init_fixup_file(profile, p15card, df);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "SetCOS file ACL fixup failed");
|
||||
LOG_TEST_RET(ctx, r, "SetCOS file ACL fixup failed");
|
||||
|
||||
r = sc_create_file(p15card->card, df);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "SetCOS create file failed");
|
||||
LOG_TEST_RET(ctx, r, "SetCOS create file failed");
|
||||
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
}
|
||||
|
@ -209,10 +209,10 @@ setcos_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
|
||||
/* Create the global pin file if it doesn't exist yet */
|
||||
r = sc_profile_get_file(profile, "pinfile", &pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "No 'pinfile' template in profile");
|
||||
LOG_TEST_RET(ctx, r, "No 'pinfile' template in profile");
|
||||
|
||||
r = sc_select_file(p15card->card, &pinfile->path, &pinfile);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot select 'pinfile'");
|
||||
LOG_TEST_RET(ctx, r, "Cannot select 'pinfile'");
|
||||
|
||||
sc_log(ctx, "pinfile->status:%X", pinfile->status);
|
||||
sc_log(ctx, "create PIN with reference:%X, flags:%X, path:%s",
|
||||
|
@ -231,13 +231,13 @@ setcos_create_pin(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
sc_file_t *mf = profile->mf_info->file;
|
||||
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_ACTIVATE_FILE, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot set 'pinfile' into the activated state");
|
||||
LOG_TEST_RET(ctx, r, "Cannot set 'pinfile' into the activated state");
|
||||
|
||||
r = sc_select_file(p15card->card, &mf->path, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot select MF");
|
||||
LOG_TEST_RET(ctx, r, "Cannot select MF");
|
||||
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_ACTIVATE_FILE, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot set MF into the activated state");
|
||||
LOG_TEST_RET(ctx, r, "Cannot set MF into the activated state");
|
||||
}
|
||||
|
||||
sc_file_free(pinfile);
|
||||
|
@ -328,17 +328,17 @@ setcos_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Create key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Create key failed: RSA only supported");
|
||||
|
||||
/* Parameter check */
|
||||
if ( (keybits < 512) || (keybits > 1024) || (keybits & 0x7))
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
|
||||
sc_log(ctx, "create private key ID:%s\n", sc_pkcs15_print_id(&key_info->id));
|
||||
|
||||
/* Get the private key file */
|
||||
r = setcos_new_file(profile, p15card->card, SC_PKCS15_TYPE_PRKEY_RSA, key_info->key_reference, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot get new private key file");
|
||||
LOG_TEST_RET(ctx, r, "Cannot get new private key file");
|
||||
|
||||
/* Take enough room for a 1024 bit key */
|
||||
if (file->size < 512)
|
||||
|
@ -356,15 +356,15 @@ setcos_create_key(sc_profile_t *profile, sc_pkcs15_card_t *p15card,
|
|||
r = sc_select_file(p15card->card, &file->path, NULL);
|
||||
if (!r) {
|
||||
r = sc_pkcs15init_delete_by_path(profile, p15card, &file->path);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Failed to delete private key file");
|
||||
LOG_TEST_RET(ctx, r, "Failed to delete private key file");
|
||||
}
|
||||
else if (r != SC_ERROR_FILE_NOT_FOUND) {
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Select private key file error");
|
||||
LOG_TEST_RET(ctx, r, "Select private key file error");
|
||||
}
|
||||
|
||||
/* Now create the key file */
|
||||
r = sc_pkcs15init_create_file(profile, p15card, file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot create private key file");
|
||||
LOG_TEST_RET(ctx, r, "Cannot create private key file");
|
||||
|
||||
sc_file_free(file);
|
||||
LOG_FUNC_RETURN(ctx, r);
|
||||
|
@ -387,20 +387,20 @@ setcos_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Store key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Store key failed: RSA only supported");
|
||||
|
||||
/* Parameter check */
|
||||
if ( (keybits < 512) || (keybits > 1024) || (keybits & 0x7))
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
|
||||
sc_log(ctx, "store key with ID:%s and path:%s\n", sc_pkcs15_print_id(&key_info->id),
|
||||
sc_print_path(&key_info->path));
|
||||
|
||||
r = sc_select_file(p15card->card, &key_info->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot store key: select key file failed");
|
||||
LOG_TEST_RET(ctx, r, "Cannot store key: select key file failed");
|
||||
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "No authorisation to store private key");
|
||||
LOG_TEST_RET(ctx, r, "No authorisation to store private key");
|
||||
|
||||
/* Fill in data structure */
|
||||
memset(&args, 0, sizeof(args));
|
||||
|
@ -415,7 +415,7 @@ setcos_store_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
/* Generate/store rsa key */
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_GENERATE_STORE_KEY, &args);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Card control 'GENERATE_STORE_KEY' failed");
|
||||
LOG_TEST_RET(ctx, r, "Card control 'GENERATE_STORE_KEY' failed");
|
||||
|
||||
sc_file_free(file);
|
||||
|
||||
|
@ -439,18 +439,18 @@ setcos_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
SC_FUNC_CALLED(ctx, SC_LOG_DEBUG_VERBOSE);
|
||||
if (object->type != SC_PKCS15_TYPE_PRKEY_RSA)
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_NOT_SUPPORTED, "Generate key failed: RSA only supported");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_NOT_SUPPORTED, "Generate key failed: RSA only supported");
|
||||
|
||||
/* Parameter check */
|
||||
if ( (keybits < 512) || (keybits > 1024) || (keybits & 0x7))
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid key length");
|
||||
|
||||
r = sc_select_file(p15card->card, &key_info->path, &file);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot store key: select key file failed");
|
||||
LOG_TEST_RET(ctx, r, "Cannot store key: select key file failed");
|
||||
|
||||
/* Authenticate */
|
||||
r = sc_pkcs15init_authenticate(profile, p15card, file, SC_AC_OP_UPDATE);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "No authorisation to store private key");
|
||||
LOG_TEST_RET(ctx, r, "No authorisation to store private key");
|
||||
|
||||
/* Fill in data structure */
|
||||
memset(&args, 0, sizeof(args));
|
||||
|
@ -461,7 +461,7 @@ setcos_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
/* Generate/store rsa key */
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_GENERATE_STORE_KEY, &args);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Card control 'GENERATE_STORE_KEY' failed");
|
||||
LOG_TEST_RET(ctx, r, "Card control 'GENERATE_STORE_KEY' failed");
|
||||
|
||||
/* Keypair generation -> collect public key info */
|
||||
if (pubkey != NULL) {
|
||||
|
@ -474,7 +474,7 @@ setcos_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
|
||||
/* Get public key modulus */
|
||||
r = sc_select_file(p15card->card, &file->path, NULL);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot get key modulus: select key file failed");
|
||||
LOG_TEST_RET(ctx, r, "Cannot get key modulus: select key file failed");
|
||||
|
||||
data_obj.P1 = 0x01;
|
||||
data_obj.P2 = 0x01;
|
||||
|
@ -482,14 +482,14 @@ setcos_generate_key(struct sc_profile *profile, struct sc_pkcs15_card *p15card,
|
|||
data_obj.DataLen = sizeof(raw_pubkey);
|
||||
|
||||
r = sc_card_ctl(p15card->card, SC_CARDCTL_SETCOS_GETDATA, &data_obj);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, r, "Cannot get key modulus: 'SETCOS_GETDATA' failed");
|
||||
LOG_TEST_RET(ctx, r, "Cannot get key modulus: 'SETCOS_GETDATA' failed");
|
||||
|
||||
keybits = ((raw_pubkey[0] * 256) + raw_pubkey[1]); /* modulus bit length */
|
||||
if (keybits != key_info->modulus_length) {
|
||||
sc_log(ctx,
|
||||
"key-size from card[%"SC_FORMAT_LEN_SIZE_T"u] does not match[%"SC_FORMAT_LEN_SIZE_T"u]\n",
|
||||
keybits, key_info->modulus_length);
|
||||
SC_TEST_RET(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_PKCS15INIT, "Failed to generate key");
|
||||
LOG_TEST_RET(ctx, SC_ERROR_PKCS15INIT, "Failed to generate key");
|
||||
}
|
||||
memcpy (pubkey->u.rsa.modulus.data, &raw_pubkey[2], pubkey->u.rsa.modulus.len);
|
||||
}
|
||||
|
|
|
@ -644,15 +644,15 @@ static int iso_add_sm(struct iso_sm_ctx *sctx, sc_card_t *card,
|
|||
|
||||
if ((apdu->cla & 0x0C) == 0x0C) {
|
||||
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Given APDU is already protected with some secure messaging. Closing own SM context.");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sc_sm_stop(card),
|
||||
LOG_TEST_RET(card->ctx, sc_sm_stop(card),
|
||||
"Could not close ISO SM session");
|
||||
return SC_ERROR_SM_NOT_APPLIED;
|
||||
}
|
||||
|
||||
if (sctx->pre_transmit)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sctx->pre_transmit(card, sctx, apdu),
|
||||
LOG_TEST_RET(card->ctx, sctx->pre_transmit(card, sctx, apdu),
|
||||
"Could not complete SM specific pre transmit routine");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sm_encrypt(sctx, card, apdu, sm_apdu),
|
||||
LOG_TEST_RET(card->ctx, sm_encrypt(sctx, card, apdu, sm_apdu),
|
||||
"Could not encrypt APDU");
|
||||
|
||||
return SC_SUCCESS;
|
||||
|
@ -662,16 +662,16 @@ static int iso_rm_sm(struct iso_sm_ctx *sctx, sc_card_t *card,
|
|||
sc_apdu_t *sm_apdu, sc_apdu_t *apdu)
|
||||
{
|
||||
if (!sctx)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_INVALID_ARGUMENTS,
|
||||
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS,
|
||||
"Invalid SM context. No SM processing performed.");
|
||||
|
||||
if (sctx->post_transmit)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sctx->post_transmit(card, sctx, sm_apdu),
|
||||
LOG_TEST_RET(card->ctx, sctx->post_transmit(card, sctx, sm_apdu),
|
||||
"Could not complete SM specific post transmit routine");
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sm_decrypt(sctx, card, sm_apdu, apdu),
|
||||
LOG_TEST_RET(card->ctx, sm_decrypt(sctx, card, sm_apdu, apdu),
|
||||
"Could not decrypt APDU");
|
||||
if (sctx->finish)
|
||||
SC_TEST_RET(card->ctx, SC_LOG_DEBUG_NORMAL, sctx->finish(card, sctx, apdu),
|
||||
LOG_TEST_RET(card->ctx, sctx->finish(card, sctx, apdu),
|
||||
"Could not complete SM specific post transmit routine");
|
||||
|
||||
return SC_SUCCESS;
|
||||
|
|
Loading…
Reference in New Issue