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

Problem with label formatting in C_GetTokenInfo / opensc 0.20.0 #1922

Closed
pboguslawski opened this issue Jan 30, 2020 · 5 comments · Fixed by #1926
Closed

Problem with label formatting in C_GetTokenInfo / opensc 0.20.0 #1922

pboguslawski opened this issue Jan 30, 2020 · 5 comments · Fixed by #1926

Comments

@pboguslawski
Copy link
Contributor

Hello,

There seems to be a problem with label formatting in C_GetTokenInfo in opensc 0.20.0 (compiled in debian 10 from sources https://github.com/OpenSC/OpenSC/releases):

$ PKCS11SPY=/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so PKCS11SPY_OUTPUT=logfile pkcs11-tool -T --module /usr/lib/x86_64-linux-gnu/pkcs11-spy.so

$ cat logfile 
[...]
5: C_GetTokenInfo
2020-01-30 12:55:30.442
[in] slotID = 0x0
[out] pInfo: 
      label:                  '               IBHS001 (UserPIN)'
      manufacturerID:         'www.CardContact.de              '
[...]

original opensc 0.19.0-1 from dpkg in debian 10 returns:

$ PKCS11SPY=/usr/lib/x86_64-linux-gnu/opensc-pkcs11.so PKCS11SPY_OUTPUT=logfile pkcs11-tool -T --module /usr/lib/x86_64-linux-gnu/pkcs11-spy.so

user@d10:~/tmp$ cat logfile 
[...]
5: C_GetTokenInfo
2020-01-30 13:13:10.851
[in] slotID = 0x0
[out] pInfo: 
      label:                  'UserPIN (IBHS001)               '
      manufacturerID:         'www.CardContact.de              '
[...]

This breaks apps like

(*) https://github.com/miekg/pkcs11/blob/master/pkcs11.go#L866

that seems to expect label to be formatted according to

http://docs.oasis-open.org/pkcs11/pkcs11-base/v2.40/os/pkcs11-base-v2.40-os.html

label application-defined label, assigned during token initialization. MUST be padded with the blank character (‘ ‘). MUST NOT be null-terminated.

Debug show, that app (*) reads label as "IBHS001 (UserPIN)<here 15x zero byte>"

Problems:

(1)

Seems that label returned by C_GetTokenInfo from opensc 0.20.0 does not contain padding with spaces - it just ends after last letter. No such problem in manufacturerID field.

(2)

Order of label/pin in final label returned by C_GetTokenInfo is different in 0.19.0 and 0.20.0:

IBHS001 (UserPIN) != UserPIN (IBHS001)

Is it intentional (may require config changes after upgrade to 0.20.0 if one uses label as parameter).

Regards,
Paweł

@pboguslawski pboguslawski changed the title Problem with label padding in 0.20.0 Problem with label formatiing in C_GetTokenInfo / opensc 0.20.0 Jan 30, 2020
@pboguslawski pboguslawski changed the title Problem with label formatiing in C_GetTokenInfo / opensc 0.20.0 Problem with label formatting in C_GetTokenInfo / opensc 0.20.0 Jan 30, 2020
@frankmorgner
Copy link
Member

Duplicate of #1901

Sorry for the inconvenience.

@frankmorgner
Copy link
Member

I may have closed this too quickly.

Do I read correctly, that your label is padded with spaces in the front?!

@pboguslawski
Copy link
Contributor Author

pboguslawski commented Jan 31, 2020

Thank you for checking #1901 - this explains (2) but (1) still needs attention.

Do I read correctly, that your label is padded with spaces in the front?!

Seems spaces added in the front of "IBHS001 (UserPIN)" in pkcs11-tool -T output in 0.20.0 like above are caused by fprintf (%32.32s) used in pkcs11-display.c for displaying label...

https://github.com/OpenSC/OpenSC/blob/master/src/pkcs11/pkcs11-display.c#L928

...and are not part of label - displaying label works here ok.

Label value returned by C_GetTokenInfo seems to be "IBHS001 (UserPIN)" but should be "IBHS001 (UserPIN)<15x space here>" (see oasis info above).

After fixing 0.20.0, pkcs11-tool -T command should NOT probably display

label:                  '               IBHS001 (UserPIN)'

but

label:                  'IBHS001 (UserPIN)               '

@frankmorgner
Copy link
Member

please check if #1926 fixes the padding

@pboguslawski
Copy link
Contributor Author

Just compiled 0.20.0 with fix #1926 applied (Debian 10) and now label works ok. Thank you!

Regards,
Paweł

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.

2 participants