dump data with sc_debug_hex and sc_log_hex

This commit is contained in:
Frank Morgner 2017-11-13 15:11:58 +01:00
parent 9468ce7f89
commit 8de544653c
16 changed files with 93 additions and 151 deletions

View File

@ -468,7 +468,7 @@ sc_get_response(struct sc_card *card, struct sc_apdu *apdu, size_t olen)
if (rv < 0) {
#ifdef ENABLE_SM
if (resp_len) {
sc_log(ctx, "SM response data %s", sc_dump_hex(resp, resp_len));
sc_log_hex(ctx, "SM response data", resp, resp_len);
sc_sm_update_apdu_response(card, resp, resp_len, rv, apdu);
}
#endif

View File

@ -413,7 +413,7 @@ authentic_match_card(struct sc_card *card)
struct sc_context *ctx = card->ctx;
int i;
sc_log(ctx, "try to match card with ATR %s", sc_dump_hex(card->atr.value, card->atr.len));
sc_log_hex(ctx, "try to match card with ATR", card->atr.value, card->atr.len);
i = _sc_match_atr(card, authentic_known_atrs, &card->type);
if (i < 0) {
sc_log(ctx, "card not matched");
@ -1041,9 +1041,7 @@ authentic_process_fci(struct sc_card *card, struct sc_file *file,
LOG_TEST_RET(ctx, rv, "ISO parse FCI failed");
if (!file->sec_attr_len) {
sc_log(ctx,
"ACLs not found in data(%"SC_FORMAT_LEN_SIZE_T"u) %s",
buflen, sc_dump_hex(buf, buflen));
sc_log_hex(ctx, "ACLs not found in data", buf, buflen);
sc_log(ctx, "Path:%s; Type:%X; PathType:%X", sc_print_path(&file->path), file->type, file->path.type);
if (file->path.type == SC_PATH_TYPE_DF_NAME || file->type == SC_FILE_TYPE_DF) {
file->type = SC_FILE_TYPE_DF;
@ -1053,8 +1051,7 @@ authentic_process_fci(struct sc_card *card, struct sc_file *file,
}
}
sc_log(ctx, "ACL data(%"SC_FORMAT_LEN_SIZE_T"u):%s", file->sec_attr_len,
sc_dump_hex(file->sec_attr, file->sec_attr_len));
sc_log_hex(ctx, "ACL data", file->sec_attr, file->sec_attr_len);
for (ii = 0; ii < file->sec_attr_len / 2; ii++) {
unsigned char op = file->type == SC_FILE_TYPE_DF ? ops_DF[ii] : ops_EF[ii];
unsigned char acl = *(file->sec_attr + ii*2);
@ -1908,7 +1905,7 @@ authentic_manage_sdo_encode(struct sc_card *card, struct sc_authentic_sdo *sdo,
free(data);
sc_log(ctx, "encoded SDO operation data %s", sc_dump_hex(*out, *out_len));
sc_log_hex(ctx, "encoded SDO operation data", *out, *out_len);
LOG_FUNC_RETURN(ctx, rv);
}

View File

@ -645,8 +645,7 @@ static int dnie_get_serialnr(sc_card_t * card, sc_serial_number_t * serial)
/* if serial number is cached, use it */
if (card->serialnr.len) {
memcpy(serial, &card->serialnr, sizeof(*serial));
sc_log(card->ctx, "Serial Number (cached): '%s'",
sc_dump_hex(serial->value, serial->len));
sc_log_hex(card->ctx, "Serial Number (cached)", serial->value, serial->len);
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
}
/* not cached, retrieve it by mean of an APDU */
@ -672,8 +671,7 @@ static int dnie_get_serialnr(sc_card_t * card, sc_serial_number_t * serial)
*/
/* copy and return serial number */
memcpy(serial, &card->serialnr, sizeof(*serial));
sc_log(card->ctx, "Serial Number (apdu): '%s'",
sc_dump_hex(serial->value, serial->len));
sc_log_hex(card->ctx, "Serial Number (apdu)", serial->value, serial->len);
LOG_FUNC_RETURN(card->ctx, SC_SUCCESS);
}
@ -962,13 +960,8 @@ static u8 *dnie_uncompress(sc_card_t * card, u8 * from, size_t *len)
}
/* Done; update buffer len and return pt to uncompressed data */
*len = uncompressed;
sc_log(card->ctx, "Compressed data:\n%s\n",
sc_dump_hex(from + 8, compressed));
sc_log(card->ctx,
"Uncompress() done. Before:'%"SC_FORMAT_LEN_SIZE_T"u' After: '%"SC_FORMAT_LEN_SIZE_T"u'",
compressed, uncompressed);
sc_log(card->ctx, "Uncompressed data:\n%s\n",
sc_dump_hex(upt, uncompressed));
sc_log_hex(card->ctx, "Compressed data", from + 8, compressed);
sc_log_hex(card->ctx, "Uncompressed data", upt, uncompressed);
compress_exit:
#endif
@ -1259,18 +1252,18 @@ static int dnie_select_file(struct sc_card *card,
*/
if (in_path->len != 2)
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "select_file(ID): %s", sc_dump_hex(in_path->value, in_path->len));
sc_log_hex(ctx, "select_file(ID)", in_path->value, in_path->len);
res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 0, file_out);
break;
case SC_PATH_TYPE_DF_NAME:
sc_log(ctx, "select_file(NAME): %s", sc_dump_hex(in_path->value, in_path->len));
sc_log_hex(ctx, "select_file(NAME)", in_path->value, in_path->len);
res = dnie_compose_and_send_apdu(card, in_path->value, in_path->len, 4, file_out);
break;
case SC_PATH_TYPE_PATH:
if ((in_path->len == 0) || ((in_path->len & 1) != 0)) /* not divisible by 2 */
LOG_FUNC_RETURN(ctx, SC_ERROR_INVALID_ARGUMENTS);
sc_log(ctx, "select_file(PATH): requested:%s ", sc_dump_hex(in_path->value, in_path->len));
sc_log_hex(ctx, "select_file(PATH): requested", in_path->value, in_path->len);
/* convert to SC_PATH_TYPE_FILE_ID */
res = sc_lock(card); /* lock to ensure path traversal */
@ -1278,7 +1271,7 @@ static int dnie_select_file(struct sc_card *card,
if (memcmp(in_path->value, "\x3F\x00", 2) == 0) {
/* if MF, use the name as path */
strcpy((char *)tmp_path, DNIE_MF_NAME);
sc_log(ctx, "select_file(NAME): requested:%s ", sc_dump_hex(tmp_path, sizeof(DNIE_MF_NAME) - 1));
sc_log_hex(ctx, "select_file(NAME): requested", tmp_path, sizeof(DNIE_MF_NAME) - 1);
res = dnie_compose_and_send_apdu(card, tmp_path, sizeof(DNIE_MF_NAME) - 1, 4, file_out);
if (res != SC_SUCCESS) {
sc_unlock(card);
@ -1689,9 +1682,9 @@ static int dnie_compute_signature(struct sc_card *card,
So just extract 15+20 DigestInfo+Hash info from ASN.1 provided
data and feed them into sign() command
*/
sc_log(card->ctx,
"Compute signature len: '%"SC_FORMAT_LEN_SIZE_T"u' bytes:\n%s\n============================================================",
datalen, sc_dump_hex(data, datalen));
sc_log_hex(card->ctx,
"Compute signature\n============================================================",
data, datalen);
/*INS: 0x2A PERFORM SECURITY OPERATION
* P1: 0x9E Resp: Digital Signature

View File

@ -1868,12 +1868,10 @@ epass2003_process_fci(struct sc_card *card, sc_file_t * file, const u8 * buf, si
tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
if (tag != NULL && taglen > 0 && taglen <= 16) {
char tbuf[128];
memcpy(file->name, tag, taglen);
file->namelen = taglen;
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, file->name, file->namelen, tbuf, sizeof(tbuf));
sc_log(ctx, "File name: %s", tbuf);
sc_log_hex(ctx, "File name", file->name, file->namelen);
if (!file->type)
file->type = SC_FILE_TYPE_DF;
}

View File

@ -902,7 +902,7 @@ static int gids_read_public_key (struct sc_card *card , unsigned int algorithm,
}
if (response && responselen)
sc_log(card->ctx, "encoded public key: %s", sc_dump_hex(*response, *responselen));
sc_log_hex(card->ctx, "encoded public key", *response, *responselen);
return SC_SUCCESS;
}

View File

@ -1527,13 +1527,8 @@ gpk_pkfile_load(sc_card_t *card, struct sc_cardctl_gpk_pkload *args)
return SC_ERROR_INTERNAL;
if (0) {
char buf[2048];
sc_hex_dump(card->ctx, SC_LOG_DEBUG_NORMAL,
args->data, args->datalen,
buf, sizeof(buf));
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Sending %d bytes (cleartext):\n%s",
args->datalen, buf);
sc_log_hex(card->ctx, "Sending (cleartext)",
args->data, args->datalen);
}
memset(&apdu, 0, sizeof(apdu));

View File

@ -157,7 +157,7 @@ iasecc_chv_cache_verified(struct sc_card *card, struct sc_pin_cmd_data *pin_cmd)
else
memset(pin_status->sha1, 0, SHA_DIGEST_LENGTH);
sc_log(ctx, "iasecc_chv_cache_verified() sha1(PIN): %s", sc_dump_hex(pin_status->sha1, SHA_DIGEST_LENGTH));
sc_log_hex(ctx, "iasecc_chv_cache_verified() sha1(PIN)", pin_status->sha1, SHA_DIGEST_LENGTH);
if (!current) {
if (!checked_pins) {
@ -219,7 +219,7 @@ iasecc_chv_cache_is_verified(struct sc_card *card, struct sc_pin_cmd_data *pin_c
SHA1(pin_cmd->pin1.data, pin_cmd->pin1.len, data_sha1);
else
memset(data_sha1, 0, SHA_DIGEST_LENGTH);
sc_log(ctx, "data_sha1: %s", sc_dump_hex(data_sha1, SHA_DIGEST_LENGTH));
sc_log_hex(ctx, "data_sha1: %s", data_sha1, SHA_DIGEST_LENGTH);
for(current = checked_pins; current; current = current->next)
if (current->reference == pin_cmd->pin_reference)
@ -345,7 +345,6 @@ iasecc_match_card(struct sc_card *card)
struct sc_context *ctx = card->ctx;
int i;
sc_log(ctx, "iasecc_match_card(%s) called", sc_dump_hex(card->atr.value, card->atr.len));
i = _sc_match_atr(card, iasecc_known_atrs, &card->type);
if (i < 0) {
sc_log(ctx, "card not matched");
@ -457,7 +456,7 @@ iasecc_oberthur_match(struct sc_card *card)
if (*hist != 0x80 || ((*(hist+1)&0xF0) != 0xF0))
LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
sc_log(ctx, "AID in historical_bytes '%s'", sc_dump_hex(hist + 2, *(hist+1) & 0x0F));
sc_log_hex(ctx, "AID in historical_bytes", hist + 2, *(hist+1) & 0x0F);
if (memcmp(hist + 2, OberthurIASECC_AID.value, *(hist+1) & 0x0F))
LOG_FUNC_RETURN(ctx, SC_ERROR_RECORD_NOT_FOUND);

View File

@ -152,7 +152,7 @@ static struct df_info_s *get_df_info(sc_card_t * card)
assert(!priv->is_ef);
if (!priv->curpathlen) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "no current path to find the df_info\n");
sc_log(ctx, "no current path to find the df_info\n");
return NULL;
}
@ -165,7 +165,7 @@ static struct df_info_s *get_df_info(sc_card_t * card)
/* Not found, create it. */
dfi = calloc(1, sizeof *dfi);
if (!dfi) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "out of memory while allocating df_info\n");
sc_log(ctx, "out of memory while allocating df_info\n");
return NULL;
}
dfi->pathlen = priv->curpathlen;
@ -253,11 +253,11 @@ static int mcrd_set_decipher_key_ref(sc_card_t * card, int key_reference)
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!");
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"authkey reference 0x%02x%02x\n",
keyref_data[9], keyref_data[10]);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"signkey reference 0x%02x%02x\n",
keyref_data[19], keyref_data[20]);
@ -474,12 +474,12 @@ static int load_special_files(sc_card_t * card)
}
}
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "new EF_Rule file loaded (%d records)\n", recno - 1);
sc_log(ctx, "new EF_Rule file loaded (%d records)\n", recno - 1);
/* Read the KeyD file. Note that we bypass our cache here. */
r = select_part(card, MCRD_SEL_EF, EF_KeyD, NULL);
if (r == SC_ERROR_FILE_NOT_FOUND) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "no EF_KeyD file available\n");
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");
@ -505,7 +505,7 @@ static int load_special_files(sc_card_t * card)
}
}
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "new EF_KeyD file loaded (%d records)\n", recno - 1);
sc_log(ctx, "new EF_KeyD file loaded (%d records)\n", recno - 1);
/* FIXME: Do we need to restore the current DF? I guess it is
not required, but we could try to do so by selecting 3fff? */
return 0;
@ -522,7 +522,6 @@ static int get_se_num_from_keyd(sc_card_t * card, unsigned short fid,
struct keyd_record_s *keyd;
size_t len, taglen;
const u8 *p, *tag;
char dbgbuf[2048];
u8 fidbuf[2];
fidbuf[0] = (fid >> 8) & 0xFF;
@ -530,7 +529,7 @@ static int get_se_num_from_keyd(sc_card_t * card, unsigned short fid,
dfi = get_df_info(card);
if (!dfi || !dfi->keyd_file) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "EF_keyD not loaded\n");
sc_log(ctx, "EF_keyD not loaded\n");
return -1;
}
@ -538,9 +537,8 @@ static int get_se_num_from_keyd(sc_card_t * card, unsigned short fid,
p = keyd->data;
len = keyd->datalen;
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL,
p, len, dbgbuf, sizeof dbgbuf);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "keyd no %d:\n%s", keyd->recno, dbgbuf);
sc_log(ctx, "keyd no %d", keyd->recno);
sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, "", p, len);
tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
if (!tag || taglen != 4 ||
@ -563,7 +561,7 @@ static int get_se_num_from_keyd(sc_card_t * card, unsigned short fid,
continue;
return *tag; /* found. */
}
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "EF_keyD for %04hx not found\n", fid);
sc_log(ctx, "EF_keyD for %04hx not found\n", fid);
return -1;
}
@ -582,7 +580,7 @@ static void process_arr(sc_card_t * card, sc_file_t * file,
/* Currently we support only the short for. */
if (buflen != 1) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "can't handle long ARRs\n");
sc_log(ctx, "can't handle long ARRs\n");
return;
}
@ -590,13 +588,12 @@ static void process_arr(sc_card_t * card, sc_file_t * file,
for (rule = dfi ? dfi->rule_file : NULL; rule && rule->recno != *buf;
rule = rule->next) ;
if (!rule) {
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "referenced EF_rule record %d not found\n", *buf);
sc_log(ctx, "referenced EF_rule record %d not found\n", *buf);
return;
}
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL,
rule->data, rule->datalen, dbgbuf, sizeof dbgbuf);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_hex_dump(rule->data, rule->datalen, dbgbuf, sizeof dbgbuf);
sc_log(ctx,
"rule for record %d:\n%s", *buf, dbgbuf);
p = rule->data;
@ -613,11 +610,11 @@ static void process_arr(sc_card_t * card, sc_file_t * file,
if (tag == 0x80 && taglen != 1) {
skip = 1;
} else if (tag == 0x80) { /* AM byte. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " AM_DO: %02x\n", *p);
sc_log(ctx, " AM_DO: %02x\n", *p);
skip = 0;
} else if (tag >= 0x81 && tag <= 0x8f) { /* Cmd description */
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, p, taglen, dbgbuf, sizeof dbgbuf);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " AM_DO: cmd[%s%s%s%s] %s",
sc_hex_dump(p, taglen, dbgbuf, sizeof dbgbuf);
sc_log(ctx, " AM_DO: cmd[%s%s%s%s] %s",
(tag & 8) ? "C" : "",
(tag & 4) ? "I" : "",
(tag & 2) ? "1" : "",
@ -626,33 +623,32 @@ static void process_arr(sc_card_t * card, sc_file_t * file,
} else if (tag == 0x9C) { /* Proprietary state machine descrip. */
skip = 1;
} else if (!skip) {
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, p, taglen, dbgbuf, sizeof dbgbuf);
switch (tag) {
case 0x90: /* Always */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: always\n");
sc_log(ctx, " SC: always\n");
break;
case 0x97: /* Never */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: never\n");
sc_log(ctx, " SC: never\n");
break;
case 0xA4: /* Authentication, value is a CRT. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: auth %s", dbgbuf);
sc_log_hex(ctx, " SC: auth", p, taglen);
break;
case 0xB4:
case 0xB6:
case 0xB8: /* Cmd or resp with SM, value is a CRT. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: cmd/resp %s", dbgbuf);
sc_log_hex(ctx, " SC: cmd/resp", p, taglen);
break;
case 0x9E: /* Security Condition byte. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: condition %s", dbgbuf);
sc_log_hex(ctx, " SC: condition", p, taglen);
break;
case 0xA0: /* OR template. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: OR\n");
sc_log(ctx, " SC: OR\n");
break;
case 0xAF: /* AND template. */
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " SC: AND\n");
sc_log(ctx, " SC: AND\n");
break;
}
}
@ -670,13 +666,13 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
const u8 *tag = NULL, *p = buf;
int bad_fde = 0;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "processing FCI bytes\n");
sc_log(ctx, "processing FCI bytes\n");
/* File identifier. */
tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
if (tag != NULL && taglen == 2) {
file->id = (tag[0] << 8) | tag[1];
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" file identifier: 0x%02X%02X\n", tag[0], tag[1]);
}
/* Number of data bytes in the file including structural information. */
@ -691,7 +687,7 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
}
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" bytes in file: %d\n", bytes);
file->size = bytes;
}
@ -699,7 +695,7 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
tag = sc_asn1_find_tag(ctx, p, len, 0x80, &taglen);
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" bytes in file: %d\n", bytes);
file->size = bytes;
}
@ -714,7 +710,7 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
const char *type;
file->shareable = byte & 0x40 ? 1 : 0;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" shareable: %s\n",
(byte & 0x40) ? "yes" : "no");
file->ef_structure = byte & 0x07;
@ -735,9 +731,9 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
type = "unknown";
break;
}
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" type: %s\n", type);
sc_debug(ctx, SC_LOG_DEBUG_NORMAL,
sc_log(ctx,
" EF structure: %d\n", byte & 0x07);
}
}
@ -759,7 +755,7 @@ static void process_fcp(sc_card_t * card, sc_file_t * file,
name[i] = '?';
}
name[taglen] = 0;
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, " file name: %s\n", name);
sc_log(ctx, " file name: %s\n", name);
}
/* Proprietary information. */
@ -875,7 +871,7 @@ select_part(sc_card_t * card, u8 kind, unsigned short int fid,
unsigned int len;
int r;
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"select_part (0x%04X, kind=%u)\n", fid, kind);
if (fid == MFID) {
@ -1106,7 +1102,7 @@ mcrd_select_file(sc_card_t * card, const sc_path_t * path, sc_file_t ** file)
linep += 4;
}
strcpy(linep, "\n");
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "%s", line);
sc_log(card->ctx, "%s", line);
}
if (path->type == SC_PATH_TYPE_DF_NAME) {
@ -1169,7 +1165,7 @@ mcrd_select_file(sc_card_t * card, const sc_path_t * path, sc_file_t ** file)
linep += 4;
}
strcpy(linep, "\n");
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "%s", line);
sc_log(card->ctx, "%s", line);
}
return r;
}
@ -1227,7 +1223,7 @@ static int mcrd_set_security_env(sc_card_t * card,
switch (env->operation) {
case SC_SEC_OPERATION_DECIPHER:
case SC_SEC_OPERATION_DERIVE:
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"Using keyref %d to dechiper\n",
env->key_ref[0]);
mcrd_restore_se(card, 6);
@ -1236,7 +1232,7 @@ static int mcrd_set_security_env(sc_card_t * card,
mcrd_set_decipher_key_ref(card, env->key_ref[0]);
break;
case SC_SEC_OPERATION_SIGN:
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Using keyref %d to sign\n",
sc_log(card->ctx, "Using keyref %d to sign\n",
env->key_ref[0]);
mcrd_restore_se(card, 1);
break;
@ -1249,7 +1245,7 @@ static int mcrd_set_security_env(sc_card_t * card,
if (card->type == SC_CARD_TYPE_MCRD_DTRUST
|| card->type == SC_CARD_TYPE_MCRD_GENERIC) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Using SC_CARD_TYPE_MCRD_DTRUST\n");
sc_log(card->ctx, "Using SC_CARD_TYPE_MCRD_DTRUST\n");
/* some sanity checks */
if (env->flags & SC_SEC_ENV_ALG_PRESENT) {
if (env->algorithm != SC_ALGORITHM_RSA)
@ -1261,7 +1257,7 @@ static int mcrd_set_security_env(sc_card_t * card,
switch (env->operation) {
case SC_SEC_OPERATION_DECIPHER:
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"Using keyref %d to dechiper\n",
env->key_ref[0]);
mcrd_delete_ref_to_authkey(card);
@ -1269,7 +1265,7 @@ static int mcrd_set_security_env(sc_card_t * card,
mcrd_set_decipher_key_ref(card, env->key_ref[0]);
break;
case SC_SEC_OPERATION_SIGN:
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "Using keyref %d to sign\n",
sc_log(card->ctx, "Using keyref %d to sign\n",
env->key_ref[0]);
break;
default:
@ -1342,13 +1338,13 @@ static int mcrd_set_security_env(sc_card_t * card,
if (apdu.datalen != 0) {
r = sc_transmit_apdu(card, &apdu);
if (r) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"%s: APDU transmit failed", sc_strerror(r));
goto err;
}
r = sc_check_sw(card, apdu.sw1, apdu.sw2);
if (r) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"%s: Card returned error", sc_strerror(r));
goto err;
}
@ -1384,7 +1380,7 @@ static int mcrd_compute_signature(sc_card_t * card,
if (datalen > 255)
SC_FUNC_RETURN(card->ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_ARGUMENTS);
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
sc_log(card->ctx,
"Will compute signature (%d) for %"SC_FORMAT_LEN_SIZE_T"u (0x%02"SC_FORMAT_LEN_SIZE_T"x) bytes using key %d algorithm %d flags %d\n",
env->operation, datalen, datalen, env->key_ref[0],
env->algorithm, env->algorithm_flags);
@ -1511,7 +1507,7 @@ static int mcrd_pin_cmd(sc_card_t * card, struct sc_pin_cmd_data *data,
if (card->type == SC_CARD_TYPE_MCRD_DTRUST
|| card->type == SC_CARD_TYPE_MCRD_GENERIC) {
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL, "modify pin reference for D-Trust\n");
sc_log(card->ctx, "modify pin reference for D-Trust\n");
if (data->pin_reference == 0x02)
data->pin_reference = data->pin_reference | 0x80;
}

View File

@ -2023,16 +2023,10 @@ write_publickey (struct sc_card *card, unsigned int offset,
struct sc_pkcs15_pubkey_rsa key;
int ii, rv;
size_t len = 0, der_size = 0;
char debug_buf[2048];
LOG_FUNC_CALLED(card->ctx);
debug_buf[0] = 0;
sc_hex_dump(card->ctx, SC_LOG_DEBUG_NORMAL,
buf, count, debug_buf, sizeof(debug_buf));
sc_log(card->ctx,
"write_publickey in %"SC_FORMAT_LEN_SIZE_T"u bytes :\n%s",
count, debug_buf);
sc_log_hex(card->ctx, "write_publickey", buf, count);
if (1+offset > sizeof(rsa_der))
LOG_TEST_RET(card->ctx, SC_ERROR_INVALID_ARGUMENTS, "Invalid offset value");
@ -2121,7 +2115,6 @@ auth_read_binary(struct sc_card *card, unsigned int offset,
unsigned char *buf, size_t count, unsigned long flags)
{
int rv;
char debug_buf[2048];
struct sc_pkcs15_bignum bn[2];
unsigned char *out = NULL;
bn[0].data = NULL;
@ -2183,12 +2176,7 @@ auth_read_binary(struct sc_card *card, unsigned int offset,
rv = out_len - offset > count ? count : out_len - offset;
memcpy(buf, out + offset, rv);
debug_buf[0] = 0;
sc_hex_dump(card->ctx, SC_LOG_DEBUG_NORMAL,
buf, rv, debug_buf, sizeof(debug_buf));
sc_log(card->ctx,
"write_publickey in %"SC_FORMAT_LEN_SIZE_T"u bytes :\n%s",
count, debug_buf);
sc_log_hex(card->ctx, "write_publickey", buf, rv);
}
}
else {

View File

@ -361,13 +361,7 @@ static int westcos_process_fci(sc_card_t * card, sc_file_t * file,
if (tag != NULL && taglen > 0 && taglen <= 16) {
memcpy(file->name, tag, taglen);
file->namelen = taglen;
{
char tbuf[128];
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL,
file->name, file->namelen, tbuf, sizeof(tbuf));
sc_debug(card->ctx, SC_LOG_DEBUG_NORMAL,
" File name: %s\n", tbuf);
}
sc_log_hex(card->ctx, " File name", file->name, file->namelen);
}
if (file->type == SC_FILE_TYPE_DF) {
tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);

View File

@ -83,7 +83,7 @@ static void cwa_trace_apdu(sc_card_t * card, sc_apdu_t * apdu, int flag)
return;
if (flag == 0) { /* apdu command */
if (apdu->datalen > 0) { /* apdu data to show */
sc_hex_dump(card->ctx, SC_LOG_DEBUG_NORMAL, apdu->data, apdu->datalen, buf, sizeof(buf));
sc_hex_dump(apdu->data, apdu->datalen, buf, sizeof(buf));
sc_log(card->ctx,
"\nAPDU before encode: ==================================================\nCLA: %02X INS: %02X P1: %02X P2: %02X Lc: %02"SC_FORMAT_LEN_SIZE_T"X Le: %02"SC_FORMAT_LEN_SIZE_T"X DATA: [%5"SC_FORMAT_LEN_SIZE_T"u bytes]\n%s======================================================================\n",
apdu->cla, apdu->ins, apdu->p1, apdu->p2,
@ -95,7 +95,7 @@ static void cwa_trace_apdu(sc_card_t * card, sc_apdu_t * apdu, int flag)
apdu->lc, apdu->le);
}
} else { /* apdu response */
sc_hex_dump(card->ctx, SC_LOG_DEBUG_NORMAL, apdu->resp, apdu->resplen, buf, sizeof(buf));
sc_hex_dump(apdu->resp, apdu->resplen, buf, sizeof(buf));
sc_log(card->ctx,
"\nAPDU response after decode: ==========================================\nSW1: %02X SW2: %02X RESP: [%5"SC_FORMAT_LEN_SIZE_T"u bytes]\n%s======================================================================\n",
apdu->sw1, apdu->sw2, apdu->resplen, buf);

View File

@ -403,13 +403,10 @@ iso7816_process_fci(struct sc_card *card, struct sc_file *file,
tag = sc_asn1_find_tag(ctx, p, len, 0x84, &taglen);
if (tag != NULL && taglen > 0 && taglen <= 16) {
char tbuf[128];
memcpy(file->name, tag, taglen);
file->namelen = taglen;
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, file->name, file->namelen, tbuf, sizeof(tbuf));
sc_log(ctx, " File name: %s", tbuf);
sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, " File name:", file->name, file->namelen);
if (!file->type)
file->type = SC_FILE_TYPE_DF;
}

View File

@ -163,29 +163,25 @@ void _sc_debug_hex(sc_context_t *ctx, int type, const char *file, int line,
if (buf == NULL)
return;
sc_hex_dump(ctx, type, data, len, buf, blen);
sc_hex_dump(data, len, buf, blen);
if (label)
sc_do_log(ctx, type, file, line, func,
"\n%s (%u byte%s):\n%s",
label, (unsigned int) len, len==1?"":"s", buf);
"\n%s (%"SC_FORMAT_LEN_SIZE_T"u byte%s):\n%s",
label, len, len==1?"":"s", buf);
else
sc_do_log(ctx, type, file, line, func,
"%u byte%s:\n%s",
(unsigned int) len, len==1?"":"s", buf);
"%"SC_FORMAT_LEN_SIZE_T"u byte%s:\n%s",
len, len==1?"":"s", buf);
free(buf);
}
/* Although not used, we need this for consistent exports */
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * in, size_t count, char *buf, size_t len)
void sc_hex_dump(const u8 * in, size_t count, char *buf, size_t len)
{
char *p = buf;
int lines = 0;
if (!ctx || ctx->debug < level)
return;
if (buf == NULL || (in == NULL && count != 0)) {
return;
}
@ -219,7 +215,7 @@ void sc_hex_dump(struct sc_context *ctx, int level, const u8 * in, size_t count,
}
}
char *
const char *
sc_dump_hex(const u8 * in, size_t count)
{
static char dump_buf[0x1000];
@ -252,7 +248,7 @@ sc_dump_hex(const u8 * in, size_t count)
return dump_buf;
}
char *
const char *
sc_dump_oid(const struct sc_object_id *oid)
{
static char dump_buf[SC_MAX_OBJECT_ID_OCTETS * 20];

View File

@ -87,6 +87,8 @@ void _sc_log(struct sc_context *ctx, const char *format, ...);
*/
#define sc_debug_hex(ctx, level, label, data, len) \
_sc_debug_hex(ctx, level, __FILE__, __LINE__, __FUNCTION__, label, data, len)
#define sc_log_hex(ctx, label, data, len) \
sc_debug_hex(ctx, SC_LOG_DEBUG_NORMAL, label, data, len)
/**
* @brief Log binary data
*
@ -102,9 +104,9 @@ void _sc_log(struct sc_context *ctx, const char *format, ...);
void _sc_debug_hex(struct sc_context *ctx, int level, const char *file, int line,
const char *func, const char *label, const u8 *data, size_t len);
void sc_hex_dump(struct sc_context *ctx, int level, const u8 * buf, size_t len, char *out, size_t outlen);
char * sc_dump_hex(const u8 * in, size_t count);
char * sc_dump_oid(const struct sc_object_id *oid);
void sc_hex_dump(const u8 *buf, size_t len, char *out, size_t outlen);
const char * sc_dump_hex(const u8 * in, size_t count);
const char * sc_dump_oid(const struct sc_object_id *oid);
#define SC_FUNC_CALLED(ctx, level) do { \
sc_do_log(ctx, level, __FILE__, __LINE__, __FUNCTION__, "called\n"); \
} while (0)

View File

@ -91,24 +91,11 @@ sm_oberthur_diversify_keyset(struct sc_context *ctx, struct sm_info *sm_info,
}
if (!rv && ctx) {
char dump_buf[2048];
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL,
gp_session->card_challenge, sizeof(gp_session->card_challenge), dump_buf, sizeof(dump_buf));
sc_log(ctx, "Card challenge: %s", dump_buf);
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL,
gp_session->host_challenge, sizeof(gp_session->host_challenge), dump_buf, sizeof(dump_buf));
sc_log(ctx, "Host challenge: %s", dump_buf);
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, gp_keyset->enc, sizeof(gp_keyset->enc), dump_buf, sizeof(dump_buf));
sc_log(ctx, "ENC: %s", dump_buf);
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, gp_keyset->mac, sizeof(gp_keyset->mac), dump_buf, sizeof(dump_buf));
sc_log(ctx, "MAC: %s", dump_buf);
sc_hex_dump(ctx, SC_LOG_DEBUG_NORMAL, gp_keyset->kek, sizeof(gp_keyset->kek), dump_buf, sizeof(dump_buf));
sc_log(ctx, "KEK: %s", dump_buf);
sc_log_hex(ctx, "Card challenge", gp_session->card_challenge, sizeof(gp_session->card_challenge));
sc_log_hex(ctx, "Host challenge", gp_session->host_challenge, sizeof(gp_session->host_challenge));
sc_log_hex(ctx, "ENC", gp_keyset->enc, sizeof(gp_keyset->enc));
sc_log_hex(ctx, "MAC", gp_keyset->mac, sizeof(gp_keyset->mac));
sc_log_hex(ctx, "KEK", gp_keyset->kek, sizeof(gp_keyset->kek));
}
return rv;

View File

@ -172,7 +172,7 @@ static void read_dg(sc_card_t *card, unsigned char sfid, const char *dg_str,
sfid, dg_str, sc_strerror(r));
else {
char buf[0x200];
sc_hex_dump(NULL, 0, *dg, *dg_len, buf, sizeof buf);
sc_hex_dump(*dg, *dg_len, buf, sizeof buf);
fprintf(stdout, "Read %s", buf);
}
}