~ireas/nitrokey-rs

ref: db48656015d958594b4818582439f7515359cd60 nitrokey-rs/tests/device.rs -rw-r--r-- 22.2 KiB
Refactor PWS slot access

Previously, the PasswordSafe::get_slot_{name,login,password} methods
would return a SlotNotProgrammed error if the libnitrokey functions
return an empty string.  This was because libnitrokey does not return an
error code when accessing an unprogrammed slot.  But this was ambigous
as the slot values might actually be empty.

With this patch, we deprecate the existing methods for accessing the
slot data.  Instead, we introduce the PasswordSlot struct that can be
used to access the (empty or non-empty) values of programmed slots.
Instances of this struct can be obtained using the get_slots (all
programmed slots), get_slot (one slot that is checked to be programmed)
and get_slot_unchecked (one slot without checking whether it is
programmed) methods.

See this discussion for more information:
	https://github.com/d-e-s-o/nitrocli/issues/133
Fix serial number check in device tests

The serial numuer check in the device tests are different for Storage
devices because the Nitrokey Storage currently does not report its
serial number in the status.  Our previous implementation matched the
model to determine how to check the serial number.  This no longer works
as we marked the model as non-exhaustive and was unnecessary.  This
patch changes the test logic to perform the serial number test for all
devices except the Nitrokey Storage.
Represent serial numbers using SerialNumber struct

In a previous commit, we changed the serial number representation from a
string to an integer.  This made it easier to compare serial numbers,
but also introduced new problems:
- Serial numbers should be formatted consistently, for example as
  "{:#010x}".  It is hard to ensure this for an integer value.
- The format of the serial number may be subject to change.  Users
  should not rely too much on the u32 representation.

Therefore we introduce a new SerialNumber struct that represents a
serial number.  Currently it only stores a u32 value.  The following
traits and functions can be used to access its value:
- FromStr for string parsing
- ToString/Display for string formatting
- as_u32 to access the underlying integer value
Always store serial numbers as integers

This patch consistently uses u32 integers to store and return the serial
number of a Nitrokey device.  This makes it easier to convert and
compare the serial number, as it is a unique representation and as
formatting an integer cannot fail.  For more details, see this RFC:
	https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20200126074816.GA1314%40ireas.org%3E
Merge branch 'release-0.5.0'
Add the fill_sd_card function to Storage

This patch adds support for libnitrokey’s
NK_fill_SD_card_with_random_data function.  It is executed by the
fill_sd_card function of the Storage struct.  We also add a new test
case that is set to ignore because it takes between 30 and 60 minutes to
run.
Add the get_operation_status function to the Storage struct

This patch adds support for the NK_get_progress_bar_value function:  It
adds the OperationStatus enum that stores the return value of this
command and adds the get_operation_status function to the Storage struct
that executes the command.
Add the get_sd_card_usage function to the Storage struct

This patch adds support for the NK_get_SD_usage_data function.  It
returns a range of the SD card that has not been accessed during this
power cycle.
Rename Status::get_status to get_storage_status

In the last patch, we added the get_status function to the Device trait.
This patch renames the Storage::get_status function to
get_storage_status to resolve the name clash – though allowed by the
compiler, it is rather confusing for the end user.
Add support for the GET_STATUS command

This patch adds support for the GET_STATUS command that returns the
status information common to all Nitrokey devices.  It can be accessed
using the Device::get_status function and is stored in a Status struct.

Due to a bug in the Storage firmware [0], the GET_STATUS command returns
wrong firmware versions and serial numbers.  Until this is fixed in
libnitrokey [1], we have to manually execute the GET_DEVICE_STATUS
command to fix these values for the Nitrokey Storage.

Also, this leads to a name clash with the existing Storage::get_status
function, which will be renamed in an upcoming patch.

[0] https://github.com/Nitrokey/nitrokey-storage-firmware/issues/96
[1] https://github.com/Nitrokey/libnitrokey/issues/166
Merge branch 'connect_path' into next

This patch series adds the list_devices function that returns a list of
available Nitrokey devices and the Manager::connect_path function that
connects to one of the available devices.
Add the connect_path function to the Manager struct

This patch adds the connect_path function to the Manager struct that
uses NK_connect_with_path to connect to a Nitrokey device at a given USB
path.
Add list_devices function

This patch adds support for libnitrokey’s NK_list_devices function by
introducing the top-level list_devices function.  It returns a vector of
DeviceInfo structs with information about all connected Nitrokey
devices.
Merge branch 'release-0.4.0'
Check retry count before building AES key in test

Due to a timing issue, some calls to the build_aes_key function may fail
after a factory reset.  As a workaround for this firmware bug, we check
the user retry count before building the aes key in the factory_reset
test.  For details, see the upstream issue:
	https://github.com/Nitrokey/nitrokey-pro-firmware/issues/57
Use into_manager in device connection tests

To avoid a ConcurrentAccessError, we have to use the
Device::into_manager function instead of calling take to obtain a
Manager instance.
Merge branch 'connection-manager-mut' into next

Refactor the connection management to prevent multiple device
connections at the same time.

RFC: https://lists.sr.ht/~ireas/nitrokey-rs-dev/%3C20190126174327.tbuyk2s535kfiqm4%40localhost%3E
Use Manager in device connection tests

The previous patches refactored the connection handling to use the
Manager struct.  This patch changes the tests to use the new Manager
methods instead of the deprecated functions.
Introduce into_manager for Device

To enable applications like nitrokey-test to go back to a manager
instance from a Device instance, we add the into_manager function to the
Device trait.  To do that, we have to keep track of the Manager’s
lifetime by adding a lifetime to Device (and then to some other traits
that use Device).
Move {Pro, Storage}::connect into Manager

As part of the connection refactoring, this patch moves the connect
methods of the Pro and Storage structs into the Manager struct.  To
maintain compatibility with nitrokey-test, the old methods are not
removed but marked as deprecated.
Next