aboutsummaryrefslogtreecommitdiff
path: root/nitrocli/src/args.rs
Commit message (Collapse)AuthorAge
* Move nitrocli source code into repository rootDaniel Mueller2020-04-04
| | | | | | Now that all vendored dependencies have been removed, this change moves the program's source code from the nitrocli/ directory into the root of the repository.
* Properly show the default format used in otp set subcommandDaniel Mueller2019-10-13
| | | | | | | | | The otp set subcommand allows for three different formats in which the user may pass in the secret, with the default being hexadecimal. By convention we convey the default being used in the help text to the respective command, but that default was missing here. To that end, this change makes sure to include the default format being used in corresponding help text.
* Introduce NITROCLI constantDaniel Mueller2019-08-24
| | | | | | This change introduces a constant for the frequently used string "nitrocli" to the program and replaces usages of those strings with references to the constant.
* Fix incomplete help text for encrypted & unencrypted subcommandsDaniel Mueller2019-08-22
| | | | | | | | | | | Subcommands of the encrypted and unencrypted commands were found to have a wrong help text displayed. The reason for that behavior was that the subargs were are constructing as part of the argument parsing process were missing the command being requested and instead containing only the subcommand. This change fixes this deficiency. It also adds a test ensuring that the "Usage" string displayed in the help text of each command and subcommand contains the proper arguments.
* Include Nitrokey model in error message when no device is foundDaniel Mueller2019-07-14
| | | | | | | | For functionality that explicitly works with the storage device we emit an error message stating that a "Nitrokey Storage" device could not be found. When the user chooses the model using the -m/--model argument that is not the case. With this patch we adjust the error message printed.
* Add support for changing read-write mode of unencrypted volumeDaniel Mueller2019-06-08
| | | | | | | This change adds support for changing the read-write mode of the unencrypted volume. To do so, we introduce a new top-level command, unencrypted, with a new subcommand, set, that accepts the new mode of the volume.
* Reword an incorrect error messageDaniel Mueller2019-06-08
| | | | | | | | | This change rewords the error message that is emitted if the lock command fails. The old message was incorrectly stating a problem with the retrieval of the device's status. While at it, also slightly rephrase the description for the hidden command to be more in line with that of the other storage commands, and replace lowercase 'nitrokey' with a capitalized one in a few comments.
* Remove deprecated --ascii option of otp set subcommandDaniel Mueller2019-05-27
| | | | | | | The --ascii option of the otp set subcommand has been deprecated a while in favor of --format. As the next release is slated to be a major one breaking backwards compatibility, this change removes this option for good.
* Rename storage command to encryptedDaniel Mueller2019-05-27
| | | | | | | | This change is the last step in the process of restructuring the storage command. In particular, now that functionality pertaining hidden volumes has been moved out into a dedicated top-level command, it renames said command to encrypted, because dealing with the encrypted volume is the only functionality it provides.
* Make storage hidden subcommand a top-level commandDaniel Mueller2019-05-27
| | | | | | This patch marks the next step in the process of restructuring the storage command. Specifically, it promotes the storage hidden subcommand to a top-level command, hidden.
* Move storage status subcommand into status commandDaniel Mueller2019-05-27
| | | | | | | | In an attempt to rework the structure of the storage command to better accommodate future requirements for allowing to change the read-write state of the unencrypted volume (as well as potentially the encrypted one), this change removes the storage status subcommand and merges its output into the storage command.
* Allow for disabling of secret cachingDaniel Mueller2019-05-27
| | | | | | | | | | | | So far we have cached secrets in gpg-agent(1) whenever that made sense to do (i.e., for the two PINs in most contexts but not for passwords). While there is reason to believe that such caching is desired by the majority of users, not everybody has a use for it. To give users an opportunity to opt out of such caching, this change introduces a new environment variable, NITROCLI_NO_CACHE, that, when present in the environment, instructs the program to bypass the cache for all operations that require a secret and to instead inquire such secrets each time they are needed.
* Require trailing comma in Enum macro's inputDaniel Mueller2019-05-27
| | | | | | | | | | The input to the Enum macro is supposed to resemble the definition of an enum in Rust code. When manually defining an enum (or a struct for that matter), we typically terminate all branches with a comma, and don't just omit that on the last line. To mirror this behavior, this change adjusts the Enum macro to accept (and in fact, require) a comma-terminated last line as well, as opposed to not accepting it as had been the case so far.
* Allow for unused doc comments on macrosDaniel Mueller2019-05-24
| | | | | | | | | | With Rust 1.35 we get compile errors due to doc comments that are added to macro invocations but not actually included in the expanded output. The rustc wrongly assumes that we want to document the resulting code and not just provide details about the invocation itself. This change explicitly allows for those cases. Alternatively we could have "downgraded" the doc comments to normal comments or removed them altogether. There is little difference between those alternatives.
* Respect ctx.std{out,err} for version outputRobin Krahl2019-02-17
| | | | | | | | | | | | | Due to a bug in argparse [0], custom stdout and stderr settings are ignored when using argparse::Print, as we currently do for the --version option. This patch adds a workaround for this problem: Instead of using argparse::Print, we use argparse::StoreTrue for the --version option. The argument parsing will fail as the command is missing, but the version variable will still be set to true if the version option was set. So we ignore the parsing result and discard the argparse output if the version variable is set. [0] https://github.com/tailhook/rust-argparse/pull/50
* Remove args::parse_arguments functionDaniel Mueller2019-02-17
| | | | | | | | | The split between the parse_arguments and the handle_arguments functions is not really useful for reasoning about the code. In fact, it just adds additional overhead in the form of complex function signatures into the picture. As it provides no real other value, this change merges the functionality of both functions into a single one: handle_arguments.
* Use buffered writer in args::parse_argumentsRobin Krahl2019-02-17
| | | | | | | | | To be able to decide whether to print the argparse output depending on the result of the argument parsing, this patch wraps stdout and stderr in a BufWriter before invoking argparse. Our BufWriter implementation only writes to the inner Write if the flush method is called. This allows us to decide whether the buffered data should be written or silently dropped.
* Consume ArgumentParser object as part of parsingDaniel Mueller2019-02-08
| | | | | | | | | | We have introduced the parse function to unify the common parsing related tasks. In that vein, this change goes one step further and adjusts the function to actually consume the ArgumentParser object used by it. All clients using this function actually do not access the parser afterwards, and, in fact, some of them have to explicitly drop it because of borrow conflicts with "referred" arguments.
* Simplify error handling in the parse functionDaniel Mueller2019-02-08
| | | | | This patch changes the error handling in the args' module parse function to use the Result's map_err instead of a more verbose if let expression.
* Add the reset command to perform a factory resetRobin Krahl2019-01-26
| | | | | | After performing the factory reset, we also build the AES key so that the device is fully usable. Due to timing issue, we have to add a delay between the factory reset and building the AES key.
* Add the -V/--version optionRobin Krahl2019-01-26
| | | | | | | | The -V/--version option prints the nitrocli version to stdout and exits. In the future, it should also print the used libnitrokey version, but as the required function is only available with nitrokey 0.3.2 and as the current interface does not reflect the latest change in version naming, I skipped that in this patch.
* Add test for storage hidden subcommandDaniel Mueller2019-01-20
| | | | | | | This change adds a test for the creation, opening, and closing of a hidden subvolume. In order to support that in a non-interactive fashion, we introduce and honor the NITROCLI_PASSWORD environment variable, that prevents an interactive password query.
* Implement storage hidden subcommandDaniel Mueller2019-01-20
| | | | | | | | | With this change we implement the storage hidden subcommand. We support creation, opening, and closing of hidden volumes. Note that the opening of a hidden volume automatically closes any opened encrypted volumes and vice versa. To that end, we force file system level caches to disk even from the storage open and storage hidden open commands.
* Introduce storage hidden subcommand scaffoldingDaniel Mueller2019-01-15
| | | | | | | | | This change introduces a new subcommand to the storage command called 'hidden'. This subcommand can be used to interact with hidden volumes. Right now we support three operations pertaining hidden volumes: create, open, and close. This patch merely provides the infrastructure for parsing the commands and all their arguments, it does not yet implement them fully.
* Add tests for pws commandDaniel Mueller2019-01-19
| | | | | This change adds a set of tests for the pws command. Covered are all subcommands with the most commonly used parameter combinations.
* Auto-generate help text for Option-based argumentsDaniel Mueller2019-01-15
| | | | | | | | | The previous change to properly format the help text for optional arguments left one thing out: parameters that are based on an Option as opposed to an enum. The problem with those is that we cannot simply ask the value (i.e., the Option) for all the variants of the inner type. Instead, we have to reference the actual type of the inner enum in order to retrieve all its possible variants.
* Auto-generate help text for enum-backed optional argumentsDaniel Mueller2019-01-15
| | | | | | | This change continues the effort of auto-generating more of the help text content by extending the logic to optional arguments. We make use of the fmt_enum macro to format the description of the argument with the available variants (as well as the default, if any) interpolated.
* Auto-populate help text contentDaniel Mueller2019-01-14
| | | | | | | | | With the ability to fully generate the command enums we use for working with the argparse crate, we can now take things one step further and populate the contents of the help string we print for the user that lists the available commands. Doing so we also fix a bug where we forgot to mention the "storage status" command in the help text.
* Auto-generate execute methods for generated command enumsDaniel Mueller2019-01-14
| | | | | | | | | | | | | | | Not too long ago we added a macro to auto generate the command enums and the required trait implementations from a concise declarative representation. This change extends this mechanism to the execute method implementation that some of those enums provide. When a tuple is specified as the "destination", e.g., here: > Enum! {ConfigCommand, [ > Get => ("get", config_get), > Set => ("set", config_set) > ]} the second component of this tuple will be interpreted as the function to invoke when this variant used in the newly generated execute method.
* Add tests for otp commandDaniel Mueller2019-01-14
| | | | | | | This change adds a set of tests for the otp command. We cover some variants of the status, set, get, and clear. Testing all the possible combinations is out of scope and so only a more or less arbitrary subset of arguments was chosen.
* Isolate cached PINs for multiple devices from each otherDaniel Mueller2019-01-11
| | | | | | | | | | | | | | | | | | | The application supports multiple devices both plugged in at the same time as well as when used after the other. However, the GPG cache ID we use for storing and retrieving the respective PIN is effectively a constant. This constraint can cause problems when devices have different PINs, as the PIN of a previously plugged in device may be reused for an operation on a different one. To resolve this problem this change adds the respective device's model and serial number to the cache ID. As each serial number is supposed to be different, this will ensure that the correct PIN is used for each device. With this change we also show the model and serial number of the currently used device in the pinentry dialog. Note that because we do not store the serial numbers of all previously plugged in devices, the pin clear command will only clear the PIN for the currently plugged in device. If a user wants to make sure that a cached PIN is cleared, the pin clear command should be invoked before unplugging the device.
* Implement From<&str> for ErrorRobin Krahl2019-01-26
| | | | | | This patch implements From<&str> for Error so that we can use Error::from(s) as a shorthand for Error::Error(s.to_string()). It also replaces Error::Error with Error::from where possible.
* Refactor get_device to use nitrokey::connect_modelRobin Krahl2019-01-26
| | | | | | | | | nitrokey 0.3.1 introduced the connect_model function that connects to a specific model given by an enum variant and returns a DeviceWrapper. This new function allows us to remove the manual selection of a connection method from the get_device function. We only have to implement From<DeviceModel> for nitrokey::Model to be able to convert our model enum to nitrokey's model enum.
* Introduce Admin and User PIN fields to execution contextDaniel Mueller2019-01-09
| | | | | | | | | | | | | | In order to run tests fully non-interactively we need to avoid the need for using the GPG agent's PIN entry and caching mechanism. To accomplish that, we first need an alternate way to supply the PINs to use to the program. This change offers such a way by extending the execution context with two fields representing the PINs that are populated by corresponding environment variables, NITROCLI_ADMIN_PIN & NITROCLI_USER_PIN, if set. While only two PINs are required right now, because the program allows for the changing of each of the PINs, we also add two fields representing new PINs. These latter two fields are populated by the NITROCLI_NEW_ADMIN_PIN and NITROCLI_NEW_USER_PIN environment variables.
* Add missing closing parenthesis for otp set -a/--algorithm helpDaniel Mueller2019-01-08
| | | | | The help text for the otp set -a/--algorithm option is lacking the closing parenthesis in the help text. This change adds it.
* Auto generate argument enumsDaniel Mueller2019-01-06
| | | | | | | | | | | | The argparse module we use for parsing events expects an enum in order to convey what subcommand has been supplied as an argument. Such an enum also needs to implement str::FromStr and, preferably, fmt::Display. Manually writing down those definitions is error-prone, tedious, and adds no value -- only lines of code. As it turns out the proper definitions can be generated with relative easy with a declarative macro, making the code much more concise. Hence, with this change we use a newly introduced macro for generating those enums.
* Emit all output to custom stdio channelsDaniel Mueller2019-01-05
| | | | | | | | | | | This change continues and concludes the effort of using customizable stdio channels for output of data from the program. It does so by replacing the standard println macro with a custom one that outputs the data to the supplied context's stdout object. Because this object is injected from the main function, it will be possible for tests invoking this function to supply custom Write objects that can buffer this data and make it available for verification purposes.
* Supply customizable stdio channels to argparseDaniel Mueller2019-01-05
| | | | | | | | | | | | | | | | | | | | | | | | | In order to properly test the program we need to have a way to intercept data printed to the stdio channels. There are different ways to accomplish that task. While it is reasonably easy to just start the program as a dedicated process doing so properly may be problematic from inside a test because either the path to the binary has to be retrieved or cargo -- the entity which knows the path -- be invoked. None of these approaches is very appealing from a testing and code complexity point of view: an additional fork means additional sources of errors and flakiness, executing cargo has the potential to even cause rebuilds of parts of the program, and while we are already testing against a slow I/O device this additional code running is unlikely to go unnoticed in the long-term. Lastly, doing so also means that we leave Rust's type safety behind when dealing with errors that could be nicely match'ed on when the test invocation is just a function call. To avoid all this complexity we instead strive for basically just running the main function. This patch marks a first step towards achieving this goal. It introduces the infrastructure to supply custom Write objects to the argument parsing functionality. Once more we piggy-back on the command execution context and add objects representing stdout and stderr to it. We further ensure that this context is passed to the argument parser invocations.
* Work with mutable ExecCtx referencesDaniel Mueller2019-01-05
| | | | | | | | | | So far we have used a read-only reference to a command execution context and passed that through to all consumers. However, with upcoming changes we would will need to provide data that can be modified. This change adjusts all function signatures accordingly. Also, because the ExecCtx will contain references itself in the future, this change already introduces a lifetime for the struct, as that also requires signature adjustments.
* Add the base32 format for OTP secretsRobin Krahl2019-01-13
| | | | | | | Many applications display OTP secrets in the base32 format (according to RFC 4648). This patch adds base32 as a possible value for the --format option to the otp set subcommand.
* Add the --format option to otp set to select the secret formatRobin Krahl2019-01-13
| | | | | | | | | | | | | | This patch introduces the -f/--format options for the otp set subcommand to specify the format of the OTP secret. Previously, the default format was hexadecimal and ASCII format could be selected using the --ascii option. The new --format option takes the argument hex or ascii, defaulting to hex, and replaces the --ascii option. This patch does not remove the --ascii option but marks it as deprecated. It may not be set together with --format, and a warning is printed if it is set. It should be deleted with the next minor release. This patch prepares the addition of a new format, base32.
* Add the --model option to restrict the device model to connect toRobin Krahl2019-01-13
| | | | | | | | | | | | This patch adds the -m/--model option that can be used to restrict the device model to connect to. Per default, nitrocli connects to any available Nitrokey device. If this new option is set, it will instead only connect to devices of the given Nitrokey model. We introduce a new struct DeviceModel instead of using nitrokey::DeviceModel to make sure that the command-line options are parsed properly. On the long term, we should add a connect_model function to the nitrokey crate to make the connection code easier.
* Introduce -v/--verbose optionDaniel Mueller2019-01-04
| | | | | | | | | | | | | | | | This change introduces a new option, -v/--verbose, that can be used to increase the log level of libnitrokey. The option can be supplied multiple times, with each occurrence increasing the verbosity of the logging. On the implementation side, the option is set as part of connecting the device (piggy-backing on the previously introduced command execution context), although it describes global state that strictly speaking could be set anywhere. It is bad enough that libnitrokey just prints log messages to stderr (and does not accept a file handle) and that it does not track the log level on a per-device basis, but we don't want setting of global state from arbitrary locations inside the program. Instead, let's do that along with what pretty much is the first call into libnitrokey anyway: the connection to the device.
* Introduce command execution context supportDaniel Mueller2019-01-04
| | | | | | | | | In the future we will need the ability to pass additional state that is deduced from arguments or elsewhere into the commands module. To enable such scenarios, this change introduces the concept of a command execution context. Such a context can store more or less arbitrary data, and the args module will take care of passing it through to the individual commands.
* Document the lock commandRobin Krahl2019-01-07
| | | | | | This patch adds documentation and examples for the lock command to the README and to the man page. It also adds the lock command to the top-level help message.
* Implement the lock commandRobin Krahl2019-01-07
| | | | | | This patch implements the lock command that locks the password safe and, on the Nitrokey Storage, the encrypted volume. See issue #18 for details on the locking mechanism.
* Implement the pws status subcommandRobin Krahl2019-01-07
| | | | | This patch implements the pws status command that can be used to print status information for the slots in the password safe.
* Implement the pws clear subcommandRobin Krahl2019-01-07
| | | | | This patch implements the pws clear command which allows the user to clear a slot in the password safe.
* Implement the pws set subcommandRobin Krahl2019-01-07
| | | | This patch adds the pws set subcommand that writes a PWS slot.
* Implement the pws get subcommandRobin Krahl2019-01-07
| | | | | | | | | This patch implements the pws get subcommand that provides read access to a slot of the password safe. Per default, all available information – slot name, login and password – are printed. If one or more of the options --name, --login and --password are set, only the selected fields are printed. If --quiet is set, the field description is omitted such that the output can be easily parsed by other applications.