Rename libopensc specific error/debug to sc_error/sc_debug

We should have done this ages ago.


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1392 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
aet 2003-08-25 14:21:18 +00:00
parent f9f8b1f92f
commit 763fc16704
41 changed files with 374 additions and 376 deletions

View File

@ -362,7 +362,7 @@ const u8 *sc_asn1_skip_tag(struct sc_context *ctx, const u8 ** buf, size_t *bufl
return NULL;
len -= (p - *buf); /* header size */
if (taglen > len) {
error(ctx, "too long ASN.1 object (size %d while only %d available)\n",
sc_error(ctx, "too long ASN.1 object (size %d while only %d available)\n",
taglen, len);
return NULL;
}
@ -671,7 +671,7 @@ int asn1_write_element(struct sc_context *ctx, unsigned int tag, const u8 * data
t = tag & 0x1F;
if (t != (tag & SC_ASN1_TAG_MASK)) {
error(ctx, "Long tags not supported\n");
sc_error(ctx, "Long tags not supported\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
switch (tag & SC_ASN1_CLASS_MASK) {
@ -859,7 +859,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry
linep += 2;
}
sprintf((char *) linep, "decoding '%s'\n", entry->name);
debug(ctx, (char *) line);
sc_debug(ctx, (char *) line);
}
switch (entry->type) {
@ -873,7 +873,7 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry
case SC_ASN1_BOOLEAN:
if (parm != NULL) {
if (objlen != 1) {
error(ctx, "invalid ASN.1 object length: %d\n", objlen);
sc_error(ctx, "invalid ASN.1 object length: %d\n", objlen);
r = SC_ERROR_INVALID_ASN1_OBJECT;
} else
*((u8 *) parm) = obj[0] ? 1 : 0;
@ -1011,11 +1011,11 @@ static int asn1_decode_entry(struct sc_context *ctx, struct sc_asn1_entry *entry
r = callback_func(ctx, entry->arg, obj, objlen, depth);
break;
default:
error(ctx, "invalid ASN.1 type: %d\n", entry->type);
sc_error(ctx, "invalid ASN.1 type: %d\n", entry->type);
assert(0);
}
if (r) {
error(ctx, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
sc_error(ctx, "decoding of ASN.1 object '%s' failed: %s\n", entry->name,
sc_strerror(r));
return r;
}
@ -1033,7 +1033,7 @@ static int asn1_decode(struct sc_context *ctx, struct sc_asn1_entry *asn1,
size_t left = len, objlen;
if (ctx->debug >= 3)
debug(ctx, "called, depth %d%s\n", depth, choice ? ", choice" : "");
sc_debug(ctx, "called, depth %d%s\n", depth, choice ? ", choice" : "");
if (left < 2) {
while (asn1->name && (asn1->flags & SC_ASN1_OPTIONAL))
asn1++;
@ -1065,11 +1065,11 @@ static int asn1_decode(struct sc_context *ctx, struct sc_asn1_entry *asn1,
continue;
if (entry->flags & SC_ASN1_OPTIONAL) {
if (ctx->debug >= 3)
debug(ctx, "optional ASN.1 object '%s' not present\n",
sc_debug(ctx, "optional ASN.1 object '%s' not present\n",
entry->name);
continue;
}
error(ctx, "mandatory ASN.1 object '%s' not found\n", entry->name);
sc_error(ctx, "mandatory ASN.1 object '%s' not found\n", entry->name);
if (ctx->debug && left) {
u8 line[128], *linep = line;
size_t i;
@ -1079,7 +1079,7 @@ static int asn1_decode(struct sc_context *ctx, struct sc_asn1_entry *asn1,
sprintf((char *) linep, "%02X ", p[i]);
linep += 3;
}
debug(ctx, "next tag: %s\n", line);
sc_debug(ctx, "next tag: %s\n", line);
}
SC_FUNC_RETURN(ctx, 3, SC_ERROR_ASN1_OBJECT_NOT_FOUND);
}
@ -1136,7 +1136,7 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry
linep += 2;
}
sprintf((char *) linep, "encoding '%s'\n", entry->name);
debug(ctx, (char *) line);
sc_debug(ctx, (char *) line);
}
assert(entry->type == SC_ASN1_NULL || parm != NULL);
@ -1222,11 +1222,11 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry
r = callback_func(ctx, entry->arg, &buf, &buflen, depth);
break;
default:
error(ctx, "invalid ASN.1 type: %d\n", entry->type);
sc_error(ctx, "invalid ASN.1 type: %d\n", entry->type);
assert(0);
}
if (r) {
error(ctx, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
sc_error(ctx, "encoding of ASN.1 object '%s' failed: %s\n", entry->name,
sc_strerror(r));
if (buf)
free(buf);
@ -1251,10 +1251,10 @@ static int asn1_encode_entry(struct sc_context *ctx, const struct sc_asn1_entry
r = asn1_write_element(ctx, entry->tag,
buf, buflen, obj, objlen);
if (r)
error(ctx, "error writing ASN.1 tag and length: %s\n",
sc_error(ctx, "error writing ASN.1 tag and length: %s\n",
sc_strerror(r));
} else {
error(ctx, "cannot encode empty non-optional ASN.1 object");
sc_error(ctx, "cannot encode empty non-optional ASN.1 object");
r = SC_ERROR_INVALID_ASN1_OBJECT;
}
if (buf)
@ -1271,7 +1271,7 @@ static int asn1_encode(struct sc_context *ctx, const struct sc_asn1_entry *asn1,
size_t total = 0, objsize;
if (ctx->debug >= 3)
debug(ctx, "called, depth %d\n", depth);
sc_debug(ctx, "called, depth %d\n", depth);
for (idx = 0; asn1[idx].name != NULL; idx++) {
entry = &asn1[idx];

View File

@ -47,10 +47,10 @@ static int autodetect_class(struct sc_card *card)
int i, r;
if (card->ctx->debug >= 2)
debug(card->ctx, "autodetecting CLA byte\n");
sc_debug(card->ctx, "autodetecting CLA byte\n");
for (i = 0; i < class_count; i++) {
if (card->ctx->debug >= 2)
debug(card->ctx, "trying with 0x%02X\n", classes[i]);
sc_debug(card->ctx, "trying with 0x%02X\n", classes[i]);
apdu.cla = classes[i];
apdu.cse = SC_APDU_CASE_2_SHORT;
apdu.ins = 0xC0;
@ -69,7 +69,7 @@ static int autodetect_class(struct sc_card *card)
if (apdu.sw1 == 0x61)
break;
if (card->ctx->debug >= 2)
debug(card->ctx, "got strange SWs: 0x%02X 0x%02X\n",
sc_debug(card->ctx, "got strange SWs: 0x%02X 0x%02X\n",
apdu.sw1, apdu.sw2);
break;
}
@ -77,22 +77,22 @@ static int autodetect_class(struct sc_card *card)
return -1;
card->cla = classes[i];
if (card->ctx->debug >= 2)
debug(card->ctx, "detected CLA byte as 0x%02X\n", card->cla);
sc_debug(card->ctx, "detected CLA byte as 0x%02X\n", card->cla);
if (apdu.resplen < 2) {
if (card->ctx->debug >= 2)
debug(card->ctx, "SELECT FILE returned %d bytes\n",
sc_debug(card->ctx, "SELECT FILE returned %d bytes\n",
apdu.resplen);
return 0;
}
if (rbuf[0] == 0x6F) {
if (card->ctx->debug >= 2)
debug(card->ctx, "SELECT FILE seems to behave according to ISO 7816-4\n");
sc_debug(card->ctx, "SELECT FILE seems to behave according to ISO 7816-4\n");
return 0;
}
if (rbuf[0] == 0x00 && rbuf[1] == 0x00) {
struct sc_card_driver *drv;
if (card->ctx->debug >= 2)
debug(card->ctx, "SELECT FILE seems to return Schlumberger 'flex stuff\n");
sc_debug(card->ctx, "SELECT FILE seems to return Schlumberger 'flex stuff\n");
drv = sc_get_flex_driver();
card->ops->select_file = drv->ops->select_file;
return 0;
@ -108,7 +108,7 @@ static int default_init(struct sc_card *card)
card->drv_data = NULL;
r = autodetect_class(card);
if (r) {
error(card->ctx, "unable to determine the right class byte\n");
sc_error(card->ctx, "unable to determine the right class byte\n");
return SC_ERROR_INVALID_CARD;
}

View File

@ -96,10 +96,10 @@ static int emv_match_card(struct sc_card *card)
if (tx2[i] != -1)
linep += sprintf(linep, "T%c2 = 0x%02X ", 'A' + i, tx2[i]);
if (card->ctx->debug >= 4) {
debug(card->ctx, "ATR parse: %s\n", line);
sc_debug(card->ctx, "ATR parse: %s\n", line);
if (hbcount) {
sc_hex_dump(card->ctx, hist_bytes, hbcount, line, sizeof(line));
debug(card->ctx, "historic bytes:\n%s", line);
sc_debug(card->ctx, "historic bytes:\n%s", line);
}
}
if ((t0 & 0xF0) != 0x60)

View File

@ -174,13 +174,13 @@ static int etoken_check_sw(struct sc_card *card, int sw1, int sw2)
for (i = 0; i < err_count; i++) {
if (etoken_errors[i].SWs == ((sw1 << 8) | sw2)) {
if ( etoken_errors[i].errorstr )
error(card->ctx, "%s\n",
sc_error(card->ctx, "%s\n",
etoken_errors[i].errorstr);
return etoken_errors[i].errorno;
}
}
error(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
sc_error(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
return SC_ERROR_CARD_CMD_FAILED;
}
@ -285,22 +285,22 @@ get_next_part:
SC_TEST_RET(card->ctx, r, "DIRECTORY command returned error");
if (apdu.resplen > 256) {
error(card->ctx, "directory listing > 256 bytes, cutting");
sc_error(card->ctx, "directory listing > 256 bytes, cutting");
r = 256;
}
for (i=0; i < apdu.resplen;) {
/* is there a file informatin block (0x6f) ? */
if (rbuf[i] != 0x6f) {
error(card->ctx, "directory listing not parseable");
sc_error(card->ctx, "directory listing not parseable");
break;
}
if (i+1 > apdu.resplen) {
error(card->ctx, "directory listing short");
sc_error(card->ctx, "directory listing short");
break;
}
len = rbuf[i+1];
if (i + 1 + len > apdu.resplen) {
error(card->ctx, "directory listing short");
sc_error(card->ctx, "directory listing short");
break;
}
fid = etoken_extract_fid(&rbuf[i+2], len);
@ -437,7 +437,7 @@ static int etoken_create_file(struct sc_card *card, struct sc_file *file)
"%02X", file->path.value[n]);
}
debug(card->ctx, "etoken_create_file(%s)\n", pbuf);
sc_debug(card->ctx, "etoken_create_file(%s)\n", pbuf);
}
if (file->type_attr_len == 0) {
@ -498,7 +498,7 @@ static int etoken_create_file(struct sc_card *card, struct sc_file *file)
byte = acl_to_byte(
sc_file_get_acl_entry(file, idx[i]));
if (byte < 0) {
error(card->ctx, "Invalid ACL\n");
sc_error(card->ctx, "Invalid ACL\n");
r = SC_ERROR_INVALID_ARGUMENTS;
goto out;
}
@ -561,7 +561,7 @@ etoken_set_security_env(struct sc_card *card,
if (!(env->flags & SC_SEC_ENV_KEY_REF_PRESENT)
|| env->key_ref_len != 1) {
error(card->ctx, "No or invalid key reference\n");
sc_error(card->ctx, "No or invalid key reference\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
key_id = env->key_ref[0];
@ -659,12 +659,12 @@ etoken_compute_signature(struct sc_card *card, const u8 *data, size_t datalen,
* only way I see) -- Nils
*/
if (ctx->debug >= 3)
debug(ctx, "trying RSA_PURE_SIG (padded DigestInfo)\n");
sc_debug(ctx, "trying RSA_PURE_SIG (padded DigestInfo)\n");
r = do_compute_signature(card, data, datalen, out, outlen);
if (r >= SC_SUCCESS)
SC_FUNC_RETURN(ctx, 4, r);
if (ctx->debug >= 3)
debug(ctx, "trying RSA_SIG (just the DigestInfo)\n");
sc_debug(ctx, "trying RSA_SIG (just the DigestInfo)\n");
/* remove padding: first try pkcs1 bt01 padding */
r = sc_pkcs1_strip_01_padding(data, datalen, buf, &tmp_len);
if (r != SC_SUCCESS) {
@ -678,7 +678,7 @@ etoken_compute_signature(struct sc_card *card, const u8 *data, size_t datalen,
if (r >= SC_SUCCESS)
SC_FUNC_RETURN(ctx, 4, r);
if (ctx->debug >= 3)
debug(ctx, "trying to sign raw hash value\n");
sc_debug(ctx, "trying to sign raw hash value\n");
r = sc_pkcs1_strip_digest_info_prefix(NULL,buf,tmp_len,buf,&buf_len);
if (r != SC_SUCCESS)
SC_FUNC_RETURN(ctx, 4, r);
@ -715,7 +715,7 @@ etoken_lifecycle_get(struct sc_card *card, int *mode)
} else if (rbuf[0] == 16) {
*mode = SC_CARDCTRL_LIFECYCLE_USER;
} else {
error(card->ctx, "Unknown lifecycle byte %d", rbuf[0]);
sc_error(card->ctx, "Unknown lifecycle byte %d", rbuf[0]);
return SC_ERROR_INTERNAL;
}
@ -822,7 +822,7 @@ etoken_generate_key(struct sc_card *card,
if (args->random_len) {
/* XXX FIXME: do a GIVE_RANDOM command with this data */
error(card->ctx,
sc_error(card->ctx,
"initialization of card's random pool "
"not yet implemented\n");
return SC_ERROR_INTERNAL;

View File

@ -268,7 +268,7 @@ static int parse_flex_sf_reply(struct sc_context *ctx, const u8 *buf, int buflen
file->type = SC_FILE_TYPE_DF;
break;
default:
error(ctx, "invalid file type: 0x%02X\n", *p);
sc_error(ctx, "invalid file type: 0x%02X\n", *p);
return SC_ERROR_UNKNOWN_DATA_RECEIVED;
}
p += 2;
@ -394,7 +394,7 @@ static int get_flex_ac_keys(struct sc_card *card, struct sc_file *file)
SC_TEST_RET(card->ctx, r, "APDU transmit failed");
if (apdu.sw1 != 0x90 && apdu.sw2 != 0x00)
return 0;
debug(card->ctx, "AC Keys: %02X %02X %02X\n", rbuf[0], rbuf[1], rbuf[2]);
sc_debug(card->ctx, "AC Keys: %02X %02X %02X\n", rbuf[0], rbuf[1], rbuf[2]);
#endif
return 0;
}
@ -428,7 +428,7 @@ static int select_file_id(struct sc_card *card, const u8 *buf, size_t buflen,
if (apdu.resplen < 14)
return SC_ERROR_UNKNOWN_DATA_RECEIVED;
if (apdu.resp[0] == 0x6F) {
error(card->ctx, "unsupported: card returned FCI\n");
sc_error(card->ctx, "unsupported: card returned FCI\n");
return SC_ERROR_UNKNOWN_DATA_RECEIVED; /* FIXME */
}
file = sc_file_new();
@ -521,7 +521,7 @@ static int flex_list_files(struct sc_card *card, u8 *buf, size_t buflen)
if (r)
return r;
if (apdu.resplen != 4) {
error(card->ctx, "expected 4 bytes, got %d.\n", apdu.resplen);
sc_error(card->ctx, "expected 4 bytes, got %d.\n", apdu.resplen);
return SC_ERROR_UNKNOWN_DATA_RECEIVED;
}
memcpy(buf, rbuf + 2, 2);
@ -540,7 +540,7 @@ static int flex_delete_file(struct sc_card *card, const struct sc_path *path)
SC_FUNC_CALLED(card->ctx, 1);
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
sbuf[0] = path->value[0];
@ -625,7 +625,7 @@ static int encode_file_structure(struct sc_card *card, const struct sc_file *fil
p[6] = 0x06;
break;
default:
error(card->ctx, "Invalid EF structure\n");
sc_error(card->ctx, "Invalid EF structure\n");
return -1;
}
p[7] = 0xFF; /* allow Decrease and Increase */
@ -682,7 +682,7 @@ static int flex_create_file(struct sc_card *card, struct sc_file *file)
r = encode_file_structure(card, file, sbuf, &sendlen);
if (r) {
error(card->ctx, "File structure encoding failed.\n");
sc_error(card->ctx, "File structure encoding failed.\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
if (file->type != SC_FILE_TYPE_DF && file->ef_structure != SC_FILE_EF_TRANSPARENT)
@ -718,33 +718,33 @@ static int flex_set_security_env(struct sc_card *card,
if (env->operation != SC_SEC_OPERATION_SIGN &&
env->operation != SC_SEC_OPERATION_DECIPHER) {
error(card->ctx, "Invalid crypto operation supplied.\n");
sc_error(card->ctx, "Invalid crypto operation supplied.\n");
return SC_ERROR_NOT_SUPPORTED;
}
if (env->algorithm != SC_ALGORITHM_RSA) {
error(card->ctx, "Invalid crypto algorithm supplied.\n");
sc_error(card->ctx, "Invalid crypto algorithm supplied.\n");
return SC_ERROR_NOT_SUPPORTED;
}
if ((env->algorithm_flags & SC_ALGORITHM_RSA_PADS) ||
(env->algorithm_flags & SC_ALGORITHM_RSA_HASHES)) {
error(card->ctx, "Card supports only raw RSA.\n");
sc_error(card->ctx, "Card supports only raw RSA.\n");
return SC_ERROR_NOT_SUPPORTED;
}
if (env->flags & SC_SEC_ENV_KEY_REF_PRESENT) {
if (env->key_ref_len != 1 ||
(env->key_ref[0] != 0 && env->key_ref[0] != 1)) {
error(card->ctx, "Invalid key reference supplied.\n");
sc_error(card->ctx, "Invalid key reference supplied.\n");
return SC_ERROR_NOT_SUPPORTED;
}
prv->rsa_key_ref = env->key_ref[0];
}
if (env->flags & SC_SEC_ENV_ALG_REF_PRESENT) {
error(card->ctx, "Algorithm reference not supported.\n");
sc_error(card->ctx, "Algorithm reference not supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT)
if (memcmp(env->file_ref.value, "\x00\x12", 2) != 0) {
error(card->ctx, "File reference is not 0012.\n");
sc_error(card->ctx, "File reference is not 0012.\n");
return SC_ERROR_NOT_SUPPORTED;
}
return 0;
@ -765,11 +765,11 @@ static int flex_compute_signature(struct sc_card *card, const u8 *data,
size_t i;
if (data_len != 64 && data_len != 96 && data_len != 128 && data_len != 256) {
error(card->ctx, "Illegal input length: %d\n", data_len);
sc_error(card->ctx, "Illegal input length: %d\n", data_len);
return SC_ERROR_INVALID_ARGUMENTS;
}
if (outlen < data_len) {
error(card->ctx, "Output buffer too small.\n");
sc_error(card->ctx, "Output buffer too small.\n");
return SC_ERROR_BUFFER_TOO_SMALL;
}
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x88, 0x00, prv->rsa_key_ref);
@ -859,7 +859,7 @@ static int flex_generate_key(sc_card_t *card, struct sc_cardctl_cryptoflex_genke
case 1024: p2 = 0x80; break;
case 2048: p2 = 0x00; break;
default:
error(card->ctx, "Illegal key length: %d\n", data->key_bits);
sc_error(card->ctx, "Illegal key length: %d\n", data->key_bits);
return SC_ERROR_INVALID_ARGUMENTS;
}

View File

@ -268,23 +268,23 @@ gpk_check_sw(struct sc_card *card, u8 sw1, u8 sw2)
unsigned short int sw = (sw1 << 8) | sw2;
if ((sw & 0xFFF0) == 0x63C0) {
error(card->ctx, "wrong PIN, %u tries left\n", sw&0xf);
sc_error(card->ctx, "wrong PIN, %u tries left\n", sw&0xf);
return SC_ERROR_PIN_CODE_INCORRECT;
}
switch (sw) {
case 0x6400:
error(card->ctx, "wrong crypto context\n");
sc_error(card->ctx, "wrong crypto context\n");
return SC_ERROR_OBJECT_NOT_VALID; /* XXX ??? */
/* The following are handled by iso7816_check_sw
* but all return SC_ERROR_UNKNOWN_DATA_RECEIVED
* XXX: fix in the iso driver? */
case 0x6983:
error(card->ctx, "PIN is blocked\n");
sc_error(card->ctx, "PIN is blocked\n");
return SC_ERROR_PIN_CODE_INCORRECT;
case 0x6581:
error(card->ctx, "out of space on card or file\n");
sc_error(card->ctx, "out of space on card or file\n");
return SC_ERROR_OUT_OF_MEMORY;
case 0x6981:
return SC_ERROR_FILE_NOT_FOUND;
@ -603,7 +603,7 @@ gpk_select_id(struct sc_card *card, u8 kind, unsigned short int fid,
int r, log_errs;
if (card->ctx->debug)
debug(card->ctx, "gpk_select_id(0x%04X, kind=%u)\n", fid, kind);
sc_debug(card->ctx, "gpk_select_id(0x%04X, kind=%u)\n", fid, kind);
fbuf[0] = fid >> 8;
fbuf[1] = fid & 0xff;
@ -756,7 +756,7 @@ gpk_read_binary(struct sc_card *card, unsigned int offset,
struct gpk_private_data *priv = DRVDATA(card);
if (offset & priv->offset_mask) {
error(card->ctx, "Invalid file offset (not a multiple of %d)",
sc_error(card->ctx, "Invalid file offset (not a multiple of %d)",
priv->offset_mask + 1);
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -771,7 +771,7 @@ gpk_write_binary(struct sc_card *card, unsigned int offset,
struct gpk_private_data *priv = DRVDATA(card);
if (offset & priv->offset_mask) {
error(card->ctx, "Invalid file offset (not a multiple of %d)",
sc_error(card->ctx, "Invalid file offset (not a multiple of %d)",
priv->offset_mask + 1);
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -786,7 +786,7 @@ gpk_update_binary(struct sc_card *card, unsigned int offset,
struct gpk_private_data *priv = DRVDATA(card);
if (offset & priv->offset_mask) {
error(card->ctx, "Invalid file offset (not a multiple of %d)",
sc_error(card->ctx, "Invalid file offset (not a multiple of %d)",
priv->offset_mask + 1);
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -857,7 +857,7 @@ gpk_verify_crycks(struct sc_card *card, struct sc_apdu *apdu, u8 *crycks)
if (apdu->resplen < 3
|| memcmp(apdu->resp + apdu->resplen - 3, crycks, 3)) {
if (card->ctx->debug)
debug(card->ctx, "Invalid secure messaging reply\n");
sc_debug(card->ctx, "Invalid secure messaging reply\n");
return SC_ERROR_UNKNOWN_DATA_RECEIVED;
}
apdu->resplen -= 3;
@ -880,7 +880,7 @@ gpk_create_file(struct sc_card *card, struct sc_file *file)
int r;
if (card->ctx->debug)
debug(card->ctx, "gpk_create_file(0x%04X)\n", file->id);
sc_debug(card->ctx, "gpk_create_file(0x%04X)\n", file->id);
/* Prepare APDU */
memset(&apdu, 0, sizeof(apdu));
@ -1069,7 +1069,7 @@ gpk_set_security_env(struct sc_card *card,
if (env->flags & SC_SEC_ENV_ALG_PRESENT)
algorithm = env->algorithm;
if (algorithm != SC_ALGORITHM_RSA) {
error(card->ctx, "Algorithm not supported.\n");
sc_error(card->ctx, "Algorithm not supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
priv->sec_algorithm = algorithm;
@ -1077,7 +1077,7 @@ gpk_set_security_env(struct sc_card *card,
/* If there's a key reference, it must be 0 */
if ((env->flags & SC_SEC_ENV_KEY_REF_PRESENT)
&& (env->key_ref_len != 1 || env->key_ref[0] != 0)) {
error(card->ctx, "Unknown key referenced.\n");
sc_error(card->ctx, "Unknown key referenced.\n");
return SC_ERROR_NOT_SUPPORTED;
}
@ -1090,7 +1090,7 @@ gpk_set_security_env(struct sc_card *card,
else if (env->flags & SC_ALGORITHM_RSA_PAD_ISO9796)
priv->sec_padding = 2;
else {
error(card->ctx, "Padding algorithm not supported.\n");
sc_error(card->ctx, "Padding algorithm not supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
@ -1113,7 +1113,7 @@ gpk_set_security_env(struct sc_card *card,
context = GPK_SIGN_RSA_MD5;
priv->sec_hash_len = 16;
} else {
error(card->ctx, "Unsupported signature algorithm");
sc_error(card->ctx, "Unsupported signature algorithm");
return SC_ERROR_NOT_SUPPORTED;
}
break;
@ -1121,20 +1121,20 @@ gpk_set_security_env(struct sc_card *card,
context = GPK_UNWRAP_RSA;
break;
default:
error(card->ctx, "Crypto operation not supported.\n");
sc_error(card->ctx, "Crypto operation not supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
/* Get the file ID */
if (env->flags & SC_SEC_ENV_FILE_REF_PRESENT) {
if (env->file_ref.len != 2) {
error(card->ctx, "File reference: invalid length.\n");
sc_error(card->ctx, "File reference: invalid length.\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
file_id = (env->file_ref.value[0] << 8)
| env->file_ref.value[1];
} else {
error(card->ctx, "File reference missing.\n");
sc_error(card->ctx, "File reference missing.\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -1148,11 +1148,11 @@ gpk_set_security_env(struct sc_card *card,
SC_RECORD_BY_REC_NR);
SC_TEST_RET(card->ctx, r, "Failed to read PK sysrec");
if (r != 7 || sysrec[0] != 0) {
error(card->ctx, "First record of file is not the sysrec");
sc_error(card->ctx, "First record of file is not the sysrec");
return SC_ERROR_OBJECT_NOT_VALID;
}
if (sysrec[5] != 0x00) {
error(card->ctx, "Public key is not an RSA key");
sc_error(card->ctx, "Public key is not an RSA key");
return SC_ERROR_OBJECT_NOT_VALID;
}
switch (sysrec[1]) {
@ -1160,7 +1160,7 @@ gpk_set_security_env(struct sc_card *card,
case 0x10: priv->sec_mod_len = 768 / 8; break;
case 0x11: priv->sec_mod_len = 1024 / 8; break;
default:
error(card->ctx, "Unsupported modulus length");
sc_error(card->ctx, "Unsupported modulus length");
return SC_ERROR_OBJECT_NOT_VALID;
}
@ -1292,7 +1292,7 @@ gpk_compute_signature(struct sc_card *card, const u8 *data,
int r;
if (data_len > priv->sec_mod_len) {
error(card->ctx,
sc_error(card->ctx,
"Data length (%u) does not match key modulus %u.\n",
data_len, priv->sec_mod_len);
return SC_ERROR_INTERNAL;
@ -1353,7 +1353,7 @@ gpk_decipher(struct sc_card *card, const u8 *in, size_t inlen,
int r;
if (inlen != priv->sec_mod_len) {
error(card->ctx,
sc_error(card->ctx,
"Data length (%u) does not match key modulus %u.\n",
inlen, priv->sec_mod_len);
return SC_ERROR_INVALID_ARGUMENTS;
@ -1454,7 +1454,7 @@ gpk_lock(struct sc_card *card, struct sc_cardctl_gpk_lock *args)
int r;
if (card->ctx->debug)
debug(card->ctx, "gpk_lock(0x%04X, %u)\n",
sc_debug(card->ctx, "gpk_lock(0x%04X, %u)\n",
file->id, args->operation);
memset(data, 0, sizeof(data));
@ -1512,7 +1512,7 @@ gpk_pkfile_init(struct sc_card *card, struct sc_cardctl_gpk_pkinit *args)
int r;
if (card->ctx->debug)
debug(card->ctx, "gpk_pkfile_init(%u)\n", args->privlen);
sc_debug(card->ctx, "gpk_pkfile_init(%u)\n", args->privlen);
memset(&apdu, 0, sizeof(apdu));
apdu.cse = SC_APDU_CASE_1;
@ -1542,7 +1542,7 @@ gpk_pkfile_load(struct sc_card *card, struct sc_cardctl_gpk_pkload *args)
u8 temp[256];
int r;
debug(card->ctx, "gpk_pkfile_load(fid=%04x, len=%d, datalen=%d)\n",
sc_debug(card->ctx, "gpk_pkfile_load(fid=%04x, len=%d, datalen=%d)\n",
args->file->id, args->len, args->datalen);
#if 0
@ -1551,7 +1551,7 @@ gpk_pkfile_load(struct sc_card *card, struct sc_cardctl_gpk_pkload *args)
sc_hex_dump(card->ctx, args->data, args->datalen,
buf, sizeof(buf));
debug(card->ctx, "Sending %d bytes (cleartext):\n%s",
sc_debug(card->ctx, "Sending %d bytes (cleartext):\n%s",
args->datalen, buf);
}
#endif
@ -1567,7 +1567,7 @@ gpk_pkfile_load(struct sc_card *card, struct sc_cardctl_gpk_pkload *args)
/* encrypt the private key material */
assert(args->datalen <= sizeof(temp));
if (!priv->key_set) {
error(card->ctx, "No secure messaging key set!\n");
sc_error(card->ctx, "No secure messaging key set!\n");
return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
}
DES_set_key_unchecked((des_cblock *) priv->key, &k1);

View File

@ -108,7 +108,7 @@ static struct df_info_s *get_df_info (struct sc_card *card)
assert (!priv->is_ef);
if (!priv->curpathlen) {
debug(ctx, "no current path to find the df_info\n");
sc_debug(ctx, "no current path to find the df_info\n");
return NULL;
}
@ -121,7 +121,7 @@ static struct df_info_s *get_df_info (struct sc_card *card)
/* Not found, create it. */
dfi = (struct df_info_s *) calloc (1, sizeof *dfi);
if (!dfi) {
debug(ctx, "out of core while allocating df_info\n");
sc_debug(ctx, "out of core while allocating df_info\n");
return NULL;
}
dfi->pathlen = priv->curpathlen;
@ -272,12 +272,12 @@ static int load_special_files (struct sc_card *card)
dfi->rule_file = rule;
}
debug(ctx, "new EF_Rule file loaded (%d records)\n", recno-1);
sc_debug(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, 2, EF_KeyD, NULL);
if (r == SC_ERROR_FILE_NOT_FOUND) {
debug(ctx, "no EF_KeyD file available\n");
sc_debug(ctx, "no EF_KeyD file available\n");
return 0; /* That is okay. */
}
SC_TEST_RET(ctx, r, "selecting EF_KeyD failed");
@ -309,7 +309,7 @@ static int load_special_files (struct sc_card *card)
dfi->keyd_file = keyd;
}
debug(ctx, "new EF_KeyD file loaded (%d records)\n", recno-1);
sc_debug(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;
@ -336,7 +336,7 @@ static int get_se_num_from_keyd (struct sc_card *card, unsigned short fid,
dfi = get_df_info (card);
if (!dfi || !dfi->keyd_file) {
debug (ctx, "EF_keyD not loaded\n");
sc_debug (ctx, "EF_keyD not loaded\n");
return -1;
}
@ -345,7 +345,7 @@ static int get_se_num_from_keyd (struct sc_card *card, unsigned short fid,
len = keyd->datalen;
sc_hex_dump (ctx, p,len, dbgbuf, sizeof dbgbuf);
debug (ctx, "keyd no %d:\n%s", keyd->recno, dbgbuf);
sc_debug (ctx, "keyd no %d:\n%s", keyd->recno, dbgbuf);
tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
if (!tag || taglen != 4 ||
@ -368,7 +368,7 @@ static int get_se_num_from_keyd (struct sc_card *card, unsigned short fid,
continue;
return *tag; /* found. */
}
debug (ctx, "EF_keyD for %04hx not found\n", fid);
sc_debug (ctx, "EF_keyD for %04hx not found\n", fid);
return -1;
}
@ -387,7 +387,7 @@ static void process_arr(struct sc_card *card, struct sc_file *file,
/* Currently we support only the short for. */
if (buflen != 1) {
debug (ctx, "can't handle long ARRs\n");
sc_debug (ctx, "can't handle long ARRs\n");
return;
}
@ -396,13 +396,13 @@ static void process_arr(struct sc_card *card, struct sc_file *file,
rule = rule->next)
;
if (!rule) {
debug (ctx, "referenced EF_rule record %d not found\n", *buf);
sc_debug (ctx, "referenced EF_rule record %d not found\n", *buf);
return;
}
if (ctx->debug) {
sc_hex_dump (ctx, rule->data, rule->datalen, dbgbuf, sizeof dbgbuf);
debug (ctx, "rule for record %d:\n%s", *buf, dbgbuf);
sc_debug (ctx, "rule for record %d:\n%s", *buf, dbgbuf);
}
p = rule->data;
@ -419,12 +419,12 @@ static void process_arr(struct sc_card *card, struct sc_file *file,
skip = 1;
}
else if (tag == 0x80) { /* AM byte. */
debug (ctx," AM_DO: %02x\n", *p);
sc_debug (ctx," AM_DO: %02x\n", *p);
skip = 0;
}
else if (tag >= 0x81 && tag <= 0x8f) {/* Cmd description */
sc_hex_dump (ctx, p, taglen, dbgbuf, sizeof dbgbuf);
debug (ctx, " AM_DO: cmd[%s%s%s%s] %s",
sc_debug (ctx, " AM_DO: cmd[%s%s%s%s] %s",
(tag & 8)? "C":"",
(tag & 4)? "I":"",
(tag & 2)? "1":"",
@ -439,30 +439,30 @@ static void process_arr(struct sc_card *card, struct sc_file *file,
sc_hex_dump (ctx, p, taglen, dbgbuf, sizeof dbgbuf);
switch (tag) {
case 0x90: /* Always */
debug (ctx," SC: always\n");
sc_debug (ctx," SC: always\n");
break;
case 0x97: /* Never */
debug (ctx," SC: never\n");
sc_debug (ctx," SC: never\n");
break;
case 0xA4: /* Authentication, value is a CRT. */
debug (ctx," SC: auth %s", dbgbuf);
sc_debug (ctx," SC: auth %s", dbgbuf);
break;
case 0xB4:
case 0xB6:
case 0xB8: /* Cmd or resp with SM, value is a CRT. */
debug (ctx," SC: cmd/resp %s", dbgbuf);
sc_debug (ctx," SC: cmd/resp %s", dbgbuf);
break;
case 0x9E: /* Security Condition byte. */
debug (ctx," SC: condition %s", dbgbuf);
sc_debug (ctx," SC: condition %s", dbgbuf);
break;
case 0xA0: /* OR template. */
debug (ctx," SC: OR\n");
sc_debug (ctx," SC: OR\n");
break;
case 0xAF: /* AND template. */
debug (ctx," SC: AND\n");
sc_debug (ctx," SC: AND\n");
break;
}
}
@ -482,13 +482,13 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
int bad_fde = 0;
if (ctx->debug >= 3)
debug(ctx, "processing FCI bytes\n");
sc_debug(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];
if (ctx->debug >= 3)
debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
sc_debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
tag[1]);
}
/* Number of data bytes in the file including structural information.*/
@ -504,7 +504,7 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
if (tag == NULL) {
@ -512,7 +512,7 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
}
@ -527,7 +527,7 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
file->shareable = byte & 0x40 ? 1 : 0;
if (ctx->debug >= 3)
debug(ctx, " shareable: %s\n",
sc_debug(ctx, " shareable: %s\n",
(byte & 0x40) ? "yes" : "no");
file->ef_structure = byte & 0x07;
switch ((byte >> 3) & 7) {
@ -548,8 +548,8 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
break;
}
if (ctx->debug >= 3) {
debug(ctx, " type: %s\n", type);
debug(ctx, " EF structure: %d\n",
sc_debug(ctx, " type: %s\n", type);
sc_debug(ctx, " EF structure: %d\n",
byte & 0x07);
}
}
@ -573,7 +573,7 @@ static void process_fcp(struct sc_card *card, struct sc_file *file,
}
name[taglen] = 0;
if (ctx->debug >= 3)
debug(ctx, " file name: %s\n", name);
sc_debug(ctx, " file name: %s\n", name);
}
/* Proprietary information. */
@ -677,7 +677,7 @@ select_part (struct sc_card *card, u8 kind, unsigned short int fid,
int r, log_errs;
if (card->ctx->debug >=3)
debug(card->ctx, "select_part (0x%04X, kind=%u)\n",
sc_debug(card->ctx, "select_part (0x%04X, kind=%u)\n",
fid, kind);
if (fid == MFID)
@ -923,7 +923,7 @@ mcrd_select_file(struct sc_card *card, const struct sc_path *path,
linep += 2;
}
strcpy(linep, "\n");
debug(card->ctx, line);
sc_debug(card->ctx, line);
linep = line;
linep += sprintf(linep, " ef=%d, curpath=",
@ -933,7 +933,7 @@ mcrd_select_file(struct sc_card *card, const struct sc_path *path,
linep += 4;
}
strcpy(linep, "\n");
debug(card->ctx, line);
sc_debug(card->ctx, line);
}
if (path->type == SC_PATH_TYPE_DF_NAME) {
@ -973,7 +973,7 @@ mcrd_select_file(struct sc_card *card, const struct sc_path *path,
linep += 4;
}
strcpy(linep, "\n");
debug(card->ctx, line);
sc_debug(card->ctx, line);
}

View File

@ -153,7 +153,7 @@ static int encode_file_structure(struct sc_card *card, const struct sc_file *fil
*p++ = 0x43;
break;
default:
error(card->ctx, "Invalid EF structure\n");
sc_error(card->ctx, "Invalid EF structure\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
ops = ef_ops;
@ -163,7 +163,7 @@ static int encode_file_structure(struct sc_card *card, const struct sc_file *fil
ops = key_ops;
break;
default:
error(card->ctx, "Unknown file type\n");
sc_error(card->ctx, "Unknown file type\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
if (file->type == SC_FILE_TYPE_DF) {
@ -184,7 +184,7 @@ static int encode_file_structure(struct sc_card *card, const struct sc_file *fil
else {
int byte = acl_to_byte(sc_file_get_acl_entry(file, ops[i]));
if (byte < 0) {
error(card->ctx, "Invalid ACL\n");
sc_error(card->ctx, "Invalid ACL\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
nibble = byte;
@ -251,7 +251,7 @@ static int miocos_set_security_env(struct sc_card *card,
tmp.flags &= ~SC_SEC_ENV_ALG_PRESENT;
tmp.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
if (tmp.algorithm != SC_ALGORITHM_RSA) {
error(card->ctx, "Only RSA algorithm supported.\n");
sc_error(card->ctx, "Only RSA algorithm supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
tmp.algorithm_ref = 0x00;
@ -429,7 +429,7 @@ static int miocos_delete_file(struct sc_card *card, const struct sc_path *path)
SC_FUNC_CALLED(card->ctx, 1);
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
r = sc_select_file(card, path, NULL);
@ -467,7 +467,7 @@ static int miocos_create_ac(sc_card_t *card,
sendsize = 20;
break;
default:
error(card->ctx, "AC type %d not supported\n", ac->type);
sc_error(card->ctx, "AC type %d not supported\n", ac->type);
return SC_ERROR_NOT_SUPPORTED;
}
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0x1E, miocos_type,
@ -487,7 +487,7 @@ static int miocos_card_ctl(struct sc_card *card, unsigned long cmd,
case SC_CARDCTL_MIOCOS_CREATE_AC:
return miocos_create_ac(card, (struct sc_cardctl_miocos_ac_info *) arg);
}
error(card->ctx, "card_ctl command 0x%X not supported\n", cmd);
sc_error(card->ctx, "card_ctl command 0x%X not supported\n", cmd);
return SC_ERROR_NOT_SUPPORTED;
}

View File

@ -255,11 +255,11 @@ static int setcos_set_security_env(struct sc_card *card,
tmp.flags &= ~SC_SEC_ENV_ALG_PRESENT;
tmp.flags |= SC_SEC_ENV_ALG_REF_PRESENT;
if (tmp.algorithm != SC_ALGORITHM_RSA) {
error(card->ctx, "Only RSA algorithm supported.\n");
sc_error(card->ctx, "Only RSA algorithm supported.\n");
return SC_ERROR_NOT_SUPPORTED;
}
if (priv->type != SETEC_PKI) {
error(card->ctx, "Card does not support RSA.\n");
sc_error(card->ctx, "Card does not support RSA.\n");
return SC_ERROR_NOT_SUPPORTED;
}
tmp.algorithm_ref = 0x00;

View File

@ -281,7 +281,7 @@ static void process_fci(struct sc_context *ctx, struct sc_file *file,
const u8 *tag = NULL, *p = buf;
if (ctx->debug >= 3)
debug(ctx, "processing FCI bytes\n");
sc_debug(ctx, "processing FCI bytes\n");
/* defaults */
file->type = SC_FILE_TYPE_WORKING_EF;
@ -295,7 +295,7 @@ static void process_fci(struct sc_context *ctx, struct sc_file *file,
{
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
@ -351,8 +351,8 @@ static void process_fci(struct sc_context *ctx, struct sc_file *file,
if (ctx->debug >= 3)
{
debug(ctx, " type: %s\n", type);
debug(ctx, " EF structure: %s\n", structure);
sc_debug(ctx, " type: %s\n", type);
sc_debug(ctx, " EF structure: %s\n", structure);
}
}
file->magic = SC_FILE_MAGIC;
@ -545,7 +545,7 @@ static int starcos_select_file(struct sc_card *card,
p_buf += 2;
}
p_buf[0] = 0x00;
debug(card->ctx, "current path (%s, %s): %s (len: %u)\n",
sc_debug(card->ctx, "current path (%s, %s): %s (len: %u)\n",
(card->cache.current_path.type==SC_PATH_TYPE_DF_NAME?"aid":"path"),
(card->cache_valid?"valid":"invalid"),
buf, card->cache.current_path.len);
@ -570,7 +570,7 @@ static int starcos_select_file(struct sc_card *card,
&& memcmp(card->cache.current_path.value, pathbuf, pathlen) == 0 )
{
if (card->ctx->debug >= 4)
debug(card->ctx, "cache hit\n");
sc_debug(card->ctx, "cache hit\n");
SC_FUNC_RETURN(card->ctx, 2, SC_SUCCESS);
}
else
@ -642,7 +642,7 @@ static int starcos_select_file(struct sc_card *card,
/* done: we are already in the
* requested directory */
if ( card->ctx->debug >= 4 )
debug(card->ctx, "cache hit\n");
sc_debug(card->ctx, "cache hit\n");
/* TODO: Should SELECT DF be called again ?
* (Calling SELECT DF resets the status
* of the current DF).
@ -816,14 +816,14 @@ static int starcos_delete_file(struct sc_card *card, const struct sc_path *path)
SC_FUNC_CALLED(card->ctx, 1);
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2)
{
error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
sbuf[0] = path->value[0];
sbuf[1] = path->value[1];
if (sbuf[0] != 0x3f || sbuf[1] != 0x00)
{
error(card->ctx, "Only the MF can be deleted\n");
sc_error(card->ctx, "Only the MF can be deleted\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
@ -1181,13 +1181,13 @@ static int starcos_check_sw(struct sc_card *card, int sw1, int sw2)
int i;
if (card->ctx->debug >= 3)
debug(card->ctx, "sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
sc_debug(card->ctx, "sw1 = 0x%02x, sw2 = 0x%02x\n", sw1, sw2);
if (sw1 == 0x90)
return SC_NO_ERROR;
if (sw1 == 0x63 && (sw2 & ~0x0f) == 0xc0 )
{
error(card->ctx, "Verification failed (remaining tries: %d)\n",
sc_error(card->ctx, "Verification failed (remaining tries: %d)\n",
(sw2 & 0x0f));
return SC_ERROR_PIN_CODE_INCORRECT;
}
@ -1196,7 +1196,7 @@ static int starcos_check_sw(struct sc_card *card, int sw1, int sw2)
for (i = 0; i < err_count; i++)
if (starcos_errors[i].SWs == ((sw1 << 8) | sw2))
{
error(card->ctx, "%s\n", starcos_errors[i].errorstr);
sc_error(card->ctx, "%s\n", starcos_errors[i].errorstr);
return starcos_errors[i].errorno;
}

View File

@ -293,7 +293,7 @@ static void parse_sec_attr(struct sc_card *card,
op = map_operations (buf[0]);
if (op == -1)
{
debug (card->ctx,
sc_debug (card->ctx,
"Unknown security command byte %02x\n",
buf[0]);
continue;
@ -326,19 +326,19 @@ static void tcos_process_fci(struct sc_context *ctx, struct sc_file *file,
const u8 *tag = NULL, *p = buf;
if (ctx->debug >= 3)
debug(ctx, "processing FCI bytes\n");
sc_debug(ctx, "processing FCI bytes\n");
tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
if (tag != NULL && taglen == 2) {
file->id = (tag[0] << 8) | tag[1];
if (ctx->debug >= 3)
debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
sc_debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
tag[1]);
}
tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
if (tag == NULL) {
@ -346,7 +346,7 @@ static void tcos_process_fci(struct sc_context *ctx, struct sc_file *file,
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
}
@ -358,7 +358,7 @@ static void tcos_process_fci(struct sc_context *ctx, struct sc_file *file,
file->shareable = byte & 0x40 ? 1 : 0;
if (ctx->debug >= 3)
debug(ctx, " shareable: %s\n",
sc_debug(ctx, " shareable: %s\n",
(byte & 0x40) ? "yes" : "no");
file->ef_structure = byte & 0x07;
switch ((byte >> 3) & 7) {
@ -379,8 +379,8 @@ static void tcos_process_fci(struct sc_context *ctx, struct sc_file *file,
break;
}
if (ctx->debug >= 3) {
debug(ctx, " type: %s\n", type);
debug(ctx, " EF structure: %d\n",
sc_debug(ctx, " type: %s\n", type);
sc_debug(ctx, " EF structure: %d\n",
byte & 0x07);
}
}
@ -402,7 +402,7 @@ static void tcos_process_fci(struct sc_context *ctx, struct sc_file *file,
}
name[taglen] = 0;
if (ctx->debug >= 3)
debug(ctx, "File name: %s\n", name);
sc_debug(ctx, "File name: %s\n", name);
}
tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
if (tag != NULL && taglen) {
@ -576,7 +576,7 @@ static int tcos_delete_file(struct sc_card *card, const struct sc_path *path)
SC_FUNC_CALLED(card->ctx, 1);
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
sbuf[0] = path->value[0];
@ -711,7 +711,7 @@ static int tcos_card_ctl(struct sc_card *card, unsigned long cmd, void *ptr)
case SC_CARDCTL_TCOS_SETPERM:
return tcos_setperm(card, !!ptr);
}
error(card->ctx, "card_ctl command %u not supported\n", cmd);
sc_error(card->ctx, "card_ctl command %u not supported\n", cmd);
return SC_ERROR_NOT_SUPPORTED;
}

View File

@ -34,51 +34,51 @@ int sc_check_sw(struct sc_card *card, int sw1, int sw2)
static int sc_check_apdu(struct sc_context *ctx, const struct sc_apdu *apdu)
{
if (apdu->le > 256) {
error(ctx, "Value of Le too big (maximum 256 bytes)\n");
sc_error(ctx, "Value of Le too big (maximum 256 bytes)\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
if (apdu->lc > 255) {
error(ctx, "Value of Lc too big (maximum 255 bytes)\n");
sc_error(ctx, "Value of Lc too big (maximum 255 bytes)\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
switch (apdu->cse) {
case SC_APDU_CASE_1:
if (apdu->datalen > 0) {
error(ctx, "Case 1 APDU with data supplied\n");
sc_error(ctx, "Case 1 APDU with data supplied\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
break;
case SC_APDU_CASE_2_SHORT:
if (apdu->datalen > 0) {
error(ctx, "Case 2 APDU with data supplied\n");
sc_error(ctx, "Case 2 APDU with data supplied\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
if (apdu->le == 0) {
error(ctx, "Case 2 APDU with no response expected\n");
sc_error(ctx, "Case 2 APDU with no response expected\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
if (apdu->resplen < apdu->le) {
error(ctx, "Response buffer size < Le\n");
sc_error(ctx, "Response buffer size < Le\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
break;
case SC_APDU_CASE_3_SHORT:
if (apdu->datalen == 0 || apdu->data == NULL) {
error(ctx, "Case 3 APDU with no data supplied\n");
sc_error(ctx, "Case 3 APDU with no data supplied\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
break;
case SC_APDU_CASE_4_SHORT:
if (apdu->datalen == 0 || apdu->data == NULL) {
error(ctx, "Case 4 APDU with no data supplied\n");
sc_error(ctx, "Case 4 APDU with no data supplied\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
if (apdu->le == 0) {
error(ctx, "Case 4 APDU with no response expected\n");
sc_error(ctx, "Case 4 APDU with no response expected\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
if (apdu->resplen < apdu->le) {
error(ctx, "Le > response buffer size\n");
sc_error(ctx, "Le > response buffer size\n");
SC_FUNC_RETURN(ctx, 4, SC_ERROR_INVALID_ARGUMENTS);
}
break;
@ -146,7 +146,7 @@ static int sc_transceive(struct sc_card *card, struct sc_apdu *apdu)
buf[0] = 0;
if (!apdu->sensitive || card->ctx->debug >= 6)
sc_hex_dump(card->ctx, sbuf, sendsize, buf, sizeof(buf));
debug(card->ctx, "Sending %d bytes (resp. %d bytes%s):\n%s",
sc_debug(card->ctx, "Sending %d bytes (resp. %d bytes%s):\n%s",
sendsize, recvsize,
apdu->sensitive ? ", sensitive" : "", buf);
}
@ -200,7 +200,7 @@ int sc_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu)
sc_hex_dump(card->ctx, apdu->resp, apdu->resplen,
buf, sizeof(buf));
}
debug(card->ctx, "Received %d bytes (SW1=%02X SW2=%02X)\n%s",
sc_debug(card->ctx, "Received %d bytes (SW1=%02X SW2=%02X)\n%s",
apdu->resplen, apdu->sw1, apdu->sw2, buf);
}
if (apdu->sw1 == 0x6C && apdu->resplen == 0) {
@ -340,7 +340,7 @@ int sc_connect_card(struct sc_reader *reader, int slot_id,
if (card->ops->init != NULL) {
r = card->ops->init(card);
if (r) {
error(ctx, "driver '%s' init() failed: %s\n", card->driver->name,
sc_error(ctx, "driver '%s' init() failed: %s\n", card->driver->name,
sc_strerror(r));
goto err;
}
@ -350,18 +350,18 @@ int sc_connect_card(struct sc_reader *reader, int slot_id,
const struct sc_card_operations *ops = drv->ops;
if (ctx->debug >= 3)
debug(ctx, "trying driver: %s\n", drv->name);
sc_debug(ctx, "trying driver: %s\n", drv->name);
if (ops == NULL || ops->match_card == NULL)
continue;
if (ops->match_card(card) != 1)
continue;
if (ctx->debug >= 3)
debug(ctx, "matched: %s\n", drv->name);
sc_debug(ctx, "matched: %s\n", drv->name);
memcpy(card->ops, ops, sizeof(struct sc_card_operations));
card->driver = drv;
r = ops->init(card);
if (r) {
error(ctx, "driver '%s' init() failed: %s\n", drv->name,
sc_error(ctx, "driver '%s' init() failed: %s\n", drv->name,
sc_strerror(r));
if (r == SC_ERROR_INVALID_CARD) {
card->driver = NULL;
@ -372,7 +372,7 @@ int sc_connect_card(struct sc_reader *reader, int slot_id,
break;
}
if (card->driver == NULL) {
error(ctx, "unable to find driver for inserted card\n");
sc_error(ctx, "unable to find driver for inserted card\n");
r = SC_ERROR_INVALID_CARD;
goto err;
}
@ -397,13 +397,13 @@ int sc_disconnect_card(struct sc_card *card, int action)
if (card->ops->finish) {
int r = card->ops->finish(card);
if (r)
error(card->ctx, "card driver finish() failed: %s\n",
sc_error(card->ctx, "card driver finish() failed: %s\n",
sc_strerror(r));
}
if (card->reader->ops->disconnect) {
int r = card->reader->ops->disconnect(card->reader, card->slot, action);
if (r)
error(card->ctx, "disconnect() failed: %s\n",
sc_error(card->ctx, "disconnect() failed: %s\n",
sc_strerror(r));
}
sc_card_free(card);
@ -500,7 +500,7 @@ int sc_read_binary(struct sc_card *card, unsigned int idx,
assert(card != NULL && card->ops != NULL && buf != NULL);
if (card->ctx->debug >= 2)
debug(card->ctx, "sc_read_binary: %d bytes at index %d\n", count, idx);
sc_debug(card->ctx, "sc_read_binary: %d bytes at index %d\n", count, idx);
if (count == 0)
return 0;
if (card->ops->read_binary == NULL)
@ -541,7 +541,7 @@ int sc_write_binary(struct sc_card *card, unsigned int idx,
assert(card != NULL && card->ops != NULL && buf != NULL);
if (card->ctx->debug >= 2)
debug(card->ctx, "sc_write_binary: %d bytes at index %d\n", count, idx);
sc_debug(card->ctx, "sc_write_binary: %d bytes at index %d\n", count, idx);
if (count == 0)
return 0;
if (card->ops->write_binary == NULL)
@ -582,7 +582,7 @@ int sc_update_binary(struct sc_card *card, unsigned int idx,
assert(card != NULL && card->ops != NULL && buf != NULL);
if (card->ctx->debug >= 2)
debug(card->ctx, "sc_update_binary: %d bytes at index %d\n", count, idx);
sc_debug(card->ctx, "sc_update_binary: %d bytes at index %d\n", count, idx);
if (count == 0)
return 0;
if (card->ops->update_binary == NULL)
@ -647,7 +647,7 @@ int sc_select_file(struct sc_card *card,
linep += 2;
}
strcpy(linep, "\n");
debug(card->ctx, line);
sc_debug(card->ctx, line);
}
if (card->ops->select_file == NULL)
SC_FUNC_RETURN(card->ctx, 2, SC_ERROR_NOT_SUPPORTED);
@ -741,7 +741,7 @@ sc_card_ctl(struct sc_card *card, unsigned long cmd, void *args)
/* suppress "not supported" error messages */
if (r == SC_ERROR_NOT_SUPPORTED) {
debug(card->ctx, "card_ctl(%lu) not supported\n", cmd);
sc_debug(card->ctx, "card_ctl(%lu) not supported\n", cmd);
return r;
}
SC_FUNC_RETURN(card->ctx, 2, r);

View File

@ -167,7 +167,7 @@ ctbcs_pin_cmd(struct sc_reader *reader, sc_slot_info_t *slot,
r = ctbcs_build_modify_verification_apdu(&apdu, data);
break;
default:
error(reader->ctx, "unknown pin command %d", data->cmd);
sc_error(reader->ctx, "unknown pin command %d", data->cmd);
return SC_ERROR_NOT_SUPPORTED;
}

View File

@ -248,7 +248,7 @@ static int load_reader_drivers(struct sc_context *ctx,
if (func == NULL) {
/* External driver */
/* FIXME: Load shared library */
error(ctx, "Unable to load '%s'. External drivers not supported yet.\n",
sc_error(ctx, "Unable to load '%s'. External drivers not supported yet.\n",
ent->name);
continue;
}
@ -285,7 +285,7 @@ static int load_card_driver_options(struct sc_context *ctx,
r = sc_hex_to_bin(list->data,
atr_buf, &atr_len);
if (r < 0) {
error(ctx,
sc_error(ctx,
"Unable to parse ATR '%s'.\n",
list->data);
continue;
@ -320,7 +320,7 @@ static int load_card_drivers(struct sc_context *ctx,
if (func == NULL) {
/* External driver */
/* FIXME: Load shared library */
error(ctx, "Unable to load '%s'. External drivers not supported yet.\n",
sc_error(ctx, "Unable to load '%s'. External drivers not supported yet.\n",
ent->name);
continue;
}
@ -394,7 +394,7 @@ int sc_establish_context(struct sc_context **ctx_out, const char *app_name)
ctx->app_name = app_name ? strdup(app_name) : strdup(default_app);
process_config_file(ctx, &opts);
ctx->mutex = sc_mutex_new();
debug(ctx, "===================================\n"); /* first thing in the log */
sc_debug(ctx, "===================================\n"); /* first thing in the log */
load_reader_drivers(ctx, &opts);
load_card_drivers(ctx, &opts);
if (opts.forced_card_driver) {
@ -525,6 +525,6 @@ int sc_make_cache_dir(struct sc_context *ctx)
return 0;
/* for lack of a better return code */
failed: error(ctx, "failed to create cache directory\n");
failed: sc_error(ctx, "failed to create cache directory\n");
return SC_ERROR_INTERNAL;
}

View File

@ -97,12 +97,12 @@ static int parse_dir_record(struct sc_card *card, u8 ** buf, size_t *buflen,
if (r == SC_ERROR_ASN1_END_OF_CONTENTS)
return r;
if (r) {
error(card->ctx, "EF(DIR) parsing failed: %s\n",
sc_error(card->ctx, "EF(DIR) parsing failed: %s\n",
sc_strerror(r));
return r;
}
if (aid_len > SC_MAX_AID_SIZE) {
error(card->ctx, "AID is too long.\n");
sc_error(card->ctx, "AID is too long.\n");
return SC_ERROR_INVALID_ASN1_OBJECT;
}
app = (struct sc_app_info *) malloc(sizeof(struct sc_app_info));
@ -117,7 +117,7 @@ static int parse_dir_record(struct sc_card *card, u8 ** buf, size_t *buflen,
app->label = NULL;
if (asn1_dirrecord[2].flags & SC_ASN1_PRESENT) {
if (path_len > SC_MAX_PATH_SIZE) {
error(card->ctx, "Application path is too long.\n");
sc_error(card->ctx, "Application path is too long.\n");
return SC_ERROR_INVALID_ASN1_OBJECT;
}
memcpy(app->path.value, path, path_len);
@ -168,7 +168,7 @@ int sc_enum_apps(struct sc_card *card)
if (r)
return r;
if (card->ef_dir->type != SC_FILE_TYPE_WORKING_EF) {
error(card->ctx, "EF(DIR) is not a working EF.\n");
sc_error(card->ctx, "EF(DIR) is not a working EF.\n");
sc_file_free(card->ef_dir);
card->ef_dir = NULL;
return SC_ERROR_INVALID_CARD;
@ -193,7 +193,7 @@ int sc_enum_apps(struct sc_card *card)
bufsize = r;
while (bufsize > 0) {
if (card->app_count == SC_MAX_CARD_APPS) {
error(card->ctx, "Too many applications on card");
sc_error(card->ctx, "Too many applications on card");
break;
}
r = parse_dir_record(card, &p, &bufsize, -1);
@ -214,7 +214,7 @@ int sc_enum_apps(struct sc_card *card)
break;
SC_TEST_RET(card->ctx, r, "read_record() failed");
if (card->app_count == SC_MAX_CARD_APPS) {
error(card->ctx, "Too many applications on card");
sc_error(card->ctx, "Too many applications on card");
break;
}
rec_size = r;
@ -276,7 +276,7 @@ static int encode_dir_record(struct sc_context *ctx, const struct sc_app_info *a
(void *) &app->ddo_len, 1);
r = sc_asn1_encode(ctx, asn1_dir, buf, buflen);
if (r) {
error(ctx, "sc_asn1_encode() failed: %s\n",
sc_error(ctx, "sc_asn1_encode() failed: %s\n",
sc_strerror(r));
return r;
}

View File

@ -85,22 +85,22 @@ int iso7816_check_sw(struct sc_card *card, int sw1, int sw2)
/* Handle special cases here */
if (sw1 == 0x6C) {
error(card->ctx, "Wrong length; correct length is %d\n", sw2);
sc_error(card->ctx, "Wrong length; correct length is %d\n", sw2);
return SC_ERROR_WRONG_LENGTH;
}
if (sw1 == 0x90)
return SC_NO_ERROR;
if (sw1 == 0x63 && (sw2 & ~0x0f) == 0xc0 ) {
error(card->ctx, "Verification failed (remaining tries: %d)\n",
sc_error(card->ctx, "Verification failed (remaining tries: %d)\n",
(sw2 & 0x0f));
return SC_ERROR_PIN_CODE_INCORRECT;
}
for (i = 0; i < err_count; i++)
if (iso7816_errors[i].SWs == ((sw1 << 8) | sw2)) {
error(card->ctx, "%s\n", iso7816_errors[i].errorstr);
sc_error(card->ctx, "%s\n", iso7816_errors[i].errorstr);
return iso7816_errors[i].errorno;
}
error(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
sc_error(card->ctx, "Unknown SWs; SW1=%02X, SW2=%02X\n", sw1, sw2);
return SC_ERROR_CARD_CMD_FAILED;
}
@ -161,7 +161,7 @@ static int iso7816_write_record(struct sc_card *card, unsigned int rec_nr,
int r;
if (count > 256) {
error(card->ctx, "Trying to send too many bytes\n");
sc_error(card->ctx, "Trying to send too many bytes\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xD2, rec_nr, 0);
@ -188,7 +188,7 @@ static int iso7816_append_record(struct sc_card *card,
int r;
if (count > 256) {
error(card->ctx, "Trying to send too many bytes\n");
sc_error(card->ctx, "Trying to send too many bytes\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xE2, 0, 0);
@ -213,7 +213,7 @@ static int iso7816_update_record(struct sc_card *card, unsigned int rec_nr,
int r;
if (count > 256) {
error(card->ctx, "Trying to send too many bytes\n");
sc_error(card->ctx, "Trying to send too many bytes\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
sc_format_apdu(card, &apdu, SC_APDU_CASE_3_SHORT, 0xDC, rec_nr, 0);
@ -282,19 +282,19 @@ int iso7816_process_fci(struct sc_card *card, struct sc_file *file,
const u8 *tag = NULL, *p = buf;
if (ctx->debug >= 3)
debug(ctx, "processing FCI bytes\n");
sc_debug(ctx, "processing FCI bytes\n");
tag = sc_asn1_find_tag(ctx, p, len, 0x83, &taglen);
if (tag != NULL && taglen == 2) {
file->id = (tag[0] << 8) | tag[1];
if (ctx->debug >= 3)
debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
sc_debug(ctx, " file identifier: 0x%02X%02X\n", tag[0],
tag[1]);
}
tag = sc_asn1_find_tag(ctx, p, len, 0x81, &taglen);
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
if (tag == NULL) {
@ -302,7 +302,7 @@ int iso7816_process_fci(struct sc_card *card, struct sc_file *file,
if (tag != NULL && taglen >= 2) {
int bytes = (tag[0] << 8) + tag[1];
if (ctx->debug >= 3)
debug(ctx, " bytes in file: %d\n", bytes);
sc_debug(ctx, " bytes in file: %d\n", bytes);
file->size = bytes;
}
}
@ -314,7 +314,7 @@ int iso7816_process_fci(struct sc_card *card, struct sc_file *file,
file->shareable = byte & 0x40 ? 1 : 0;
if (ctx->debug >= 3)
debug(ctx, " shareable: %s\n",
sc_debug(ctx, " shareable: %s\n",
(byte & 0x40) ? "yes" : "no");
file->ef_structure = byte & 0x07;
switch ((byte >> 3) & 7) {
@ -335,8 +335,8 @@ int iso7816_process_fci(struct sc_card *card, struct sc_file *file,
break;
}
if (ctx->debug >= 3) {
debug(ctx, " type: %s\n", type);
debug(ctx, " EF structure: %d\n",
sc_debug(ctx, " type: %s\n", type);
sc_debug(ctx, " EF structure: %d\n",
byte & 0x07);
}
}
@ -358,7 +358,7 @@ int iso7816_process_fci(struct sc_card *card, struct sc_file *file,
}
name[taglen] = 0;
if (ctx->debug >= 3)
debug(ctx, "File name: %s\n", name);
sc_debug(ctx, "File name: %s\n", name);
}
tag = sc_asn1_find_tag(ctx, p, len, 0x85, &taglen);
if (tag != NULL && taglen) {
@ -600,7 +600,7 @@ static int iso7816_delete_file(struct sc_card *card, const struct sc_path *path)
SC_FUNC_CALLED(card->ctx, 1);
if (path->type != SC_PATH_TYPE_FILE_ID && path->len != 2) {
error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
sc_error(card->ctx, "File type has to be SC_PATH_TYPE_FILE_ID\n");
SC_FUNC_RETURN(card->ctx, 1, SC_ERROR_INVALID_ARGUMENTS);
}
sbuf[0] = path->value[0];
@ -884,7 +884,7 @@ static int iso7816_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data,
/* Call the reader driver to collect
* the PIN and pass on the APDU to the card */
if (data->pin1.offset == 0) {
error(card->ctx,
sc_error(card->ctx,
"Card driver didn't set PIN offset");
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -896,7 +896,7 @@ static int iso7816_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data,
data);
/* sw1/sw2 filled in by reader driver */
} else {
error(card->ctx,
sc_error(card->ctx,
"Card reader driver does not support "
"PIN entry through reader key pad");
r = SC_ERROR_NOT_SUPPORTED;

View File

@ -39,7 +39,7 @@
#endif
#ifndef __GNUC__
void error(struct sc_context *ctx, const char *format, ...)
void sc_error(struct sc_context *ctx, const char *format, ...)
{
va_list ap;
@ -48,7 +48,7 @@ void error(struct sc_context *ctx, const char *format, ...)
va_end(ap);
}
void debug(struct sc_context *ctx, const char *format, ...)
void sc_debug(struct sc_context *ctx, const char *format, ...)
{
va_list ap;

View File

@ -38,17 +38,15 @@ extern "C" {
#define __FUNCTION__ NULL
#endif
/* XXX: Add sc_ prefix? */
#if defined(__GNUC__)
#define error(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, format , ## args)
#define debug(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, format , ## args)
#define sc_error(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_ERROR, __FILE__, __LINE__, __FUNCTION__, format , ## args)
#define sc_debug(ctx, format, args...) sc_do_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, format , ## args)
#else
void error(struct sc_context *ctx, const char *format, ...);
void debug(struct sc_context *ctx, const char *format, ...);
void sc_error(struct sc_context *ctx, const char *format, ...);
void sc_debug(struct sc_context *ctx, const char *format, ...);
#endif

View File

@ -40,7 +40,7 @@ int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filena
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_open: %s\n", error);
sc_debug(ctx, "sc_module_open: %s\n", error);
return SC_ERROR_UNKNOWN;
}
*mod_handle = handle;
@ -60,7 +60,7 @@ int sc_module_close(struct sc_context *ctx, void *mod_handle)
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_close: %s\n", error);
sc_debug(ctx, "sc_module_close: %s\n", error);
return SC_ERROR_UNKNOWN;
}
return SC_SUCCESS;
@ -89,7 +89,7 @@ int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_a
if ((error = dlerror()) != NULL) {
if (ctx->debug)
debug(ctx, "sc_module_get_address: %s\n", error);
sc_debug(ctx, "sc_module_get_address: %s\n", error);
return SC_ERROR_UNKNOWN;
}
*sym_address = address;
@ -113,7 +113,7 @@ int sc_module_open(struct sc_context *ctx, void **mod_handle, const char *filena
if (handle == NULL) {
if (ctx->debug)
/* TODO: GetLastError */
debug(ctx, "sc_module_open: unknown error");
sc_debug(ctx, "sc_module_open: unknown error");
return SC_ERROR_UNKNOWN;
}
*mod_handle = handle;
@ -148,7 +148,7 @@ int sc_module_get_address(struct sc_context *ctx, void *mod_handle, void **sym_a
if (address == NULL) {
if (ctx->debug)
/* TODO: GetLastError */
debug(ctx, "sc_module_get_address: unknown error");
sc_debug(ctx, "sc_module_get_address: unknown error");
return SC_ERROR_UNKNOWN;
}
*sym_address = address;

View File

@ -217,7 +217,7 @@ int sc_pkcs1_encode(struct sc_context *ctx, unsigned long flags,
i = sc_pkcs1_add_digest_info_prefix(hash_algo, in, in_len,
out, &tmp_len);
if (i != SC_SUCCESS) {
error(ctx, "Unable to add digest info 0x%x\n",
sc_error(ctx, "Unable to add digest info 0x%x\n",
hash_algo);
return i;
}
@ -236,7 +236,7 @@ int sc_pkcs1_encode(struct sc_context *ctx, unsigned long flags,
mod_len);
default:
/* currently only pkcs1 padding is supported */
error(ctx, "Unsupported padding algorithm 0x%x\n", pad_algo);
sc_error(ctx, "Unsupported padding algorithm 0x%x\n", pad_algo);
return SC_ERROR_NOT_SUPPORTED;
}
}

View File

@ -333,7 +333,7 @@ sc_asn1_encode_algorithm_id(struct sc_context *ctx,
/* Set the oid if not yet given */
if (id->obj_id.value[0] <= 0) {
if (alg_info == NULL) {
error(ctx, "Cannot encode unknown algorithm %u.\n",
sc_error(ctx, "Cannot encode unknown algorithm %u.\n",
id->algorithm);
return SC_ERROR_INVALID_ARGUMENTS;
}

View File

@ -149,7 +149,7 @@ int sc_pkcs15_cache_file(struct sc_pkcs15_card *p15card,
c = fwrite(buf, 1, bufsize, f);
fclose(f);
if (c != bufsize) {
error(p15card->card->ctx, "fwrite() wrote only %d bytes", c);
sc_error(p15card->card->ctx, "fwrite() wrote only %d bytes", c);
unlink(fname);
return SC_ERROR_INTERNAL;
}

View File

@ -81,7 +81,7 @@ static int parse_x509_cert(struct sc_context *ctx, const u8 *buf, size_t buflen,
obj = sc_asn1_verify_tag(ctx, buf, buflen, ASN1_SEQUENCE | SC_ASN1_CONS,
&objlen);
if (obj == NULL) {
error(ctx, "X.509 certificate not found\n");
sc_error(ctx, "X.509 certificate not found\n");
return SC_ERROR_INVALID_ASN1_OBJECT;
}
cert->data_len = objlen + (obj - buf);

View File

@ -214,7 +214,7 @@ int sc_pkcs15_encode_prkdf_entry(struct sc_context *ctx,
}
break;
default:
error(ctx, "Invalid private key type: %X\n", obj->type);
sc_error(ctx, "Invalid private key type: %X\n", obj->type);
SC_FUNC_RETURN(ctx, 0, SC_ERROR_INTERNAL);
break;
}
@ -277,7 +277,7 @@ sc_pkcs15_encode_prkey(struct sc_context *ctx,
{
if (key->algorithm == SC_ALGORITHM_DSA)
return sc_pkcs15_encode_prkey_dsa(ctx, &key->u.dsa, buf, len);
error(ctx, "Cannot encode private key type %u.\n",
sc_error(ctx, "Cannot encode private key type %u.\n",
key->algorithm);
return SC_ERROR_NOT_SUPPORTED;
}
@ -289,7 +289,7 @@ sc_pkcs15_decode_prkey(struct sc_context *ctx,
{
if (key->algorithm == SC_ALGORITHM_DSA)
return sc_pkcs15_decode_prkey_dsa(ctx, &key->u.dsa, buf, len);
error(ctx, "Cannot decode private key type %u.\n",
sc_error(ctx, "Cannot decode private key type %u.\n",
key->algorithm);
return SC_ERROR_NOT_SUPPORTED;
}
@ -317,12 +317,12 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card,
key.algorithm = SC_ALGORITHM_DSA;
break;
default:
error(ctx, "Unsupported object type.\n");
sc_error(ctx, "Unsupported object type.\n");
return SC_ERROR_NOT_SUPPORTED;
}
info = (struct sc_pkcs15_prkey_info *) obj->data;
if (info->native) {
error(ctx, "Private key is native, will not read.");
sc_error(ctx, "Private key is native, will not read.");
return SC_ERROR_NOT_ALLOWED;
}
@ -332,7 +332,7 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card,
r = sc_pkcs15_read_file(p15card, &path, &data, &len, NULL);
if (r < 0) {
error(ctx, "Unable to read private key file.\n");
sc_error(ctx, "Unable to read private key file.\n");
return r;
}
@ -350,7 +350,7 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card,
data, len,
&clear, &clear_len);
if (r < 0) {
error(ctx, "Failed to unwrap privat key.");
sc_error(ctx, "Failed to unwrap privat key.");
goto fail;
}
free(data);
@ -360,7 +360,7 @@ sc_pkcs15_read_prkey(struct sc_pkcs15_card *p15card,
r = sc_pkcs15_decode_prkey(ctx, &key, data, len);
if (r < 0) {
error(ctx, "Unable to decode private key");
sc_error(ctx, "Unable to decode private key");
goto fail;
}

View File

@ -179,7 +179,7 @@ int sc_pkcs15_encode_pukdf_entry(struct sc_context *ctx,
sc_format_asn1_entry(asn1_dsakey_attr + 0, &pubkey->path, NULL, 1);
break;
default:
error(ctx, "Unsupported public key type: %X\n", obj->type);
sc_error(ctx, "Unsupported public key type: %X\n", obj->type);
SC_FUNC_RETURN(ctx, 0, SC_ERROR_INTERNAL);
break;
}
@ -333,7 +333,7 @@ sc_pkcs15_encode_pubkey(struct sc_context *ctx,
return sc_pkcs15_encode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
if (key->algorithm == SC_ALGORITHM_DSA)
return sc_pkcs15_encode_pubkey_dsa(ctx, &key->u.dsa, buf, len);
error(ctx, "Encoding of public key type %u not supported\n",
sc_error(ctx, "Encoding of public key type %u not supported\n",
key->algorithm);
return SC_ERROR_NOT_SUPPORTED;
}
@ -347,7 +347,7 @@ sc_pkcs15_decode_pubkey(struct sc_context *ctx,
return sc_pkcs15_decode_pubkey_rsa(ctx, &key->u.rsa, buf, len);
if (key->algorithm == SC_ALGORITHM_DSA)
return sc_pkcs15_decode_pubkey_dsa(ctx, &key->u.dsa, buf, len);
error(ctx, "Decoding of public key type %u not supported\n",
sc_error(ctx, "Decoding of public key type %u not supported\n",
key->algorithm);
return SC_ERROR_NOT_SUPPORTED;
}
@ -377,14 +377,14 @@ sc_pkcs15_read_pubkey(struct sc_pkcs15_card *p15card,
algorithm = SC_ALGORITHM_DSA;
break;
default:
error(p15card->card->ctx, "Unsupported public key type.");
sc_error(p15card->card->ctx, "Unsupported public key type.");
return SC_ERROR_NOT_SUPPORTED;
}
info = (const struct sc_pkcs15_pubkey_info *) obj->data;
r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, NULL);
if (r < 0) {
error(p15card->card->ctx, "Failed to read public key file.");
sc_error(p15card->card->ctx, "Failed to read public key file.");
return r;
}

View File

@ -75,13 +75,13 @@ int sc_pkcs15_decipher(struct sc_pkcs15_card *p15card,
return SC_ERROR_EXTRACTABLE_KEY;
if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_DECRYPT|SC_PKCS15_PRKEY_USAGE_UNWRAP))) {
error(ctx, "This key cannot be used for decryption\n");
sc_error(ctx, "This key cannot be used for decryption\n");
return SC_ERROR_NOT_ALLOWED;
}
alg_info = _sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
if (alg_info == NULL) {
error(ctx, "Card does not support RSA with key length %d\n", prkey->modulus_length);
sc_error(ctx, "Card does not support RSA with key length %d\n", prkey->modulus_length);
return SC_ERROR_NOT_SUPPORTED;
}
senv.algorithm = SC_ALGORITHM_RSA;
@ -94,11 +94,11 @@ int sc_pkcs15_decipher(struct sc_pkcs15_card *p15card,
senv.algorithm_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
} else if ((flags & SC_ALGORITHM_RSA_PAD_ANSI) ||
(flags & SC_ALGORITHM_RSA_PAD_ISO9796)) {
error(ctx, "Only PKCS #1 padding method supported\n");
sc_error(ctx, "Only PKCS #1 padding method supported\n");
return SC_ERROR_NOT_SUPPORTED;
} else {
if (!(alg_info->flags & SC_ALGORITHM_RSA_RAW)) {
error(ctx, "Card requires RSA padding\n");
sc_error(ctx, "Card requires RSA padding\n");
return SC_ERROR_NOT_SUPPORTED;
}
senv.algorithm_flags |= SC_ALGORITHM_RSA_RAW;
@ -162,13 +162,13 @@ int sc_pkcs15_compute_signature(struct sc_pkcs15_card *p15card,
if (!(prkey->usage & (SC_PKCS15_PRKEY_USAGE_SIGN|SC_PKCS15_PRKEY_USAGE_SIGNRECOVER|
SC_PKCS15_PRKEY_USAGE_NONREPUDIATION))) {
error(ctx, "This key cannot be used for signing\n");
sc_error(ctx, "This key cannot be used for signing\n");
return SC_ERROR_NOT_ALLOWED;
}
alg_info = _sc_card_find_rsa_alg(p15card->card, prkey->modulus_length);
if (alg_info == NULL) {
error(ctx, "Card does not support RSA with key length %d\n", prkey->modulus_length);
sc_error(ctx, "Card does not support RSA with key length %d\n", prkey->modulus_length);
return SC_ERROR_NOT_SUPPORTED;
}
senv.algorithm = SC_ALGORITHM_RSA;
@ -217,11 +217,11 @@ int sc_pkcs15_compute_signature(struct sc_pkcs15_card *p15card,
senv.algorithm_flags |= SC_ALGORITHM_RSA_PAD_PKCS1;
} else if ((flags & SC_ALGORITHM_RSA_PAD_ANSI) ||
(flags & SC_ALGORITHM_RSA_PAD_ISO9796)) {
error(ctx, "Only PKCS #1 padding method supported\n");
sc_error(ctx, "Only PKCS #1 padding method supported\n");
return SC_ERROR_NOT_SUPPORTED;
} else {
if (!(alg_info->flags & SC_ALGORITHM_RSA_RAW)) {
error(ctx, "Card requires RSA padding\n");
sc_error(ctx, "Card requires RSA padding\n");
return SC_ERROR_NOT_SUPPORTED;
}
senv.algorithm_flags |= SC_ALGORITHM_RSA_RAW;

View File

@ -78,7 +78,7 @@ sc_pkcs15_derive_key(struct sc_context *ctx,
/* XXX: We might also encounter PBES2 here */
if (der_alg->algorithm != SC_ALGORITHM_PBKDF2) {
error(ctx, "Unsupported key derivation algorithm.\n");
sc_error(ctx, "Unsupported key derivation algorithm.\n");
return SC_ERROR_NOT_SUPPORTED;
}
@ -92,18 +92,18 @@ sc_pkcs15_derive_key(struct sc_context *ctx,
iv = (u8 *) enc_alg->params;
break;
default:
error(ctx, "Unsupported key encryption algorithm.\n");
sc_error(ctx, "Unsupported key encryption algorithm.\n");
return SC_ERROR_NOT_SUPPORTED;
}
key_len = EVP_CIPHER_key_length(cipher);
info = (struct sc_pbkdf2_params *) der_alg->params;
if (info->key_length && info->key_length != key_len) {
error(ctx, "Incompatible key length.\n");
sc_error(ctx, "Incompatible key length.\n");
return SC_ERROR_INVALID_ARGUMENTS;
}
if (key_len > sizeof(key)) {
error(ctx, "Huge key length (%u).\n", key_len);
sc_error(ctx, "Huge key length (%u).\n", key_len);
return SC_ERROR_INVALID_ARGUMENTS;
}
@ -111,7 +111,7 @@ sc_pkcs15_derive_key(struct sc_context *ctx,
info->salt, info->salt_len,
info->iterations, key_len, key);
if (r == 0) {
error(ctx, "Key derivation failed.\n");
sc_error(ctx, "Key derivation failed.\n");
return SC_ERROR_INTERNAL; /* for lack of something better */
}
@ -215,7 +215,7 @@ sc_pkcs15_unwrap_data(struct sc_context *ctx,
memset(&envdata, 0, sizeof(envdata));
r = sc_pkcs15_decode_enveloped_data(ctx, &envdata, in, in_len);
if (r < 0) {
error(ctx, "Failed to decode EnvelopedData.\n");
sc_error(ctx, "Failed to decode EnvelopedData.\n");
return r;
}

View File

@ -109,7 +109,7 @@ static void parse_tokeninfo(struct sc_pkcs15_card *card, const u8 * buf, size_t
r = sc_asn1_decode(card->card->ctx, asn1_tokeninfo, buf, buflen, NULL, NULL);
if (r) {
error(card->card->ctx,
sc_error(card->card->ctx,
"ASN.1 parsing of EF(TokenInfo) failed: %s\n",
sc_strerror(r));
goto err;
@ -186,7 +186,7 @@ int sc_pkcs15_encode_tokeninfo(struct sc_context *ctx,
r = sc_asn1_encode(ctx, asn1_tokeninfo, buf, buflen);
if (r) {
error(ctx, "sc_asn1_encode() failed: %s\n", sc_strerror(r));
sc_error(ctx, "sc_asn1_encode() failed: %s\n", sc_strerror(r));
return r;
}
return 0;
@ -212,7 +212,7 @@ static int parse_ddo(struct sc_pkcs15_card *p15card, const u8 * buf, size_t bufl
r = sc_asn1_decode(p15card->card->ctx, asn1_ddo, buf, buflen, NULL, NULL);
if (r) {
error(p15card->card->ctx, "DDO parsing failed: %s\n",
sc_error(p15card->card->ctx, "DDO parsing failed: %s\n",
sc_strerror(r));
return r;
}
@ -255,7 +255,7 @@ static int encode_ddo(struct sc_pkcs15_card *p15card, u8 **buf, size_t *buflen)
r = sc_asn1_encode(ctx, asn1_dir, buf, buflen);
if (r) {
error(ctx, "sc_asn1_encode() failed: %s\n",
sc_error(ctx, "sc_asn1_encode() failed: %s\n",
sc_strerror(r));
return r;
}
@ -384,7 +384,7 @@ int sc_pkcs15_encode_odf(struct sc_context *ctx,
df = df->next;
};
if (df_count == 0) {
error(ctx, "No DF's found.\n");
sc_error(ctx, "No DF's found.\n");
return SC_ERROR_OBJECT_NOT_FOUND;
}
asn1_odf = (struct sc_asn1_entry *) malloc(sizeof(struct sc_asn1_entry) * (df_count + 1));
@ -406,7 +406,7 @@ int sc_pkcs15_encode_odf(struct sc_context *ctx,
break;
}
if (type == -1) {
error(ctx, "Unsupported DF type.\n");
sc_error(ctx, "Unsupported DF type.\n");
continue;
}
asn1_odf[c] = c_asn1_odf[type];
@ -492,7 +492,7 @@ int sc_pkcs15_bind(struct sc_card *card,
err = sc_lock(card);
if (err) {
error(ctx, "sc_lock() failed: %s\n", sc_strerror(err));
sc_error(ctx, "sc_lock() failed: %s\n", sc_strerror(err));
sc_pkcs15_card_free(p15card);
SC_FUNC_RETURN(ctx, 1, err);
}
@ -500,7 +500,7 @@ int sc_pkcs15_bind(struct sc_card *card,
if (card->app_count < 0) {
err = sc_enum_apps(card);
if (err < 0 && err != SC_ERROR_FILE_NOT_FOUND) {
error(ctx, "unable to enumerate apps: %s\n", sc_strerror(err));
sc_error(ctx, "unable to enumerate apps: %s\n", sc_strerror(err));
goto error;
}
}
@ -560,7 +560,7 @@ int sc_pkcs15_bind(struct sc_card *card,
len = err;
if (parse_odf(buf, len, p15card)) {
err = SC_ERROR_PKCS15_APP_NOT_FOUND;
error(card->ctx, "Unable to parse ODF\n");
sc_error(card->ctx, "Unable to parse ODF\n");
goto error;
}
if (p15card->file_tokeninfo == NULL) {
@ -628,7 +628,7 @@ int sc_pkcs15_bind_synthetic(struct sc_pkcs15_card *p15card)
int (*init_func)(sc_pkcs15_card_t *);
if (ctx->debug >= 4) {
debug(ctx, "Loading: %s\n", tmp->data);
sc_debug(ctx, "Loading: %s\n", tmp->data);
}
/* try to open dynamic library */
r = sc_module_open(ctx, &handle, tmp->data);
@ -659,7 +659,7 @@ int sc_pkcs15_bind_synthetic(struct sc_pkcs15_card *p15card)
else if (tmp_r == SC_ERROR_WRONG_CARD) {
/* wrong init_func => try next one (if existing) */
if (ctx->debug >= 4) {
debug(ctx, "init_func failed => trying next one\n");
sc_debug(ctx, "init_func failed => trying next one\n");
}
continue;
}
@ -1056,7 +1056,7 @@ int sc_pkcs15_encode_df(struct sc_context *ctx,
break;
}
if (func == NULL) {
error(ctx, "unknown DF type: %d\n", df->type);
sc_error(ctx, "unknown DF type: %d\n", df->type);
*buf_out = NULL;
*bufsize_out = 0;
return 0;
@ -1112,7 +1112,7 @@ int sc_pkcs15_parse_df(struct sc_pkcs15_card *p15card,
break;
}
if (func == NULL) {
error(ctx, "unknown DF type: %d\n", df->type);
sc_error(ctx, "unknown DF type: %d\n", df->type);
return SC_ERROR_INVALID_ARGUMENTS;
}
if (df->file != NULL)

View File

@ -80,7 +80,7 @@ static int refresh_slot_attributes(struct sc_reader *reader,
rv = priv->funcs.CT_data(priv->ctn, &dad, &sad, 5, cmd, &lr, rbuf);
if (rv || rbuf[lr-2] != 0x90) {
error(reader->ctx, "Error getting status of terminal: %d\n", rv);
sc_error(reader->ctx, "Error getting status of terminal: %d\n", rv);
return SC_ERROR_TRANSMIT_FAILED;
}
if (rbuf[0] == CTBCS_DATA_STATUS_CARD_CONNECT)
@ -105,7 +105,7 @@ static int ctapi_transmit(struct sc_reader *reader, struct sc_slot_info *slot,
rv = priv->funcs.CT_data(priv->ctn, &dad, &sad, sendsize, (u8 *) sendbuf, &lr, recvbuf);
if (rv != 0) {
error(reader->ctx, "Error transmitting APDU: %d\n", rv);
sc_error(reader->ctx, "Error transmitting APDU: %d\n", rv);
return SC_ERROR_TRANSMIT_FAILED;
}
*recvsize = lr;
@ -142,7 +142,7 @@ static int ctapi_connect(struct sc_reader *reader, struct sc_slot_info *slot)
rv = priv->funcs.CT_data(priv->ctn, &dad, &sad, 5, cmd, &lr, rbuf);
if (rv || rbuf[lr-2] != 0x90) {
error(reader->ctx, "Error activating card: %d\n", rv);
sc_error(reader->ctx, "Error activating card: %d\n", rv);
return SC_ERROR_TRANSMIT_FAILED;
}
if (lr < 2)
@ -169,7 +169,7 @@ static int ctapi_connect(struct sc_reader *reader, struct sc_slot_info *slot)
rv = priv->funcs.CT_data(priv->ctn, &dad, &sad, 9, cmd, &lr, rbuf);
if (rv) {
error(reader->ctx, "Error negotiating PPS: %d\n", rv);
sc_error(reader->ctx, "Error negotiating PPS: %d\n", rv);
return SC_ERROR_TRANSMIT_FAILED;
}
}
@ -239,14 +239,14 @@ static int ctapi_load_module(struct sc_context *ctx,
list = scconf_find_list(conf, "ports");
if (list == NULL) {
error(ctx, "No ports configured.\n");
sc_error(ctx, "No ports configured.\n");
return -1;
}
val = conf->name->data;
r = sc_module_open(ctx, &dlh, val);
if (r != SC_SUCCESS) {
error(ctx, "Unable to open shared library '%s'\n", val);
sc_error(ctx, "Unable to open shared library '%s'\n", val);
return -1;
}
r = sc_module_get_address(ctx, dlh, (void **) &funcs.CT_init, "CT_init");
@ -268,12 +268,12 @@ static int ctapi_load_module(struct sc_context *ctx,
struct sc_slot_info *slot;
if (sscanf(list->data, "%d", &port) != 1) {
error(ctx, "Port '%s' is not a number.\n", list->data);
sc_error(ctx, "Port '%s' is not a number.\n", list->data);
continue;
}
rv = funcs.CT_init(mod->ctn_count, port);
if (rv) {
error(ctx, "CT_init() failed with %d\n", rv);
sc_error(ctx, "CT_init() failed with %d\n", rv);
continue;
}
reader = (struct sc_reader *) malloc(sizeof(struct sc_reader));
@ -307,7 +307,7 @@ static int ctapi_load_module(struct sc_context *ctx,
}
return 0;
symerr:
error(ctx, "Unable to resolve CT-API symbols.\n");
sc_error(ctx, "Unable to resolve CT-API symbols.\n");
sc_module_close(ctx, dlh);
return -1;
}

View File

@ -239,21 +239,21 @@ openct_reader_connect(struct sc_reader *reader,
ct_reader_disconnect(data->h);
if (!(data->h = ct_reader_connect(data->num))) {
error(reader->ctx, "ct_reader_connect socket failed\n");
sc_error(reader->ctx, "ct_reader_connect socket failed\n");
return SC_ERROR_CARD_NOT_PRESENT;
}
rc = ct_card_request(data->h, slot->id, 0, NULL,
slot->atr, sizeof(slot->atr));
if (rc < 0) {
error(reader->ctx,
sc_error(reader->ctx,
"openct_reader_connect read failed: %s\n",
ct_strerror(rc));
return SC_ERROR_CARD_NOT_PRESENT;
}
if (rc == 0) {
error(reader->ctx, "openct_reader_connect recved no data\n");
sc_error(reader->ctx, "openct_reader_connect recved no data\n");
return SC_ERROR_READER;
}

View File

@ -49,11 +49,11 @@
#define SCARD_SCOPE_GLOBAL SCARD_SCOPE_USER
/* Error printing */
#define PCSC_ERROR(ctx, desc, rv) error(ctx, desc ": %lx\n", rv);
#define PCSC_ERROR(ctx, desc, rv) sc_error(ctx, desc ": %lx\n", rv);
#else
#define PCSC_ERROR(ctx, desc, rv) error(ctx, desc ": %s\n", pcsc_stringify_error(rv));
#define PCSC_ERROR(ctx, desc, rv) sc_error(ctx, desc ": %s\n", pcsc_stringify_error(rv));
#endif
@ -162,7 +162,7 @@ static int pcsc_transmit(struct sc_reader *reader, struct sc_slot_info *slot,
lc = 256;
if (sendsize == lc + 6) {
/* Le is present, cut it out */
debug(reader->ctx, "Cutting out Le byte from Case 4 APDU\n");
sc_debug(reader->ctx, "Cutting out Le byte from Case 4 APDU\n");
sendsize--;
}
}

View File

@ -196,14 +196,14 @@ int usbtoken_reader_unix_cmd(struct sc_reader *reader,
assert(myprivslot->fd >= 0);
rc = write(myprivslot->fd, &cmd, sizeof(cmd));
if (rc != sizeof(cmd)) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_unix_cmd write failed\n");
return SC_ERROR_READER;
}
rc = read(myprivslot->fd, &msg, sizeof(msg));
if (rc != 1 || msg != 0) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_unix_cmd read failed\n");
return SC_ERROR_READER;
}
@ -222,7 +222,7 @@ int usbtoken_reader_connect(struct sc_reader *reader,
rc = socket(AF_UNIX, SOCK_STREAM, 0);
if (rc < 0) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_connect: socket() failed\n");
return SC_ERROR_READER;
}
@ -236,7 +236,7 @@ int usbtoken_reader_connect(struct sc_reader *reader,
if (rc < 0) {
close(myprivslot->fd);
myprivslot->fd = -1;
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_connect: connect(%s) failed\n",
myprivslot->sa_un.sun_path);
return SC_ERROR_CARD_NOT_PRESENT;
@ -244,14 +244,14 @@ int usbtoken_reader_connect(struct sc_reader *reader,
rc = read(myprivslot->fd, slot->atr, SC_MAX_ATR_SIZE);
if (rc == -1) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_connect: read failed on %s\n",
myprivslot->sa_un.sun_path);
return SC_ERROR_READER;
}
if (rc == 0) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_connect: read on %s recieved no data\n",
myprivslot->sa_un.sun_path);
return SC_ERROR_READER;
@ -290,7 +290,7 @@ int usbtoken_reader_transmit(struct sc_reader *reader,
assert(myprivslot->fd >= 0);
if (sendsize > 1023) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit sendsize %d too big\n",
sendsize);
return SC_ERROR_READER;
@ -300,32 +300,32 @@ int usbtoken_reader_transmit(struct sc_reader *reader,
memcpy(&buffer[1], sendbuf, sendsize);
rc = write(myprivslot->fd, buffer, sendsize + 1);
if (rc != sendsize + 1) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit write failed\n");
return SC_ERROR_READER;
}
rc = read(myprivslot->fd, buffer, sizeof(buffer));
if (rc == -1) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit read failed\n");
return SC_ERROR_READER;
}
if (rc == 0) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit recved no data\n");
return SC_ERROR_READER;
}
if (buffer[0] != 3) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit token failed\n");
return SC_ERROR_READER;
}
if (rc - 1 > *recvsize) {
error(reader->ctx,
sc_error(reader->ctx,
"usbtoken_reader_transmit recved too much (%d > %d)\n",
rc - 1, *recvsize);
return SC_ERROR_READER;

View File

@ -440,12 +440,12 @@ int _sc_parse_atr(struct sc_context *ctx, struct sc_slot_info *slot)
slot->atr_info.hist_bytes = NULL;
if (atr_len == 0) {
error(ctx, "empty ATR - card not present?\n");
sc_error(ctx, "empty ATR - card not present?\n");
return SC_ERROR_INTERNAL;
}
if (p[0] != 0x3B && p[0] != 0x3F) {
error(ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
sc_error(ctx, "invalid sync byte in ATR: 0x%02X\n", p[0]);
return SC_ERROR_INTERNAL;
}
n_hist = p[1] & 0x0F;

View File

@ -196,10 +196,10 @@ int sc_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *data,
break;
}
if (r == SC_ERROR_NOT_SUPPORTED)
error(card->ctx, "unsupported PIN operation (%d)",
sc_error(card->ctx, "unsupported PIN operation (%d)",
data->cmd);
} else {
error(card->ctx, "Use of pin pad not supported by card driver");
sc_error(card->ctx, "Use of pin pad not supported by card driver");
r = SC_ERROR_NOT_SUPPORTED;
}
SC_FUNC_RETURN(card->ctx, 2, r);

View File

@ -137,7 +137,7 @@ static CK_RV pkcs15_bind(struct sc_pkcs11_card *p11card)
p11card->fw_data = fw_data;
rc = sc_pkcs15_bind(p11card->card, &fw_data->p15_card);
debug(context, "Binding to PKCS#15, rc=%d\n", rc);
sc_debug(context, "Binding to PKCS#15, rc=%d\n", rc);
if (rc < 0)
return sc_to_cryptoki_error(rc, p11card->reader);
return register_mechanisms(p11card);
@ -322,7 +322,7 @@ pkcs15_create_pkcs11_objects(struct pkcs15_fw_data *fw_data,
rv = count = sc_pkcs15_get_objects(fw_data->p15_card, p15_type, p15_object, MAX_OBJECTS);
if (rv >= 0) {
debug(context, "Found %d %s%s\n", count,
sc_debug(context, "Found %d %s%s\n", count,
name, (count == 1)? "" : "s");
}
@ -514,7 +514,7 @@ static void pkcs15_init_slot(struct sc_pkcs15_card *card,
slot->token_info.ulMinPinLen = 4;
}
debug(context, "Initialized token '%s'\n", tmp);
sc_debug(context, "Initialized token '%s'\n", tmp);
}
static CK_RV pkcs15_create_slot(struct sc_pkcs11_card *p11card,
@ -554,7 +554,7 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
SC_PKCS15_MAX_PINS);
if (rv < 0)
return sc_to_cryptoki_error(rv, reader);
debug(context, "Found %d authentication objects\n", rv);
sc_debug(context, "Found %d authentication objects\n", rv);
auth_count = rv;
rv = pkcs15_create_pkcs11_objects(fw_data,
@ -603,7 +603,7 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
&obj->p15_object->auth_id))
continue;
debug(context, "Adding private key %d to PIN %d\n", j, i);
sc_debug(context, "Adding private key %d to PIN %d\n", j, i);
pkcs15_add_object(slot, obj, NULL);
}
}
@ -616,7 +616,7 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
struct pkcs15_any_object *obj = fw_data->objects[j];
if (!(obj->base.flags & SC_PKCS11_OBJECT_SEEN)) {
debug(context, "Object %d was not seen previously\n", j);
sc_debug(context, "Object %d was not seen previously\n", j);
if (!slot) {
rv = pkcs15_create_slot(p11card, NULL, &slot);
if (rv != CKR_OK)
@ -636,7 +636,7 @@ static CK_RV pkcs15_create_tokens(struct sc_pkcs11_card *p11card)
}
}
debug(context, "All tokens created\n");
sc_debug(context, "All tokens created\n");
return CKR_OK;
}
@ -704,7 +704,7 @@ static CK_RV pkcs15_login(struct sc_pkcs11_card *p11card,
return sc_to_cryptoki_error(rc, p11card->reader);
rc = sc_pkcs15_verify_pin(card, pin, pPin, ulPinLen);
debug(context, "PIN verification returned %d\n", rc);
sc_debug(context, "PIN verification returned %d\n", rc);
if (rc >= 0)
cache_pin(fw_token, userType, pPin, ulPinLen);
@ -755,7 +755,7 @@ static CK_RV pkcs15_change_pin(struct sc_pkcs11_card *p11card,
rc = sc_pkcs15_change_pin(fw_data->p15_card, pin, pOldPin, ulOldLen,
pNewPin, ulNewLen);
debug(context, "PIN verification returned %d\n", rc);
sc_debug(context, "PIN verification returned %d\n", rc);
if (rc >= 0)
cache_pin(fw_token, CKU_USER, pNewPin, ulNewLen);
@ -1132,7 +1132,7 @@ get_X509_usage_privk(CK_ATTRIBUTE_PTR pTempl, CK_ULONG ulCount, unsigned long *x
if (typ == CKA_DERIVE && *val)
*x509_usage |= 16;
if (typ == CKA_VERIFY || typ == CKA_WRAP || typ == CKA_ENCRYPT) {
debug(context, "get_X509_usage_privk(): invalid typ = 0x%0x\n", typ);
sc_debug(context, "get_X509_usage_privk(): invalid typ = 0x%0x\n", typ);
return CKR_ATTRIBUTE_TYPE_INVALID;
}
}
@ -1157,7 +1157,7 @@ get_X509_usage_pubk(CK_ATTRIBUTE_PTR pTempl, CK_ULONG ulCount, unsigned long *x5
if (typ == CKA_DERIVE && *val)
*x509_usage |= 16;
if (typ == CKA_SIGN || typ == CKA_UNWRAP || typ == CKA_DECRYPT) {
debug(context, "get_X509_usage_pubk(): invalid typ = 0x%0x\n", typ);
sc_debug(context, "get_X509_usage_pubk(): invalid typ = 0x%0x\n", typ);
return CKR_ATTRIBUTE_TYPE_INVALID;
}
}
@ -1190,7 +1190,7 @@ CK_RV pkcs15_gen_keypair(struct sc_pkcs11_card *p11card, struct sc_pkcs11_slot *
char priv_label[SC_PKCS15_MAX_LABEL_SIZE];
int rc, rv = CKR_OK;
debug(context, "Keypair generation, mech = 0x%0x\n", pMechanism->mechanism);
sc_debug(context, "Keypair generation, mech = 0x%0x\n", pMechanism->mechanism);
if (pMechanism->mechanism != CKM_RSA_PKCS_KEY_PAIR_GEN)
return CKR_MECHANISM_INVALID;
@ -1267,13 +1267,13 @@ CK_RV pkcs15_gen_keypair(struct sc_pkcs11_card *p11card, struct sc_pkcs11_slot *
id = ((struct sc_pkcs15_prkey_info *) priv_key_obj->data)->id;
rc = sc_pkcs15_find_pubkey_by_id(fw_data->p15_card, &id, &pub_key_obj);
if (rc != 0) {
debug(context, "sc_pkcs15_find_pubkey_by_id returned %d\n", rc);
sc_debug(context, "sc_pkcs15_find_pubkey_by_id returned %d\n", rc);
rv = sc_to_cryptoki_error(rc, p11card->reader);
goto kpgen_done;
}
}
else if (rc != SC_ERROR_NOT_SUPPORTED) {
debug(context, "sc_pkcs15init_generate_key returned %d\n", rc);
sc_debug(context, "sc_pkcs15init_generate_key returned %d\n", rc);
rv = sc_to_cryptoki_error(rc, p11card->reader);
goto kpgen_done;
}
@ -1281,16 +1281,16 @@ CK_RV pkcs15_gen_keypair(struct sc_pkcs11_card *p11card, struct sc_pkcs11_slot *
/* 3.b Try key pair generation in software, if allowed */
if (!sc_pkcs11_conf.soft_keygen_allowed) {
debug(context, "On card keypair gen not supported, software keypair gen not allowed");
sc_debug(context, "On card keypair gen not supported, software keypair gen not allowed");
rv = CKR_FUNCTION_FAILED;
goto kpgen_done;
}
debug(context, "Doing key pair generation in software\n");
sc_debug(context, "Doing key pair generation in software\n");
rv = sc_pkcs11_gen_keypair_soft(keytype, keybits,
&priv_args.key, &pub_args.key);
if (rv != CKR_OK) {
debug(context, "sc_pkcs11_gen_keypair_soft failed: 0x%0x\n", rv);
sc_debug(context, "sc_pkcs11_gen_keypair_soft failed: 0x%0x\n", rv);
goto kpgen_done;
}
@ -1301,7 +1301,7 @@ CK_RV pkcs15_gen_keypair(struct sc_pkcs11_card *p11card, struct sc_pkcs11_slot *
rc = sc_pkcs15init_store_public_key(p15card, profile,
&pub_args, &pub_key_obj);
if (rc < 0) {
debug(context, "private/public keys not stored: %d\n", rc);
sc_debug(context, "private/public keys not stored: %d\n", rc);
rv = sc_to_cryptoki_error(rc, p11card->reader);
goto kpgen_done;
}
@ -1313,7 +1313,7 @@ CK_RV pkcs15_gen_keypair(struct sc_pkcs11_card *p11card, struct sc_pkcs11_slot *
if (rc == 0)
__pkcs15_create_pubkey_object(fw_data, pub_key_obj, &pub_any_obj);
if (rc != 0) {
debug(context, "__pkcs15_create_pr/pubkey_object returned %d\n", rc);
sc_debug(context, "__pkcs15_create_pr/pubkey_object returned %d\n", rc);
rv = sc_to_cryptoki_error(rc, p11card->reader);
goto kpgen_done;
}
@ -1666,7 +1666,7 @@ CK_RV pkcs15_prkey_sign(struct sc_pkcs11_session *ses, void *obj,
struct pkcs15_slot_data *data = slot_data(ses->slot->fw_data);
int rv, flags = 0;
debug(context, "Initiating signing operation, mechanism 0x%x.\n",
sc_debug(context, "Initiating signing operation, mechanism 0x%x.\n",
pMechanism->mechanism);
/* If this key requires user consent for every N operations,
@ -1742,7 +1742,7 @@ CK_RV pkcs15_prkey_sign(struct sc_pkcs11_session *ses, void *obj,
return CKR_MECHANISM_INVALID;
}
debug(context, "Selected flags %X. Now computing signature for %d bytes. %d bytes reserved.\n", flags, ulDataLen, *pulDataLen);
sc_debug(context, "Selected flags %X. Now computing signature for %d bytes. %d bytes reserved.\n", flags, ulDataLen, *pulDataLen);
rv = sc_pkcs15_compute_signature(fw_data->p15_card,
prkey->prv_p15obj,
flags,
@ -1768,7 +1768,7 @@ CK_RV pkcs15_prkey_sign(struct sc_pkcs11_session *ses, void *obj,
sc_unlock(ses->slot->card->card);
}
debug(context, "Sign complete. Result %d.\n", rv);
sc_debug(context, "Sign complete. Result %d.\n", rv);
if (rv > 0) {
*pulDataLen = rv;
@ -1791,7 +1791,7 @@ pkcs15_prkey_unwrap(struct sc_pkcs11_session *ses, void *obj,
u8 unwrapped_key[256];
int rv;
debug(context, "Initiating key unwrap.\n");
sc_debug(context, "Initiating key unwrap.\n");
/* See which of the alternative keys supports unwrap */
prkey = (struct pkcs15_prkey_object *) obj;
@ -1830,7 +1830,7 @@ pkcs15_prkey_unwrap(struct sc_pkcs11_session *ses, void *obj,
sc_unlock(ses->slot->card->card);
}
debug(context, "Key unwrap complete. Result %d.\n", rv);
sc_debug(context, "Key unwrap complete. Result %d.\n", rv);
if (rv < 0)
return sc_to_cryptoki_error(rv, ses->slot->card->reader);
@ -2130,7 +2130,7 @@ revalidate_pin(struct pkcs15_slot_data *data, struct sc_pkcs11_session *ses)
int rv;
u8 value[MAX_CACHE_PIN];
debug(context, "revalidate_pin called\n");
sc_debug(context, "revalidate_pin called\n");
if (!sc_pkcs11_conf.cache_pins &&
!(ses->slot->token_info.flags & CKF_PROTECTED_AUTHENTICATION_PATH))
return SC_ERROR_SECURITY_STATUS_NOT_SATISFIED;
@ -2144,7 +2144,7 @@ revalidate_pin(struct pkcs15_slot_data *data, struct sc_pkcs11_session *ses)
}
if (rv != CKR_OK)
debug(context, "Re-login failed: 0x%0x (%d)\n", rv, rv);
sc_debug(context, "Re-login failed: 0x%0x (%d)\n", rv, rv);
return rv;
}
@ -2256,7 +2256,7 @@ lock_card(struct pkcs15_fw_data *fw_data)
int rc;
if ((rc = sc_lock(fw_data->p15_card->card)) < 0)
debug(context, "Failed to lock card (%d)\n", rc);
sc_debug(context, "Failed to lock card (%d)\n", rc);
else
fw_data->locked++;

View File

@ -69,7 +69,7 @@ CK_RV sc_to_cryptoki_error(int rc, int reader)
case SC_ERROR_INVALID_ARGUMENTS:
return CKR_ARGUMENTS_BAD;
}
debug(context, "opensc error: %s (%d)\n", sc_strerror(rc), rc);
sc_debug(context, "opensc error: %s (%d)\n", sc_strerror(rc), rc);
return CKR_GENERAL_ERROR;
}

View File

@ -152,7 +152,7 @@ sc_pkcs11_openssl_add_gen_rand(struct sc_pkcs11_session *session,
return CKR_OK;
if (scrandom_get_data(seed, 20) == -1) {
error(context, "scrandom_get_data() failed\n");
sc_error(context, "scrandom_get_data() failed\n");
return CKR_FUNCTION_FAILED;
}
RAND_seed(seed, 20);
@ -160,7 +160,7 @@ sc_pkcs11_openssl_add_gen_rand(struct sc_pkcs11_session *session,
if (rng_seeded == 0) {
r = sc_get_challenge(session->slot->card->card, seed, 20);
if (r != 0) {
error(context, "sc_get_challenge() returned %d\n", r);
sc_error(context, "sc_get_challenge() returned %d\n", r);
return sc_to_cryptoki_error(r, session->slot->card->reader);
}
rng_seeded = 1;
@ -198,7 +198,7 @@ sc_pkcs11_gen_keypair_soft(CK_KEY_TYPE keytype, CK_ULONG keybits,
rsa = RSA_generate_key(keybits, 0x10001, NULL, err);
BIO_free(err);
if (rsa == NULL) {
debug(context, "RSA_generate_key() failed\n");
sc_debug(context, "RSA_generate_key() failed\n");
return CKR_FUNCTION_FAILED;
}
@ -209,7 +209,7 @@ sc_pkcs11_gen_keypair_soft(CK_KEY_TYPE keytype, CK_ULONG keybits,
|| !do_convert_bignum(&sc_priv->d, rsa->d)
|| !do_convert_bignum(&sc_priv->p, rsa->p)
|| !do_convert_bignum(&sc_priv->q, rsa->q)) {
debug(context, "do_convert_bignum() failed\n");
sc_debug(context, "do_convert_bignum() failed\n");
RSA_free(rsa);
return CKR_FUNCTION_FAILED;
}
@ -221,7 +221,7 @@ sc_pkcs11_gen_keypair_soft(CK_KEY_TYPE keytype, CK_ULONG keybits,
if (!do_convert_bignum(&sc_pub->modulus, rsa->n)
|| !do_convert_bignum(&sc_pub->exponent, rsa->e)) {
debug(context, "do_convert_bignum() failed\n");
sc_debug(context, "do_convert_bignum() failed\n");
RSA_free(rsa);
return CKR_FUNCTION_FAILED;
}
@ -265,7 +265,7 @@ CK_RV sc_pkcs11_verify_data(unsigned char *pubkey, int pubkey_len,
else if (res == 0)
return CKR_SIGNATURE_INVALID;
else {
debug(context, "EVP_VerifyFinal() returned %d\n", res);
sc_debug(context, "EVP_VerifyFinal() returned %d\n", res);
return CKR_GENERAL_ERROR;
}
}
@ -300,7 +300,7 @@ CK_RV sc_pkcs11_verify_data(unsigned char *pubkey, int pubkey_len,
RSA_free(rsa);
if(rsa_outlen <= 0) {
free(rsa_out);
debug(context, "RSA_public_decrypt() returned %d\n", rsa_outlen);
sc_debug(context, "RSA_public_decrypt() returned %d\n", rsa_outlen);
return CKR_GENERAL_ERROR;
}

View File

@ -35,7 +35,7 @@ CK_RV C_Initialize(CK_VOID_PTR pReserved)
int i, rc, rv;
if (context != NULL) {
error(context, "C_Initialize(): Cryptoki already initialized\n");
sc_error(context, "C_Initialize(): Cryptoki already initialized\n");
return CKR_CRYPTOKI_ALREADY_INITIALIZED;
}
rc = sc_establish_context(&context, "opensc-pkcs11");
@ -60,7 +60,7 @@ CK_RV C_Initialize(CK_VOID_PTR pReserved)
rv = sc_pkcs11_init_lock((CK_C_INITIALIZE_ARGS_PTR) pReserved);
out: if (context != NULL)
debug(context, "C_Initialize: result = %d\n", rv);
sc_debug(context, "C_Initialize: result = %d\n", rv);
return rv;
}
@ -78,7 +78,7 @@ CK_RV C_Finalize(CK_VOID_PTR pReserved)
goto out;
}
debug(context, "Shutting down Cryptoki\n");
sc_debug(context, "Shutting down Cryptoki\n");
for (i=0; i<context->reader_count; i++)
card_removed(i);
@ -104,7 +104,7 @@ CK_RV C_GetInfo(CK_INFO_PTR pInfo)
goto out;
}
debug(context, "Cryptoki info query\n");
sc_debug(context, "Cryptoki info query\n");
memset(pInfo, 0, sizeof(CK_INFO));
pInfo->cryptokiVersion.major = 2;
@ -149,7 +149,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
goto out;
}
debug(context, "Getting slot listing\n");
sc_debug(context, "Getting slot listing\n");
card_detect_all();
numMatches = 0;
@ -161,14 +161,14 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
}
if (pSlotList == NULL_PTR) {
debug(context, "was only a size inquiry (%d)\n", numMatches);
sc_debug(context, "was only a size inquiry (%d)\n", numMatches);
*pulCount = numMatches;
rv = CKR_OK;
goto out;
}
if (*pulCount < numMatches) {
debug(context, "buffer was too small (needed %d)\n", numMatches);
sc_debug(context, "buffer was too small (needed %d)\n", numMatches);
*pulCount = numMatches;
rv = CKR_BUFFER_TOO_SMALL;
goto out;
@ -178,7 +178,7 @@ CK_RV C_GetSlotList(CK_BBOOL tokenPresent, /* only slots with token prese
*pulCount = numMatches;
rv = CKR_OK;
debug(context, "returned %d slots\n", numMatches);
sc_debug(context, "returned %d slots\n", numMatches);
out: sc_pkcs11_unlock();
return rv;
@ -199,7 +199,7 @@ CK_RV C_GetSlotInfo(CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo)
goto out;
}
debug(context, "Getting info about slot %d\n", slotID);
sc_debug(context, "Getting info about slot %d\n", slotID);
rv = slot_get_slot(slotID, &slot);
if (rv == CKR_OK){
@ -235,7 +235,7 @@ CK_RV C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo)
goto out;
}
debug(context, "Getting info about token in slot %d\n", slotID);
sc_debug(context, "Getting info about token in slot %d\n", slotID);
rv = slot_get_token(slotID, &slot);
if (rv == CKR_OK)
@ -372,7 +372,7 @@ again:
return rv;
if (r != SC_SUCCESS) {
error(context, "sc_wait_for_event() returned %d\n", r);
sc_error(context, "sc_wait_for_event() returned %d\n", r);
rv = sc_to_cryptoki_error(r, -1);
goto out;
}

View File

@ -204,7 +204,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv != CKR_OK)
goto out;
debug(context, "C_FindObjectsInit(slot = %d)\n", session->slot->id);
sc_debug(context, "C_FindObjectsInit(slot = %d)\n", session->slot->id);
dump_template("C_FindObjectsInit()", pTemplate, ulCount);
rv = session_start_operation(session, SC_PKCS11_OPERATION_FIND,
@ -232,7 +232,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, /* the session's handle */
if (object->ops->get_attribute(session, object, &private_attribute) != CKR_OK)
continue;
if (is_private) {
debug(context, "Object %d/%d: Private object and not logged in.\n",
sc_debug(context, "Object %d/%d: Private object and not logged in.\n",
slot->id,
item->handle);
continue;
@ -246,7 +246,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, /* the session's handle */
&pTemplate[j]);
if (rv == 0) {
if (context->debug >= 4) {
debug(context, "Object %d/%d: Attribute 0x%x does NOT match.\n",
sc_debug(context, "Object %d/%d: Attribute 0x%x does NOT match.\n",
slot->id,
item->handle, pTemplate[j].type);
}
@ -255,18 +255,18 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, /* the session's handle */
}
if (context->debug >= 4) {
debug(context, "Object %d/%d: Attribute 0x%x matches.\n",
sc_debug(context, "Object %d/%d: Attribute 0x%x matches.\n",
slot->id,
item->handle, pTemplate[j].type);
}
}
if (match) {
debug(context, "Object %d/%d matches\n",
sc_debug(context, "Object %d/%d matches\n",
slot->id, item->handle);
/* Avoid buffer overflow --okir */
if (operation->num_handles >= SC_PKCS11_FIND_MAX_HANDLES) {
debug(context, "Too many matching objects\n");
sc_debug(context, "Too many matching objects\n");
break;
}
operation->handles[operation->num_handles++] = item->handle;
@ -274,7 +274,7 @@ CK_RV C_FindObjectsInit(CK_SESSION_HANDLE hSession, /* the session's handle */
}
rv = CKR_OK;
debug(context, "%d matching objects\n", operation->num_handles);
sc_debug(context, "%d matching objects\n", operation->num_handles);
out: sc_pkcs11_unlock();
return rv;
@ -357,7 +357,7 @@ CK_RV C_DigestInit(CK_SESSION_HANDLE hSession, /* the session's handle */
rv = pool_find(&session_pool, hSession, (void**) &session);
if (rv == CKR_OK)
rv = sc_pkcs11_md_init(session, pMechanism);
debug(context, "C_DigestInit returns %d\n", rv);
sc_debug(context, "C_DigestInit returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -384,7 +384,7 @@ CK_RV C_Digest(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_md_final(session, pDigest, pulDigestLen);
out: debug(context, "C_Digest returns %d\n", rv);
out: sc_debug(context, "C_Digest returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -405,7 +405,7 @@ CK_RV C_DigestUpdate(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_md_update(session, pPart, ulPartLen);
debug(context, "C_DigestUpdate returns %d\n", rv);
sc_debug(context, "C_DigestUpdate returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
}
@ -431,7 +431,7 @@ CK_RV C_DigestFinal(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_md_final(session, pDigest, pulDigestLen);
debug(context, "C_DigestFinal returns %d\n", rv);
sc_debug(context, "C_DigestFinal returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
}
@ -478,7 +478,7 @@ CK_RV C_SignInit(CK_SESSION_HANDLE hSession, /* the session's handle */
rv = sc_pkcs11_sign_init(session, pMechanism, object, key_type);
out: debug(context, "Sign initialization returns %d\n", rv);
out: sc_debug(context, "Sign initialization returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -520,7 +520,7 @@ CK_RV C_Sign(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_sign_final(session, pSignature, pulSignatureLen);
out: debug(context, "Signing result was %d\n", rv);
out: sc_debug(context, "Signing result was %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -541,7 +541,7 @@ CK_RV C_SignUpdate(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_sign_update(session, pPart, ulPartLen);
debug(context, "C_SignUpdate returns %d\n", rv);
sc_debug(context, "C_SignUpdate returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
}
@ -577,7 +577,7 @@ CK_RV C_SignFinal(CK_SESSION_HANDLE hSession, /* the session's handle */
rv = sc_pkcs11_sign_final(session, pSignature, pulSignatureLen);
}
out: debug(context, "C_SignFinal returns %d\n", rv);
out: sc_debug(context, "C_SignFinal returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -625,11 +625,11 @@ CK_RV C_SignRecoverInit(CK_SESSION_HANDLE hSession, /* the session's handle */
/* XXX: need to tell the signature algorithm that we want
* to recover the signature */
debug(context, "SignRecover operation initialized\n");
sc_debug(context, "SignRecover operation initialized\n");
rv = sc_pkcs11_sign_init(session, pMechanism, object, key_type);
out: debug(context, "Sign initialization returns %d\n", rv);
out: sc_debug(context, "Sign initialization returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
}
@ -835,7 +835,7 @@ CK_RV C_UnwrapKey(CK_SESSION_HANDLE hSession, /* the session's handl
pTemplate, ulAttributeCount,
(void **) &result);
debug(context, "Unwrapping result was %d\n", rv);
sc_debug(context, "Unwrapping result was %d\n", rv);
if (rv == CKR_OK)
rv = pool_insert(&session->slot->object_pool, result, phKey);
@ -954,7 +954,7 @@ CK_RV C_VerifyInit(CK_SESSION_HANDLE hSession, /* the session's handle */
rv = sc_pkcs11_verif_init(session, pMechanism, object, key_type);
out: debug(context, "Verify initialization returns %d\n", rv);
out: sc_debug(context, "Verify initialization returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
@ -985,7 +985,7 @@ CK_RV C_Verify(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_verif_final(session, pSignature, ulSignatureLen);
out: debug(context, "Verify result was %d\n", rv);
out: sc_debug(context, "Verify result was %d\n", rv);
sc_pkcs11_unlock();
return rv;
#endif
@ -1009,7 +1009,7 @@ CK_RV C_VerifyUpdate(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv == CKR_OK)
rv = sc_pkcs11_verif_update(session, pPart, ulPartLen);
debug(context, "C_VerifyUpdate returns %d\n", rv);
sc_debug(context, "C_VerifyUpdate returns %d\n", rv);
sc_pkcs11_unlock();
return rv;
#endif
@ -1035,7 +1035,7 @@ CK_RV C_VerifyFinal(CK_SESSION_HANDLE hSession, /* the session's handle */
rv = sc_pkcs11_verif_final(session, pSignature, ulSignatureLen);
out: debug(context, "C_VerifyFinal returns %d\n", rv);
out: sc_debug(context, "C_VerifyFinal returns %d\n", rv);
sc_pkcs11_unlock();
return rv;

View File

@ -37,7 +37,7 @@ CK_RV C_OpenSession(CK_SLOT_ID slotID, /* the slot's ID */
if (rv != CKR_OK)
return rv;
debug(context, "Opening new session for slot %d\n", slotID);
sc_debug(context, "Opening new session for slot %d\n", slotID);
if (!(flags & CKF_SERIAL_SESSION)) {
rv = CKR_SESSION_PARALLEL_NOT_SUPPORTED;
@ -90,7 +90,7 @@ CK_RV C_CloseSession(CK_SESSION_HANDLE hSession) /* the session's handle */
if (rv != CKR_OK)
goto out;
debug(context, "C_CloseSession(slot %d)\n", session->slot->id);
sc_debug(context, "C_CloseSession(slot %d)\n", session->slot->id);
/* If we're the last session using this slot, make sure
* we log out */
@ -114,7 +114,7 @@ CK_RV sc_pkcs11_close_all_sessions(CK_SLOT_ID slotID)
struct sc_pkcs11_pool_item *item, *next;
struct sc_pkcs11_session *session;
debug(context, "C_CloseAllSessions().\n");
sc_debug(context, "C_CloseAllSessions().\n");
for (item = session_pool.head; item != NULL; item = next) {
session = (struct sc_pkcs11_session*) item->item;
next = item->next;
@ -166,7 +166,7 @@ CK_RV C_GetSessionInfo(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv != CKR_OK)
goto out;
debug(context, "C_GetSessionInfo(slot %d).\n", session->slot->id);
sc_debug(context, "C_GetSessionInfo(slot %d).\n", session->slot->id);
pInfo->slotID = session->slot->id;
pInfo->flags = session->flags;
pInfo->ulDeviceError = 0;
@ -226,7 +226,7 @@ CK_RV C_Login(CK_SESSION_HANDLE hSession, /* the session's handle */
if (rv != CKR_OK)
goto out;
debug(context, "Login for session %d\n", hSession);
sc_debug(context, "Login for session %d\n", hSession);
slot = session->slot;
@ -264,7 +264,7 @@ CK_RV C_Logout(CK_SESSION_HANDLE hSession) /* the session's handle */
if (rv != CKR_OK)
goto out;
debug(context, "Logout for session %d\n", hSession);
sc_debug(context, "Logout for session %d\n", hSession);
slot = session->slot;
@ -328,7 +328,7 @@ CK_RV C_SetPIN(CK_SESSION_HANDLE hSession,
if (rv != CKR_OK)
goto out;
debug(context, "Changing PIN (session %d)\n", hSession);
sc_debug(context, "Changing PIN (session %d)\n", hSession);
#if 0
if (!(ses->flags & CKF_RW_SESSION)) {
rv = CKR_SESSION_READ_ONLY;

View File

@ -80,7 +80,7 @@ CK_RV card_detect(int reader)
rv = CKR_OK;
debug(context, "%d: Detecting SmartCard\n", reader);
sc_debug(context, "%d: Detecting SmartCard\n", reader);
for (i = card->max_slots; i--; ) {
struct sc_pkcs11_slot *slot;
@ -94,19 +94,19 @@ CK_RV card_detect(int reader)
/* Check if someone inserted a card */
again: rc = sc_detect_card_presence(context->reader[reader], 0);
if (rc < 0) {
debug(context, "Card detection failed for reader %d: %s\n",
sc_debug(context, "Card detection failed for reader %d: %s\n",
reader, sc_strerror(rc));
return sc_to_cryptoki_error(rc, reader);
}
if (rc == 0) {
debug(context, "%d: Card absent\n", reader);
sc_debug(context, "%d: Card absent\n", reader);
card_removed(reader); /* Release all resources */
return CKR_TOKEN_NOT_PRESENT;
}
/* If the card was changed, disconnect the current one */
if (rc & SC_SLOT_CARD_CHANGED) {
debug(context, "%d: Card changed\n", reader);
sc_debug(context, "%d: Card changed\n", reader);
/* The following should never happen - but if it
* does we'll be stuck in an endless loop.
* So better be fussy. */
@ -118,7 +118,7 @@ again: rc = sc_detect_card_presence(context->reader[reader], 0);
/* Detect the card if it's not known already */
if (card->card == NULL) {
debug(context, "%d: Connecting to SmartCard\n", reader);
sc_debug(context, "%d: Connecting to SmartCard\n", reader);
rc = sc_connect_card(context->reader[reader], 0, &card->card);
if (rc != SC_SUCCESS)
return sc_to_cryptoki_error(rc, reader);
@ -126,7 +126,7 @@ again: rc = sc_detect_card_presence(context->reader[reader], 0);
/* Detect the framework */
if (card->framework == NULL) {
debug(context, "%d: Detecting Framework\n", reader);
sc_debug(context, "%d: Detecting Framework\n", reader);
for (i = 0; frameworks[i]; i++) {
if (frameworks[i]->bind == NULL)
@ -140,7 +140,7 @@ again: rc = sc_detect_card_presence(context->reader[reader], 0);
return CKR_TOKEN_NOT_RECOGNIZED;
/* Initialize framework */
debug(context, "%d: Detected framework %d. Creating tokens.\n", reader, i);
sc_debug(context, "%d: Detected framework %d. Creating tokens.\n", reader, i);
rv = frameworks[i]->create_tokens(card);
if (rv != CKR_OK)
return rv;
@ -148,7 +148,7 @@ again: rc = sc_detect_card_presence(context->reader[reader], 0);
card->framework = frameworks[i];
}
debug(context, "%d: Detection ended\n", reader);
sc_debug(context, "%d: Detection ended\n", reader);
return rv;
}
@ -180,7 +180,7 @@ CK_RV card_removed(int reader)
int i;
struct sc_pkcs11_card *card;
debug(context, "%d: SmartCard removed\n", reader);
sc_debug(context, "%d: SmartCard removed\n", reader);
for (i=0; i<SC_PKCS11_MAX_VIRTUAL_SLOTS; i++) {
if (virtual_slots[i].card &&
@ -227,7 +227,7 @@ CK_RV slot_allocate(struct sc_pkcs11_slot **slot, struct sc_pkcs11_card *card)
for (i = first; i < last; i++) {
if (!virtual_slots[i].card) {
debug(context, "Allocated slot %d\n", i);
sc_debug(context, "Allocated slot %d\n", i);
virtual_slots[i].card = card;
virtual_slots[i].events = SC_EVENT_CARD_INSERTED;