- some unneded functions are no longer available in header files

- cleaned memory leaks in pace-tool and ccid-emulator


git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@264 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
frankmorgner
2010-09-14 20:37:43 +00:00
parent 4a7fc6c457
commit 8623c7fe6e
5 changed files with 72 additions and 30 deletions

View File

@@ -776,8 +776,10 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
__le16 word; __le16 word;
__u8 *p; __u8 *p;
if (!abDataOut || !abDataOutLen) if (!abDataOut || !abDataOutLen) {
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
}
memset(&pace_input, 0, sizeof(pace_input)); memset(&pace_input, 0, sizeof(pace_input));
memset(&pace_output, 0, sizeof(pace_output)); memset(&pace_output, 0, sizeof(pace_output));
@@ -785,7 +787,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (abDatalen < parsed+1) { if (abDatalen < parsed+1) {
sc_error(ctx, "Buffer too small, could not get PinID"); sc_error(ctx, "Buffer too small, could not get PinID");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.pin_id = abData[parsed]; pace_input.pin_id = abData[parsed];
parsed++; parsed++;
@@ -793,14 +796,16 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (abDatalen < parsed+1) { if (abDatalen < parsed+1) {
sc_error(ctx, "Buffer too small, could not get lengthCHAT"); sc_error(ctx, "Buffer too small, could not get lengthCHAT");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.chat_length = abData[parsed]; pace_input.chat_length = abData[parsed];
parsed++; parsed++;
if (abDatalen < parsed+pace_input.chat_length) { if (abDatalen < parsed+pace_input.chat_length) {
sc_error(ctx, "Buffer too small, could not get CHAT"); sc_error(ctx, "Buffer too small, could not get CHAT");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.chat = &abData[parsed]; pace_input.chat = &abData[parsed];
parsed += pace_input.chat_length; parsed += pace_input.chat_length;
@@ -812,14 +817,16 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (abDatalen < parsed+1) { if (abDatalen < parsed+1) {
sc_error(ctx, "Buffer too small, could not get lengthPIN"); sc_error(ctx, "Buffer too small, could not get lengthPIN");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.pin_length = abData[parsed]; pace_input.pin_length = abData[parsed];
parsed++; parsed++;
if (abDatalen < parsed+pace_input.pin_length) { if (abDatalen < parsed+pace_input.pin_length) {
sc_error(ctx, "Buffer too small, could not get PIN"); sc_error(ctx, "Buffer too small, could not get PIN");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.pin = &abData[parsed]; pace_input.pin = &abData[parsed];
parsed += pace_input.pin_length; parsed += pace_input.pin_length;
@@ -827,7 +834,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (abDatalen < parsed+sizeof(word)) { if (abDatalen < parsed+sizeof(word)) {
sc_error(ctx, "Buffer too small, could not get lengthCertificateDescription"); sc_error(ctx, "Buffer too small, could not get lengthCertificateDescription");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
memcpy(&word, &abData[parsed], sizeof word); memcpy(&word, &abData[parsed], sizeof word);
pace_input.certificate_description_length = __le16_to_cpu(word); pace_input.certificate_description_length = __le16_to_cpu(word);
@@ -835,7 +843,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (abDatalen < parsed+pace_input.certificate_description_length) { if (abDatalen < parsed+pace_input.certificate_description_length) {
sc_error(ctx, "Buffer too small, could not get CertificateDescription"); sc_error(ctx, "Buffer too small, could not get CertificateDescription");
return SC_ERROR_INVALID_ARGUMENTS; sc_result = SC_ERROR_INVALID_ARGUMENTS;
goto err;
} }
pace_input.certificate_description = &abData[parsed]; pace_input.certificate_description = &abData[parsed];
parsed += pace_input.certificate_description_length; parsed += pace_input.certificate_description_length;
@@ -856,7 +865,7 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
sc_result = EstablishPACEChannel(NULL, card, pace_input, &pace_output, sc_result = EstablishPACEChannel(NULL, card, pace_input, &pace_output,
&sctx); &sctx);
if (sc_result < 0) if (sc_result < 0)
return sc_result; goto err;
p = realloc(*abDataOut, 2 + /* Statusbytes */ p = realloc(*abDataOut, 2 + /* Statusbytes */
@@ -864,8 +873,10 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
1+pace_output.recent_car_length + /* Most recent CAR */ 1+pace_output.recent_car_length + /* Most recent CAR */
1+pace_output.previous_car_length + /* Previous CAR */ 1+pace_output.previous_car_length + /* Previous CAR */
2+pace_output.id_icc_length); /* identifier of the MRTD chip */ 2+pace_output.id_icc_length); /* identifier of the MRTD chip */
if (!p) if (!p) {
return SC_ERROR_OUT_OF_MEMORY; sc_result = SC_ERROR_OUT_OF_MEMORY;
goto err;
}
*abDataOut = p; *abDataOut = p;
@@ -879,7 +890,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (pace_output.ef_cardaccess_length > 0xffff) { if (pace_output.ef_cardaccess_length > 0xffff) {
sc_error(ctx, "EF.CardAcces %u bytes too long", sc_error(ctx, "EF.CardAcces %u bytes too long",
pace_output.ef_cardaccess_length-0xffff); pace_output.ef_cardaccess_length-0xffff);
return SC_ERROR_INVALID_DATA; sc_result = SC_ERROR_INVALID_DATA;
goto err;
} }
word = __cpu_to_le16(pace_output.ef_cardaccess_length); word = __cpu_to_le16(pace_output.ef_cardaccess_length);
memcpy(p, &word, sizeof word); memcpy(p, &word, sizeof word);
@@ -893,7 +905,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (pace_output.recent_car_length > 0xff) { if (pace_output.recent_car_length > 0xff) {
sc_error(ctx, "Most recent CAR %u bytes too long", sc_error(ctx, "Most recent CAR %u bytes too long",
pace_output.recent_car_length-0xff); pace_output.recent_car_length-0xff);
return SC_ERROR_INVALID_DATA; sc_result = SC_ERROR_INVALID_DATA;
goto err;
} }
*p = pace_output.recent_car_length; *p = pace_output.recent_car_length;
p += 1; p += 1;
@@ -906,7 +919,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (pace_output.previous_car_length > 0xff) { if (pace_output.previous_car_length > 0xff) {
sc_error(ctx, "Most previous CAR %u bytes too long", sc_error(ctx, "Most previous CAR %u bytes too long",
pace_output.previous_car_length-0xff); pace_output.previous_car_length-0xff);
return SC_ERROR_INVALID_DATA; sc_result = SC_ERROR_INVALID_DATA;
goto err;
} }
*p = pace_output.previous_car_length; *p = pace_output.previous_car_length;
p += 1; p += 1;
@@ -919,7 +933,8 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
if (pace_output.id_icc_length > 0xffff) { if (pace_output.id_icc_length > 0xffff) {
sc_error(ctx, "ID ICC %u bytes too long", sc_error(ctx, "ID ICC %u bytes too long",
pace_output.id_icc_length-0xffff); pace_output.id_icc_length-0xffff);
return SC_ERROR_INVALID_DATA; sc_result = SC_ERROR_INVALID_DATA;
goto err;
} }
word = __cpu_to_le16(pace_output.id_icc_length); word = __cpu_to_le16(pace_output.id_icc_length);
memcpy(p, &word, sizeof word); memcpy(p, &word, sizeof word);
@@ -936,7 +951,19 @@ perform_PC_to_RDR_Secure_EstablishPACEChannel(sc_card_t *card,
1+pace_output.previous_car_length + 1+pace_output.previous_car_length +
2+pace_output.id_icc_length; 2+pace_output.id_icc_length;
return SC_SUCCESS; sc_result = SC_SUCCESS;
err:
if (pace_output.recent_car)
free(pace_output.recent_car);
if (pace_output.previous_car)
free(pace_output.previous_car);
if (pace_output.id_icc)
free(pace_output.id_icc);
if (pace_output.id_pcd)
free(pace_output.id_pcd);
return sc_result;
} }
static int static int

View File

@@ -502,6 +502,19 @@ main (int argc, char **argv)
} }
err: err:
pace_sm_ctx_clear_free(sctx.cipher_ctx);
pace_sm_ctx_clear_free(tmpctx.cipher_ctx);
if (pace_output.ef_cardaccess)
free(pace_output.ef_cardaccess);
if (pace_output.recent_car)
free(pace_output.recent_car);
if (pace_output.previous_car)
free(pace_output.previous_car);
if (pace_output.id_icc)
free(pace_output.id_icc);
if (pace_output.id_pcd)
free(pace_output.id_pcd);
sc_disconnect_card(card, 0); sc_disconnect_card(card, 0);
sc_release_context(ctx); sc_release_context(ctx);

View File

@@ -1280,7 +1280,8 @@ reset_ssc(struct pace_sm_ctx *psmctx)
return SC_SUCCESS; return SC_SUCCESS;
} }
int pace_sm_encrypt(sc_card_t *card, const struct sm_ctx *ctx, static int
pace_sm_encrypt(sc_card_t *card, const struct sm_ctx *ctx,
const u8 *data, size_t datalen, u8 **enc) const u8 *data, size_t datalen, u8 **enc)
{ {
BUF_MEM *encbuf = NULL, *databuf = NULL; BUF_MEM *encbuf = NULL, *databuf = NULL;
@@ -1322,7 +1323,8 @@ err:
return r; return r;
} }
int pace_sm_decrypt(sc_card_t *card, const struct sm_ctx *ctx, static int
pace_sm_decrypt(sc_card_t *card, const struct sm_ctx *ctx,
const u8 *enc, size_t enclen, u8 **data) const u8 *enc, size_t enclen, u8 **data)
{ {
BUF_MEM *encbuf = NULL, *databuf = NULL; BUF_MEM *encbuf = NULL, *databuf = NULL;
@@ -1364,7 +1366,8 @@ err:
return r; return r;
} }
int pace_sm_authenticate(sc_card_t *card, const struct sm_ctx *ctx, static int
pace_sm_authenticate(sc_card_t *card, const struct sm_ctx *ctx,
const u8 *data, size_t datalen, u8 **macdata) const u8 *data, size_t datalen, u8 **macdata)
{ {
BUF_MEM *macbuf = NULL; BUF_MEM *macbuf = NULL;
@@ -1405,7 +1408,8 @@ err:
return r; return r;
} }
int pace_sm_verify_authentication(sc_card_t *card, const struct sm_ctx *ctx, static int
pace_sm_verify_authentication(sc_card_t *card, const struct sm_ctx *ctx,
const u8 *mac, size_t maclen, const u8 *mac, size_t maclen,
const u8 *macdata, size_t macdatalen) const u8 *macdata, size_t macdatalen)
{ {
@@ -1448,14 +1452,15 @@ err:
return r; return r;
} }
int pace_sm_pre_transmit(sc_card_t *card, const struct sm_ctx *ctx, static int
pace_sm_pre_transmit(sc_card_t *card, const struct sm_ctx *ctx,
sc_apdu_t *apdu) sc_apdu_t *apdu)
{ {
SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG, SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG,
increment_ssc(ctx->cipher_ctx)); increment_ssc(ctx->cipher_ctx));
} }
int pace_sm_post_transmit(sc_card_t *card, const struct sm_ctx *ctx, static int pace_sm_post_transmit(sc_card_t *card, const struct sm_ctx *ctx,
sc_apdu_t *sm_apdu) sc_apdu_t *sm_apdu)
{ {
SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG, SC_FUNC_RETURN(card->ctx, SC_LOG_TYPE_DEBUG,

View File

@@ -56,10 +56,6 @@ struct sm_ctx {
int sm_transmit_apdu(const struct sm_ctx *sctx, sc_card_t *card, int sm_transmit_apdu(const struct sm_ctx *sctx, sc_card_t *card,
sc_apdu_t *apdu); sc_apdu_t *apdu);
int add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded);
int add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen,
u8 **padded);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -44,7 +44,7 @@ static const struct sc_asn1_entry c_sm_rapdu[] = {
{ NULL, 0, 0, 0, NULL, NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int static int
add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded) add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded)
{ {
u8 *p; u8 *p;
@@ -72,7 +72,7 @@ add_iso_pad(const u8 *data, size_t datalen, int block_size, u8 **padded)
return p_len; return p_len;
} }
int static int
add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen, add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen,
u8 **padded) u8 **padded)
{ {
@@ -95,7 +95,8 @@ add_padding(const struct sm_ctx *ctx, const u8 *data, size_t datalen,
} }
} }
int no_padding(u8 padding_indicator, const u8 *data, size_t datalen) static int
no_padding(u8 padding_indicator, const u8 *data, size_t datalen)
{ {
if (!datalen || !data) if (!datalen || !data)
return SC_ERROR_INVALID_ARGUMENTS; return SC_ERROR_INVALID_ARGUMENTS;