libcacard/cac: change big switch functions to single return point
Signed-off-by: Alon Levy <alevy@redhat.com> Reviewed-by: Marc-André Lureau <mlureau@redhat.com>
This commit is contained in:
parent
58aeda15ab
commit
57f97834ef
@ -40,41 +40,51 @@ static VCardStatus
|
|||||||
cac_common_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
|
cac_common_process_apdu(VCard *card, VCardAPDU *apdu, VCardResponse **response)
|
||||||
{
|
{
|
||||||
int ef;
|
int ef;
|
||||||
|
VCardStatus ret = VCARD_FAIL;
|
||||||
|
|
||||||
switch (apdu->a_ins) {
|
switch (apdu->a_ins) {
|
||||||
case VCARD7816_INS_SELECT_FILE:
|
case VCARD7816_INS_SELECT_FILE:
|
||||||
if (apdu->a_p1 != 0x02) {
|
if (apdu->a_p1 != 0x02) {
|
||||||
/* let the 7816 code handle applet switches */
|
/* let the 7816 code handle applet switches */
|
||||||
return VCARD_NEXT;
|
ret = VCARD_NEXT;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* handle file id setting */
|
/* handle file id setting */
|
||||||
if (apdu->a_Lc != 2) {
|
if (apdu->a_Lc != 2) {
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_DATA_INVALID);
|
VCARD7816_STATUS_ERROR_DATA_INVALID);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
/* CAC 1.0 only supports ef = 0 */
|
/* CAC 1.0 only supports ef = 0 */
|
||||||
ef = apdu->a_body[0] | (apdu->a_body[1] << 8);
|
ef = apdu->a_body[0] | (apdu->a_body[1] << 8);
|
||||||
if (ef != 0) {
|
if (ef != 0) {
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_FILE_NOT_FOUND);
|
VCARD7816_STATUS_ERROR_FILE_NOT_FOUND);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
*response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
|
*response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case VCARD7816_INS_GET_RESPONSE:
|
case VCARD7816_INS_GET_RESPONSE:
|
||||||
case VCARD7816_INS_VERIFY:
|
case VCARD7816_INS_VERIFY:
|
||||||
/* let the 7816 code handle these */
|
/* let the 7816 code handle these */
|
||||||
return VCARD_NEXT;
|
ret = VCARD_NEXT;
|
||||||
|
break;
|
||||||
case CAC_GET_PROPERTIES:
|
case CAC_GET_PROPERTIES:
|
||||||
case CAC_GET_ACR:
|
case CAC_GET_ACR:
|
||||||
/* skip these for now, this will probably be needed */
|
/* skip these for now, this will probably be needed */
|
||||||
*response = vcard_make_response(VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
|
*response = vcard_make_response(VCARD7816_STATUS_ERROR_P1_P2_INCORRECT);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
*response = vcard_make_response(
|
||||||
|
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
||||||
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
*response = vcard_make_response(
|
return ret;
|
||||||
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
|
||||||
return VCARD_DONE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -108,6 +118,7 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
int size, next;
|
int size, next;
|
||||||
unsigned char *sign_buffer;
|
unsigned char *sign_buffer;
|
||||||
vcard_7816_status_t status;
|
vcard_7816_status_t status;
|
||||||
|
VCardStatus ret = VCARD_FAIL;
|
||||||
|
|
||||||
applet_private = vcard_get_current_applet_private(card, apdu->a_channel);
|
applet_private = vcard_get_current_applet_private(card, apdu->a_channel);
|
||||||
assert(applet_private);
|
assert(applet_private);
|
||||||
@ -117,7 +128,8 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
case CAC_UPDATE_BUFFER:
|
case CAC_UPDATE_BUFFER:
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED);
|
VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case CAC_GET_CERTIFICATE:
|
case CAC_GET_CERTIFICATE:
|
||||||
if ((apdu->a_p2 != 0) || (apdu->a_p1 != 0)) {
|
if ((apdu->a_p2 != 0) || (apdu->a_p1 != 0)) {
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
@ -147,7 +159,8 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
|
VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
|
||||||
}
|
}
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case CAC_SIGN_DECRYPT:
|
case CAC_SIGN_DECRYPT:
|
||||||
if (apdu->a_p2 != 0) {
|
if (apdu->a_p2 != 0) {
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
@ -164,7 +177,8 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
pki_applet->sign_buffer_len = 0;
|
pki_applet->sign_buffer_len = 0;
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
|
VCARD7816_STATUS_EXC_ERROR_MEMORY_FAILURE);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
memcpy(sign_buffer+pki_applet->sign_buffer_len, apdu->a_body, size);
|
memcpy(sign_buffer+pki_applet->sign_buffer_len, apdu->a_body, size);
|
||||||
size += pki_applet->sign_buffer_len;
|
size += pki_applet->sign_buffer_len;
|
||||||
@ -175,7 +189,8 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
pki_applet->sign_buffer = sign_buffer;
|
pki_applet->sign_buffer = sign_buffer;
|
||||||
pki_applet->sign_buffer_len = size;
|
pki_applet->sign_buffer_len = size;
|
||||||
*response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
|
*response = vcard_make_response(VCARD7816_STATUS_SUCCESS);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case 0x00:
|
case 0x00:
|
||||||
/* we now have the whole buffer, do the operation, result will be
|
/* we now have the whole buffer, do the operation, result will be
|
||||||
* in the sign_buffer */
|
* in the sign_buffer */
|
||||||
@ -200,15 +215,20 @@ cac_applet_pki_process_apdu(VCard *card, VCardAPDU *apdu,
|
|||||||
g_free(sign_buffer);
|
g_free(sign_buffer);
|
||||||
pki_applet->sign_buffer = NULL;
|
pki_applet->sign_buffer = NULL;
|
||||||
pki_applet->sign_buffer_len = 0;
|
pki_applet->sign_buffer_len = 0;
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case CAC_READ_BUFFER:
|
case CAC_READ_BUFFER:
|
||||||
/* new CAC call, go ahead and use the old version for now */
|
/* new CAC call, go ahead and use the old version for now */
|
||||||
/* TODO: implement */
|
/* TODO: implement */
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = cac_common_process_apdu(card, apdu, response);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return cac_common_process_apdu(card, apdu, response);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -216,19 +236,26 @@ static VCardStatus
|
|||||||
cac_applet_id_process_apdu(VCard *card, VCardAPDU *apdu,
|
cac_applet_id_process_apdu(VCard *card, VCardAPDU *apdu,
|
||||||
VCardResponse **response)
|
VCardResponse **response)
|
||||||
{
|
{
|
||||||
|
VCardStatus ret = VCARD_FAIL;
|
||||||
|
|
||||||
switch (apdu->a_ins) {
|
switch (apdu->a_ins) {
|
||||||
case CAC_UPDATE_BUFFER:
|
case CAC_UPDATE_BUFFER:
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED);
|
VCARD7816_STATUS_ERROR_CONDITION_NOT_SATISFIED);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
case CAC_READ_BUFFER:
|
case CAC_READ_BUFFER:
|
||||||
/* new CAC call, go ahead and use the old version for now */
|
/* new CAC call, go ahead and use the old version for now */
|
||||||
/* TODO: implement */
|
/* TODO: implement */
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
ret = cac_common_process_apdu(card, apdu, response);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return cac_common_process_apdu(card, apdu, response);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -240,16 +267,20 @@ static VCardStatus
|
|||||||
cac_applet_container_process_apdu(VCard *card, VCardAPDU *apdu,
|
cac_applet_container_process_apdu(VCard *card, VCardAPDU *apdu,
|
||||||
VCardResponse **response)
|
VCardResponse **response)
|
||||||
{
|
{
|
||||||
|
VCardStatus ret = VCARD_FAIL;
|
||||||
|
|
||||||
switch (apdu->a_ins) {
|
switch (apdu->a_ins) {
|
||||||
case CAC_READ_BUFFER:
|
case CAC_READ_BUFFER:
|
||||||
case CAC_UPDATE_BUFFER:
|
case CAC_UPDATE_BUFFER:
|
||||||
*response = vcard_make_response(
|
*response = vcard_make_response(
|
||||||
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
VCARD7816_STATUS_ERROR_COMMAND_NOT_SUPPORTED);
|
||||||
return VCARD_DONE;
|
ret = VCARD_DONE;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
|
ret = cac_common_process_apdu(card, apdu, response);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return cac_common_process_apdu(card, apdu, response);
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user