Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite translated code to use the pcsc crate #17

Merged
merged 9 commits into from
Nov 25, 2019
Merged

Rewrite translated code to use the pcsc crate #17

merged 9 commits into from
Nov 25, 2019

Conversation

tarcieri
Copy link
Collaborator

@tarcieri tarcieri commented Nov 25, 2019

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: https://github.com/bluetech/pcsc-rust
  • 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.

This was referenced Nov 25, 2019
@tarcieri tarcieri force-pushed the pcsc branch 2 times, most recently from 6fc9b8c to f992391 Compare November 25, 2019 00:22
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.
src/cccid.rs Outdated Show resolved Hide resolved
src/certificate.rs Show resolved Hide resolved
src/config.rs Show resolved Hide resolved
src/container.rs Outdated Show resolved Hide resolved
src/container.rs Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/transaction.rs Outdated Show resolved Hide resolved
src/yubikey.rs Outdated Show resolved Hide resolved
src/yubikey.rs Show resolved Hide resolved
src/yubikey.rs Outdated Show resolved Hide resolved
src/yubikey.rs Outdated Show resolved Hide resolved
src/yubikey.rs Show resolved Hide resolved
tarcieri and others added 7 commits November 25, 2019 07:19
@str4d's suggested fixes

Co-Authored-By: str4d <[email protected]>
More of @str4d's suggested changes

Co-Authored-By: str4d <[email protected]>
It seems like given we're inside a while loop which also has this
conditional, the original code should've been fine, but this change
makes it closer to the original C code.
Callers of this function always pad up to `CB_PIN_MAX` with `0xFF`.

The logic being changed here was previously identical to the `_verify`
function in `ykpiv.c`:

https://github.com/Yubico/yubico-piv-tool/blob/8ba243f/lib/ykpiv.c#L1299

...but @str4d noticed this potentially allows a caller to send an
unpadded PIN, which may (or may not) be an issue.
Also the same one @str4d made originally, guess I should've listened!

#17 (comment)
...replacing them with `CB_BUF_MAX`.

Both constants are 3072, however `CB_BUF_MAX` is what the original code
was using.

See discussion here:

#17 (comment)
Needs to match the original C code:

    memmove(data, data + 1 + offs, outlen);
@tarcieri tarcieri merged commit 4039560 into develop Nov 25, 2019
@tarcieri tarcieri deleted the pcsc branch November 25, 2019 17:17
@tarcieri tarcieri mentioned this pull request Nov 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants