Commit Graph

1140 Commits

Author SHA1 Message Date
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
Tony Arcieri 7d40a9917e oxidize: Fix second pass of compile errors and commented-out code
This commit gets the Rust code to compile! 🎉

Additionally, it fixes all of the commented out code that was failing
translation from C due to the use of unions, namely around the APDU
messages.

It does a fair amount of reformatting around branches, with the net
result hopefully being something actually a bit closer to the C code,
and a straightforward list of `if` statements.

It also removes all of the remaining externs that aren't supposed to be
externs, replacing them with a more straightforward usage of the module
system.

Finally it fixes all errors and warnings (relating to e.g. usage of
uninitialized memory), in addition to most clippy lints! (some have
been explicitly disabled)

All that said, it still doesn't do anything: it needs to be wired up to
a PCSC library first before that will be possible. But hey, it compiles!
2019-11-18 15:32:45 -08:00
Tony Arcieri 1d86885ab1 oxidize: Fix first pass of compile errors
This commit contains a multitude of fixes and some initial translation
work so the first rustc pass compiles.

It removes `unsafe extern "C"` declarations, so now there are a number
of errors about invocations of unsafe functions that need to be
addressed. They should each be scoped to an `unsafe` block so as to aid
in an eventual safe translation.

Some of the functions are now using the module system rather than
`extern "C"` bindings, but the translation is not complete.
2019-11-17 08:21:48 -08:00
Tony Arcieri 4cd59cb992 oxidize: Add pub mod directives and run rustfmt
Makes all translated files part of the crate, and then runs rustfmt
on all of them, hopefully making them marginally more bearable.
2019-08-10 14:53:25 -07:00
Tony Arcieri 5e0e0fe0c2 oxidize: Fix or note any translation errata
This either fixes or adds "FIXME" notes for any parts of the code that
corrode had trouble translating.

Namely there are a number of places members of the APDU struct(?) were
accessed which corrode failed to translate.
2019-08-10 14:50:36 -07:00
Tony Arcieri 29fe670896 oxidize: Factor into standard Rust crate structure
- Adds initial `Cargo.toml` (and `Cargo.lock` to `.gitignore`)
- Deletes `tool` (it seems hard to `corrode`)
- Moves `lib/tests` => `tests` (we should figure out how to translate them)
- Moves `lib` => `src` to match Rust conventions
- Renames `lib/ykpiv.rs` => `src/lib.rs` to match Rust conventions
- Adds copyright from `ykpiv.h` to the top of all `*.rs` files
2019-08-10 14:49:48 -07:00
Tony Arcieri 45ba342f57 oxidize: Initial corrode translation
Includes changes to the original C code needed for `corrode` to accept
the input.

There were a lot of problems with APDU fields. These need to be copied
into the translated Rust code and fixed up manually.

Code otherwise contains the raw `corrode` output.
2019-08-10 10:48:02 -07:00
Tony Arcieri a226b56696 oxidize: Prep directory structure for Rust translation
- Keeps: `lib`, `tool`
- Deletes everything else except for `COPYING` (i.e. license)
- Replaces `.gitignore` with a more standard Rust one
2019-08-10 10:12:34 -07:00
Alessio Di Mauro f794d02392 Merge PR #201 2019-07-17 09:29:30 +02:00
Tharsan Ponnampalam 48e310c33f lib: Implemented change pin for the puk key 2019-07-16 16:04:39 -04:00
Alessio Di Mauro cd2acd3ee5 Merge PR #198 2019-07-15 09:19:44 +02:00
Tharsan Ponnampalam ce5fca5d71 lib: Implemented change pin for the management key 2019-07-12 12:42:25 -04:00
Klas Lindfors 8ba243f0b3 lib: correct parentheses around condition+assignment
fixes #197
2019-07-03 16:00:57 +02:00
Dain Nilsson 682d91be2b Remove note about ifd-yubico. 2019-06-24 15:01:48 +02:00
Alessio Di Mauro 8a9223a380 Merge PR #194 2019-05-22 12:33:02 +02:00
Peter Jones a4c64c8c21 Initialize C_Initialize's reader list to NULs.
valgrind --track-origins=true says:

==13529== Conditional jump or move depends on uninitialised value(s)
==13529==    at 0x4AF92D1: PK11_MakeString (pk11slot.c:1073)
==13529==    by 0x4AFA5AA: PK11_InitSlot (pk11slot.c:1456)
==13529==    by 0x4AE315E: secmod_LoadPKCS11Module (pk11load.c:563)
==13529==    by 0x4AEF68C: SECMOD_LoadModule (pk11pars.c:1838)
==13529==    by 0x4AEF7C7: SECMOD_LoadModule (pk11pars.c:1874)
==13529==    by 0x4ABCB6A: nss_InitModules (nssinit.c:464)
==13529==    by 0x4ABCB6A: nss_Init (nssinit.c:689)
==13529==    by 0x4ABD17C: NSS_Init (nssinit.c:824)
==13529==    by 0x4059C0: main (pesign.c:354)
==13529==  Uninitialised value was created by a stack allocation
==13529==    at 0x484D175: C_Initialize (in /usr/lib64/libykcs11.so.1.5.0)

This is the result of a combination of two problems.  In
ykcs11/utils.c:parse_readers(), the code does:

  for (i = 0; i < len; i++)
    if (readers[i] == '\0' && i != len - 1) {

But in ykcs11/ykcs11.c:C_Initialize(), the parts of readers[] that are
initialized are only the parts that have been populated; the rest of
the array is still just whatever value is on the stack.  Additionally,
in lib/ykpiv.c:ykpiv_list_readers(), which populates the array, the
length is updated only in the case where the buffer is smaller than the
data, not when there is additional buffer but no data:

  if (num_readers > *len) {
    num_readers = (pcsc_word)*len;
  }

The result is that if the amount of reader data is smaller than 2048
bytes, PK11_InitSlot() will try to find reader data in the rest of the
array, which has not been initialized.

This patch adds an initialization for the data to set it all '\0', and
also updates the length when there is excess buffer available.

Signed-off-by: Peter Jones <pjones@redhat.com>
2019-05-21 11:01:24 -04:00
Alessio Di Mauro 6dd9ab09d4 Merge PR #193 2019-05-20 09:04:33 +02:00
Kelby Ludwig 08b32ef3e0 added switch to ignore CKA_LABEL on calls to check_pubkey_template and check_pvtkey_template 2019-05-18 21:39:36 -05:00