use built-in function to parse pseudo apdu

This commit is contained in:
Frank Morgner
2013-05-29 22:16:37 +02:00
parent 95f31a21f5
commit 532d85ee53

View File

@@ -426,6 +426,7 @@ static int
perform_pseudo_apdu(const __u8 *in, size_t inlen, __u8 **out, size_t *outlen) perform_pseudo_apdu(const __u8 *in, size_t inlen, __u8 **out, size_t *outlen)
{ {
__u8 *p; __u8 *p;
sc_apdu_t apdu;
if (!in || !out || !outlen) if (!in || !out || !outlen)
return SC_ERROR_INVALID_ARGUMENTS; return SC_ERROR_INVALID_ARGUMENTS;
@@ -433,11 +434,9 @@ perform_pseudo_apdu(const __u8 *in, size_t inlen, __u8 **out, size_t *outlen)
if (*in != 0xFF) if (*in != 0xFF)
sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "malformed PC_to_RDR_XfrBlock, will continue anyway"); sc_debug(ctx, SC_LOG_DEBUG_NORMAL, "malformed PC_to_RDR_XfrBlock, will continue anyway");
if (inlen < 5) { LOG_TEST_RET(ctx, sc_bytes2apdu(ctx, in, inlen, &apdu), "Could not parse Pseudo-APDU");
sc_debug(ctx, SC_LOG_DEBUG_VERBOSE, "Not enough Data for Pseudo-APDU");
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_INVALID_DATA); switch (apdu.ins) {
}
switch (in[1]) {
case 0x9A: case 0x9A:
/* GetReaderInfo */ /* GetReaderInfo */
if (in[2] != 0x01 || inlen != 5 || in[4] != 0x00) { if (in[2] != 0x01 || inlen != 5 || in[4] != 0x00) {
@@ -473,12 +472,14 @@ parse_error:
goto parse_error; goto parse_error;
} }
size_t infolen = strlen(info); size_t infolen = strlen(info);
p = realloc(*out, infolen); p = realloc(*out, infolen+2);
if (!p) if (!p)
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_OUT_OF_MEMORY); SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_VERBOSE, SC_ERROR_OUT_OF_MEMORY);
*out = p; *out = p;
memcpy(*out, info, infolen); memcpy(*out, info, infolen);
*outlen = infolen; *out[infolen] = 0x90;
*out[infolen+1] = 0x00;
*outlen = infolen+2;
break; break;
default: default: