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

Given an SO-PIN, how do you change the PIN? #2867

Closed
minfrin opened this issue Sep 20, 2023 · 4 comments · Fixed by #2983
Closed

Given an SO-PIN, how do you change the PIN? #2867

minfrin opened this issue Sep 20, 2023 · 4 comments · Fixed by #2983

Comments

@minfrin
Copy link

minfrin commented Sep 20, 2023

Problem Description

I have a smartcard where the PIN and PUK have been lost. I have the SO-PIN, and would like to re-set the PIN. There does not seem to be a way to do this.

Steps to reproduce

Test is good:

blackadder ~ # pkcs11-tool --login-type so --login --test
Using slot 0 with a present token (0x0)
Logging in to "xxx (Smartcard PIN)".
Please enter SO PIN: 
C_SeedRandom() and C_GenerateRandom():
  seeding (C_SeedRandom) not supported
  seems to be OK
Digests:
  all 4 digest functions seem to work
  MD5: OK
  SHA-1: OK
  RIPEMD160: OK
Signature: not a R/W session, skipping signature tests
Verify: not a R/W session, skipping verify tests
Decryption: not a R/W session, skipping decryption tests
No errors

Change PIN is no good, asks for the existing PIN:

blackadder ~ # pkcs11-tool --login-type so --login --change-pin
Using slot 0 with a present token (0x0)
Logging in to "xxx (Smartcard PIN)".
Please enter SO PIN: 
Please enter the current PIN: 
^C

Init PIN no good, fails complaining about the PIN length (with no way to indicate which PIN, I'm assuming this might be trying to change the SO PIN, which I do not want to do):

blackadder ~ # pkcs11-tool --login-type so --login --init-pin
Using slot 0 with a present token (0x0)
Logging in to "xxx (Smartcard PIN)".
Please enter SO PIN: 
Please enter the new PIN: 
Please enter the new PIN again: 
error: PKCS11 function C_InitPIN failed: rv = CKR_PIN_LEN_RANGE (0xa2)
Aborting.

The pkcs15-tool also appears to not work, we try change the PIN, and the SO-PIN is being changed (no):

blackadder ~ # pkcs15-tool --change-pin
Using reader with a card: ACS ACR39U ICC Reader 00 00
Enter old PIN [Security Officer PIN]: 
^C

Try change the PIN by specifying the auth-id, we're asked for the old PIN we don't have:

blackadder ~ # pkcs15-tool --auth-id 01 --change-pin
Using reader with a card: ACS ACR39U ICC Reader 00 00
Enter old PIN [Smartcard PIN]: 
^C

Is this even possible?

@Jakuje
Copy link
Member

Jakuje commented Sep 21, 2023

This will likely depend on the card type. The SO-pin is usually part of the card management, which is out of scope of pkcs11 (or is not implemented in the drivers).

Again, depending on the card, the SO pin can be either used to change the PIN or reset the card or neither of these.

@CardContact
Copy link
Member

On the SmartCard-HSM you can change the SO-PIN using

pkcs11-tool --login --login-type so --so-pin ${SOPIN} --change-pin --new-pin ${SOPIN2}

@popovec
Copy link
Member

popovec commented Sep 21, 2023

MyEID card, the above procedure also works

pkcs11-tool --login --login-type so --so-pin ${SOPIN} --change-pin --new-pin ${SOPIN2}

but the question concerns something else, how to use SO-PIN to reset the user PIN.

MyEID supports the so-called global unblocker and global admin flags, which must be assigned for a specific PIN during card initialization. Currently, OpenSC /MyEID driver - src/pkcs15init/pkcs15-myeid.c/, sets the flags during SO-PIN initialization so that not a single PIN has support for global unblocker or admin status. Therefore, if the user PIN is lost, it is not possible to unblock it via SO-PIN.

@CardContact
Copy link
Member

Yes, you are right, the question was different. Resetting the user PIN is:

pkcs11-tool --login --login-type so --so-pin ${SOPIN} --init-pin --new-pin ${PIN}

In the SmartCard-HSM you need to have set the "User PIN reset with SO-PIN enabled" option set during initialization. That is the default when using sc-hsm-tool and can be selected when using the Smart Card Shell.

frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 12, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 16, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Jan 30, 2024
frankmorgner added a commit to frankmorgner/OpenSC that referenced this issue Feb 13, 2024
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