191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
+
+
+
+
|
if (retval != ptr) {
fprintf(stderr, "%s():%i: ", func, line);
fprintf(stderr, "REALLOC(%p) = %p", ptr, retval);
fprintf(stderr, "\n");
fflush(stderr);
}
if (retval == NULL) {
CACKEY_DEBUG_PRINTF(" *** ERROR *** realloc returned NULL");
}
return(retval);
}
static char *CACKEY_DEBUG_FUNC_STRDUP(const char *ptr, const char *func, int line) {
char *retval;
|
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
|
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
|
-
+
|
typedef enum {
CACKEY_PCSC_S_TOKENPRESENT = 1,
CACKEY_PCSC_S_OK = 0,
CACKEY_PCSC_E_GENERIC = -1,
CACKEY_PCSC_E_BADPIN = -2,
CACKEY_PCSC_E_LOCKED = -3,
CACKEY_PCSC_E_NEEDLOGIN = -4,
CACKEY_PCSC_E_TOKENABSENT = -6,
CACKEY_PCSC_E_TOKENABSENT = -6
} cackey_ret;
struct cackey_tlv_cardurl {
unsigned char rid[5];
cackey_tlv_apptype apptype;
cackey_tlv_objectid objectid;
cackey_tlv_objectid appid;
|
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
|
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
|
-
+
|
return(CACKEY_PCSC_E_GENERIC);
}
/* Connect to reader, if needed */
if (!slot->pcsc_card_connected) {
CACKEY_DEBUG_PRINTF("SCardConnect(%s) called", slot->pcsc_reader);
scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &slot->pcsc_card, &protocol);
scard_conn_ret = SCardConnect(*cackey_pcsc_handle, slot->pcsc_reader, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &slot->pcsc_card, &protocol);
if (scard_conn_ret != SCARD_S_SUCCESS) {
CACKEY_DEBUG_PRINTF("Connection to card failed, returning in failure (SCardConnect() = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_conn_ret), (long) scard_conn_ret);
return(CACKEY_PCSC_E_GENERIC);
}
|
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
|
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
|
-
+
-
+
-
+
|
if (class == GSCIS_CLASS_ISO7816 && instruction == GSCIS_INSTR_VERIFY && p1 == 0x00 && p2 == 0x00) {
CACKEY_DEBUG_PRINTF("Sending APDU: <<censored>>");
} else {
CACKEY_DEBUG_PRINTBUF("Sending APDU:", xmit_buf, xmit_len);
}
recv_len = sizeof(recv_buf);
scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, SCARD_PCI_T1, recv_buf, &recv_len);
scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, NULL, recv_buf, &recv_len);
if (scard_xmit_ret != SCARD_S_SUCCESS) {
CACKEY_DEBUG_PRINTF("Failed to send APDU to card (SCardTransmit() = %s/%lx)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (unsigned long) scard_xmit_ret);
CACKEY_DEBUG_PRINTF("Marking slot as having been reset");
slot->transaction_depth = 0;
slot->slot_reset = 1;
if (scard_xmit_ret == SCARD_W_RESET_CARD) {
CACKEY_DEBUG_PRINTF("Reset required, please hold...");
scard_reconn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &protocol);
scard_reconn_ret = SCardReconnect(slot->pcsc_card, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, SCARD_RESET_CARD, &protocol);
if (scard_reconn_ret == SCARD_S_SUCCESS) {
/* Re-establish transaction, if it was present */
if (slot->transaction_depth > 0) {
slot->transaction_depth--;
cackey_begin_transaction(slot);
}
CACKEY_DEBUG_PRINTF("Reset successful, retransmitting");
recv_len = sizeof(recv_buf);
scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, SCARD_PCI_T0, recv_buf, &recv_len);
scard_xmit_ret = SCardTransmit(slot->pcsc_card, SCARD_PCI_T0, xmit_buf, xmit_len, NULL, recv_buf, &recv_len);
if (scard_xmit_ret != SCARD_S_SUCCESS) {
CACKEY_DEBUG_PRINTF("Retransmit failed, returning in failure after disconnecting the card (SCardTransmit = %s/%li)", CACKEY_DEBUG_FUNC_SCARDERR_TO_STR(scard_xmit_ret), (long) scard_xmit_ret);
SCardDisconnect(slot->pcsc_card, SCARD_RESET_CARD);
slot->pcsc_card_connected = 0;
|