How to reset a smartcard ?

Werner Koch wk at gnupg.org
Fri Sep 25 11:48:36 CEST 2009


On Fri, 25 Sep 2009 10:33, tux.tsndcb at free.fr said:

> No body has an idea to "reset" a smartcard as factory settings ? I think it is possible, but I don't know how to do that.

If you have a version 2 card, this is possible.

WARNING: Don't run the commands given below on version 1 cards - you
will brick the card.

1. First you have to lock the PIN by decremeting the retry counters.  I
   do it this way:

  $ gpg-connect-agent --hex
  > scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
  D[0000]  69 82                                              i.              
  OK
  > scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
  D[0000]  69 82                                              i.              
  OK
  > scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
  D[0000]  69 82                                              i.              
  OK
  > scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
  D[0000]  69 83                                              i.   
  > scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
  D[0000]  69 82                                              i.              
  OK
  > scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
  D[0000]  69 82                                              i.              
  OK
  > scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
  D[0000]  69 83                                              i.   


The status code 6983 says that the PIN is locked.  I use a PIN of
"@@@@@@@@" which is very likey invalid.

2. You terminate the card and activate it again:

  >  scd apdu 00 e6 00 00
  D[0000]  90 00                                              ..              
  OK
  >  scd apdu 00 44 00 00
  D[0000]  90 00                                              ..              
  OK
  > bye
  OK closing connection
  >   

Remove the card and insert it again.  That's all.  gpg --card-status
shows a fresh card. 

To make things easier you may send the lines below as input to
gpg-connect-agent (store them in a file and run "gpg-connect-agent < FILE").

======
/hex
scd serialno
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 81 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 20 00 83 08 40 40 40 40 40 40 40 40
scd apdu 00 e6 00 00
scd apdu 00 44 00 00
/echo card has been reset to factory defaults
=====

gpg-connect-agent has a complete scripting language, you may use it to
write a more robust script with error checking etc.


Salam-Shalom,

   Werner


-- 
Die Gedanken sind frei.  Auschnahme regelt ein Bundeschgesetz.




More information about the Gnupg-users mailing list