|
1 Upstream fixes already included in the latest community updates to coolkey v1.1.0 |
|
2 |
|
3 Addresses various SCARD API and APDU issues. |
|
4 |
|
5 --- ORIGINAL/./src/libckyapplet/cky_card.c 2016-06-24 16:08:04.287949643 -0400 |
|
6 +++ ././src/libckyapplet/cky_card.c 2016-06-24 12:53:46.337857570 -0400 |
|
7 @@ -129,6 +129,7 @@ |
|
8 SCardGetStatusChangeFn SCardGetStatusChange; |
|
9 SCardCancelFn SCardCancel; |
|
10 SCARD_IO_REQUEST *SCARD_PCI_T0_; |
|
11 + SCARD_IO_REQUEST *SCARD_PCI_T1_; |
|
12 } SCard; |
|
13 |
|
14 #define GET_ADDRESS(library, scard, name) \ |
|
15 @@ -195,6 +196,12 @@ |
|
16 if( status != CKYSUCCESS ) { |
|
17 goto fail; |
|
18 } |
|
19 + |
|
20 + status = ckyShLibrary_getAddress( library, |
|
21 + (void**) &scard->SCARD_PCI_T1_, MAKE_DLL_SYMBOL(g_rgSCardT1Pci)); |
|
22 + if( status != CKYSUCCESS ) { |
|
23 + goto fail; |
|
24 + } |
|
25 return scard; |
|
26 |
|
27 fail: |
|
28 @@ -837,6 +844,11 @@ |
|
29 rv = ctx->scard->SCardGetStatusChange(ctx->context, timeout, |
|
30 readers, readerCount); |
|
31 if (rv != SCARD_S_SUCCESS) { |
|
32 + if ((rv == SCARD_E_NO_SERVICE) || (rv == SCARD_E_SERVICE_STOPPED)) { |
|
33 + /* if we were stopped, don't reuse the old context, |
|
34 + * pcsc-lite hangs */ |
|
35 + ckyCardContext_release(ctx); |
|
36 + } |
|
37 ctx->lastError = rv; |
|
38 return CKYSCARDERR; |
|
39 } |
|
40 @@ -884,6 +896,7 @@ |
|
41 SCARDHANDLE cardHandle; |
|
42 unsigned long lastError; |
|
43 CKYBool inTransaction; |
|
44 + unsigned long protocol; |
|
45 }; |
|
46 |
|
47 static void |
|
48 @@ -894,6 +907,7 @@ |
|
49 conn->cardHandle = 0; |
|
50 conn->lastError = 0; |
|
51 conn->inTransaction = 0; |
|
52 + conn->protocol = SCARD_PROTOCOL_T0; |
|
53 } |
|
54 |
|
55 CKYCardConnection * |
|
56 @@ -934,14 +948,13 @@ |
|
57 { |
|
58 CKYStatus ret; |
|
59 unsigned long rv; |
|
60 - unsigned long protocol; |
|
61 |
|
62 ret = CKYCardConnection_Disconnect(conn); |
|
63 if (ret != CKYSUCCESS) { |
|
64 return ret; |
|
65 } |
|
66 rv = conn->scard->SCardConnect( conn->ctx->context, readerName, |
|
67 - SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &conn->cardHandle, &protocol); |
|
68 + SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &conn->cardHandle, &conn->protocol); |
|
69 if (rv != SCARD_S_SUCCESS) { |
|
70 conn->lastError = rv; |
|
71 return CKYSCARDERR; |
|
72 @@ -978,7 +991,7 @@ |
|
73 unsigned long protocol; |
|
74 |
|
75 rv = conn->scard->SCardReconnect(conn->cardHandle, |
|
76 - SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, init, &protocol); |
|
77 + SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1 , init, &protocol); |
|
78 if (rv != SCARD_S_SUCCESS) { |
|
79 conn->lastError = rv; |
|
80 return CKYSCARDERR; |
|
81 @@ -1039,10 +1052,17 @@ |
|
82 return ret; |
|
83 } |
|
84 |
|
85 - rv = conn->scard->SCardTransmit(conn->cardHandle, |
|
86 - conn->scard->SCARD_PCI_T0_, |
|
87 - CKYBuffer_Data(&apdu->apduBuf), CKYBuffer_Size(&apdu->apduBuf), |
|
88 - NULL, response->data, &response->len); |
|
89 + if( conn->protocol == SCARD_PROTOCOL_T0 ) { |
|
90 + rv = conn->scard->SCardTransmit(conn->cardHandle, |
|
91 + conn->scard->SCARD_PCI_T0_, |
|
92 + CKYBuffer_Data(&apdu->apduBuf), CKYBuffer_Size(&apdu->apduBuf), |
|
93 + NULL, response->data, &response->len); |
|
94 + } else { |
|
95 + rv = conn->scard->SCardTransmit(conn->cardHandle, |
|
96 + conn->scard->SCARD_PCI_T1_, |
|
97 + CKYBuffer_Data(&apdu->apduBuf), CKYBuffer_Size(&apdu->apduBuf), |
|
98 + NULL, response->data, &response->len); |
|
99 + } |
|
100 |
|
101 if (rv != SCARD_S_SUCCESS) { |
|
102 conn->lastError =rv; |
|
103 @@ -1057,25 +1077,39 @@ |
|
104 CKYBuffer *response) |
|
105 { |
|
106 CKYStatus ret; |
|
107 + CKYBuffer getResponse; |
|
108 + CKYSize size = 0; |
|
109 |
|
110 ret = CKYCardConnection_TransmitAPDU(conn, apdu, response); |
|
111 if (ret != CKYSUCCESS) { |
|
112 return ret; |
|
113 } |
|
114 + CKYBuffer_InitEmpty(&getResponse); |
|
115 |
|
116 - if (CKYBuffer_Size(response) == 2 && CKYBuffer_GetChar(response,0) == 0x61) { |
|
117 + /* automatically handle the response data protocol */ |
|
118 + while ((ret == CKYSUCCESS) && |
|
119 + (size = CKYBuffer_Size(response)) >= 2 && |
|
120 + (CKYBuffer_GetChar(response,size-2) == 0x61)) { |
|
121 /* get the response */ |
|
122 CKYAPDU getResponseAPDU; |
|
123 |
|
124 + CKYBuffer_Zero(&getResponse); |
|
125 CKYAPDU_Init(&getResponseAPDU); |
|
126 CKYAPDU_SetCLA(&getResponseAPDU, 0x00); |
|
127 CKYAPDU_SetINS(&getResponseAPDU, 0xc0); |
|
128 CKYAPDU_SetP1(&getResponseAPDU, 0x00); |
|
129 CKYAPDU_SetP2(&getResponseAPDU, 0x00); |
|
130 - CKYAPDU_SetReceiveLen(&getResponseAPDU, CKYBuffer_GetChar(response,1)); |
|
131 - ret = CKYCardConnection_TransmitAPDU(conn, &getResponseAPDU, response); |
|
132 + CKYAPDU_SetReceiveLen(&getResponseAPDU, |
|
133 + CKYBuffer_GetChar(response,size-1)); |
|
134 + ret = CKYCardConnection_TransmitAPDU(conn, &getResponseAPDU, |
|
135 + &getResponse); |
|
136 CKYAPDU_FreeData(&getResponseAPDU); |
|
137 + if ((ret == CKYSUCCESS) && (CKYBuffer_Size(&getResponse) >= 2)) { |
|
138 + CKYBuffer_Resize(response, size-2); |
|
139 + CKYBuffer_AppendCopy(response,&getResponse); |
|
140 + } |
|
141 } |
|
142 + CKYBuffer_FreeData(&getResponse); |
|
143 return ret; |
|
144 } |
|
145 |
|
146 @@ -1086,7 +1120,7 @@ |
|
147 unsigned long readerLen = 0; |
|
148 unsigned long protocol; |
|
149 unsigned long rv; |
|
150 - CKYSize atrLen; |
|
151 + CKYSize atrLen = 0; |
|
152 char *readerStr; |
|
153 CKYStatus ret; |
|
154 |