initialize EAC_CTX when doing TA/CA without PACE

This commit is contained in:
Frank Morgner
2014-10-27 08:02:32 +01:00
parent f7513ed6ff
commit 6e3805748a

View File

@@ -1581,11 +1581,13 @@ int perform_terminal_authentication(sc_card_t *card,
{ {
int r; int r;
const unsigned char *cert = NULL; const unsigned char *cert = NULL;
size_t cert_len = 0; size_t cert_len = 0, ef_cardaccess_length = 0;
CVC_CERT *cvc_cert = NULL; CVC_CERT *cvc_cert = NULL;
BUF_MEM *nonce = NULL, *signature = NULL; BUF_MEM *nonce = NULL, *signature = NULL;
struct iso_sm_ctx *isosmctx = NULL; struct iso_sm_ctx *isosmctx = NULL;
struct npa_sm_ctx *eacsmctx = NULL; struct npa_sm_ctx *eacsmctx = NULL;
unsigned char *ef_cardaccess = NULL;
EAC_CTX *eac_ctx = NULL;
if (!card || !certs_lens || !certs) { if (!card || !certs_lens || !certs) {
r = SC_ERROR_INVALID_ARGUMENTS; r = SC_ERROR_INVALID_ARGUMENTS;
@@ -1601,13 +1603,37 @@ int perform_terminal_authentication(sc_card_t *card,
isosmctx = card->sm_ctx.info.cmd_data; isosmctx = card->sm_ctx.info.cmd_data;
if (!isosmctx->priv_data) { if (!isosmctx->priv_data) {
isosmctx->priv_data = npa_sm_ctx_create(EAC_CTX_new(), NULL, 0, NULL, 0); r = get_ef_card_access(card, &ef_cardaccess, &ef_cardaccess_length);
/* XXX this is only a hack... */ if (r < 0) {
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not get EF.CardAccess.");
goto err;
}
bin_log(card->ctx, SC_LOG_DEBUG_NORMAL, "EF.CardAccess", ef_cardaccess,
ef_cardaccess_length);
/* XXX Card capabilities should be determined by the OpenSC card driver. We
* set it here to be able to use the nPA without patching OpenSC. By
* now we have read the EF.CardAccess so the assumption to have an nPA
* seems valid. */
card->caps |= SC_CARD_CAP_APDU_EXT; card->caps |= SC_CARD_CAP_APDU_EXT;
}
if (!isosmctx->priv_data) { eac_ctx = EAC_CTX_new();
r = SC_ERROR_INTERNAL; if (!eac_ctx
goto err; || !EAC_CTX_init_ef_cardaccess(ef_cardaccess,
ef_cardaccess_length, eac_ctx)) {
sc_debug(card->ctx, SC_LOG_DEBUG_VERBOSE, "Could not parse EF.CardAccess.");
ssl_error(card->ctx);
r = SC_ERROR_INTERNAL;
goto err;
}
isosmctx->priv_data = npa_sm_ctx_create(eac_ctx, NULL, 0, NULL, 0);
if (!isosmctx->priv_data) {
r = SC_ERROR_INTERNAL;
goto err;
}
eac_ctx = NULL;
} }
eacsmctx = isosmctx->priv_data; eacsmctx = isosmctx->priv_data;
@@ -1708,6 +1734,8 @@ int perform_terminal_authentication(sc_card_t *card,
err: err:
if (cvc_cert) if (cvc_cert)
CVC_CERT_free(cvc_cert); CVC_CERT_free(cvc_cert);
free(ef_cardaccess);
EAC_CTX_clear_free(eac_ctx);
BUF_MEM_clear_free(nonce); BUF_MEM_clear_free(nonce);
BUF_MEM_clear_free(signature); BUF_MEM_clear_free(signature);