From ed358e839ba025ab4c4141c5a77b0a955dfcf689 Mon Sep 17 00:00:00 2001 From: frankmorgner Date: Mon, 13 Sep 2010 14:11:30 +0000 Subject: [PATCH] added support for unambiguous PACE-channel selection (ID.icc and ID.pcd) git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@262 96b47cad-a561-4643-ad3b-153ac7d7599c --- ccid/src/pace.c | 37 +++++++++++++++++++++++++++++++++++-- ccid/src/pace/pace.h | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/ccid/src/pace.c b/ccid/src/pace.c index 15a1ac4..3e4b18a 100644 --- a/ccid/src/pace.c +++ b/ccid/src/pace.c @@ -972,7 +972,8 @@ int EstablishPACEChannel(const struct sm_ctx *oldpacectx, sc_card_t *card, PACEDomainParameterInfo *static_dp = NULL, *eph_dp = NULL; BUF_MEM *enc_nonce = NULL, *nonce = NULL, *mdata = NULL, *mdata_opp = NULL, *k_enc = NULL, *k_mac = NULL, *token_opp = NULL, - *token = NULL, *pub = NULL, *pub_opp = NULL, *key = NULL; + *token = NULL, *pub = NULL, *pub_opp = NULL, *key = NULL, + *comp_pub = NULL, *comp_pub_opp = NULL; PACE_SEC *sec = NULL; PACE_CTX *pctx = NULL; int r; @@ -1120,7 +1121,35 @@ int EstablishPACEChannel(const struct sm_ctx *oldpacectx, sc_card_t *card, goto err; } - /* XXX IDicc */ + /* Identifier for ICC and PCD */ + comp_pub = PACE_Comp(eph_dp, pctx, pub); + comp_pub_opp = PACE_Comp(eph_dp, pctx, pub_opp); + if (!comp_pub || !comp_pub_opp) { + sc_error(card->ctx, "Could not compress public keys for identification."); + ssl_error(card->ctx); + r = SC_ERROR_INTERNAL; + goto err; + } + p = realloc(pace_output->id_icc, comp_pub_opp->length); + if (!p) { + sc_error(card->ctx, "Not enough memory for ID ICC.\n"); + return SC_ERROR_OUT_OF_MEMORY; + } + pace_output->id_icc = p; + pace_output->id_icc_length = comp_pub_opp->length; + memcpy(pace_output->id_icc, comp_pub_opp->data, comp_pub_opp->length); + bin_log(card->ctx, "ID ICC", pace_output->id_icc, + pace_output->id_icc_length); + p = realloc(pace_output->id_pcd, comp_pub->length); + if (!p) { + sc_error(card->ctx, "Not enough memory for ID PCD.\n"); + return SC_ERROR_OUT_OF_MEMORY; + } + pace_output->id_pcd = p; + pace_output->id_pcd_length = comp_pub->length; + memcpy(pace_output->id_pcd, comp_pub->data, comp_pub->length); + bin_log(card->ctx, "ID PCD", pace_output->id_pcd, + pace_output->id_pcd_length); /* XXX parse CHAT to check role of terminal */ @@ -1169,6 +1198,10 @@ err: BUF_MEM_free(pub); if (pub_opp) BUF_MEM_free(pub_opp); + if (comp_pub_opp) + BUF_MEM_free(comp_pub_opp); + if (comp_pub) + BUF_MEM_free(comp_pub); if (key) { OPENSSL_cleanse(key->data, key->length); BUF_MEM_free(key); diff --git a/ccid/src/pace/pace.h b/ccid/src/pace/pace.h index 5dc10d5..1aff525 100644 --- a/ccid/src/pace/pace.h +++ b/ccid/src/pace/pace.h @@ -80,6 +80,9 @@ struct establish_pace_channel_output { size_t id_icc_length; unsigned char *id_icc; + + size_t id_pcd_length; + unsigned char *id_pcd; }; #ifdef BUERGERCLIENT_WORKAROUND