| Commit message (Collapse) | Author | Age |
|
|
|
|
|
| |
A nitrokey_sys::NK_device_model (= u32) value may correspond to a
nitrokey::Model, and vice versa. This patch adds the appropriate From
and TryFrom implementations.
|
|
|
|
|
|
| |
Since Rust 1.34.0, we no longer need a `fn main` comment in doc tests
that return results. It is sufficient to have an `Ok` return value with
type annotations.
|
|
|
|
|
|
|
|
|
| |
The take and take_blocking functions return a PoisonError if the cache
is poisoned, i. e. if a thread panicked while holding the manager. This
is a sensible default behaviour, but for example during testing, one
might want to ignore the poisoned cache. This patch adds the force_take
function that unwraps the PoisonError and returns the cached Manager
even if the cache was poisoned.
|
|
|
|
|
|
| |
During the connection manager refactoring, we temporarily used
deprecated methods. This is no longer the case, so we can remove the
allow(deprecated) attribute.
|
|
|
|
|
|
| |
This patch updates the documentation to reflect the latest changes to
connection handling. It also updates the doc tests to prefer the new
methods over the old ones.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the last patches, we ensured that devices can only be obtained using
the Manager struct. But we did not ensure that there is only one device
at a time. This patch adds a mutable reference to the Manager instance
to the Device implementations. The borrow checker makes sure that there
is only one mutable reference at a time.
In this patch, we have to remove the old connect, Pro::connect and
Storage::connect functions as they do no longer compile. (They discard
the MutexGuard which invalidates the reference to the Manager.)
Therefore the tests do no longer compile.
|
|
|
|
|
|
|
| |
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.
|
|
|
|
|
|
| |
As part of the connection refactoring, this patch moves the
connect_model function to the Manager struct. As the connect_model
function is not used by nitrokey-test, it is removed.
|
|
|
|
|
|
|
| |
As part of the connection refactoring, we replace the connect function
with the Manager::connect method. To maintain compatibility with
nitrokey-test, the connect function is not removed but marked as
deprecated.
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
As part of the connection refactoring, we introduce the Manager struct
that deals with connection management. To make sure there can be only
once instance of the manager, we add a global static Mutex that holds
the single Manager instance. We use the struct to ensure that the user
can only connect to one device at a time.
This also changes the Error::PoisonError variant to store the
sync::PoisonError. This allows the user to call into_inner on the
PoisonError to retrieve the MutexGuard and to ignore the error (for
example useful during testing).
|
|
|
|
| |
This reverts commit 0972bbe82623c3d9649b6023d8f50d304aa0cde6.
|
|
|
|
|
|
|
|
|
|
|
|
| |
In the initial nitrokey-rs implementation, the Admin and the User struct
take the Device by value to make sure that the user cannot initiate a
second authentication while this first is still active (which would
invalidate the temporary password). Now we realized that this is not
necessary – taking a mutable reference has the same effect, but leads to
a much cleaner API.
This patch refactors the Admin and User structs – and all dependent code
– to use a mutable reference instead of a Device value.
|
|
|
|
|
|
|
|
|
|
|
|
| |
Previously, all methods that access a Nitrokey device took a reference
to the device as input. This method changes methods that change the
device state to require a mutable reference instead. In most case,
this is straightforward as the method writes data to the device (for
example write_config or change_user_pin). But there are two edge cases:
- Authenticating with a PIN changes the device state as it may decrease
the PIN retry counter if the authentication fails.
- Generating an HOTP code changes the device state as it increases the
HOTP counter.
|
| |
|
|
|
|
|
| |
The DEFAULT_{ADMIN,USER}_PIN constants implicitly have static lifetime.
Therefore we can remove the static lifetime modifiers.
|
|
|
|
|
|
|
|
|
| |
Many of our functions do not return a Result<_, Error>, but for example
a Result<_, (Device, Error)>. We only use the typedef in one function,
but it makes the other functions more complicated as we have to use
result::Result (if crate::Result is imported). Therefore, this patch
removes the typedef. Applications or libraries can still redefine it if
they want to.
|
|
|
|
|
|
|
| |
This patch adds license and copyright information to all files to make
nitrokey-rs compliant with the REUSE practices [0].
[0] https://reuse.software/practices/2.0/
|
|
|
|
|
|
|
| |
Previously, we used lossy UTF-8 conversion. Yet the user should be
notified if we have a problem instead of silently changing the data.
Therefore, we now return an error if we enocunter an invalid UTF-8
string. This leads to a change in `get_library_version`’s signature.
|
|
|
|
|
|
| |
Previously, library errors were part of the CommandError enum. As
command errors and library errors are two different error types, they
should be split into two enums.
|
|
|
|
|
|
|
|
|
|
| |
This patch changes all public functions to return the Error enum instead
of the CommandError enum. This breaks the tests which will be fixed
with the next patch.
This patch also adds a placeholder variant Error::CommandError and a
placeholder enum CommandError to make the transition to a new
nitrokey-test version easier.
|
|
|
|
|
| |
The Error enum is a wrapper for the possible error types (currently only
CommandError). Result<T> is defined as Result<T, Error>.
|
|
|
|
| |
This prepares the refactoring of util::CommandError into multiple enums.
|
|
|
|
| |
The constants can be used for tests or after a factory reset.
|
| |
|
|
|
|
|
| |
If libnitrokey has not been built from a clone of the Git repository,
the Git version string may be empty.
|
|
|
|
|
|
|
|
|
|
|
| |
The get_production_info method maps to the NK_get_production_info
function of libnitrokey. The Storage firmware supports two query modes:
with or without a write test. libnitrokey only performs the query
without write test, so the fields that are only set for the write test
are ignored in our implementation. This affects:
- user and admin retry counts
- smart card ID
- SD card size
|
|
|
|
|
|
| |
The VolumeMode enum will be used when setting the access mode for the
unencrypted volume. It can also be used when refactoring the
VolumeStatus enum in a future release.
|
| |
|
|
|
|
|
|
|
| |
This patch adds the get_library_version function to the main library
module that queries and returns the libnitrokey version. As the version
fields are static values, we fetch them all at the same time and do not
provide getters for the individual fields.
|
|
|
|
|
|
| |
This patch adds the global connect_model function that can be used to
connect to a Nitrokey device of a given model. Contrary to Pro::connect
and Storage::connect, the model does not have to be set at compile time.
|
| |
|
|
|
|
|
| |
This patch adds the function Device::get_model that returns the model of
the connected Nitrokey stick.
|
|
|
|
|
|
| |
Newer Rust versions support integration tests in a top-level tests
directory. This patch refactors the existing unit tests into
integration tests.
|
|
|
|
|
|
|
| |
With Rust edition 2018, it is no longer necessary to declare
dependencies in the code using `extern crate`. Therefore, this patch
removes these declarations and replaces them with `use` declarations if
necessary.
|
|
|
|
|
|
| |
This patch changes use declarations for modules within this crate to use
the crate:: path qualifier. This will be mandatory in Rust edition
2018.
|
|
|
|
|
|
|
|
| |
This patch enables the following compiler warnings:
- missing_docs for public symbols without documentation
- rust_2018_compatibility for Rust edition 2018 support
- rust_2018_idioms for Rust edition 2018 support
- unused for different types of unused code
|
| |
|
|
|
|
|
| |
Most notably, for command errors, this will print a human-readable error
message instead of just the name of the enum.
|
|
|
|
|
|
| |
The Result enum is more idiomatic and easier to use than our custom
CommandStatus enum with the same structure. This is especially true for
the try operator ?.
|
| |
|
|
|
|
|
|
|
|
|
| |
A password safe (PWS) stores names, logins and passwords in slots. PWS
are supported both by the Nitrokey Pro and the Nitrokey Storage. They
are implemented as a struct wrapping a device as the device may not be
disconnected while the password safe is alive. The creation of a
password safe is handled by the GetPasswordSafe trait, implemented by
DeviceWrapper, Pro and Storage.
|
|
|
|
|
| |
This patch adds the Storage struct and the test-storage feature. It
also enables all currently supported Pro commands for the Storage.
|
| |
|
| |
|
|
|
|
|
|
|
| |
DeviceWrapper abstracts over the supported devices. It implements the
traits that are implemented by all supported devices. The previous
UnauthenticatedDevice is renamed to Pro to prepare Storage support.
connect_model is moved to Pro::connect.
|
| |
|
|
|
|
|
|
| |
Now, the documentation clearly states the purpose of each log level.
Also, the documentation for set_log_level is corrected: libnitrokey
always prints to stderr.
|
|
|
|
|
|
|
| |
Since libnitrokey v3.3, libnitrokey no long has debugging output enabled
per default. Therefore, a corresponding note can be removed from the
crate documentation and the set_debug calls can be removed from the
tests.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
In future versions, we want to support not only the Nitrokey Pro, but
also the Nitrokey Storage. This requires a better code layout. This
patch introduces two main changes:
First, the OTP-specific methods are moved from the Device trait and the
AdminAuthenticatedDevice struct to the functionality-based traits
ConfigureOtp and GenerateOtp. This will hopefully make it easier to
integrate the Nitrokey Storage.
Secondly, the code is split into separate modules. These modules are
currently all private and re-exported in the lib module, but we can
consider making them public in the future.
|
| |
|