added sw checking for sm
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@57 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -854,8 +854,10 @@ int pace_test(sc_card_t *card)
|
||||
sm_apdu.resp = malloc(apdu.resplen);
|
||||
SC_TEST_RET(card->ctx, my_transmit_apdu(card, &sm_apdu),
|
||||
"Could not send SM APDU.");
|
||||
SC_TEST_RET(card->ctx, sm_check_sw(card, sm_apdu.sw1, sm_apdu.sw2),
|
||||
"Card returned error.");
|
||||
SC_TEST_RET(card->ctx, sm_decrypt(&sctx, card, &sm_apdu, &apdu),
|
||||
"Could not decrypt APDU");
|
||||
"Could not decrypt APDU.");
|
||||
bin_log(card->ctx, "SM APDU response", sm_apdu.resp, apdu.resplen);
|
||||
|
||||
return SC_SUCCESS;
|
||||
|
||||
21
ccid/sm.c
21
ccid/sm.c
@@ -43,6 +43,25 @@ static const struct sc_asn1_entry c_sm_rapdu[] = {
|
||||
{ NULL, 0, 0, 0, NULL, NULL }
|
||||
};
|
||||
|
||||
static const struct sc_card_error sm_errors[] = {
|
||||
{ 0x6987, SC_ERROR_DATA_OBJECT_NOT_FOUND, "Secure Messaging data objects are missing" },
|
||||
{ 0x6988, SC_ERROR_SECURITY_STATUS_NOT_SATISFIED, "Secure Messaging data objects are incorrect" },
|
||||
};
|
||||
|
||||
int sm_check_sw(sc_card_t *card, unsigned int sw1, unsigned int sw2)
|
||||
{
|
||||
const int err_count = sizeof(sm_errors)/sizeof(sm_errors[0]);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < err_count; i++)
|
||||
if (sm_errors[i].SWs == ((sw1 << 8) | sw2)) {
|
||||
sc_error(card->ctx, "%s\n", sm_errors[i].errorstr);
|
||||
return sm_errors[i].errorno;
|
||||
}
|
||||
|
||||
return sc_check_sw(card, sw1, sw2);
|
||||
}
|
||||
|
||||
void bin_log(sc_context_t *ctx, const char *label, const u8 *data, size_t len)
|
||||
{
|
||||
char buf[1024];
|
||||
@@ -457,8 +476,6 @@ int sm_decrypt(const struct sm_ctx *ctx, sc_card_t *card,
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if (sm_rapdu[0].flags & SC_ASN1_PRESENT) {
|
||||
if (ctx->padding_indicator != fdata[0]) {
|
||||
r = SC_ERROR_UNKNOWN_DATA_RECEIVED;
|
||||
|
||||
@@ -53,6 +53,8 @@ int sm_encrypt(const struct sm_ctx *ctx, sc_card_t *card,
|
||||
int sm_decrypt(const struct sm_ctx *ctx, sc_card_t *card,
|
||||
const sc_apdu_t *sm_apdu, sc_apdu_t *apdu);
|
||||
|
||||
int sm_check_sw(sc_card_t *card, unsigned int sw1, unsigned int sw2);
|
||||
|
||||
BUF_MEM * add_iso_pad(const BUF_MEM * m, int block_size);
|
||||
BUF_MEM * add_padding(const struct sm_ctx *ctx, const char *data, size_t datalen);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user