Commit Graph

1407 Commits

Author SHA1 Message Date
Tony Arcieri 9367218c7d Apply suggestions from code review
More of @str4d's suggested changes

Co-Authored-By: str4d <thestr4d@gmail.com>
2019-11-25 07:38:33 -08:00
Tony Arcieri e18828d048 Apply suggestions from code review
@str4d's suggested fixes

Co-Authored-By: str4d <thestr4d@gmail.com>
2019-11-25 07:19:20 -08:00
Tony Arcieri ebbf043bc9 Rewrite translated code to use the pcsc crate
This commit contains a "big bang" refactor/rewrite which does the
following:

- Replaces all `SCard*` FFI calls with the `pcsc` crate, which provides
  a safe, portable PC/SC API across Windows, macOS, and Linux
- Refactors the `util` module into modules representing the various
  device functions and concepts, e.g. `certificate`, `key`, `mgm`
- Replaces all usage of `libc` with `std` functionality, and in many
  places rewriting functionality to use safe code.
- Removes `ykpiv_` from all function names, and `Piv*` from type names.

In 20/20 hindsight I wish I had done this commit more incrementally so
as to make it easier to review. Que sera sera.

However, realistically we need to test all functionality on the device
to ensure that it actually works. Going forward I would like to put
pretty much all of the current code behind an `untested` cargo feature,
and then remove it for each bit of functionality we test.
2019-11-24 16:36:43 -08:00
Tony Arcieri 96cd5d080b Merge pull request #15 from tarcieri/apdu-cleanups
Clean up APDU construction with builder API
2019-11-21 09:18:30 -08:00
Tony Arcieri bd485eb912 Clean up APDU construction with builder API
Changes the `APDU` struct into a builder for serialized APDU messages.

This makes APDU construction safer and more idiomatic, and also caught a
few bugs in the process (missing templ from the C translation).
2019-11-21 09:05:32 -08:00
Tony Arcieri 64bf135f6c Merge pull request #14 from tarcieri/yubikey-struct-methods
Factor `yubikey` module fns into struct methods
2019-11-21 08:37:31 -08:00
Tony Arcieri b5bee1aa2f Factor yubikey module fns into struct methods
Moves all of the functions in the `yubikey` module into an
`impl YubiKey` block, and changes the receiver to `&mut self` making
them methods.
2019-11-21 08:20:08 -08:00
Tony Arcieri 7b1d98f695 Merge pull request #13 from tarcieri/rename-errorkind
Rename ErrorKind to Error
2019-11-21 07:50:13 -08:00
Tony Arcieri f372cfc2a7 Rename ErrorKind to Error
There was originally another `Error` type from the translation. Now that
it's gone, and we don't presently have a type just named `Error`, this
renames the current `ErrorKind` type now that the original was deleted.
2019-11-21 07:41:29 -08:00
Tony Arcieri 9b6fb7a39c Merge pull request #12 from str4d/internal-cleanups
Internal cleanups
2019-11-21 06:50:14 -08:00
Jack Grigg d01d2dec84 Minor internal cleanups 2019-11-21 13:15:57 +00:00
Jack Grigg 7412c02892 Remove dead code from internals 2019-11-21 13:12:46 +00:00
Jack Grigg 6e24660a80 Clean up internal::setting_get_bool 2019-11-21 13:10:23 +00:00
Tony Arcieri ad21eaea81 Merge pull request #10 from str4d/3des
Use des crate for 3DES operations
2019-11-20 17:07:02 -08:00
Jack Grigg a71389a820 Remove completed TODO 2019-11-21 00:48:48 +00:00
Jack Grigg 35cc1bbf72 Address clippy lints 2019-11-21 00:44:49 +00:00
Jack Grigg 86fde50c2d Use des crate for 3DES operations 2019-11-21 00:37:16 +00:00
Tony Arcieri 634740d751 Merge pull request #9 from str4d/pbkdf2
Replace PKCS5_PBKDF2_HMAC_SHA1 with crates
2019-11-20 13:44:26 -08:00
Jack Grigg c5a486cb4b Replace PKCS5_PBKDF2_HMAC_SHA1 with crates
Also tidies up ykpiv_util_get_derived_mgm (which was the only consumer
of the function) and fixes some porting bugs.
2019-11-20 21:20:01 +00:00
Tony Arcieri 87c00a9b61 Merge pull request #8 from str4d/getrandom
Replace RAND_bytes with getrandom crate
2019-11-20 13:17:06 -08:00
Jack Grigg c0bbf9aa06 Replace RAND_bytes with getrandom crate 2019-11-20 21:02:28 +00:00
Tony Arcieri ffdb114ae5 Merge pull request #7 from tarcieri/log
Use `log` crate for logging
2019-11-20 11:42:21 -08:00
Tony Arcieri c3d5df1643 Use log crate for logging
Switches all of the previous `state->verbose`-gated `eprintln!` calls to
use macros from the `log` crate, trying to map them onto the previous
verbosity levels, more or less following this mapping:

0. off
1. error/info/warn (depending on context)
2. trace

This additionally includes a bunch of logic/branch reformatting (and
occasional missed constants), since getting rid of all the gating on
verbose provided ample opportunities to clean up the code. Hopefully I
didn't break too much in the process!
2019-11-20 11:34:07 -08:00
Tony Arcieri f25eed1a86 Merge pull request #6 from str4d/1-replace-ok-with-result
Replace ErrorKind::Ok with Result
2019-11-20 07:11:05 -08:00
Jack Grigg 683e463824 Silence _ykpiv_end_transaction "unused Result" clippy warnings
These calls will be replaced when the pcsc crate is introduced.
2019-11-20 12:38:48 +00:00
Jack Grigg ce55e08af8 Explicitly ignore _cache_pin errors
The only error that _cache_pin can return is a memory allocation failure
which will likely be removed during the refactor.
2019-11-20 12:35:38 +00:00
Jack Grigg 88ec6bcb32 Remove redundant Result from ykpiv_disconnect 2019-11-20 12:32:19 +00:00
Jack Grigg b23ed1d48a Pass response to ykpiv_auth_verifyresponse by value 2019-11-20 12:32:04 +00:00
Jack Grigg 6324f7a75d Document tries field of ErrorKind::WrongPin 2019-11-20 12:26:33 +00:00
Jack Grigg 9252765940 Fix bug in ykpiv_util_block_puk
Introduced in b750b9cbbb.
2019-11-20 12:25:35 +00:00
Jack Grigg a43bddb531 Pointers -> refs in ykpiv_auth_verifyresponse 2019-11-20 12:21:42 +00:00
Jack Grigg 71a334a9b8 fn ykpiv_auth_getchallenge() -> Result<[u8; 8], ErrorKind> 2019-11-20 12:16:58 +00:00
Jack Grigg b750b9cbbb Convert tries pointers into Result elements 2019-11-20 12:07:06 +00:00
Jack Grigg 31ef465571 fn _ykpiv_get_version() -> Result<Version, ErrorKind> 2019-11-20 11:44:13 +00:00
Jack Grigg 90bdda85cb fn _ykpiv_get_serial() -> Result<u32, ErrorKind> 2019-11-20 11:39:58 +00:00
Jack Grigg c394511c60 Convert APDU pointer into mutable reference 2019-11-20 11:31:23 +00:00
Jack Grigg 4e710da32c Remove ErrorKind::Ok 2019-11-20 11:17:17 +00:00
Jack Grigg 7add9bfa41 Convert remaining APIs to Result<(), ErrorKind> 2019-11-20 11:16:44 +00:00
Jack Grigg 6c03ea89ec Return Result<(), ErrorKind> from most internal APIs
Started with _ykpiv_begin_transaction and kept going incrementally until
it compiled again.
2019-11-20 11:09:59 +00:00
Jack Grigg 5733d0b0af Convert Yubikey pointers into mutable references 2019-11-20 01:07:15 +00:00
Jack Grigg 943dd6f146 Return Result<(), ErrorKind> from most APIs
This commit modifies all public APIs where doing so wouldn't require
modifying internal functions.
2019-11-20 01:06:54 +00:00
Tony Arcieri 65ec5aad63 Merge pull request #3 from tarcieri/gitter-badge
README.md: Update Gitter badge URLs
2019-11-19 08:36:45 -08:00
Tony Arcieri 012d164e12 README.md: Update Gitter badge URLs 2019-11-18 20:38:26 -08:00
Tony Arcieri 9bcd85bce0 Merge pull request #2 from tarcieri/v0.0.1
v0.0.1
2019-11-18 19:20:58 -08:00
Tony Arcieri cccdd8dfa9 v0.0.1 yubikey-piv/v0.0.1 2019-11-18 19:10:04 -08:00
Tony Arcieri 9195d5efd0 Merge pull request #1 from tarcieri/actions-rs
actions-rs configuration
2019-11-18 19:05:06 -08:00
Tony Arcieri 6beb077f25 actions-rs configuration
Uses GitHub Actions for CI, based on the `actions-rs` template:

<https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md>

Configured to run tests on Linux (Ubuntu), macOS, and Windows, all of
which we should theoretically be able to support via appropriately
portable PC/SC Rust crates.
2019-11-18 18:51:14 -08:00
Tony Arcieri 7e2cafd0c4 Project boilerplate (metadata, docs, code of conduct) 2019-11-18 17:58:54 -08:00
Tony Arcieri 4b0ad478b3 Reformat Cargo.toml 2019-11-18 17:04:42 -08:00
Tony Arcieri bf5cda9af9 Remove legacy C implementation
This repository contains the entire history of the C source code since
the project started.

However, the code is largely translated at this point, so keeping the C
code around at this point no longer makes sense. If we need to consult
it or the history of changes, git has them.
2019-11-18 15:47:04 -08:00