Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.8.21 and higher break pcsc-cyberjack driver #22

Closed
misery opened this issue Jul 25, 2017 · 7 comments
Closed

v1.8.21 and higher break pcsc-cyberjack driver #22

misery opened this issue Jul 25, 2017 · 7 comments

Comments

@misery
Copy link

misery commented Jul 25, 2017

Since v1.8.21 it is not possible to establish a "pace (pin)" channel to German eID card with the driver of ReinerSCT cyberjack komfort/standard. [1]

After git bisect this changeset seems to be the reason: 09cf6c7

The problem is the change from "ctStr.cbRecvLength" to "sizeof pbRecvBuffer" as the driver returns 612 (IFD_COMMUNICATION_ERROR) now.

The provided user buffer seems not the problem as it is broken before that check and we do not get a SCARD_E_INSUFFICIENT_BUFFER. If I manually set unsigned char pbRecvBuffer[MAX_BUFFER_SIZE_EXTENDED]; to e.g. 16000 instead of 65548 it will work again.

pcscd log

00000021 winscard_svc.c:679:ContextThread() TRANSMIT rv=0x0 for client 16
00010931 winscard_svc.c:359:ContextThread() Received command: CONTROL from client 16
00000022 readerfactory.c:852:RFReaderInfoById() RefReader() count was: 1
05153028 ifdwrapper.c:482:IFDControl() Card not transacted: 612
00000022 ifdwrapper.c:484:IFDControl() ControlCode: 0x42000DCC BytesReturned: 0
00000164 ifdwrapper.c:369:IFDStatusICC() Card not transacted: 612
00000025 eventhandler.c:333:EHStatusHandlerThread() Error communicating to: REINER SCT cyberJack RFID komfort (9334382841) 00 00
00000002 TxBuffer 02 CC 02 03 15 7F 4C 12 06 09 04 00 7F 00 07 03 01 02 02 53 05 00 05 13 FF 00 00 B2 02 30 82 02 AE 06 0A 04 00 7F 00 07 03 01 03 01 01 A1 16 0C 14 47 6F 76 65 72 6E 69 6B 75 73 20 54 65 73 74 20 44 56 43 41 A2 1A 13 18 68 74 74 70 3A 2F 2F 77 77 77 2E 67 6F 76 65 72 6E 69 6B 75 73 2E 64 65 A3 1A 0C 18 47 6F 76 65 72 6E 69 6B 75 73 20 47 6D 62 48 20 26 20 43 6F 2E 20 4B 47 A4 20 13 1E 68 74 74 70 73 3A 2F 2F 74 65 73 74 2E 67 6F 76 65 72 6E 69 6B 75 73 2D 65 69 64 2E 64 65 A5 82 01 51 0C 82 01 4D 41 6E 73 63 68 72 69 66 74 3A 09 0D 0A 47 6F 76 65 72 6E 69 6B 75 73 20 47 6D 62 48 20 26 20 43 6F 2E 20 4B 47 0D 0A 41 6D 20 46 61 6C 6C 74 75 72 6D 20 39 0D 0A 32 38 33 35 39 20 42 72 65 6D 65 6E 09 0D 0A 0D 0A 45 2D 4D 61 69 6C 2D 41 64 72 65 73 73 65 3A 09 68 62 40 62 6F 73 2D 62 72 65 6D 65 6E 2E 64 65 09 0D 0A 0D 0A 5A 77 65 63 6B 20 64 65 73 20 41 75 73 6C 65 73 65 76 6F 72 67 61 6E 67 73 3A 09 0D 0A 44 65 6D 6F 6E 73 74 72 61 74 69 6F 6E 20 64 65 73 20 65 49 44 2D 53 65 72 76 69 63 65 09 0D 0A 0D 0A 5A 75 73 74 C3 A4 6E 64 69 67 65 20 44 61 74 65 6E 73 63 68 75 74 7A 61 75 66 73 69 63 68 74 3A 09 0D 0A 44 69 65 20 4C 61 6E 64 65 73 62 65 61 75 66 74 72 61 67 74 65 20 66 C3 BC 72 20 44 61 74 65 6E 73 63 68 75 74 7A 20 75 6E 64 20 49 6E 66 6F 72 6D 61 74 69 6F 6E 73 66 72 65 69 68 65 69 74 20 64 65 72 20 46 72 65 69 65 6E 20 48 61 6E 73 65 73 74 61 64 74 20 42 72 65 6D 65 6E 0D 0A 41 72 6E 64 74 73 74 72 61 C3 9F 65 20 31 0D 0A 32 37 35 37 30 20 42 72 65 6D 65 72 68 61 76 65 6E A6 4B 13 49 68 74 74 70 73 3A 2F 2F 74 65 73 74 2E 67 6F 76 65 72 6E 69 6B 75 73 2D 65 69 64 2E 64 65 3A 34 34 33 2F 41 75 74 65 6E 74 2D 44 65 6D 6F 41 70 70 6C 69 63 61 74 69 6F 6E 2F 52 65 63 65 69 76 65 72 53 65 72 76 6C 65 74 A7 81 8B 31 81 88 04 20 48 B1 39 72 35 E5 5E D1 63 F3 28 0B 17 0B 69 65 CE 39 03 3D 9B 0A 83 14 83 47 FC 3F F9 DA F0 D3 04 20 8A C4 AF BF 23 6C BB 8D 30 D2 FB EB 0A D9 90 D1 01 E4 EF AA 7B 4D F4 CE 17 05 13 5E 53 0E 99 3F 04 20 D2 E5 4E 1D 26 FC 5D FC 34 08 60 98 31 BB E4 CF E3 20 43 65 60 48 49 E7 B0 94 62 35 66 B5 4A 76 04 20 E2 24 D2 5B 44 8D C0 54 C0 23 39 2C A1 10 17 75 10 41 D7 62 F8 3D 88 08 95 B3 01 8D 8E C2 B2 90 
00000085 RxBuffer 
00000012 winscard.c:1369:SCardControl() UnrefReader() count was: 2
00000012 winscard_svc.c:729:ContextThread() CONTROL rv=0x80100016 for client 16
00002469 winscard_svc.c:359:ContextThread() Received command: CMD_GET_READERS_STATE from client 15
00000166 winscard_svc.c:359:ContextThread() Received command: CMD_GET_READERS_STATE from client 7
00397512 ifdwrapper.c:369:IFDStatusICC() Card not transacted: 612
00000021 eventhandler.c:333:EHStatusHandlerThread() Error communicating to: REINER SCT cyberJack RFID komfort (9334382841) 00 00

[1] http://support.reiner-sct.de/downloads/LINUX/V3.99.5_SP11/pcsc-cyberjack-3.99.5final.SP11.tar.bz2

@misery
Copy link
Author

misery commented Jul 25, 2017

This can be triggered by this (ugly) code snippet:

g++ main.cpp `pkg-config --libs --cflags libpcsclite`

Do not forget to change "reader_name".

#include <iostream>
#include <cstring>
#include <winscard.h>
#include <algorithm>
#include <stdexcept>

std::string hex_to_string(const std::string& input)
{
    static const char* const lut = "0123456789abcdef";
    size_t len = input.length();
    if (len & 1) throw std::invalid_argument("odd length");

    std::string output;
    output.reserve(len / 2);
    for (size_t i = 0; i < len; i += 2)
    {
        char a = input[i];
        const char* p = std::lower_bound(lut, lut + 16, a);
        if (*p != a) throw std::invalid_argument("not a hex digit");

        char b = input[i + 1];
        const char* q = std::lower_bound(lut, lut + 16, b);
        if (*q != b) throw std::invalid_argument("not a hex digit");

        output.push_back(((p - lut) << 4) | (q - lut));
    }
    return output;
}

int main()
{
        typedef SCARDHANDLE PCSC_CARDHANDLE;
        typedef DWORD PCSC_INT;

        std::string dataHex = "02cc0203157f4c12060904007f0007030102025305000513ff0000b202308202ae060a04007f00070301030101a1160c14476f7665726e696b757320546573742044564341a21a1318687474703a2f2f7777772e676f7665726e696b75732e6465a31a0c18476f7665726e696b757320476d6248202620436f2e204b47a420131e68747470733a2f2f746573742e676f7665726e696b75732d6569642e6465a58201510c82014d416e736368726966743a090d0a476f7665726e696b757320476d6248202620436f2e204b470d0a416d2046616c6c7475726d20390d0a3238333539204272656d656e090d0a0d0a452d4d61696c2d416472657373653a09686240626f732d6272656d656e2e6465090d0a0d0a5a7765636b20646573204175736c657365766f7267616e67733a090d0a44656d6f6e7374726174696f6e20646573206549442d53657276696365090d0a0d0a5a757374c3a46e6469676520446174656e73636875747a61756673696368743a090d0a446965204c616e64657362656175667472616774652066c3bc7220446174656e73636875747a20756e6420496e666f726d6174696f6e736672656968656974206465722046726569656e2048616e73657374616474204272656d656e0d0a41726e647473747261c39f6520310d0a3237353730204272656d6572686176656ea64b134968747470733a2f2f746573742e676f7665726e696b75732d6569642e64653a3434332f417574656e742d44656d6f4170706c69636174696f6e2f5265636569766572536572766c6574a7818b318188042048b1397235e55ed163f3280b170b6965ce39033d9b0a83148347fc3ff9daf0d304208ac4afbf236cbb8d30d2fbeb0ad990d101e4efaa7b4df4ce1705135e530e993f0420d2e54e1d26fc5dfc3408609831bbe4cfe3204365604849e7b094623566b54a760420e224d25b448dc054c023392ca11017751041d762f83d880895b3018d8ec2b290";

        std::string data = hex_to_string(dataHex);

        SCARDCONTEXT context;
        std::cout << "establish: " << SCardEstablishContext(SCARD_SCOPE_USER, nullptr, nullptr, &context) << std::endl;

        PCSC_INT protocol;
        PCSC_CARDHANDLE cardHandle;
        PCSC_INT shareMode = SCARD_SHARE_SHARED;
        PCSC_INT preferredProtocols = SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1;

        const char* reader_name = "REINER SCT cyberJack RFID komfort (9334382841) 00 00";
        std::cout << "connect: " << SCardConnect(context, reader_name, shareMode, preferredProtocols, &cardHandle, &protocol) << std::endl;
        std::cout << "transaction: " << SCardBeginTransaction(cardHandle) << std::endl;

        const SCARD_IO_REQUEST* sendPci = SCARD_PCI_T1;
        SCARD_IO_REQUEST recvPci;
        recvPci.dwProtocol = protocol;
        recvPci.cbPciLength = sizeof(SCARD_IO_REQUEST);

        char buffer[4096];

        PCSC_INT cntrCode = 1107299788;
        PCSC_INT len;
        std::cout << "control: " << SCardControl(cardHandle,
                        cntrCode,
                        data.data(),
                        data.size(),
                        buffer,
                        sizeof(buffer),
                        &len) << std::endl;

        return 0;
}

@LudovicRousseau
Copy link
Owner

Why do you think the problem is with pcsc-lite and not with the pcsc-cyberjack driver that cannot handle large buffers?

@misery
Copy link
Author

misery commented Jul 28, 2017

I think the pcsc-cyberjack is the problem. ;-)
I already mailed with Frank Neuber. He asked me to open an issue here... hopefully he and ReinerSCT will fix the problem.

@LudovicRousseau
Copy link
Owner

Thanks. Closing the issue.

@misery
Copy link
Author

misery commented May 11, 2018

By the way... SP13 will fix this problem internally.

http://support.reiner-sct.de/downloads/LINUX/V3.99.5_SP13/pcsc-cyberjack_3.99.5final.SP13.tar.gz

oleid pushed a commit to oleid/pcsc-cyberjack that referenced this issue May 19, 2018
Add patch from

https://forum.reiner-sct.com/index.php?/topic/3728-failed_to_transmit_control_command_to_the_terminal

to PKGBUILD.

Background:

PCSC v1.8.21 and higher break pcsc-cyberjack driver:

LudovicRousseau/PCSC#22

There is no official driver, which gets it working, however,
an unofficial patch is available and it seems to work fine.
oleid pushed a commit to oleid/pcsc-cyberjack that referenced this issue May 19, 2018
Add patch from

https://forum.reiner-sct.com/index.php?/topic/3728-failed_to_transmit_control_command_to_the_terminal

to PKGBUILD.

Background:

PCSC v1.8.21 and higher break pcsc-cyberjack driver:

LudovicRousseau/PCSC#22

There is no official driver, which gets it working, however,
an unofficial patch is available and it seems to work fine.
thorstenb pushed a commit to thorstenb/pcsc-cyberjack that referenced this issue Jun 19, 2018
Add patch from
 https://forum.reiner-sct.com/index.php?/topic/3728-failed_to_transmit_control_command_to_the_terminal

Background:

PCSC v1.8.21 and higher break pcsc-cyberjack driver:
 LudovicRousseau/PCSC#22

There is no official driver, which gets it working, however,
this unofficial patch is available and it seems to work fine.
@qxlsz
Copy link

qxlsz commented Jul 25, 2018

I have the same issue now in pcscd daemon though. It powers and unpowers itself

@LudovicRousseau
Copy link
Owner

@qxlsz please open a new issue with complete details.
https://pcsclite.apdu.fr/#support

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants