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

Catch and abort illegal parallel PC/SC requests early #136

Open
emaxx-google opened this issue Jul 3, 2020 · 0 comments
Open

Catch and abort illegal parallel PC/SC requests early #136

emaxx-google opened this issue Jul 3, 2020 · 0 comments

Comments

@emaxx-google
Copy link
Collaborator

The PC/SC API requires that every thread of the application uses its own context:

Each thread of an application shall use its own SCARDCONTEXT, unless calling SCardCancel(), which MUST be called with the same context as the context used to call SCardGetStatusChange().

(https://pcsclite.apdu.fr/api/group__API.html#gaa1b8970169fd4883a6dc4a8f43f19b67)

Our implementation in the Smart Card Connector app retains this requirement. However, it's not currently enforced by the client-side libraries that we provide (neither JS nor C++ ones), which means that it can be violated without the developer being notified about that.

Practically, violating this requirement - e.g., sending a new PC/SC call before the previous one with the same hContext finished - can cause bad effects, like the calls being hung. Also - although not confirmed yet - it might lead to the hang of the Smart Card Connector app.

The proposal is to add debug assertions into our C++ and/or JS libraries that would catch these kinds of violations. Perhaps, crashing the caller is the only reasonable and effective measure in that case (note that typical clients would automatically restart after the crash, which hopefully will recover the state and let the user continue using the smart card).

As a stretch goal, we might want to investigate whether/why the Smart Card Connector app hangs for all clients in this scenario, and when that's the case try to fix that behavior.

emaxx-google added a commit that referenced this issue Dec 8, 2022
Add warning logs into Smart Card Connector whenever a client
application emits illegal concurrent PC/SC requests: an
SCARDCONTEXT must only be used from a single thread (with the
only exception of SCardCancel that can be called concurrently).

This is preparation for disallowing concurrent PC/SC calls in the
future as planned in #136. Concurrent calls are not allowed by the
PC/SC API specification, and the PC/SC-Lite's implementation
breaks in subtle ways when this is violated.
emaxx-google added a commit that referenced this issue Dec 8, 2022
Add warning logs into Smart Card Connector whenever a client
application emits illegal concurrent PC/SC requests: an
SCARDCONTEXT must only be used from a single thread (with the
only exception of SCardCancel that can be called concurrently).

This is preparation for disallowing concurrent PC/SC calls in the
future as planned in #136. Concurrent calls are not allowed by the
PC/SC API specification, and the PC/SC-Lite's implementation
breaks in subtle ways when this is violated.
emaxx-google added a commit that referenced this issue Dec 8, 2022
Add warning logs into Smart Card Connector whenever a client
application emits illegal concurrent PC/SC requests: an
SCARDCONTEXT must only be used from a single thread (with the
only exception of SCardCancel that can be called concurrently).

This is preparation for disallowing concurrent PC/SC calls in the
future as planned in #136. Concurrent calls are not allowed by the
PC/SC API specification, and the PC/SC-Lite's implementation
breaks in subtle ways when this is violated.
emaxx-google added a commit that referenced this issue Dec 9, 2022
Add warning logs into Smart Card Connector whenever a client
application emits illegal concurrent PC/SC requests: an
SCARDCONTEXT must only be used from a single thread (with the
only exception of SCardCancel that can be called concurrently).

This is preparation for disallowing concurrent PC/SC calls in the
future as planned in #136. Concurrent calls are not allowed by the
PC/SC API specification, and the PC/SC-Lite's implementation
breaks in subtle ways when this is violated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant