Unable to reset PIV on v1.7.2-test.20240813

As stated in v1.7.2-test.20241022 release notes, I have to reset the PIV application before trying to upgrade to it or any later version. I am currently on v1.7.2-test.20240813.

Using pynitrokey 0.7.3, I have tried the following (output slightly shortened):

$ nitropy nk3 status

UUID: REDACTED
Firmware version: v1.7.2-test.20240813
Init status: ok
Free blocks (int): 11
Free blocks (ext): 460
Variant: LPC55

$ nitropy nk3 factory-reset-app piv

Please touch the device to confirm the operation
Critical error:
An unhandled exception occurred
Exception encountered: Exception(‘Failed to factory reset the application: The application does not support factory reset through nitropy’)

$ nitropy nk3 piv --experimental factory-reset

Critical error:
An unhandled exception occurred
Exception encountered: StatusError(27013)

$ opensc-tool -s 00:A4:04:00:0B:A000000308000010000100 -s 00:20:00:80:08:FFFFFFFFFFFFFFFF -s 00:20:00:80:08:FFFFFFFFFFFFFFFF -s 00:20:00:80:08:FFFFFFFFFFFFFFFF -s 00:FB:00:00

Using reader with a card: Nitrokey Nitrokey 3 [CCID/ICCD Interface] 00 00
Sending: 00 A4 04 00 0B A0 00 00 03 08 00 00 10 00 01 00
Received (SW1=0x90, SW2=0x00)
Sending: 00 20 00 80 08 FF FF FF FF FF FF FF FF
Received (SW1=0x6A, SW2=0x80)
Sending: 00 20 00 80 08 FF FF FF FF FF FF FF FF
Received (SW1=0x6A, SW2=0x80)
Sending: 00 20 00 80 08 FF FF FF FF FF FF FF FF
Received (SW1=0x6A, SW2=0x80)
Sending: 00 FB 00 00
Received (SW1=0x69, SW2=0x85)

One update to 1.7.2-test.20241022 later:

$ nitropy nk3 piv --experimental info

Critical error:
An unhandled exception occurred
Exception encountered: StatusError(25856)

Reverting to v1.7.2-test.20240813 did not change a thing, so did downgrading to v1.7.2-test.20240625.


Logs have sensitive data redacted.

StatusError(27013)
430        INFO pynitrokey.cli Python version: 3.13.2
430        INFO pynitrokey.cli Cli arguments: ['nk3', 'piv', '--experimental', 'factory-reset']
432        INFO pynitrokey.cli pynitrokey version: 0.7.3
433        INFO pynitrokey.cli cryptography version: 44.0.1
433        INFO pynitrokey.cli ecdsa version: 0.19.0
434        INFO pynitrokey.cli fido2 version: 1.2.0
434        INFO pynitrokey.cli pyusb version: 1.3.1
455        INFO     pivapp Sending 251 '00fb0000'
462        INFO     pivapp Received [6985] 
462      WARNING pynitrokey.cli An unhandled exception occurred
Traceback (most recent call last):
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/__init__.py", line 137, in main
    nitropy()
    ~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/nk3/piv.py", line 289, in factory_reset
    device.factory_reset()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 289, in factory_reset
    self.send_receive(0xFB, 0, 0)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 107, in send_receive
    return self._send_receive_inner(bytes_data, log_info=f"{ins}")
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 151, in _send_receive_inner
    raise StatusError(int.from_bytes(status_bytes, byteorder="big"))
pynitrokey.nk3.piv_app.StatusError: 0x6985
465       DEBUG       root print: Critical error:
465       DEBUG       root print: An unhandled exception occurred
465       ERROR       root 0x6985
Traceback (most recent call last):
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/__init__.py", line 137, in main
    nitropy()
    ~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/nk3/piv.py", line 289, in factory_reset
    device.factory_reset()
    ~~~~~~~~~~~~~~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 289, in factory_reset
    self.send_receive(0xFB, 0, 0)
    ~~~~~~~~~~~~~~~~~^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 107, in send_receive
    return self._send_receive_inner(bytes_data, log_info=f"{ins}")
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 151, in _send_receive_inner
    raise StatusError(int.from_bytes(status_bytes, byteorder="big"))
pynitrokey.nk3.piv_app.StatusError: 0x6985
468       DEBUG       root listing all connected devices:
584       DEBUG       root :: 'Nitrokey FIDO2' keys
584       DEBUG       root :: 'Nitrokey Start' keys:
597       DEBUG       root :: 'NK3' keys
616       DEBUG       root /dev/hidraw0: Nitrokey 3 ** REDACTED **
616       DEBUG       root :: 'NKPK' keys
StatusError(25856)
451        INFO pynitrokey.cli Python version: 3.13.2
451        INFO pynitrokey.cli Cli arguments: ['nk3', 'piv', '--experimental', 'info']
453        INFO pynitrokey.cli pynitrokey version: 0.7.3
454        INFO pynitrokey.cli cryptography version: 44.0.1
455        INFO pynitrokey.cli ecdsa version: 0.19.0
455        INFO pynitrokey.cli fido2 version: 1.2.0
456        INFO pynitrokey.cli pyusb version: 1.3.1
482        INFO     pivapp Sending 1 '00010000'
484        INFO     pivapp Received [6104] 
485        INFO     pivapp Received [9000] **DEVICE NUMBER REDACTED**
485        INFO     pivapp Received final data: [9000] '**DEVICE NUMBER REDACTED**'
485        INFO     pivapp Decoded received: **DEVICE NUMBER REDACTED**
485       DEBUG       root print: Device: **DEVICE NUMBER REDACTED**
485       DEBUG       root print: Reader: Nitrokey Nitrokey 3 [CCID/ICCD Interface] 00 00
485        INFO     pivapp Sending 203 '00cb3fff055c035fc102'
567        INFO     pivapp Received [6500] 
567      WARNING pynitrokey.cli An unhandled exception occurred
Traceback (most recent call last):
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/__init__.py", line 137, in main
    nitropy()
    ~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/nk3/piv.py", line 180, in info
    guid = device.guid()
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 365, in guid
    chuid = self.send_receive(0xCB, 0x3F, 0xFF, payload)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 107, in send_receive
    return self._send_receive_inner(bytes_data, log_info=f"{ins}")
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 151, in _send_receive_inner
    raise StatusError(int.from_bytes(status_bytes, byteorder="big"))
pynitrokey.nk3.piv_app.StatusError: 0x6500
570       DEBUG       root print: Critical error:
570       DEBUG       root print: An unhandled exception occurred
570       ERROR       root 0x6500
Traceback (most recent call last):
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/__init__.py", line 137, in main
    nitropy()
    ~~~~~~~^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1161, in __call__
    return self.main(*args, **kwargs)
           ~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1082, in main
    rv = self.invoke(ctx)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1697, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 1443, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/click/core.py", line 788, in invoke
    return __callback(*args, **kwargs)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/cli/nk3/piv.py", line 180, in info
    guid = device.guid()
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 365, in guid
    chuid = self.send_receive(0xCB, 0x3F, 0xFF, payload)
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 107, in send_receive
    return self._send_receive_inner(bytes_data, log_info=f"{ins}")
           ~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.local/share/pipx/venvs/pynitrokey/lib/python3.13/site-packages/pynitrokey/nk3/piv_app.py", line 151, in _send_receive_inner
    raise StatusError(int.from_bytes(status_bytes, byteorder="big"))
pynitrokey.nk3.piv_app.StatusError: 0x6500
572       DEBUG       root listing all connected devices:
689       DEBUG       root :: 'Nitrokey FIDO2' keys
689       DEBUG       root :: 'Nitrokey Start' keys:
702       DEBUG       root :: 'NK3' keys
721       DEBUG       root /dev/hidraw1: Nitrokey 3 ** REDACTED **
721       DEBUG       root :: 'NKPK' keys

It looks like the state is corrupted. You should be able to update to 1.8.1 and factory reset from there. In 1.8.0 fixes the issue you are encountering.

Factory reset the PIV app, or the whole device?

i think only the piv app. Try doing that after updating your key.

1 Like

The PIV app with nitropy nk3 piv --experimental factory-reset or the OpenSC command.