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

vicc cannot connect to vpcd in 5a6b330b154a6b6b3ad30c4b69fae83a031d0f36 #204

Closed
eriknellessen opened this issue Aug 13, 2021 · 7 comments · Fixed by #206
Closed

vicc cannot connect to vpcd in 5a6b330b154a6b6b3ad30c4b69fae83a031d0f36 #204

eriknellessen opened this issue Aug 13, 2021 · 7 comments · Fixed by #206

Comments

@eriknellessen
Copy link
Contributor

eriknellessen commented Aug 13, 2021

Expected behaviour

What should happen?

vicc should connect to vpcd. This works for me when using commit 4658f86.

Actual behaviour

What happens instead?

The connection times out. I can see that vpcd is listening on the correct ports using netstat -tulpn. I can also see that vicc sends TCP SYN packets using tshark. But I cannot see that vpcd is answering these SYN packets.

Steps to reproduce

  1. Build vsmartcard at commit 5a6b330, start pcscd
  2. Run vicc, cancel with CTRL+C
  3. Run vicc again
  4. Wait for the error message

Logs

13.08.2021 14:21:05  [WARNING] Using default SAM parameters. PIN=1234, Card Nr=1234567890
13.08.2021 14:23:16  [ERROR] Failed to open socket: [Errno 110] Connection timed out
13.08.2021 14:23:16  [ERROR] Is pcscd running at localhost? Is vpcd loaded? Is a                               firewall blocking port 35963?```
@eriknellessen
Copy link
Contributor Author

Following the hint "New in version 0.7: The Virtual Smart Card optionally brings its own standalone implementation of PC/SC. This allows accessing vpicc without PCSC-Lite. Our PC/SC implementation acts as replacement for libpcsclite which can lead to problems when used in parallel with PCSC-Lite.":
Looks like this problem only arises when you have pcscd already installed before installing virtualsmartcard. If I do not have it installed before, it works with 5a6b330 just as good as with 4658f86.

@eriknellessen
Copy link
Contributor Author

Actually I saw the described behavior in the mentioned commit again when I tried to connect more than once. So I updated the description of this issue and I reopen the issue again.

@eriknellessen eriknellessen reopened this Aug 13, 2021
@frankmorgner
Copy link
Owner

please try python3 vicc

@frankmorgner
Copy link
Owner

It looks like 5a6b330 needs to be reverted as well...

@dengert
Copy link

dengert commented Aug 21, 2021

looks like pfd is not initialized correctly.

Possible (untested) fix.  if someone to try this please submit the PR:

diff --git a/virtualsmartcard/src/vpcd/vpcd.c b/virtualsmartcard/src/vpcd/vpcd.c
index 8d3be0d..ee9e981 100644
--- a/virtualsmartcard/src/vpcd/vpcd.c
+++ b/virtualsmartcard/src/vpcd/vpcd.c
@@ -197,8 +197,10 @@ SOCKET waitforclient(SOCKET server, long secs, long usecs)
     struct pollfd pfd;
 
     pfd.fd = server;
+    pfd.events = POLLIN;
+    pfd.revents = 0;
 
-    timeout = (secs * 1000000 + usecs / 1000);
+    timeout = (secs * 1000 + usecs / 1000);
 
     if (poll(&pfd, 1, timeout) == -1)
         return INVALID_SOCKET;

The timeout argument specifies the number of milliseconds, but looks like is secs and usecs are always zero in this code.

@Jakuje
Copy link
Contributor

Jakuje commented Aug 23, 2021

You are right. Tested with above changes in container and all stuff works as expected. Testing again with master shows us our known issue no-readers.

@frankmorgner
Copy link
Owner

thanks for helping to everyone!

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

Successfully merging a pull request may close this issue.

4 participants