mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-03 12:11:33 +01:00
SCD: API cleanup for keypad handling.
* scd/iso7816.h (struct pininfo_s): Rename from iso7816_pininfo_s. Change meaning of MODE. (pininfo_t): Rename from iso7816_pininfo_t. * scd/sc-copykeys.c: Include "iso7816.h". * scd/scdaemon.c, scd/command.c: Likewise. * scd/ccid-driver.c: Include "scdaemon.h" and "iso7816.h". (ccid_transceive_secure): Follow the change of PININFO_T. * scd/app.c: Include "apdu.h" after "iso7816.h". * scd/iso7816.c (iso7816_check_keypad, iso7816_verify_kp) (iso7816_change_reference_data_kp): Follow the change of API. * scd/apdu.c (struct reader_table_s): Change API of CHECK_KEYPAD, KEYPAD_VERIFY, KEYPAD_MODIFY to have arg of PININFO_T. (check_pcsc_keypad, check_ccid_keypad): Likewise. (apdu_check_keypad, apdu_keypad_verify, apdu_keypad_modify): Likewise. (pcsc_keypad_verify, pcsc_keypad_modify, ct_send_apdu) (pcsc_send_apdu_direct, pcsc_send_apdu_wrapped, pcsc_send_apdu) (send_apdu_ccid, ccid_keypad_operation, my_rapdu_send_apdu, send_apdu) (send_le): Follow the change of API. * scd/apdu.h (apdu_check_keypad, apdu_keypad_verify) (apdu_keypad_modify): Change the API. * scd/app-dinsig.c, scd/app-nks.c, scd/app-openpgp.c: Follow the change.
This commit is contained in:
parent
3d863c298b
commit
4fe024cf33
99
scd/apdu.c
99
scd/apdu.c
@ -59,10 +59,9 @@
|
|||||||
#include "exechelp.h"
|
#include "exechelp.h"
|
||||||
#endif /* GNUPG_MAJOR_VERSION != 1 */
|
#endif /* GNUPG_MAJOR_VERSION != 1 */
|
||||||
|
|
||||||
|
#include "iso7816.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "ccid-driver.h"
|
#include "ccid-driver.h"
|
||||||
#include "iso7816.h"
|
|
||||||
|
|
||||||
|
|
||||||
/* Due to conflicting use of threading libraries we usually can't link
|
/* Due to conflicting use of threading libraries we usually can't link
|
||||||
against libpcsclite. Instead we use a wrapper program. */
|
against libpcsclite. Instead we use a wrapper program. */
|
||||||
@ -82,8 +81,6 @@
|
|||||||
#define DLSTDCALL
|
#define DLSTDCALL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define pininfo_s iso7816_pininfo_s
|
|
||||||
|
|
||||||
/* A structure to collect information pertaining to one reader
|
/* A structure to collect information pertaining to one reader
|
||||||
slot. */
|
slot. */
|
||||||
struct reader_table_s {
|
struct reader_table_s {
|
||||||
@ -98,12 +95,12 @@ struct reader_table_s {
|
|||||||
int (*reset_reader)(int);
|
int (*reset_reader)(int);
|
||||||
int (*get_status_reader)(int, unsigned int *);
|
int (*get_status_reader)(int, unsigned int *);
|
||||||
int (*send_apdu_reader)(int,unsigned char *,size_t,
|
int (*send_apdu_reader)(int,unsigned char *,size_t,
|
||||||
unsigned char *, size_t *, struct pininfo_s *);
|
unsigned char *, size_t *, pininfo_t *);
|
||||||
int (*check_keypad)(int, int, int, int, int);
|
int (*check_keypad)(int, int, pininfo_t *);
|
||||||
void (*dump_status_reader)(int);
|
void (*dump_status_reader)(int);
|
||||||
int (*set_progress_cb)(int, gcry_handler_progress_t, void*);
|
int (*set_progress_cb)(int, gcry_handler_progress_t, void*);
|
||||||
int (*keypad_verify)(int, int, int, int, int, struct pininfo_s *);
|
int (*keypad_verify)(int, int, int, int, int, pininfo_t *);
|
||||||
int (*keypad_modify)(int, int, int, int, int, struct pininfo_s *);
|
int (*keypad_modify)(int, int, int, int, int, pininfo_t *);
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
ccid_driver_t handle;
|
ccid_driver_t handle;
|
||||||
@ -304,12 +301,11 @@ static int reset_pcsc_reader (int slot);
|
|||||||
static int apdu_get_status_internal (int slot, int hang, int no_atr_reset,
|
static int apdu_get_status_internal (int slot, int hang, int no_atr_reset,
|
||||||
unsigned int *status,
|
unsigned int *status,
|
||||||
unsigned int *changed);
|
unsigned int *changed);
|
||||||
static int check_pcsc_keypad (int slot, int command, int pin_mode,
|
static int check_pcsc_keypad (int slot, int command, pininfo_t *pininfo);
|
||||||
int pinlen_min, int pinlen_max);
|
|
||||||
static int pcsc_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
static int pcsc_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
||||||
struct pininfo_s *pininfo);
|
pininfo_t *pininfo);
|
||||||
static int pcsc_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
static int pcsc_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
||||||
struct pininfo_s *pininfo);
|
pininfo_t *pininfo);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -621,7 +617,7 @@ ct_get_status (int slot, unsigned int *status)
|
|||||||
set to BUFLEN. Returns: CT API error code. */
|
set to BUFLEN. Returns: CT API error code. */
|
||||||
static int
|
static int
|
||||||
ct_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
ct_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen, struct pininfo_s *pininfo)
|
unsigned char *buffer, size_t *buflen, pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
unsigned char dad[1], sad[1];
|
unsigned char dad[1], sad[1];
|
||||||
@ -1053,7 +1049,7 @@ pcsc_get_status (int slot, unsigned int *status)
|
|||||||
static int
|
static int
|
||||||
pcsc_send_apdu_direct (int slot, unsigned char *apdu, size_t apdulen,
|
pcsc_send_apdu_direct (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen,
|
unsigned char *buffer, size_t *buflen,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
long err;
|
long err;
|
||||||
struct pcsc_io_request_s send_pci;
|
struct pcsc_io_request_s send_pci;
|
||||||
@ -1089,7 +1085,7 @@ pcsc_send_apdu_direct (int slot, unsigned char *apdu, size_t apdulen,
|
|||||||
static int
|
static int
|
||||||
pcsc_send_apdu_wrapped (int slot, unsigned char *apdu, size_t apdulen,
|
pcsc_send_apdu_wrapped (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen,
|
unsigned char *buffer, size_t *buflen,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
long err;
|
long err;
|
||||||
reader_table_t slotp;
|
reader_table_t slotp;
|
||||||
@ -1208,7 +1204,7 @@ pcsc_send_apdu_wrapped (int slot, unsigned char *apdu, size_t apdulen,
|
|||||||
static int
|
static int
|
||||||
pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
pcsc_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen,
|
unsigned char *buffer, size_t *buflen,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
#ifdef NEED_PCSC_WRAPPER
|
#ifdef NEED_PCSC_WRAPPER
|
||||||
return pcsc_send_apdu_wrapped (slot, apdu, apdulen, buffer, buflen, pininfo);
|
return pcsc_send_apdu_wrapped (slot, apdu, apdulen, buffer, buflen, pininfo);
|
||||||
@ -2014,16 +2010,13 @@ open_pcsc_reader (const char *portstr)
|
|||||||
/* Check whether the reader supports the ISO command code COMMAND
|
/* Check whether the reader supports the ISO command code COMMAND
|
||||||
on the keypad. Return 0 on success. */
|
on the keypad. Return 0 on success. */
|
||||||
static int
|
static int
|
||||||
check_pcsc_keypad (int slot, int command, int pin_mode,
|
check_pcsc_keypad (int slot, int command, pininfo_t *pininfo)
|
||||||
int pinlen_min, int pinlen_max)
|
|
||||||
{
|
{
|
||||||
unsigned char buf[256];
|
unsigned char buf[256];
|
||||||
size_t len = 256;
|
size_t len = 256;
|
||||||
int sw;
|
int sw;
|
||||||
|
|
||||||
(void)pin_mode;
|
(void)pininfo;
|
||||||
(void)pinlen_min;
|
|
||||||
(void)pinlen_max;
|
|
||||||
|
|
||||||
check_again:
|
check_again:
|
||||||
if (command == ISO7816_VERIFY)
|
if (command == ISO7816_VERIFY)
|
||||||
@ -2075,7 +2068,7 @@ check_pcsc_keypad (int slot, int command, int pin_mode,
|
|||||||
#define PIN_VERIFY_STRUCTURE_SIZE 24
|
#define PIN_VERIFY_STRUCTURE_SIZE 24
|
||||||
static int
|
static int
|
||||||
pcsc_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
pcsc_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
unsigned char *pin_verify;
|
unsigned char *pin_verify;
|
||||||
@ -2154,7 +2147,7 @@ pcsc_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
|||||||
#define PIN_MODIFY_STRUCTURE_SIZE 29
|
#define PIN_MODIFY_STRUCTURE_SIZE 29
|
||||||
static int
|
static int
|
||||||
pcsc_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
pcsc_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
unsigned char *pin_modify;
|
unsigned char *pin_modify;
|
||||||
@ -2325,7 +2318,7 @@ get_status_ccid (int slot, unsigned int *status)
|
|||||||
static int
|
static int
|
||||||
send_apdu_ccid (int slot, unsigned char *apdu, size_t apdulen,
|
send_apdu_ccid (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen,
|
unsigned char *buffer, size_t *buflen,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
long err;
|
long err;
|
||||||
size_t maxbuflen;
|
size_t maxbuflen;
|
||||||
@ -2341,10 +2334,7 @@ send_apdu_ccid (int slot, unsigned char *apdu, size_t apdulen,
|
|||||||
maxbuflen = *buflen;
|
maxbuflen = *buflen;
|
||||||
if (pininfo)
|
if (pininfo)
|
||||||
err = ccid_transceive_secure (reader_table[slot].ccid.handle,
|
err = ccid_transceive_secure (reader_table[slot].ccid.handle,
|
||||||
apdu, apdulen,
|
apdu, apdulen, pininfo,
|
||||||
pininfo->mode,
|
|
||||||
pininfo->minlen,
|
|
||||||
pininfo->maxlen,
|
|
||||||
buffer, maxbuflen, buflen);
|
buffer, maxbuflen, buflen);
|
||||||
else
|
else
|
||||||
err = ccid_transceive (reader_table[slot].ccid.handle,
|
err = ccid_transceive (reader_table[slot].ccid.handle,
|
||||||
@ -2362,22 +2352,19 @@ send_apdu_ccid (int slot, unsigned char *apdu, size_t apdulen,
|
|||||||
on the keypad. Return 0 on success. For a description of the pin
|
on the keypad. Return 0 on success. For a description of the pin
|
||||||
parameters, see ccid-driver.c */
|
parameters, see ccid-driver.c */
|
||||||
static int
|
static int
|
||||||
check_ccid_keypad (int slot, int command, int pin_mode,
|
check_ccid_keypad (int slot, int command, pininfo_t *pininfo)
|
||||||
int pinlen_min, int pinlen_max)
|
|
||||||
{
|
{
|
||||||
unsigned char apdu[] = { 0, 0, 0, 0x81 };
|
unsigned char apdu[] = { 0, 0, 0, 0x81 };
|
||||||
|
|
||||||
apdu[1] = command;
|
apdu[1] = command;
|
||||||
return ccid_transceive_secure (reader_table[slot].ccid.handle,
|
return ccid_transceive_secure (reader_table[slot].ccid.handle, apdu,
|
||||||
apdu, sizeof apdu,
|
sizeof apdu, pininfo, NULL, 0, NULL);
|
||||||
pin_mode, pinlen_min, pinlen_max,
|
|
||||||
NULL, 0, NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ccid_keypad_operation (int slot, int class, int ins, int p0, int p1,
|
ccid_keypad_operation (int slot, int class, int ins, int p0, int p1,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
unsigned char apdu[4];
|
unsigned char apdu[4];
|
||||||
int err, sw;
|
int err, sw;
|
||||||
@ -2389,8 +2376,7 @@ ccid_keypad_operation (int slot, int class, int ins, int p0, int p1,
|
|||||||
apdu[2] = p0;
|
apdu[2] = p0;
|
||||||
apdu[3] = p1;
|
apdu[3] = p1;
|
||||||
err = ccid_transceive_secure (reader_table[slot].ccid.handle,
|
err = ccid_transceive_secure (reader_table[slot].ccid.handle,
|
||||||
apdu, sizeof apdu,
|
apdu, sizeof apdu, pininfo,
|
||||||
pininfo->mode, pininfo->minlen, pininfo->maxlen,
|
|
||||||
result, 2, &resultlen);
|
result, 2, &resultlen);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
@ -2610,7 +2596,7 @@ my_rapdu_get_status (int slot, unsigned int *status)
|
|||||||
static int
|
static int
|
||||||
my_rapdu_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
my_rapdu_send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen,
|
unsigned char *buffer, size_t *buflen,
|
||||||
struct pininfo_s *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
reader_table_t slotp;
|
reader_table_t slotp;
|
||||||
@ -3300,12 +3286,14 @@ apdu_get_status (int slot, int hang,
|
|||||||
the keypad. Return 0 on success. For a description of the pin
|
the keypad. Return 0 on success. For a description of the pin
|
||||||
parameters, see ccid-driver.c */
|
parameters, see ccid-driver.c */
|
||||||
int
|
int
|
||||||
apdu_check_keypad (int slot, int command, int pin_mode,
|
apdu_check_keypad (int slot, int command, pininfo_t *pininfo)
|
||||||
int pinlen_min, int pinlen_max)
|
|
||||||
{
|
{
|
||||||
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
||||||
return SW_HOST_NO_DRIVER;
|
return SW_HOST_NO_DRIVER;
|
||||||
|
|
||||||
|
if (opt.enable_keypad_varlen)
|
||||||
|
pininfo->mode = 0;
|
||||||
|
|
||||||
if (reader_table[slot].check_keypad)
|
if (reader_table[slot].check_keypad)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
@ -3313,8 +3301,7 @@ apdu_check_keypad (int slot, int command, int pin_mode,
|
|||||||
if ((sw = lock_slot (slot)))
|
if ((sw = lock_slot (slot)))
|
||||||
return sw;
|
return sw;
|
||||||
|
|
||||||
sw = reader_table[slot].check_keypad (slot, command,
|
sw = reader_table[slot].check_keypad (slot, command, pininfo);
|
||||||
pin_mode, pinlen_min, pinlen_max);
|
|
||||||
unlock_slot (slot);
|
unlock_slot (slot);
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
@ -3324,15 +3311,9 @@ apdu_check_keypad (int slot, int command, int pin_mode,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
apdu_keypad_verify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
apdu_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
||||||
int pinlen_min, int pinlen_max)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
struct pininfo_s pininfo;
|
|
||||||
|
|
||||||
pininfo.mode = pin_mode;
|
|
||||||
pininfo.minlen = pinlen_min;
|
|
||||||
pininfo.maxlen = pinlen_max;
|
|
||||||
|
|
||||||
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
||||||
return SW_HOST_NO_DRIVER;
|
return SW_HOST_NO_DRIVER;
|
||||||
|
|
||||||
@ -3344,7 +3325,7 @@ apdu_keypad_verify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
|||||||
return sw;
|
return sw;
|
||||||
|
|
||||||
sw = reader_table[slot].keypad_verify (slot, class, ins, p0, p1,
|
sw = reader_table[slot].keypad_verify (slot, class, ins, p0, p1,
|
||||||
&pininfo);
|
pininfo);
|
||||||
unlock_slot (slot);
|
unlock_slot (slot);
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
@ -3354,15 +3335,9 @@ apdu_keypad_verify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
|||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
apdu_keypad_modify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
apdu_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
||||||
int pinlen_min, int pinlen_max)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
struct pininfo_s pininfo;
|
|
||||||
|
|
||||||
pininfo.mode = pin_mode;
|
|
||||||
pininfo.minlen = pinlen_min;
|
|
||||||
pininfo.maxlen = pinlen_max;
|
|
||||||
|
|
||||||
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
||||||
return SW_HOST_NO_DRIVER;
|
return SW_HOST_NO_DRIVER;
|
||||||
|
|
||||||
@ -3374,7 +3349,7 @@ apdu_keypad_modify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
|||||||
return sw;
|
return sw;
|
||||||
|
|
||||||
sw = reader_table[slot].keypad_modify (slot, class, ins, p0, p1,
|
sw = reader_table[slot].keypad_modify (slot, class, ins, p0, p1,
|
||||||
&pininfo);
|
pininfo);
|
||||||
unlock_slot (slot);
|
unlock_slot (slot);
|
||||||
return sw;
|
return sw;
|
||||||
}
|
}
|
||||||
@ -3387,7 +3362,7 @@ apdu_keypad_modify (int slot, int class, int ins, int p0, int p1, int pin_mode,
|
|||||||
function should be called in locked state. */
|
function should be called in locked state. */
|
||||||
static int
|
static int
|
||||||
send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
send_apdu (int slot, unsigned char *apdu, size_t apdulen,
|
||||||
unsigned char *buffer, size_t *buflen, struct pininfo_s *pininfo)
|
unsigned char *buffer, size_t *buflen, pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
if (slot < 0 || slot >= MAX_READER || !reader_table[slot].used )
|
||||||
return SW_HOST_NO_DRIVER;
|
return SW_HOST_NO_DRIVER;
|
||||||
@ -3419,7 +3394,7 @@ static int
|
|||||||
send_le (int slot, int class, int ins, int p0, int p1,
|
send_le (int slot, int class, int ins, int p0, int p1,
|
||||||
int lc, const char *data, int le,
|
int lc, const char *data, int le,
|
||||||
unsigned char **retbuf, size_t *retbuflen,
|
unsigned char **retbuf, size_t *retbuflen,
|
||||||
struct pininfo_s *pininfo, int extended_mode)
|
pininfo_t *pininfo, int extended_mode)
|
||||||
{
|
{
|
||||||
#define SHORT_RESULT_BUFFER_SIZE 258
|
#define SHORT_RESULT_BUFFER_SIZE 258
|
||||||
/* We allocate 8 extra bytes as a safety margin towards a driver bug. */
|
/* We allocate 8 extra bytes as a safety margin towards a driver bug. */
|
||||||
|
@ -112,12 +112,11 @@ int apdu_activate (int slot);
|
|||||||
int apdu_reset (int slot);
|
int apdu_reset (int slot);
|
||||||
int apdu_get_status (int slot, int hang,
|
int apdu_get_status (int slot, int hang,
|
||||||
unsigned int *status, unsigned int *changed);
|
unsigned int *status, unsigned int *changed);
|
||||||
int apdu_check_keypad (int slot, int command, int pin_mode,
|
int apdu_check_keypad (int slot, int command, pininfo_t *pininfo);
|
||||||
int pinlen_min, int pinlen_max);
|
|
||||||
int apdu_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
int apdu_keypad_verify (int slot, int class, int ins, int p0, int p1,
|
||||||
int pin_mode, int pinlen_min, int pinlen_max);
|
pininfo_t *pininfo);
|
||||||
int apdu_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
int apdu_keypad_modify (int slot, int class, int ins, int p0, int p1,
|
||||||
int pin_mode, int pinlen_min, int pinlen_max);
|
pininfo_t *pininfo);
|
||||||
int apdu_send_simple (int slot, int extended_mode,
|
int apdu_send_simple (int slot, int extended_mode,
|
||||||
int class, int ins, int p0, int p1,
|
int class, int ins, int p0, int p1,
|
||||||
int lc, const char *data);
|
int lc, const char *data);
|
||||||
|
@ -282,7 +282,7 @@ verify_pin (app_t app,
|
|||||||
{
|
{
|
||||||
const char *s;
|
const char *s;
|
||||||
int rc;
|
int rc;
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
|
|
||||||
if ( app->did_chv1 && !app->force_chv1 )
|
if ( app->did_chv1 && !app->force_chv1 )
|
||||||
return 0; /* No need to verify it again. */
|
return 0; /* No need to verify it again. */
|
||||||
|
@ -781,7 +781,7 @@ verify_pin (app_t app, int pwid, const char *desc,
|
|||||||
gpg_error_t (*pincb)(void*, const char *, char **),
|
gpg_error_t (*pincb)(void*, const char *, char **),
|
||||||
void *pincb_arg)
|
void *pincb_arg)
|
||||||
{
|
{
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!desc)
|
if (!desc)
|
||||||
@ -1144,7 +1144,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *pwidstr,
|
|||||||
int is_sigg;
|
int is_sigg;
|
||||||
const char *newdesc;
|
const char *newdesc;
|
||||||
int pwid;
|
int pwid;
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
|
|
||||||
(void)ctrl;
|
(void)ctrl;
|
||||||
|
|
||||||
|
@ -1489,7 +1489,7 @@ verify_a_chv (app_t app,
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
char *prompt_buffer = NULL;
|
char *prompt_buffer = NULL;
|
||||||
const char *prompt;
|
const char *prompt;
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
int minlen = 6;
|
int minlen = 6;
|
||||||
|
|
||||||
assert (chvno == 1 || chvno == 2);
|
assert (chvno == 1 || chvno == 2);
|
||||||
@ -1707,7 +1707,7 @@ verify_chv3 (app_t app,
|
|||||||
|
|
||||||
if (!app->did_chv3)
|
if (!app->did_chv3)
|
||||||
{
|
{
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
int minlen = 8;
|
int minlen = 8;
|
||||||
char *prompt;
|
char *prompt;
|
||||||
|
|
||||||
@ -1917,7 +1917,7 @@ do_change_pin (app_t app, ctrl_t ctrl, const char *chvnostr,
|
|||||||
char *pinvalue = NULL;
|
char *pinvalue = NULL;
|
||||||
int reset_mode = !!(flags & APP_CHANGE_FLAG_RESET);
|
int reset_mode = !!(flags & APP_CHANGE_FLAG_RESET);
|
||||||
int set_resetcode = 0;
|
int set_resetcode = 0;
|
||||||
iso7816_pininfo_t pininfo;
|
pininfo_t pininfo;
|
||||||
int use_keypad = 0;
|
int use_keypad = 0;
|
||||||
int minlen = 6;
|
int minlen = 6;
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
#include "scdaemon.h"
|
#include "scdaemon.h"
|
||||||
#include "app-common.h"
|
#include "app-common.h"
|
||||||
#include "apdu.h"
|
|
||||||
#include "iso7816.h"
|
#include "iso7816.h"
|
||||||
|
#include "apdu.h"
|
||||||
#include "tlv.h"
|
#include "tlv.h"
|
||||||
|
|
||||||
/* This table is used to keep track of locks on a per reader base.
|
/* This table is used to keep track of locks on a per reader base.
|
||||||
|
@ -91,6 +91,8 @@
|
|||||||
|
|
||||||
#include <usb.h>
|
#include <usb.h>
|
||||||
|
|
||||||
|
#include "scdaemon.h"
|
||||||
|
#include "iso7816.h"
|
||||||
#include "ccid-driver.h"
|
#include "ccid-driver.h"
|
||||||
|
|
||||||
#define DRVNAME "ccid-driver: "
|
#define DRVNAME "ccid-driver: "
|
||||||
@ -3297,7 +3299,7 @@ ccid_transceive (ccid_driver_t handle,
|
|||||||
int
|
int
|
||||||
ccid_transceive_secure (ccid_driver_t handle,
|
ccid_transceive_secure (ccid_driver_t handle,
|
||||||
const unsigned char *apdu_buf, size_t apdu_buflen,
|
const unsigned char *apdu_buf, size_t apdu_buflen,
|
||||||
int pin_mode, int pinlen_min, int pinlen_max,
|
pininfo_t *pininfo,
|
||||||
unsigned char *resp, size_t maxresplen, size_t *nresp)
|
unsigned char *resp, size_t maxresplen, size_t *nresp)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -3308,7 +3310,7 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
size_t dummy_nresp;
|
size_t dummy_nresp;
|
||||||
int testmode;
|
int testmode;
|
||||||
int cherry_mode = 0;
|
int cherry_mode = 0;
|
||||||
int enable_varlen = opt.enable_keypad_varlen;
|
int enable_varlen = 0;
|
||||||
|
|
||||||
testmode = !resp && !nresp;
|
testmode = !resp && !nresp;
|
||||||
|
|
||||||
@ -3322,19 +3324,16 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
;
|
;
|
||||||
else
|
else
|
||||||
return CCID_DRIVER_ERR_NO_KEYPAD;
|
return CCID_DRIVER_ERR_NO_KEYPAD;
|
||||||
|
|
||||||
if (pin_mode != 1)
|
|
||||||
return CCID_DRIVER_ERR_NOT_SUPPORTED;
|
|
||||||
|
|
||||||
if (!pinlen_min)
|
if (!pininfo->minlen)
|
||||||
pinlen_min = 1;
|
pininfo->minlen = 1;
|
||||||
if (!pinlen_max)
|
if (!pininfo->maxlen)
|
||||||
pinlen_max = 25;
|
pininfo->maxlen = 25;
|
||||||
|
|
||||||
/* Note that the 25 is the maximum value the SPR532 allows. */
|
/* Note that the 25 is the maximum value the SPR532 allows. */
|
||||||
if (pinlen_min < 1 || pinlen_min > 25
|
if (pininfo->minlen < 1 || pininfo->minlen > 25
|
||||||
|| pinlen_max < 1 || pinlen_max > 25
|
|| pininfo->maxlen < 1 || pininfo->maxlen > 25
|
||||||
|| pinlen_min > pinlen_max)
|
|| pininfo->minlen > pininfo->maxlen)
|
||||||
return CCID_DRIVER_ERR_INV_VALUE;
|
return CCID_DRIVER_ERR_INV_VALUE;
|
||||||
|
|
||||||
/* We have only tested a few readers so better don't risk anything
|
/* We have only tested a few readers so better don't risk anything
|
||||||
@ -3348,7 +3347,7 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
break;
|
break;
|
||||||
case VENDOR_VASCO: /* Tested with DIGIPASS 920 */
|
case VENDOR_VASCO: /* Tested with DIGIPASS 920 */
|
||||||
enable_varlen = 1;
|
enable_varlen = 1;
|
||||||
pinlen_max = 15;
|
pininfo->maxlen = 15;
|
||||||
break;
|
break;
|
||||||
case VENDOR_CHERRY:
|
case VENDOR_CHERRY:
|
||||||
enable_varlen = 1;
|
enable_varlen = 1;
|
||||||
@ -3371,6 +3370,12 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
return CCID_DRIVER_ERR_NOT_SUPPORTED;
|
return CCID_DRIVER_ERR_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (enable_varlen)
|
||||||
|
pininfo->mode = 0;
|
||||||
|
|
||||||
|
if (pininfo->mode != 0 && pininfo->mode != 1)
|
||||||
|
return CCID_DRIVER_ERR_NOT_SUPPORTED;
|
||||||
|
|
||||||
if (testmode)
|
if (testmode)
|
||||||
return 0; /* Success */
|
return 0; /* Success */
|
||||||
|
|
||||||
@ -3418,8 +3423,8 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* The following is a little endian word. */
|
/* The following is a little endian word. */
|
||||||
msg[msglen++] = pinlen_max; /* wPINMaxExtraDigit-Maximum. */
|
msg[msglen++] = pininfo->maxlen; /* wPINMaxExtraDigit-Maximum. */
|
||||||
msg[msglen++] = pinlen_min; /* wPINMaxExtraDigit-Minimum. */
|
msg[msglen++] = pininfo->minlen; /* wPINMaxExtraDigit-Minimum. */
|
||||||
|
|
||||||
if (apdu_buf[1] == 0x24)
|
if (apdu_buf[1] == 0x24)
|
||||||
msg[msglen++] = apdu_buf[2] == 0 ? 0x03 : 0x01;
|
msg[msglen++] = apdu_buf[2] == 0 ? 0x03 : 0x01;
|
||||||
@ -3432,7 +3437,7 @@ ccid_transceive_secure (ccid_driver_t handle,
|
|||||||
|
|
||||||
msg[msglen] = 0x02; /* bEntryValidationCondition:
|
msg[msglen] = 0x02; /* bEntryValidationCondition:
|
||||||
Validation key pressed */
|
Validation key pressed */
|
||||||
if (pinlen_min && pinlen_max && pinlen_min == pinlen_max)
|
if (pininfo->minlen && pininfo->maxlen && pininfo->minlen == pininfo->maxlen)
|
||||||
msg[msglen] |= 0x01; /* Max size reached. */
|
msg[msglen] |= 0x01; /* Max size reached. */
|
||||||
msglen++;
|
msglen++;
|
||||||
|
|
||||||
|
@ -93,8 +93,7 @@ int ccid_transceive (ccid_driver_t handle,
|
|||||||
unsigned char *resp, size_t maxresplen, size_t *nresp);
|
unsigned char *resp, size_t maxresplen, size_t *nresp);
|
||||||
int ccid_transceive_secure (ccid_driver_t handle,
|
int ccid_transceive_secure (ccid_driver_t handle,
|
||||||
const unsigned char *apdu, size_t apdulen,
|
const unsigned char *apdu, size_t apdulen,
|
||||||
int pin_mode,
|
pininfo_t *pininfo,
|
||||||
int pinlen_min, int pinlen_max,
|
|
||||||
unsigned char *resp, size_t maxresplen, size_t *nresp);
|
unsigned char *resp, size_t maxresplen, size_t *nresp);
|
||||||
int ccid_transceive_escape (ccid_driver_t handle,
|
int ccid_transceive_escape (ccid_driver_t handle,
|
||||||
const unsigned char *data, size_t datalen,
|
const unsigned char *data, size_t datalen,
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include <assuan.h>
|
#include <assuan.h>
|
||||||
#include <ksba.h>
|
#include <ksba.h>
|
||||||
#include "app-common.h"
|
#include "app-common.h"
|
||||||
|
#include "iso7816.h"
|
||||||
#include "apdu.h" /* Required for apdu_*_reader (). */
|
#include "apdu.h" /* Required for apdu_*_reader (). */
|
||||||
#include "exechelp.h"
|
#include "exechelp.h"
|
||||||
#ifdef HAVE_LIBUSB
|
#ifdef HAVE_LIBUSB
|
||||||
|
@ -269,12 +269,11 @@ iso7816_apdu_direct (int slot, const void *apdudata, size_t apdudatalen,
|
|||||||
/* Check whether the reader supports the ISO command code COMMAND on
|
/* Check whether the reader supports the ISO command code COMMAND on
|
||||||
the keypad. Returns 0 on success. */
|
the keypad. Returns 0 on success. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
iso7816_check_keypad (int slot, int command, iso7816_pininfo_t *pininfo)
|
iso7816_check_keypad (int slot, int command, pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
|
|
||||||
sw = apdu_check_keypad (slot, command,
|
sw = apdu_check_keypad (slot, command, pininfo);
|
||||||
pininfo->mode, pininfo->minlen, pininfo->maxlen);
|
|
||||||
return iso7816_map_sw (sw);
|
return iso7816_map_sw (sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -283,12 +282,11 @@ iso7816_check_keypad (int slot, int command, iso7816_pininfo_t *pininfo)
|
|||||||
vector CHVNO. With PININFO non-NULL the keypad of the reader will
|
vector CHVNO. With PININFO non-NULL the keypad of the reader will
|
||||||
be used. Returns 0 on success. */
|
be used. Returns 0 on success. */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
iso7816_verify_kp (int slot, int chvno, iso7816_pininfo_t *pininfo)
|
iso7816_verify_kp (int slot, int chvno, pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
|
|
||||||
sw = apdu_keypad_verify (slot, 0x00, CMD_VERIFY, 0, chvno,
|
sw = apdu_keypad_verify (slot, 0x00, CMD_VERIFY, 0, chvno, pininfo);
|
||||||
pininfo->mode, pininfo->minlen, pininfo->maxlen);
|
|
||||||
return map_sw (sw);
|
return map_sw (sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,14 +307,12 @@ iso7816_verify (int slot, int chvno, const char *chv, size_t chvlen)
|
|||||||
data" is done, otherwise an "exchange reference data". */
|
data" is done, otherwise an "exchange reference data". */
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
iso7816_change_reference_data_kp (int slot, int chvno, int is_exchange,
|
iso7816_change_reference_data_kp (int slot, int chvno, int is_exchange,
|
||||||
iso7816_pininfo_t *pininfo)
|
pininfo_t *pininfo)
|
||||||
{
|
{
|
||||||
int sw;
|
int sw;
|
||||||
|
|
||||||
sw = apdu_keypad_modify (slot, 0x00, CMD_CHANGE_REFERENCE_DATA,
|
sw = apdu_keypad_modify (slot, 0x00, CMD_CHANGE_REFERENCE_DATA,
|
||||||
is_exchange ? 1 : 0,
|
is_exchange ? 1 : 0, chvno, pininfo);
|
||||||
chvno, pininfo->mode, pininfo->minlen,
|
|
||||||
pininfo->maxlen);
|
|
||||||
return map_sw (sw);
|
return map_sw (sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,13 +32,13 @@
|
|||||||
|
|
||||||
/* Information to be passed to keypad equipped readers. See
|
/* Information to be passed to keypad equipped readers. See
|
||||||
ccid-driver.c for details. */
|
ccid-driver.c for details. */
|
||||||
struct iso7816_pininfo_s
|
struct pininfo_s
|
||||||
{
|
{
|
||||||
int mode; /* A mode of 0 means: Do not use the keypad. */
|
int mode; /* 0: Use variable length input. 1: Use fixed length input. */
|
||||||
int minlen;
|
int minlen;
|
||||||
int maxlen;
|
int maxlen;
|
||||||
};
|
};
|
||||||
typedef struct iso7816_pininfo_s iso7816_pininfo_t;
|
typedef struct pininfo_s pininfo_t;
|
||||||
|
|
||||||
|
|
||||||
gpg_error_t iso7816_map_sw (int sw);
|
gpg_error_t iso7816_map_sw (int sw);
|
||||||
@ -58,16 +58,16 @@ gpg_error_t iso7816_apdu_direct (int slot,
|
|||||||
int handle_more,
|
int handle_more,
|
||||||
unsigned char **result, size_t *resultlen);
|
unsigned char **result, size_t *resultlen);
|
||||||
gpg_error_t iso7816_check_keypad (int slot, int command,
|
gpg_error_t iso7816_check_keypad (int slot, int command,
|
||||||
iso7816_pininfo_t *pininfo);
|
pininfo_t *pininfo);
|
||||||
gpg_error_t iso7816_verify (int slot,
|
gpg_error_t iso7816_verify (int slot,
|
||||||
int chvno, const char *chv, size_t chvlen);
|
int chvno, const char *chv, size_t chvlen);
|
||||||
gpg_error_t iso7816_verify_kp (int slot, int chvno, iso7816_pininfo_t *pininfo);
|
gpg_error_t iso7816_verify_kp (int slot, int chvno, pininfo_t *pininfo);
|
||||||
gpg_error_t iso7816_change_reference_data (int slot, int chvno,
|
gpg_error_t iso7816_change_reference_data (int slot, int chvno,
|
||||||
const char *oldchv, size_t oldchvlen,
|
const char *oldchv, size_t oldchvlen,
|
||||||
const char *newchv, size_t newchvlen);
|
const char *newchv, size_t newchvlen);
|
||||||
gpg_error_t iso7816_change_reference_data_kp (int slot, int chvno,
|
gpg_error_t iso7816_change_reference_data_kp (int slot, int chvno,
|
||||||
int is_exchange,
|
int is_exchange,
|
||||||
iso7816_pininfo_t *pininfo);
|
pininfo_t *pininfo);
|
||||||
gpg_error_t iso7816_reset_retry_counter (int slot, int chvno,
|
gpg_error_t iso7816_reset_retry_counter (int slot, int chvno,
|
||||||
const char *newchv, size_t newchvlen);
|
const char *newchv, size_t newchvlen);
|
||||||
gpg_error_t iso7816_reset_retry_counter_with_rc (int slot, int chvno,
|
gpg_error_t iso7816_reset_retry_counter_with_rc (int slot, int chvno,
|
||||||
|
@ -33,6 +33,7 @@
|
|||||||
|
|
||||||
#include "../common/ttyio.h"
|
#include "../common/ttyio.h"
|
||||||
#include "../common/simple-pwquery.h"
|
#include "../common/simple-pwquery.h"
|
||||||
|
#include "iso7816.h"
|
||||||
#include "apdu.h" /* for open_reader */
|
#include "apdu.h" /* for open_reader */
|
||||||
#include "atr.h"
|
#include "atr.h"
|
||||||
#include "app-common.h"
|
#include "app-common.h"
|
||||||
|
@ -48,6 +48,7 @@
|
|||||||
#include "i18n.h"
|
#include "i18n.h"
|
||||||
#include "sysutils.h"
|
#include "sysutils.h"
|
||||||
#include "app-common.h"
|
#include "app-common.h"
|
||||||
|
#include "iso7816.h"
|
||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "ccid-driver.h"
|
#include "ccid-driver.h"
|
||||||
#include "mkdtemp.h"
|
#include "mkdtemp.h"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user