pcsc-relay: allow specifying ATR

This commit is contained in:
Frank Morgner
2018-10-20 03:45:21 +02:00
parent 04642a3bfc
commit 4ea916fef8
4 changed files with 37 additions and 2 deletions

View File

@@ -179,6 +179,8 @@ int main (int argc, char **argv)
viccport = args_info.vicc_port_arg; viccport = args_info.vicc_port_arg;
if (args_info.vicc_hostname_given) if (args_info.vicc_hostname_given)
vicchostname = args_info.vicc_hostname_arg; vicchostname = args_info.vicc_hostname_arg;
if (args_info.vicc_atr_given)
viccatr = args_info.vicc_atr_arg;
verbose = args_info.verbose_given; verbose = args_info.verbose_given;

View File

@@ -44,6 +44,10 @@ option "vicc-hostname" N
"Hostname for connecting to virtual smart card reader" "Hostname for connecting to virtual smart card reader"
string default="wait for an incoming connection" string default="wait for an incoming connection"
optional optional
option "vicc-atr" A
"ATR"
string default="3B80800101"
optional
text " text "
Report bugs to @PACKAGE_BUGREPORT@ Report bugs to @PACKAGE_BUGREPORT@

View File

@@ -61,6 +61,7 @@ extern unsigned int vpcdport;
extern char *vpcdhostname; extern char *vpcdhostname;
extern unsigned int viccport; extern unsigned int viccport;
extern char *vicchostname; extern char *vicchostname;
extern char *viccatr;
void hexdump(const char *label, unsigned char *buf, size_t len); void hexdump(const char *label, unsigned char *buf, size_t len);

View File

@@ -30,6 +30,9 @@
unsigned int viccport = VPCDPORT; unsigned int viccport = VPCDPORT;
char *vicchostname = NULL; char *vicchostname = NULL;
char *viccatr = "3B80800101";
unsigned char atr[256];
size_t atr_len = 0;
@@ -41,6 +44,32 @@ static int _vicc_connect(driver_data_t **driver_data)
if (!driver_data) if (!driver_data)
return 0; return 0;
if (viccatr) {
size_t i;
unsigned char *hex = viccatr;
unsigned char *bin = atr;
atr_len = strlen(viccatr);
if (atr_len % 2 != 0) {
RELAY_ERROR("Length of ATR needs to be even\n");
return 0;
}
atr_len /= 2;
if (atr_len > sizeof atr) {
RELAY_ERROR("ATR too long\n");
return 0;
}
while (*hex) {
if (sscanf(hex, "%2hhX", bin) != 1) {
RELAY_ERROR("bad ATR\n");
return 0;
}
hex += 2;
bin += 1;
}
} else {
atr_len = 0;
}
ctx = vicc_init(vicchostname, viccport); ctx = vicc_init(vicchostname, viccport);
if (!ctx) { if (!ctx) {
@@ -77,7 +106,6 @@ static int vicc_receive_capdu(driver_data_t *driver_data,
int r = 0; int r = 0;
ssize_t size; ssize_t size;
const unsigned char atr[] = {0x3B, 0x80, 0x80, 0x01, 0x01};
if (!len) if (!len)
goto err; goto err;
@@ -98,7 +126,7 @@ static int vicc_receive_capdu(driver_data_t *driver_data,
// ignore reset, power on, power off // ignore reset, power on, power off
break; break;
case VPCD_CTRL_ATR: case VPCD_CTRL_ATR:
if (vicc_transmit(ctx, sizeof atr, atr, NULL) < 0) { if (vicc_transmit(ctx, atr_len, atr, NULL) < 0) {
RELAY_ERROR("could not send ATR\n"); RELAY_ERROR("could not send ATR\n");
goto err; goto err;
} }