DnDpinentry: cancellation

This commit is contained in:
NIIBE Yutaka
2011-12-20 10:39:47 +09:00
parent a08669dfcd
commit c0ab2ae830
5 changed files with 54 additions and 6 deletions

View File

@@ -1,3 +1,13 @@
2011-12-20 Niibe Yutaka <gniibe@fsij.org>
* src/usb_msc.c (msc_handle_command): SCSI_START_STOP_UNIT command
with stop/eject/close means cancelling pinentry.
* src/pin-dnd.c (pinpad_finish_entry, parse_directory_sector):
Implement "cancel".
(pinpad_getline): Likewise.
(msc_scsi_stop): New.
2011-12-16 Niibe Yutaka <gniibe@fsij.org> 2011-12-16 Niibe Yutaka <gniibe@fsij.org>
* tool/gnuk_put_binary_libusb.py (gnuk_token.cmd_select_openpgp): * tool/gnuk_put_binary_libusb.py (gnuk_token.cmd_select_openpgp):

13
NEWS
View File

@@ -1,5 +1,18 @@
Gnuk NEWS - User visible changes Gnuk NEWS - User visible changes
* Major changes in Gnuk 0.17
Released 2012-01-XX, by NIIBE Yutaka
** With DnD pinentry, user can cancel pin input
Now, user can cancel pin input by unmounting device before finishing
DnD.
** New tool: pinpad-test.py
The tool pinpad-test.py is PC/SC test tool for pinentry of pinpad with
OpenPGP card v2.
* Major changes in Gnuk 0.16 * Major changes in Gnuk 0.16
Released 2011-12-14, by NIIBE Yutaka Released 2011-12-14, by NIIBE Yutaka

View File

@@ -362,6 +362,7 @@ extern void msc_init (void);
extern void msc_media_insert_change (int available); extern void msc_media_insert_change (int available);
extern int msc_scsi_write (uint32_t lba, const uint8_t *buf, size_t size); extern int msc_scsi_write (uint32_t lba, const uint8_t *buf, size_t size);
extern int msc_scsi_read (uint32_t lba, const uint8_t **sector_p); extern int msc_scsi_read (uint32_t lba, const uint8_t **sector_p);
extern void msc_scsi_stop (uint8_t code);
# endif # endif
#define PIN_INPUT_CURRENT 1 #define PIN_INPUT_CURRENT 1
#define PIN_INPUT_NEW 2 #define PIN_INPUT_NEW 2

View File

@@ -72,13 +72,16 @@ pinpad_getline (int msg_code, systime_t timeout)
chSysUnlock (); chSysUnlock ();
led_blink (0); led_blink (0);
if (msg == 1) if (msg != 0)
break; break;
} }
msc_media_insert_change (0); msc_media_insert_change (0);
if (msg == 1)
return pin_input_len; return pin_input_len;
else
return -1; /* cancel */
} }
static void pinpad_input (void) static void pinpad_input (void)
@@ -89,9 +92,12 @@ static void pinpad_input (void)
chSysUnlock (); chSysUnlock ();
} }
static void pinpad_finish_entry (void) static void pinpad_finish_entry (int cancel)
{ {
chSysLock (); chSysLock ();
if (cancel)
pin_thread->p_u.rdymsg = 2;
else
pin_thread->p_u.rdymsg = 1; pin_thread->p_u.rdymsg = 1;
chSchReadyI (pin_thread); chSchReadyI (pin_thread);
chSysUnlock (); chSysUnlock ();
@@ -328,7 +334,7 @@ static void parse_directory_sector (const uint8_t *p, uint8_t index)
} }
if (index == 0 && num_children == 1) if (index == 0 && num_children == 1)
pinpad_finish_entry (); pinpad_finish_entry (0);
else if (input) else if (input)
pinpad_input (); pinpad_input ();
} }
@@ -357,3 +363,10 @@ msc_scsi_write (uint32_t lba, const uint8_t *buf, size_t size)
return 0; return 0;
} }
} }
void
msc_scsi_stop (uint8_t code)
{
(void)code;
pinpad_finish_entry (1);
}

View File

@@ -388,6 +388,17 @@ void msc_handle_command (void)
buf[11] = (uint8_t)(secsize >> 0); buf[11] = (uint8_t)(secsize >> 0);
msc_send_result (buf, 12); msc_send_result (buf, 12);
return; return;
case SCSI_START_STOP_UNIT:
if (CBW.CBWCB[4] == 0x00 /* stop */
|| CBW.CBWCB[4] == 0x02 /* eject */ || CBW.CBWCB[4] == 0x03 /* close */)
{
msc_scsi_stop (CBW.CBWCB[4]);
set_scsi_sense_data (0x05, 0x24); /* ILLEGAL_REQUEST */
contingent_allegiance = 1;
keep_contingent_allegiance = 1;
}
/* CBW.CBWCB[4] == 0x01 *//* start */
goto success;
case SCSI_TEST_UNIT_READY: case SCSI_TEST_UNIT_READY:
if (contingent_allegiance) if (contingent_allegiance)
{ {
@@ -397,9 +408,9 @@ void msc_handle_command (void)
return; return;
} }
/* fall through */ /* fall through */
success:
case SCSI_SYNCHRONIZE_CACHE: case SCSI_SYNCHRONIZE_CACHE:
case SCSI_VERIFY10: case SCSI_VERIFY10:
case SCSI_START_STOP_UNIT:
case SCSI_ALLOW_MEDIUM_REMOVAL: case SCSI_ALLOW_MEDIUM_REMOVAL:
CSW.bCSWStatus = MSC_CSW_STATUS_PASSED; CSW.bCSWStatus = MSC_CSW_STATUS_PASSED;
CSW.dCSWDataResidue = CBW.dCBWDataTransferLength; CSW.dCSWDataResidue = CBW.dCBWDataTransferLength;