- cleaned (debug) output
- fixed error in interactive mode of pace-tool git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@345 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -48,8 +48,7 @@ static u8 usemrz = 0;
|
|||||||
static u8 chat[0xff];
|
static u8 chat[0xff];
|
||||||
static u8 desc[0xffff];
|
static u8 desc[0xffff];
|
||||||
static const char *cdriver = NULL;
|
static const char *cdriver = NULL;
|
||||||
|
static char *file = NULL;
|
||||||
static FILE *input;
|
|
||||||
|
|
||||||
static sc_context_t *ctx = NULL;
|
static sc_context_t *ctx = NULL;
|
||||||
static sc_card_t *card = NULL;
|
static sc_card_t *card = NULL;
|
||||||
@@ -110,7 +109,7 @@ static const char *option_help[] = {
|
|||||||
"Print version, available readers and drivers.",
|
"Print version, available readers and drivers.",
|
||||||
};
|
};
|
||||||
|
|
||||||
int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card, FILE *input)
|
||||||
{
|
{
|
||||||
u8 buf[4 + 3 + 0xffff + 3];
|
u8 buf[4 + 3 + 0xffff + 3];
|
||||||
char *read = NULL;
|
char *read = NULL;
|
||||||
@@ -122,7 +121,8 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
|||||||
memset(&apdu, 0, sizeof apdu);
|
memset(&apdu, 0, sizeof apdu);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
printf("Enter unencrypted APDU (empty line to exit)\n");
|
if (input == stdin)
|
||||||
|
printf("Enter unencrypted C-APDU (empty line to exit)\n");
|
||||||
|
|
||||||
linelen = getline(&read, &readlen, input);
|
linelen = getline(&read, &readlen, input);
|
||||||
if (linelen <= 1) {
|
if (linelen <= 1) {
|
||||||
@@ -135,9 +135,11 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
read[linelen - 1] = 0;
|
||||||
|
if (input != stdin)
|
||||||
|
bin_print(stdout, "Unencrypted C-APDU", read, linelen);
|
||||||
|
|
||||||
apdulen = sizeof buf;
|
apdulen = sizeof buf;
|
||||||
read[linelen - 1] = 0;
|
|
||||||
if (sc_hex_to_bin(read, buf, &apdulen) < 0) {
|
if (sc_hex_to_bin(read, buf, &apdulen) < 0) {
|
||||||
sc_error(card->ctx, "Could not format binary string");
|
sc_error(card->ctx, "Could not format binary string");
|
||||||
continue;
|
continue;
|
||||||
@@ -145,7 +147,7 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
|||||||
|
|
||||||
r = build_apdu(card->ctx, buf, apdulen, &apdu);
|
r = build_apdu(card->ctx, buf, apdulen, &apdu);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
bin_log(ctx, "Invalid APDU", buf, apdulen);
|
bin_log(ctx, "Invalid C-APDU", buf, apdulen);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,12 +156,13 @@ int pace_translate_apdus(struct sm_ctx *sctx, sc_card_t *card)
|
|||||||
|
|
||||||
r = sm_transmit_apdu(sctx, card, &apdu);
|
r = sm_transmit_apdu(sctx, card, &apdu);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
sc_error(card->ctx, "Could not send APDU: %s", sc_strerror(r));
|
sc_error(card->ctx, "Could not send C-APDU: %s", sc_strerror(r));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Decrypted APDU sw1=%02x sw2=%02x\n", apdu.sw1, apdu.sw2);
|
printf("Decrypted R-APDU sw1=%02x sw2=%02x\n", apdu.sw1, apdu.sw2);
|
||||||
bin_print(stdout, "Decrypted APDU response data", apdu.resp, apdu.resplen);
|
bin_print(stdout, "Decrypted R-APDU response data", apdu.resp, apdu.resplen);
|
||||||
|
printf("======================================================================\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (read)
|
if (read)
|
||||||
@@ -268,9 +271,7 @@ main (int argc, char **argv)
|
|||||||
case OPT_TRANSLATE:
|
case OPT_TRANSLATE:
|
||||||
dotranslate = 1;
|
dotranslate = 1;
|
||||||
if (optarg) {
|
if (optarg) {
|
||||||
input = fopen(optarg, "r");
|
file = optarg;
|
||||||
if (!input)
|
|
||||||
perror("Opening file with APDUs");
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
@@ -502,7 +503,17 @@ main (int argc, char **argv)
|
|||||||
pace_secret_name(pace_input.pin_id), difftime(t_end, t_start));
|
pace_secret_name(pace_input.pin_id), difftime(t_end, t_start));
|
||||||
|
|
||||||
if (dotranslate) {
|
if (dotranslate) {
|
||||||
i = pace_translate_apdus(&sctx, card);
|
FILE *input;
|
||||||
|
if (!file || strncmp(file, "stdin", strlen("stdin")) == 0)
|
||||||
|
input = stdin;
|
||||||
|
else {
|
||||||
|
input = fopen(file, "r");
|
||||||
|
if (!input)
|
||||||
|
perror("Opening file with APDUs");
|
||||||
|
}
|
||||||
|
|
||||||
|
i = pace_translate_apdus(&sctx, card, input);
|
||||||
|
fclose(input);
|
||||||
if (i < 0)
|
if (i < 0)
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,12 +202,10 @@ void _bin_log(sc_context_t *ctx, int type, const char *file, int line,
|
|||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
if (!f) {
|
if (!f) {
|
||||||
sc_do_log(ctx, type, file, line, func,
|
sc_do_log(ctx, type, file, line, func,
|
||||||
"\n%s (%u byte%s):\n%s"
|
"\n%s (%u byte%s):\n%s",
|
||||||
"======================================================================",
|
|
||||||
label, len, len==1?"":"s", buf);
|
label, len, len==1?"":"s", buf);
|
||||||
} else {
|
} else {
|
||||||
fprintf(f, "%s (%u byte%s):\n%s"
|
fprintf(f, "%s (%u byte%s):\n%s",
|
||||||
"======================================================================\n",
|
|
||||||
label, len, len==1?"":"s", buf);
|
label, len, len==1?"":"s", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user