[Pcsclite-cvs-commit] Drivers/ccid/src commands.c,1.11,1.12 ccid_ifdhandler.h,1.8,1.9 commands.h,1.5,1.6 ifdhandler.c,1.29,1.30
rousseau@haydn.debian.org
rousseau@haydn.debian.org
Update of /cvsroot/pcsclite/Drivers/ccid/src
In directory haydn:/tmp/cvs-serv25191/src
Modified Files:
commands.c ccid_ifdhandler.h commands.h ifdhandler.c
Log Message:
add support for Secure PIN through SCardControl() (see sample code in examples/)
Index: commands.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/commands.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- commands.c 17 May 2004 14:39:22 -0000 1.11
+++ commands.c 24 May 2004 10:02:48 -0000 1.12
@@ -83,7 +83,7 @@
{
unsigned char cmd[] = "\x1F\x01";
unsigned char res[1];
- unsigned long res_length = sizeof(res);
+ int res_length = sizeof(res);
if ((return_value = CmdEscape(lun, cmd, sizeof(cmd)-1, res,
&res_length)) != IFD_SUCCESS)
@@ -114,11 +114,77 @@
/*****************************************************************************
*
+ * SecurePIN
+ *
+ ****************************************************************************/
+RESPONSECODE SecurePIN(int lun, const unsigned char TxBuffer[], int TxLength,
+ unsigned char RxBuffer[], int *RxLength)
+{
+ unsigned char cmd[11+14+CMD_BUF_SIZE];
+ _ccid_descriptor *ccid_descriptor = get_ccid_descriptor(lun);
+ int length = 0;
+
+ /* PIN verification data structure WITHOUT TeoPrologue & bPINOperation */
+ if (TxBuffer[4] /* Lc */
+ + 5 /* CLA, INS, P1, P2, Lc */
+ + 11 /* CCID PIN verification data structure */ == TxLength)
+ {
+ i2dw(TxLength+3+1, cmd+1); /* command length */
+
+ /* copy the CCID data structure */
+ memcpy(cmd +11, TxBuffer + TxBuffer[4] + 5, 11);
+
+ /* TeoPrologue not used */
+ memset(cmd +11 + 11, 0, 3);
+
+ /* copy the APDU */
+ memcpy(cmd +11 +14, TxBuffer, TxLength-11);
+
+ length = 14 + TxLength;
+ }
+ /* PIN verification data structure WITH TeoPrologue & bPINOperation */
+ else if (TxBuffer[4] /* Lc */
+ + 5 /* CLA, INS, P1, P2, Lc */
+ + 15 /* CCID PIN verification data structure */ == TxLength)
+ {
+ i2dw(TxLength, cmd+1); /* command length */
+
+ /* copy the CCID data structure */
+ memcpy(cmd +10, TxBuffer + TxBuffer[4] + 5, 15);
+
+ /* copy the APDU */
+ memcpy(cmd +10 +15, TxBuffer, TxLength-15);
+
+ length = 10 + TxLength;
+ }
+ else
+ {
+ *RxLength = 0;
+ return IFD_COMMUNICATION_ERROR;
+ }
+
+ cmd[0] = 0x69; /* Secure */
+ cmd[5] = 0; /* slot number */
+ cmd[6] = ccid_descriptor->bSeq++;
+ cmd[7] = 0; /* bBWI */
+ cmd[8] = 0; /* wLevelParameter */
+ cmd[9] = 0;
+ cmd[10] = 0; /* bPINOperation: PIN Verification */
+
+ if (WritePort(lun, length, cmd) != STATUS_SUCCESS)
+ return IFD_COMMUNICATION_ERROR;
+
+ return CCID_Receive(lun, RxLength, RxBuffer);
+} /* SecurePIN */
+
+
+/*****************************************************************************
+ *
* Escape
*
****************************************************************************/
RESPONSECODE CmdEscape(int lun, const unsigned char TxBuffer[], int TxLength,
- unsigned char RxBuffer[], unsigned long *RxLength)
+ unsigned char RxBuffer[], int *RxLength)
{
unsigned char *cmd_in, *cmd_out;
status_t res;
@@ -324,7 +390,8 @@
* CCID_Transmit
*
****************************************************************************/
-RESPONSECODE CCID_Transmit(int lun, int tx_length, unsigned char tx_buffer[])
+RESPONSECODE CCID_Transmit(int lun, int tx_length,
+ const unsigned char tx_buffer[])
{
unsigned char cmd[10+CMD_BUF_SIZE]; /* CCID + APDU buffer */
_ccid_descriptor *ccid_descriptor = get_ccid_descriptor(lun);
Index: ccid_ifdhandler.h
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/ccid_ifdhandler.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- ccid_ifdhandler.h 17 May 2004 14:35:51 -0000 1.8
+++ ccid_ifdhandler.h 24 May 2004 10:02:48 -0000 1.9
@@ -24,7 +24,12 @@
#ifndef _ccid_ifd_handler_h_
#define _ccid_ifd_handler_h_
-#define IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE 2048
+#define SCARD_CTL_CODE(code) (0x42000000 + (code))
+
+#define IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE SCARD_CTL_CODE(1)
+#define IOCTL_SMARTCARD_VENDOR_VERIFY_PIN SCARD_CTL_CODE(2)
+#define IOCTL_SMARTCARD_VENDOR_MODIFY_PIN SCARD_CTL_CODE(3)
+#define IOCTL_SMARTCARD_VENDOR_TRANSFER_PIN SCARD_CTL_CODE(4)
#define DRIVER_OPTION_CCID_EXCHANGE_AUTHORIZED 1
#define DRIVER_OPTION_GEMPC_TWIN_KEY_APDU 2
Index: commands.h
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/commands.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- commands.h 17 May 2004 14:35:51 -0000 1.5
+++ commands.h 24 May 2004 10:02:48 -0000 1.6
@@ -26,19 +26,23 @@
#define ERROR_OFFSET 8
RESPONSECODE CmdPowerOn(int lun, int * nlength, unsigned char buffer[]);
+RESPONSECODE SecurePIN(int lun, const unsigned char TxBuffer[], int TxLength,
+ unsigned char RxBuffer[], int *RxLength);
RESPONSECODE CmdEscape(int lun, const unsigned char TxBuffer[], int TxLength,
- unsigned char RxBuffer[], unsigned long *RxLength);
+ unsigned char RxBuffer[], int *RxLength);
RESPONSECODE CmdPowerOff(int lun);
RESPONSECODE CmdGetSlotStatus(int lun, unsigned char buffer[]);
RESPONSECODE CmdXfrBlock(int lun, int tx_length, unsigned char tx_buffer[],
int *rx_length, unsigned char rx_buffer[], int protoccol);
-RESPONSECODE CCID_Transmit(int lun, int tx_length, unsigned char tx_buffer[]);
+RESPONSECODE CCID_Transmit(int lun, int tx_length,
+ const unsigned char tx_buffer[]);
RESPONSECODE CCID_Receive(int lun, int *rx_length, unsigned char rx_buffer[]);
RESPONSECODE CmdXfrBlockTPDU_T0(int lun, int tx_length,
unsigned char tx_buffer[], int *rx_length, unsigned char rx_buffer[]);
RESPONSECODE CmdXfrBlockTPDU_T1(int lun, int tx_length,
unsigned char tx_buffer[], int *rx_length, unsigned char rx_buffer[]);
-RESPONSECODE SetParameters(int lun, char protocol, int length, unsigned char buffer[]);
+RESPONSECODE SetParameters(int lun, char protocol, int length,
+ unsigned char buffer[]);
void i2dw(int value, unsigned char *buffer);
Index: ifdhandler.c
===================================================================
RCS file: /cvsroot/pcsclite/Drivers/ccid/src/ifdhandler.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- ifdhandler.c 18 May 2004 14:02:55 -0000 1.29
+++ ifdhandler.c 24 May 2004 10:02:48 -0000 1.30
@@ -533,13 +533,29 @@
if (IOCTL_SMARTCARD_VENDOR_IFD_EXCHANGE == dwControlCode)
{
if (FALSE == (DriverOptions & DRIVER_OPTION_CCID_EXCHANGE_AUTHORIZED))
+ {
+ DEBUG_INFO("ifd exchange (Escape command) not allowed");
return_value = IFD_COMMUNICATION_ERROR;
+ }
else
{
- *pdwBytesReturned = RxLength;
+ int iBytesReturned;
+
+ iBytesReturned = RxLength;
return_value = CmdEscape(Lun, TxBuffer, TxLength, RxBuffer,
- pdwBytesReturned);
+ &iBytesReturned);
+ *pdwBytesReturned = iBytesReturned;
}
+ }
+
+ if (IOCTL_SMARTCARD_VENDOR_VERIFY_PIN == dwControlCode)
+ {
+ int iBytesReturned;
+
+ iBytesReturned = RxLength;
+ return_value = SecurePIN(Lun, TxBuffer, TxLength, RxBuffer,
+ &iBytesReturned);
+ *pdwBytesReturned = iBytesReturned;
}
return return_value;