Граф коммитов

427 Коммитов

Автор SHA1 Сообщение Дата
Martin Sirringhaus f98945424e Expose U2F_OK value in C-API for successful results 2022-11-21 09:52:30 -08:00
Michael Farrell 155e546eef Rename and document `U2FAPDUHeader` and fix Nc=0.
* Fixes an issue where Lc bytes would be included when Nc = 0 (zero command data length). This is incorrect in ISO 7816-4:2005 (which FIDO v1.1 and v1.2 correctly describe).

  This affected the `GetVersion` command; and tests have been updated accordingly.

* Renames `U2FAPDUHeader` to `CTAP1RequestAPDU`.

  Using the name "CTAP1" rather than "U2F" follows the convention put forward in FIDO v2.x specs, which avoids confusion like "U2Fv2" = "CTAP1".

  The previous implementation wasn't just "a header", but rather the complete APDU.

* Renames `RequestCtap1::apdu_format` to `RequestCtap1::ctap1_format` and `FidoDevice::send_apdu` to `FidoDevice::send_ctap1`. This makes it more like `RequestCtap2`, and avoids confusion later on when adding support for CTAP2 over NFC (which still uses ISO 7816-4 APDUs).

* Documents and add tests for `CTAP1RequestAPDU`, explaining the confusing state of affairs.

* Corrects comments for sample CTAP1 requests in tests.
2022-11-17 08:42:48 -08:00
John M. Schanck 3fc7bcfae4 crypto/nss: minor documentation issues 2022-11-15 13:16:19 -08:00
John M. Schanck 94362a0e06 crypto/nss: avoid leaking a public key on an error path 2022-11-15 13:16:19 -08:00
John M. Schanck 0d8e1af1ff crypto/nss: ensure nss initialized in encapsulate 2022-11-15 13:16:19 -08:00
John M. Schanck 79aac135a8 crypto/nss: use token-specific default values for PK11 sensitive / public 2022-11-15 13:16:19 -08:00
John M. Schanck f6b0a8be00 Implement crypto/nss using nss-gk-api 2022-11-15 13:16:19 -08:00
John M. Schanck 1214655c34 Avoid using SHA256_LENGTH for comparison with u32 2022-11-15 13:16:19 -08:00
John M. Schanck 84065ba112 Rename nss-sys to nss-gk-api 2022-11-15 13:16:19 -08:00
R. Martinho Fernandes 33c6d0cd34 Use NSS directly from bindings 2022-11-15 13:16:19 -08:00
Martin Sirringhaus 506d3fb679 Don't error our when encountering unsupported GetInfo-options 2022-11-15 10:01:58 -08:00
Martin Sirringhaus bf84d23ed7 Fix warnings with newer rustc. When dropping values, drop() has to be explicitly called. 2022-11-08 13:33:46 -08:00
msirringhaus dd6e6e4562
Serialize attestation as webauthn (#186)
* Do not error out if the token returns options unknown to us

This might happen, if the token is very new and supports a newer CTAP-specification.
In that case, we simply don't support it, but shouldn't error out.

* Device selection (#163)

* Add cancel-function to HIDs, which can cancel blocking reads

* Add function to clone a (Linux) device in write-only mode

* First implementation of DeviceSelector

For selecting multiple devices, if those are present.
A few lints need to be fixed and it doesn't work with PIN-tokens yet.

* Fix stupid typo in function name

* Move PIN into StatusUpdate as a callback (discoverable_creds not yet working)

* Move workaround for unsetting uv to accomodate the new PIN-retrieval process

* Fix warnings

* Send DeviceSelectionNotice on Status channel, when devices blink

Also remove the unneccessary Mutex around the status-sender, since
we have to clone it anyways into Transaction. Then we can just clone
and hand it into each device-thread.

* Trying to add latest features to mac and win

Untested, so compilation might be broken.
netbsd is only partly done and broken anyways at the moment

* Simplify HIDDevice vs. FidoDevice traits

Instead of implementing FidoDevice for each HIDDevice and implementing a bunch
of duplicate functions, that call through to HIDDevice, just extend HIDDevice
with FidoDevice.
This _might_ become a problem once we introduce NFC or such, but it is unclear
at the moment, how this is going to look like, anyways.

* Add impl FidoDevice for Windows and Mac

* Reduce number of arguments to new-device callback function

Also move functions needed by statemachine or device_selector into the
HIDDevice trait

* Make tests compile again

* Add authenticatorSelection command (CTAP2.1 only)

* Blink only when at least one token has a PIN (or UV)

With this, we can skip the "blinking"-phase if multiple tokens are there,
because we only need to blink, if at least one of them has a PIN (otherwise
we get a PIN-prompt, even though no token has been selected yet).
For tokens with no PIN (or CTAP1 tokens) we can send the normal request right
away. That will blink anyways.

* Make only tokens with some UV blink

Only let tokens with some UV (e.g. Password) blink, the others
can get the request straight away. This way, they will also blink,
but execute the request right away and cancel all other devices.
Only UV-devices would trigger callbacks, so they have to be sent a
selection-command.

* Make the is_u2f-function part of the HIDDevice trait as every device needs to have that function currently

* Move the TestDevice into its own platform and implement tests for DeviceSelector

Mostly copy&paste, plus minor adjustments to existing tests.
For the DeviceSelector-Tests, some extensions to the device have been made
(adding Sender and Receiver, giving it a function for it).

* Some AuthenticatorOptions need a default value according to spec

* Revert f3718a3: Blink for all devices, not just those with PIN

We can't let the non-UV devices continue with the regular request, because in the error-case
we can't differentiate if it is due to a bad request or something the user did (e.g. pull the
token out, or decline the request on the token, etc.).
Some errors should lead to cancelling the request altogether, the other just means "not with
this device". With our own Blink-command, we know that it works in principle. If there is an
error then it must be because of user-actions and should lead to skipping that device.

* Add status callbacks to C-API (for ctap2)

* Don't just borrow the status result, but 'forget' it on the Rust side

If we don't do this, the callback-function on C++ side can't keep a
reference to the result, which it needs for later sending a Pin back.

* Add "DeviceSelected" status update plus tests

Also moved the "DeviceUnavailable" to DeviceSelector (and send it upon removal of the token)

* First test of multi-platform CI (excluding crypto)

* Fix builds on Mac and Windows

* Add option for PinError-callback to 'say' the error is not recoverable

We use the property of channel() here, that recv will error out if the Sender is dropped.
So the status-callback can now drop the Sender without replying first, to trigger
the code to error out the 'normal' way.
This helps us to show a popup-dialog, but also cancel the current transaction cleanly.
For this, NSS-errors needed to be made cloneable, so we replaced them with their String-representation.

* Fix typo

* Implement serializing of crypto backend errors

* Add 2 more CI pipelines for building with all crypto-backends on Linux

* Change status update C-API to combined buffer+length-interface

* Revert "Change status update C-API to combined buffer+length-interface"

This reverts commit b4342e90b6.

Co-authored-by: Martin Sirringhaus <>

* Simplify C-API by serializing AttestationObject in webauthn-format

Co-authored-by: Martin Sirringhaus <>
2022-10-17 17:43:30 +02:00
msirringhaus 20838bf2df
Return the actual serialized byte-array of the used client-data alongside the struct itself. (#184)
Co-authored-by: Martin Sirringhaus <>
2022-10-17 17:42:52 +02:00
msirringhaus 1817e883b2
Fix #187: Do not truncate leading zeros when printing AAGuids (#188)
Co-authored-by: Martin Sirringhaus <>
2022-10-13 14:48:22 +02:00
msirringhaus 99ad679e8d
Implement parsing of DER-certificate length and remove AttestationStatement::Unparsed() (#185)
Co-authored-by: Martin Sirringhaus <>
2022-10-13 14:47:39 +02:00
msirringhaus 85e55d4956
Relax keylength checks for CTAP2 and implement excludeList-support for CTAP1 (#181)
* Relax rules for keylength checking when dealing with CTAP2

* Add excludeList-support for CTAP1

Co-authored-by: Martin Sirringhaus <>
2022-10-13 14:47:11 +02:00
msirringhaus b5aeafc5d8
Remove unneeded explicit close-call, since the file will be close automatically (#180)
Co-authored-by: Martin Sirringhaus <>
2022-10-13 14:47:00 +02:00
msirringhaus f2d255c48d
Bump nom to v7 (#178)
Co-authored-by: Martin Sirringhaus <>
2022-06-20 13:51:15 +02:00
msirringhaus a438ca2d0b
Another main merge (#177)
Update tokio to 1.17
2022-06-20 13:23:34 +02:00
msirringhaus 8d37248f0b
Merge main (#174)
* Add riscv64 support (#152)

Thanks!

* Fix panic msg is not a string literal warning (#149)

Fixes the non_fmt_panic warning.

* Update rand. (#164)

* Use memoffset instead of homebrew offset_of (#171)

Co-authored-by: R. Martinho Fernandes <bugs@rmf.io>

* Remove base64 from dev-dependencies, as it is now a normal dependency

* Bump application-services to the version currently vendored in mozilla-central

Co-authored-by: Makoto Kato <m_kato@ga2.so-net.ne.jp>
Co-authored-by: est31 <est31@users.noreply.github.com>
Co-authored-by: Emilio Cobos Álvarez <emilio@crisal.io>
Co-authored-by: R. Martinho Fernandes <rmf@rmf.io>
Co-authored-by: R. Martinho Fernandes <bugs@rmf.io>
Co-authored-by: Martin Sirringhaus <>
2022-06-20 12:45:37 +02:00
msirringhaus e996506d5a
Fix stub and make NSS compile on 32bit systems (#169)
* Do not error out if the token returns options unknown to us

This might happen, if the token is very new and supports a newer CTAP-specification.
In that case, we simply don't support it, but shouldn't error out.

* Device selection (#163)

* Add cancel-function to HIDs, which can cancel blocking reads

* Add function to clone a (Linux) device in write-only mode

* First implementation of DeviceSelector

For selecting multiple devices, if those are present.
A few lints need to be fixed and it doesn't work with PIN-tokens yet.

* Fix stupid typo in function name

* Move PIN into StatusUpdate as a callback (discoverable_creds not yet working)

* Move workaround for unsetting uv to accomodate the new PIN-retrieval process

* Fix warnings

* Send DeviceSelectionNotice on Status channel, when devices blink

Also remove the unneccessary Mutex around the status-sender, since
we have to clone it anyways into Transaction. Then we can just clone
and hand it into each device-thread.

* Trying to add latest features to mac and win

Untested, so compilation might be broken.
netbsd is only partly done and broken anyways at the moment

* Simplify HIDDevice vs. FidoDevice traits

Instead of implementing FidoDevice for each HIDDevice and implementing a bunch
of duplicate functions, that call through to HIDDevice, just extend HIDDevice
with FidoDevice.
This _might_ become a problem once we introduce NFC or such, but it is unclear
at the moment, how this is going to look like, anyways.

* Add impl FidoDevice for Windows and Mac

* Reduce number of arguments to new-device callback function

Also move functions needed by statemachine or device_selector into the
HIDDevice trait

* Make tests compile again

* Add authenticatorSelection command (CTAP2.1 only)

* Blink only when at least one token has a PIN (or UV)

With this, we can skip the "blinking"-phase if multiple tokens are there,
because we only need to blink, if at least one of them has a PIN (otherwise
we get a PIN-prompt, even though no token has been selected yet).
For tokens with no PIN (or CTAP1 tokens) we can send the normal request right
away. That will blink anyways.

* Make only tokens with some UV blink

Only let tokens with some UV (e.g. Password) blink, the others
can get the request straight away. This way, they will also blink,
but execute the request right away and cancel all other devices.
Only UV-devices would trigger callbacks, so they have to be sent a
selection-command.

* Make the is_u2f-function part of the HIDDevice trait as every device needs to have that function currently

* Move the TestDevice into its own platform and implement tests for DeviceSelector

Mostly copy&paste, plus minor adjustments to existing tests.
For the DeviceSelector-Tests, some extensions to the device have been made
(adding Sender and Receiver, giving it a function for it).

* Some AuthenticatorOptions need a default value according to spec

* Revert f3718a3: Blink for all devices, not just those with PIN

We can't let the non-UV devices continue with the regular request, because in the error-case
we can't differentiate if it is due to a bad request or something the user did (e.g. pull the
token out, or decline the request on the token, etc.).
Some errors should lead to cancelling the request altogether, the other just means "not with
this device". With our own Blink-command, we know that it works in principle. If there is an
error then it must be because of user-actions and should lead to skipping that device.

* Add status callbacks to C-API (for ctap2)

* Don't just borrow the status result, but 'forget' it on the Rust side

If we don't do this, the callback-function on C++ side can't keep a
reference to the result, which it needs for later sending a Pin back.

* Add "DeviceSelected" status update plus tests

Also moved the "DeviceUnavailable" to DeviceSelector (and send it upon removal of the token)

* First test of multi-platform CI (excluding crypto)

* Fix builds on Mac and Windows

* Add option for PinError-callback to 'say' the error is not recoverable

We use the property of channel() here, that recv will error out if the Sender is dropped.
So the status-callback can now drop the Sender without replying first, to trigger
the code to error out the 'normal' way.
This helps us to show a popup-dialog, but also cancel the current transaction cleanly.
For this, NSS-errors needed to be made cloneable, so we replaced them with their String-representation.

* Fix typo

* Implement serializing of crypto backend errors

* Add 2 more CI pipelines for building with all crypto-backends on Linux

* Change status update C-API to combined buffer+length-interface

* Revert "Change status update C-API to combined buffer+length-interface"

This reverts commit b4342e90b6.

Co-authored-by: Martin Sirringhaus <>

* Make stub compile again

* Make NSS compile on 32bit systems

* Silence unused-warnings when building the stub

Co-authored-by: Martin Sirringhaus <>
2022-06-20 12:27:29 +02:00
msirringhaus 78a8cd56aa
Bump sha2-version (#168)
Co-authored-by: Martin Sirringhaus <>
2022-05-23 14:19:23 +02:00
msirringhaus 98b120bd66
Reset and setpin commands (#167)
* Add functions and example binary for Reset

* NSS should use CBC and not ECB encryption alg

* Add functions and example for set/change pin

Co-authored-by: Martin Sirringhaus <>
2022-05-20 14:15:53 +02:00
msirringhaus 3022d885fb
Do not error out if the token returns options unknown to us (#166)
This might happen, if the token is very new and supports a newer CTAP-specification.
In that case, we simply don't support it, but shouldn't error out.

Co-authored-by: Martin Sirringhaus <>
2022-05-20 13:08:29 +02:00
msirringhaus ab20df2e8c
Device selection (#163)
* Add cancel-function to HIDs, which can cancel blocking reads

* Add function to clone a (Linux) device in write-only mode

* First implementation of DeviceSelector

For selecting multiple devices, if those are present.
A few lints need to be fixed and it doesn't work with PIN-tokens yet.

* Fix stupid typo in function name

* Move PIN into StatusUpdate as a callback (discoverable_creds not yet working)

* Move workaround for unsetting uv to accomodate the new PIN-retrieval process

* Fix warnings

* Send DeviceSelectionNotice on Status channel, when devices blink

Also remove the unneccessary Mutex around the status-sender, since
we have to clone it anyways into Transaction. Then we can just clone
and hand it into each device-thread.

* Trying to add latest features to mac and win

Untested, so compilation might be broken.
netbsd is only partly done and broken anyways at the moment

* Simplify HIDDevice vs. FidoDevice traits

Instead of implementing FidoDevice for each HIDDevice and implementing a bunch
of duplicate functions, that call through to HIDDevice, just extend HIDDevice
with FidoDevice.
This _might_ become a problem once we introduce NFC or such, but it is unclear
at the moment, how this is going to look like, anyways.

* Add impl FidoDevice for Windows and Mac

* Reduce number of arguments to new-device callback function

Also move functions needed by statemachine or device_selector into the
HIDDevice trait

* Make tests compile again

* Add authenticatorSelection command (CTAP2.1 only)

* Blink only when at least one token has a PIN (or UV)

With this, we can skip the "blinking"-phase if multiple tokens are there,
because we only need to blink, if at least one of them has a PIN (otherwise
we get a PIN-prompt, even though no token has been selected yet).
For tokens with no PIN (or CTAP1 tokens) we can send the normal request right
away. That will blink anyways.

* Make only tokens with some UV blink

Only let tokens with some UV (e.g. Password) blink, the others
can get the request straight away. This way, they will also blink,
but execute the request right away and cancel all other devices.
Only UV-devices would trigger callbacks, so they have to be sent a
selection-command.

* Make the is_u2f-function part of the HIDDevice trait as every device needs to have that function currently

* Move the TestDevice into its own platform and implement tests for DeviceSelector

Mostly copy&paste, plus minor adjustments to existing tests.
For the DeviceSelector-Tests, some extensions to the device have been made
(adding Sender and Receiver, giving it a function for it).

* Some AuthenticatorOptions need a default value according to spec

* Revert f3718a3: Blink for all devices, not just those with PIN

We can't let the non-UV devices continue with the regular request, because in the error-case
we can't differentiate if it is due to a bad request or something the user did (e.g. pull the
token out, or decline the request on the token, etc.).
Some errors should lead to cancelling the request altogether, the other just means "not with
this device". With our own Blink-command, we know that it works in principle. If there is an
error then it must be because of user-actions and should lead to skipping that device.

* Add status callbacks to C-API (for ctap2)

* Don't just borrow the status result, but 'forget' it on the Rust side

If we don't do this, the callback-function on C++ side can't keep a
reference to the result, which it needs for later sending a Pin back.

* Add "DeviceSelected" status update plus tests

Also moved the "DeviceUnavailable" to DeviceSelector (and send it upon removal of the token)

* First test of multi-platform CI (excluding crypto)

* Fix builds on Mac and Windows

* Add option for PinError-callback to 'say' the error is not recoverable

We use the property of channel() here, that recv will error out if the Sender is dropped.
So the status-callback can now drop the Sender without replying first, to trigger
the code to error out the 'normal' way.
This helps us to show a popup-dialog, but also cancel the current transaction cleanly.
For this, NSS-errors needed to be made cloneable, so we replaced them with their String-representation.

* Fix typo

* Implement serializing of crypto backend errors

* Add 2 more CI pipelines for building with all crypto-backends on Linux

* Change status update C-API to combined buffer+length-interface

* Revert "Change status update C-API to combined buffer+length-interface"

This reverts commit b4342e90b6.

Co-authored-by: Martin Sirringhaus <>
2022-05-17 17:35:20 +02:00
msirringhaus f310a5b826
Ctap2 continued (#157)
* Moving platform specific modules into new module 'transport'

* Replace capability-defines with bitflags (and add ctap2 capabilities)

* Make HID commands its own type

* Run cargo fmt and clippy

* Add test for U2F_VERSION

* CTAP2: Implement first ctap2-command GetInfo as well as ctap1-fallback GetVersion, plus tests

* WIP: Add part MakeCredentials

* Add test for (and do some fixes) for MakeCredential CTAP1 mapping

* Adjust tests with RelyingParty and name-field

* Fix serialization of MakeCredentialOptions (individually serialize members)

* Temporarily parse credential_public_key just as a byte-vector, until COSE-crate is added and able to actually parse it

* Add Option Unparsed to AttestationStatement, to currently skip parsing it (which would need a DER-parser)

* Add commands GetAssertion and GetAssertionNext. Still missing tests.

* WIP: Add clientpin command with all the crypto functionality commented out

* Remove duplicate Pin-definition

* MakeCredentials and GetAssertion now do not store Pin but PinAuth, which has to be calculated before hand

* Sort CTAPHID const values according to value

* WIP: New Manager and StateMachine-slots for CTAP2. A lot of functions are still missing.

* MakeCredentials: Remove pointless alias for HIDError

* GetInfo: Fix wrong parsing of response. Forgot to strip away the status-byte

* Linux/Device: Fix bug where file was not saved and prematurely closed, leaving a dangling filedescriptor

* WIP: Add seperate statemachine for ctap2, add example which can already call MakeCredential

* Prepare for sign-functions: Make SignResult CTAP2-aware (similar to RegisterResult)

* Add some (not all) CTAP2.1 info options to GetInfo for testing.

* Implement generic Request marker trait for GetAssertion

* Fix non-conformance with spec for GetAssertion: Only RelyingParty-ID should be send, not the entire rp

* First draft implementation of manager.sign()

- SignArgs now enum for ctap1/2 like RegisterArgs
- Same for SignResult
- Add exclude_list and allow_list to RegisterArgs and SignArgs resp.

* Remove transports-option of PublicKeyCredentialDescriptor for now as older tokens dont understand it and return an error

* Fix wrongly used default of GetAssertionOptions (which has its own Default-implementation)

* Fix test for PublicKeyCredentialDescriptor because of removed transport-serialization

* Remove some unneeded dead_code cfgs

* Remove outdated TODO-comments

* Add some comments/hints/todos

* Expose Pin at a higher level to be easily found and used by users

* First draft of the framework of crypto-module, with some dummy-content for testing

* GetInfo: When deserializing key algorithms don't abort when an unknown alg is encountered. Just mark it as unknown

* Activate openssl crypto backend for PIN usage in MakeCredentials

Moved src/ctap2/crypto.rs to src/crypto/mod.rs
Fleshed out authenticate, encrypt, decrypt, etc. functions in openssl
Use them in client_pin.rs

* openssl: Clarify IV comments. Spec says IV=0 for all use cases

* GetAssertion: Implement pin_auth and use it to get user_verification in GetAssertionResponse

* PIN: Implement automated GetRetires if pin was wrong. Re-wrap several other pin-related Errors

* Implement Ring backend as far as possible for now (ring doesn't support AES-CBC yet)

* Redirect PinRequired error and update some comments

* Implement first draft of NSS backend

* Add one more testcase: Hash and encrypt PIN

* Fix GetAssertion for CTAP1-only devices

- Defaults of GetAssertionOptions were wrong
- Skip PIN-related function for CTAP1

* Fix downward compatiblity (to use CTAP2-Manager for CTAP1 requests on CTAP1 tokens)

- Repackage CTAP1 requests for "register()" and "sign()" into CTAP2 data structure
- Repackage MakeCredential result only for CTAP2 requests into CTAP2 result values
- Repackage GetAssertion result into CTAP1-result if needed
- Add "is_ctap2_request()" function and only send cbor-messages if Request AND Device are CTAP2
- Introduce RelyingPartyWrapper (CTAP1 requests provide the RpIdHash only, not the complete rp)
- Copy existing ctap1-example (main.rs), but use new CTAP2 Manager

* Fix build with feature webdriver

* Fix parsing of GetAssertionResponse: Parse PublicKeyCredentialDescriptor instead of serde::Value

* First draft of capi-additions: sign-result repackaging not yet done

* For testing purposes, switch to own repo of rc_crypto (to test vendoring)

* Undo last change, switch to application-services directly

* Expose rust_ctap2_mgr_new()

* Fix various CTAP1-only bugs

- When doing CTAP1 only, use challenge directly in the requests (not hashing the whole client data)
- Package GetAssertionResult similar to MakeCredential in CTAP1 and CTAP2
- Append flags and counter before AssertionObject.u2f_sign_data() to make it identical to the CTAP1 response

* openssl: Add incomplete verify()-function to test if signature is valid. Add some commented out code on how to eventually use it

* Make Challenge a base64-encoded String

* Make RegisterResult-matching agnostic wrt number of result arguments

* Add to_vec() function to AuthenticatorData, to be able to easily serialize it again for the answer back to the RelyingParty

* Add function to serialize Alg for passing the answer to C

* Add rust_u2f_resbuf_contains to capi, to check whether certain keys are set in the result-hashmap or not (for determining if its a ctap2 or ctap1 response)

* Expose ctap2-register function to C and repackage the result accordingly

* Remove User from Ctap2-SignArgs, as it is not needed

* Expose rust_ctap2_mgr_sign() to C

* Fix bug: sign() should use WebauthnType::Get, not Create

* C-API: Introduce CTAP2.0 indicator to check whether a response is CTAP1 or 2 (used 2.0, as 2.1 will be coming soon)

* Make ctap2-sign() work

- Add client-data to CTAP2 result
- C-API: Set CTAP2 indicator in the sign-result
- C-API: Add logic to determine credential-id (if none is returned from the token, but allow_list is length 1, use that)

* Also remap PinRequired-error

* GetInfo: Remove double definition of AAGuid

* Implement Deserialize for CollectedClientData

- Implement Deserialize for WebauthnType
- Implement Deserialize for TokenBinding
- Make TokenBinding contain String, not Vec<u8> (as we get it base64-encoded from the server)
- Add some tests for it
- Fix remaining test by fixing the client_hash (reference calculated via commandline)

* Make crossOrigin not an Option anymore, as we need it when serializing. Set a default for deserializing instead.

* test: implement tests for ctap2 get_assertion

This also fixes an issue in the test frame work. Due to the drop
implementation for the test client, a panic-while-panic could occur
which prevents the developer from seeing the actual error

* Update test_get_assertion_ctap2() to new codebase

* Start to add macos support for ctap2

* Expose PIN-related errors via C-api

* Move PinErrors to toplevel error. Enhance example to ask for pin, if required.

* Avoid multiple remapping of PinErrors and map them once directly to AuthenticatorError

* Define (most) C-API constants like hashmap-IDs only once, to avoid possible mismatch between C and Rust.

* Finish up macos

* Revert "Define (most) C-API constants like hashmap-IDs only once, to avoid possible mismatch between C and Rust."

With this change, it is not possible to use the const-values in switch-case statements in C/C++.
This reverts commit d5b400252b.

* Implement HIDDevice trait for device stub / dummy, so it (hopefully) compiles on non-supported archs

* Add some explanatory comments to the HIDDevice trait

* Rename user_validation to user_verification, which is the correct term

* Wrap various RegisterArgs in structs for smaller function API and also expose MakeCredentialOptions

* Also shrink C-API for GetAssertion and expose GetAssertionOptions. Fix bug where PIN+user verification could be provided, which is not allowed

* Make User.name optional, as it is no longer required by Webauthn

* Use correct credential-id for return-value in GetAssertion. Use the old path as a Fallback in case nothing is found

* Fix broken prev. commit.

* Fix tests because User.name is now an option

* Make naming of CommandError variants consistent and remove redundant 'Parsing'-variant

* Replace custom error with invalid_length (even though the usage is a bit weird)

* Use From<CommandError>-trait of HIDError to avoid verbose map_err-calls, by using the shorter .into()

* Add another test with discoverable credentials

* Splitting c-api into u2f and ctap2-parts

- Add a bunch of functions to access ctap2 results
- Attestation statement is now returned as "raw cbor data", instead of individual pieces, that are re-assembled
- Including possibility to have multiple credentials upon signing in ("discoverable creds" might return more, which the user has to choose from)

* Fix bug in parsing ctap1-response (wrongly set flags), which was not according to spec

* Fix missing credential_ids in GetAssertion responses (most notably when using a CTAP1-only token)

* Only try to determine PIN-Auth, if the request is actually CTAP2

* Return the actual Adpu-Error instead of generic DeviceError

* Adjust MakeCredentialsOptions::default, as uv=true is problematic for ctap1. Let the webauthn-server specify it

* Rework crypto module, with better COSE defintions and being able to parse keys as structs instead of Vec<u8>

* Follow-up to 'Only try to determine PIN-Auth, if the request is actually CTAP2': Same for GetAssertion

* Fix bug where Challenge for CTAP1 requests was base64-encoded, which is wrong

* Challenge only has to be 32 bytes in case of CTAP1-mapping, not in general

* C-API: Add functions to copy username from GetAssertions

* Implement hmac-secret extension

* Remove old, commented out code

Co-authored-by: Martin Sirringhaus <>
Co-authored-by: Dominik Süß <dominik@suess.wtf>
Co-authored-by: William Brown <william@blackhats.net.au>
2022-01-25 17:42:30 +01:00
msirringhaus 33c26aa250
Implement all commands of Ctap2 (#154)
* WIP: Add part MakeCredentials

* Add test for (and do some fixes) for MakeCredential CTAP1 mapping

* Adjust tests with RelyingParty and name-field

* Fix serialization of MakeCredentialOptions (individually serialize members)

* Temporarily parse credential_public_key just as a byte-vector, until COSE-crate is added and able to actually parse it

* Add Option Unparsed to AttestationStatement, to currently skip parsing it (which would need a DER-parser)

* Add commands GetAssertion and GetAssertionNext. Still missing tests.

* WIP: Add clientpin command with all the crypto functionality commented out

* Remove duplicate Pin-definition

* MakeCredentials and GetAssertion now do not store Pin but PinAuth, which has to be calculated before hand

* MakeCredentials: Remove pointless alias for HIDError

* GetInfo: Fix wrong parsing of response. Forgot to strip away the status-byte

* Make naming of CommandError variants consistent and remove redundant 'Parsing'-variant

* Replace custom error with invalid_length (even though the usage is a bit weird)

* Use From<CommandError>-trait of HIDError to avoid verbose map_err-calls, by using the shorter .into()

Co-authored-by: Martin Sirringhaus <>
2021-11-15 10:59:17 -08:00
msirringhaus 3377167cc1
WIP: CTAP2 support (#150)
* Moving platform specific modules into new module 'transport'

* Replace capability-defines with bitflags (and add ctap2 capabilities)

* Make HID commands its own type

* Run cargo fmt and clippy

* Add test for U2F_VERSION

* CTAP2: Implement first ctap2-command GetInfo as well as ctap1-fallback GetVersion, plus tests

* Sort CTAPHID const values according to value

Co-authored-by: Martin Sirringhaus <>
2021-06-11 09:31:14 -07:00
J.C. Jones 660a701b45
Ensure OpenBSD has `use std::io` (#140)
* Ensure OpenBSD has `use std::io`

Fix #139 and https://bugzilla.mozilla.org/show_bug.cgi?id=1666701

* Version bump 0.3.1
2020-10-07 09:18:20 -07:00
J.C. Jones 5b27c97ce9
Rust 1.46 clippy fixes (#135)
* Fix linux unneeded extra

* Other clippy issues

* Review update

* Clippy for the webdriver feature, also enable in CI

* More clippy

* More clippy
2020-09-17 10:48:39 -07:00
J.C. Jones 026ce088b9 Fix webdriver tests on the rebase 2020-09-17 10:22:17 -07:00
J.C. Jones 7d732d75fe Rebase on v0.3.0 new errors, etc. 2020-09-17 10:22:17 -07:00
J.C. Jones ec2d1bc5ed Review feedback 2020-09-17 10:22:17 -07:00
J.C. Jones 3a9a892099 Add all WebDriver methods to control TestToken 2020-09-17 10:22:17 -07:00
J.C. Jones 385b25d182 WebDriver implementation 2020-09-17 10:22:17 -07:00
J.C. Jones 6f913a2cbb Review update 2020-09-10 13:24:37 -07:00
J.C. Jones 75179d6cfb Update all other platforms with the new error mechanism 2020-09-10 13:24:37 -07:00
J.C. Jones 5b475603b1 Better errors - only MacOS 2020-09-10 13:24:37 -07:00
J.C. Jones 1ebb134e71 Absorb status updates at the C API, rather than letting the channel error
Issue #132 will plumb the status channel through to the actual C API signatures.

Fixes #131
2020-09-10 10:34:25 -07:00
J.C. Jones a73c504f31 Add a higher-level AuthenticatorService that can query multiple backends
- This moves the callback mechanism into its own file, as it gets more complex
- Reworks the C API to use the AuthenticatorService
2020-08-18 09:47:12 -07:00
J.C. Jones 51c576a2db Create status channel for MacOS 2020-08-10 14:58:49 -07:00
J.C. Jones c270f85038 Check CFGetTypeID for GetProperty on MacOS 2020-08-10 14:49:25 -07:00
J.C. Jones b820bd23dc Add authenticator USB and Firmware details to the C API
Fixes #92
2020-08-10 14:49:25 -07:00
J.C. Jones 663408ee0f edition 2018 fix for OpenBSD
Also line ending in run_cross.sh
2020-08-06 13:46:22 -07:00
J.C. Jones 9f365c6c34 stub fix 2020-08-06 13:25:35 -07:00
J.C. Jones 43c3bb0b9c cargo fix freebsd 2020-08-06 13:25:35 -07:00
J.C. Jones 2f671b1507 more targets 2020-08-06 13:25:35 -07:00
J.C. Jones df2d127278 cargo fix, move to edition 2018 2020-08-06 13:25:35 -07:00
J.C. Jones 9c65976d8a Without having to cheat with a closure, static lifetime no longer is necessary for the StateCallback's Fn trait. Thanks Dana 2020-08-03 20:31:00 -07:00
J.C. Jones e4cbf17b81 Rework callbacks in all other platforms 2020-08-03 20:31:00 -07:00
J.C. Jones d5d1a49424 Genericize StateCallback for MacOS 2020-08-03 20:31:00 -07:00
J.C. Jones c67bdd9e98 Remove boxfnonce and rename to StateCallback on MacOS 2020-08-03 20:31:00 -07:00
J.C. Jones db432d1213 Fixup Device struct initialization 2020-07-27 20:22:55 -07:00
J.C. Jones 4f9b817ec4 Switch to mem::MaybeUninit 2020-07-27 20:22:55 -07:00
J.C. Jones 8fc3deade5 rustfmt src/linux 2020-07-27 13:17:16 -07:00
J.C. Jones 72742e6e02 Fixups for PR #112 2020-07-27 10:54:55 -07:00
Fabian Henneke 8f264642c5 Extract in/out HID report sizes from descriptors
The U2F/CTAP specifications for the HID transport allow arbitrary
sizes for the HID input/output reports, not just the standard 64 bytes.
This commit adds the general logic needed to deal with varying report
sizes and implements the relevant descriptor parsing for Linux.
2020-07-22 21:57:56 -07:00
J.C. Jones 0202a14ffb rustfmt the NetBSD implementation 2020-07-22 13:02:21 -07:00
Taylor R Campbell 9ae1f96353 Add NetBSD support. 2020-07-17 14:56:16 -07:00
L. K. Post 5be4b75cfe Fix race condition causing repeated sign requests
The `break` only caused the inner loop to break, so the Transaction would
continue until the StateMachine itself is cancelled by the U2FManager,
which only happens when it is dropped.

This means that there would be a period in which the sign request is fully
done, but the manager is not yet dropped in which one or more other sign
requests can execute.
2020-06-29 12:18:15 -07:00
J.C. Jones 9015fc7e2a Catch a couple more upcoming clippy:: tags 2020-06-29 10:14:07 -07:00
Mike Hommey 043945a5d9 Add missing bindings for mips* 2020-06-29 09:26:42 -07:00
J.C. Jones 73c2d00d79 Cleanup clippy issues 2020-06-29 09:25:57 -07:00
J.C. Jones 1b1be8f682 Fix #108 - ioctl bindings for ppc64BE 2020-04-08 12:51:08 -07:00
J.C. Jones bd069c71ca Update for MacOS core-foundation v0.7.0 2020-04-08 12:09:23 -07:00
David Michael d6397f2b2d Add PowerPC (32-bit big-endian) ioctl definitions 2020-03-24 09:47:32 -07:00
Wang Qing c4768002c1 Add mips64el build support. 2020-03-10 10:04:31 -07:00
Martin Sirringhaus 9a49404301 Fix #105: Fails to build on s390x 2020-03-10 10:03:59 -07:00
J.C. Jones 2496cda472 Add newlines to avoid mercurial commit errors 2020-01-21 21:53:07 -07:00
J.C. Jones 50d63729a8 Add necessary build files for 32- and 64-bit ARM and 32-bit x86 2020-01-17 13:33:50 -07:00
Reyk Floeter a6b69fec5b Add OpenBSD support to authenticator-rs
This implementation uses OpenBSD's fido(4) interface which provides
restricted USB HID access to FIDO/U2F security keys.  fido(4) is a new
driver in OpenBSD 6.7 (6.6-current at the time of this writing);
running this code on older releases will simply not find the security
keys which is OK as full backwards compatibility is not desired.

See also: http://man.openbsd.org/fido.4
2020-01-17 11:23:44 -07:00
Jonathan Verner f68eae9984 Ignore communication on unknown channels (in HID transport protocol)
The ctap over hid protocol spec allows for different applications to
communicate with the authenticator at the same time. This is done by
allocating a "channel" for each application. An application should
ignore messages coming on channels it does not know.
(see
https://fidoalliance.org/specs/fido-v2.0-ps-20190130/fido-client-to-authenticator-protocol-v2.0-ps-20190130.html#usb-channels)

See also https://bugs.chromium.org/p/chromium/issues/detail?id=998452
for a similar bug which was fixed in chrome.
2020-01-17 11:03:03 -07:00
J.C. Jones 4ae6c62192
Update for clippy errors (#104)
* Update for clippy errors
* cargo fmt
2020-01-17 11:02:16 -07:00
J.C. Jones 066e51ba57 rustfmt 2019-10-09 13:30:57 -07:00
J.C. Jones d49a76ef3f remove unused std::mem 2019-10-09 13:30:23 -07:00
Eric Stokes d4ceec36a2 generate ioctl bindings for x86_64 2019-09-16 15:29:43 -04:00
Eric Stokes 79c5954179 make the generation of ioctl bindings an optional feature, and add bindings for powerpc64le 2019-09-16 15:24:59 -04:00
Eric Stokes 7e312b3be9 use bindgen to make linux hidraw access portable 2019-09-14 01:48:00 -04:00
Bastien Orivel 2169578675 Add a missing constant and bump version
This was added in the crate while it was in the m-c tree but was never
merged into the original repository
2019-05-22 22:25:52 +02:00
Bastien Orivel 25f637b7ad Update all the things (#75)
* Update devd-rs to 0.3

* Update rand to 0.6

* Update sha2 to 0.8

* Update base64 to 0.10

* Update env_logger to 0.6
2019-01-15 07:02:44 -07:00
J.C. Jones 9818cb7d99 rustfmt updates for rust 1.31.0 2018-12-14 10:43:02 -07:00
J.C. Jones 6b65672d13 Clang-format u2fhid-capi.h for mozilla-central 2018-12-14 10:30:42 -07:00
J.C. Jones 9bf83bc429
Fix travis (#73)
* Only do clippy on stable

* Update cargo fmt
2018-12-03 19:54:28 -07:00
J.C. Jones d1d36d1044
Fix #60 - Only use core-foundation (#71)
Earlier versions of core-foundation lacked runloop support, among other things,
prompting us to use core-foundation-sys. >0.6 supports everything needed out of
-sys, so let's retire direct use of core-foundation-sys.
2018-11-28 14:31:09 -07:00
J.C. Jones 790240a7cb
Fix #35 - Run Clippy at TravisCI, and clean up Clippy warnings (#70)
* Add fuzzing corpuses to gitignore

* Fix #35 - Run Clippy at TravisCI, and clean up Clippy warnings

Lots of this is taken from https://github.com/serianox/u2f-hid-rs/tree/ci --
thanks @serianox!
2018-10-25 12:00:37 +02:00
J.C. Jones 78a71f2b46
Make rust fmt run on "stable" only for TravisCI, and run it. (#69) 2018-10-23 01:53:29 -06:00
J.C. Jones 9a79669796 rustfmt 2018-10-22 16:22:45 +02:00
Alex Gaynor 62ddc466ce Remove unused import to resolve build warning on macOS (#68) 2018-10-22 08:21:36 -06:00
Nathan Froyd 88e8326595 use `extern "system"` rather than `extern "stdcall"` (#67)
`extern "stdcall"` really only has meaning on x86 Windows; I'm not even sure what calling `extern "stdcall"` functions on x86-64 Windows does (probably bad things?).  `extern "system"` carries the correct meaning on x86 and x86-64 (and other architectures such as AArch64), so let's use that.  (FWIW, `winapi` also uses `extern "system"` for these functions.)
2018-10-04 15:34:30 -07:00
J.C. Jones ea7244febb
Fix #65 - Update to WinAPI 0.3 (#66)
This updates to the new package layouts for the WinAPI 0.3.x crate, which doesn't appear to have had any semantic changes over 0.2.x.
2018-09-20 13:40:08 -07:00
J.C. Jones bd1f86042c Update to rustfmt-preview for travis. Update `rustfmt` 2018-06-12 09:28:13 -07:00
Greg V df493ee73a rustfmt
+ mention FreeBSD in readme
2018-06-12 09:00:59 -07:00
Greg V 398a7665f2 Add FreeBSD (uhid + devd) support
Tested with a YubiKey 4.
2018-06-12 09:00:59 -07:00
Greg V 48d87933a1 Extract hidproto module from linux::hidraw
Make the protocol parts independent of Linux code, in preparation for
adding FreeBSD support.
2018-06-12 09:00:59 -07:00
Tim Taubert d10061ae2d Bug 1464015 - Web Authentication - Rework IPC layer for future Android/Windows support r=jcj 2018-05-30 16:08:55 +02:00
Tim Taubert 85e51312c0 Bug 1460301 - Web Authentication - Don't use U2F_PING to initialize tokens r=jcj
Fixes #63
2018-05-14 17:40:21 +02:00
Tim Taubert 6d62a6ff07 Remove unused imports 2018-05-07 11:00:45 +02:00
Jeff Muizelaar a3f447c3d1 Use core-foundation to create the CFDictionary
This removes a bunch of code and takes advantage of the helpers from
core-foundation.
2018-05-04 15:21:20 -04:00
Jeff Muizelaar 547a1d7f32 Update to core-foundation-sys 0.6.0 2018-05-04 15:06:47 -04:00
Tim Taubert acf6c21a4c Bug 1459173 - Web Authentication - rustfmt u2f-hid-rs r=jcj 2018-05-04 14:41:24 +02:00
Tim Taubert ade23f7956 Sync logging changes from mozilla-central 2018-04-23 12:05:35 +02:00
Tim Taubert 198fefad6f Bug 1444547 - Propagate proper error codes from u2f-hid-rs to WebAuthn r=jcj 2018-03-14 20:09:56 +01:00
Matt Brubeck 6cf5280443 Bug 1443248 - Udpate u2fhid crate to depend on core-foundation-sys 0.5 r=ttaubert 2018-03-07 12:09:39 +01:00
Tim Taubert edba11b056 Bug 1442557 - [u2f-hid-rs] Keep polling excluded devices when creating credentials r=jcj 2018-03-02 16:09:04 +01:00
J.C. Jones 275ab2d98d rustfmt 2018-02-26 09:08:20 -07:00
Tim Taubert f112c44307 Bug 1406471 - Web Authentication - Implement FIDO AppID Extension r=jcj,smaug 2018-02-22 11:11:47 +01:00
Tim Taubert 90ceba1249 Bug 1437487 - [u2f-hid-rs] Allow passing an empty key handles list r=jcj 2018-02-12 16:04:52 +01:00
Tim Taubert 6dded23378 Bug 1406467 - Web Authentication - WD-07 Updates to Make Assertion r=jcj,smaug
Summary:
Add support for PublicKeyCredentialRequestOptions.userVerification. For now
this basically means that we'll abort the operation with NotAllowed, as we
don't support user verification yet.

Pass PublicKeyCredentialDescriptor.transports through to the token manager
implementations. The softoken will ignore those and pretend to support all
transports defined by the spec. The USB HID token will check for the "usb"
transport and either ignore credentials accordingly, or abort the operation.

Note: The `UserVerificationRequirement` in WebIDL is defined at https://w3c.github.io/webauthn/#assertion-options

Reviewers: jcj, smaug

Reviewed By: jcj, smaug

Bug #: 1406467

Differential Revision: https://phabricator.services.mozilla.com/D338
2018-01-10 10:55:38 +01:00
Tim Taubert 08d3b5495d Bug 1406462 - Web Authentication - Add support for authenticator selection criteria and attachment types r=jcj 2017-11-30 10:38:36 +01:00
Tim Taubert ed0728d259 One StateMachine to rule them all, fixes #58 2017-11-21 19:39:09 +01:00
Tim Taubert 296f6707b3 Remove KeyHandleMatcher, Implement per-device threads on Windows, fixes #47 2017-11-21 11:57:29 +01:00
Tim Taubert 7d9f31a8a2
Merge pull request #56 from ttaubert/no-khmatcher-linux
Linux-part of #47: Implement per-device threads, don't use the KeyHandleMatcher
2017-11-20 18:04:02 +01:00
Tim Taubert 3272176783 Linux-part of #47: Implement per-device threads, don't use the KeyHandleMatcher 2017-11-20 18:03:11 +01:00
Tim Taubert ceede2fd8e Follow-up: CFRelease() the IOHIDManager in the SendableRunLoop test 2017-11-17 10:05:03 +01:00
Tim Taubert 1b1d79e653 Let stubs fail, instead of running until cancellation 2017-11-16 16:17:52 -07:00
Tim Taubert c02ac553ca Use CFRetain() to ensure the CFRunLoop! is kept alive as long as we need it 2017-11-16 16:17:23 -07:00
Tim Taubert ef4332519a Small cleanup macos::Transaction::new() 2017-11-15 04:55:41 +01:00
Tim Taubert a6f911dbdc Rewrite macOS IOHIDManager communication and state machine r=jcj 2017-11-14 11:22:52 +01:00
Andrew McCreight 368c327ec7 Bug 1412125, part 2 - Fix dom/ mode lines. r=qdot
This was automatically generated by the script modeline.py.

MozReview-Commit-ID: BgulzkGteAL
2017-11-01 17:30:48 +01:00
Alex Gaynor fc0c9bfe68 Remove unnescary `mut` 2017-10-26 21:14:28 -05:00
Tim Taubert d52c7a1deb Bug 1404556 - Support libc::ioctl() call on musl libc 2017-10-04 12:12:55 +02:00
Tim Taubert 674c4769c4 Bug 1400668 - Fix Android builds by adding the key_handles arg to the stub PlatformManager 2017-09-21 16:25:20 +02:00
Tim Taubert 4d965aacd7 Bug 1400668 - Process key handle exclusion list when registering a token r=jcj 2017-09-21 16:11:18 +02:00
Tim Taubert d5e05c2fd0 rustfmt fixes 2017-09-19 16:42:14 +02:00
Tim Taubert 75cea47bf3 Bug 1400559 - Move runloop code into its own crate r=jcj 2017-09-19 16:02:20 +02:00
Ralph Giles 306c753275 Bug 1400927 - Fix Android build. r?jcj
One cannot use #[cfg(target_os)] checks in build.rs.
Build scripts can be used to generate code so the target
is set to the host platform when they are compiled.

Having this setting exported an unconditional link
depencency whenever the host was macOS, which broke
cross-compiling, in particular for fennec builds
targetting Android.

Instead, declare the IOKit dependency on the `extern`
block which imports the symbol inside macOS-specific
code. That way final link still works, but the extra
dependency is only enabled when appropriate for the
final target, like the other platform-dependent code.
2017-09-18 20:49:54 -07:00
Jan Beich e3919dce4b All unsupported platforms to use stub
error[E0432]: unresolved import `platform::PlatformManager`
  --> src/manager.rs:10:5
   |
10 | use platform::PlatformManager;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^ Maybe a missing `extern crate platform;`?
2017-09-14 18:00:19 -07:00
Tim Taubert d17dd0501c Update C API type names to be a tad more expressive 2017-09-14 15:48:48 +02:00
Tim Taubert 2f09d61559 Cleanup linux/hidraw, support long item format 2017-09-14 14:44:29 +02:00
J.C. Jones c02a80e085 Add MPL license 2017-09-13 15:47:07 -07:00
Tim Taubert 76c5a43c50 Take 2-byte status instead of separate hi,lo arguments 2017-08-30 21:53:40 +02:00
Tim Taubert f8d68cac4a fixes #39: properly unpack status codes from APDUs 2017-08-30 12:47:01 +02:00
J.C. Jones a44835b64b Add a stub for Android, so that builds on Android compile OK. 2017-08-28 16:07:52 -07:00
Manish Goregaokar 5e6149efc3 Fix most clippy issues 2017-08-10 16:18:55 -07:00
J.C. Jones f2c806e985 Fix 32-bit builds on Windows
Windows' calls to SetupDiGetDeviceInterfaceDetailW were failing on 32-bit
builds because the contract to provide a "DeviceInterfaceDetailData" struct
with an internal size "cbSize" equal to the size of the struct wasn't being
fulfilled. Sizeof(DeviceInterfaceDetailData) on 64-bit is 8 bytes, whereas
on 32-bit it is 4 bytes. The API documentation [1] says that the "cbSize"
should always be sizeof, but setting it to the struct size is actually wrong,
as it's mis-packed. Various references point out that the correct [2][3]
size is 4 bytes + the size of a TCHAR, e.g., 6 bytes.

[1] https://msdn.microsoft.com/en-us/library/windows/hardware/ff551120(v=vs.85).aspx
[2] http://pinvoke.net/default.aspx/setupapi.SetupDiGetDeviceInterfaceDetail
[3] https://stackoverflow.com/questions/30981181/c-sharp-usb-driver-from-c-setupdigetdeviceinterfacedetail
2017-08-08 17:20:17 -07:00
Tim Taubert f7f081935d Remove some duplicate code from DeviceMap implementations 2017-08-08 16:22:57 +02:00
Tim Taubert 27325341ae Some more minor cleanup 2017-08-08 16:01:52 +02:00
Tim Taubert 7b2b253ae1 Clean up u2fproto and tests 2017-08-08 15:25:10 +02:00
Tim Taubert a05cacbf95 macOS: fix UAF for real by boxing Device.scratch_buf[] 2017-08-04 17:33:40 +02:00
Tim Taubert 79d09e9f79 Make u2f_version_is_v2() return an io::Result<bool> 2017-08-04 11:38:16 +02:00
Tim Taubert 6ea2461597 Remove IOHIDDeviceID and make IOHIDDeviceRef a proper struct that derives what we need 2017-08-04 00:12:03 +02:00
Tim Taubert aeddb5cfa8 Fixes #8: Add runloop tests 2017-08-03 22:49:48 +02:00
Tim Taubert 9537c9ac48 macOS: Add DeviceMap to track devices in the platform manager 2017-08-03 16:22:19 +02:00
Tim Taubert 2e9262e0ed macOS: Move HID input report handling to the Device 2017-08-03 16:06:50 +02:00
Tim Taubert bd8c4a7e1c macOS: fix UAF by storing scratch_buf[] with the Device 2017-08-03 15:38:31 +02:00
Tim Taubert e62c5fe880 macOS: remove unsafe Report type and use Vec<u8> instead 2017-08-03 15:36:01 +02:00
Tim Taubert cbea18b5d0 Move set_report() into Device::write() 2017-08-03 15:28:27 +02:00
Tim Taubert 38ea83fb0b Fixes #28: Start fuzzing U2F HID protocol parsers and writers 2017-08-03 15:15:47 +02:00
Tim Taubert 4ceee629ab Simplify U2F packet communication, remove unused fields 2017-08-02 23:05:27 +02:00
Tim Taubert 3160df4554 Fixes #26: Copy bytes instead of using unsafe casting for HID types 2017-08-02 19:34:56 +02:00
J.C. Jones 9111bac96d OSX HID interaction cleanup
Clean up runloops and devices correctly after an operation.
Keep track of datagram lengths from the read callback.
2017-07-31 18:12:00 -07:00
J.C. Jones 34ebfe9861 Be safer with from_u8_array and byte layouts
- from_u8_array is dangerous; it can cast improper arrays into structures.
  Note that this change leaves it still dangerous for buffer underruns, where
  it might walk onto someting else on the stack.

- The byte layouts for the structures were marked packed, which as of Rust 1.0
  has undefined behavior. So switch to repr(C), which is what we want anyway.[1]

[1] https://doc.rust-lang.org/nomicon/other-reprs.html#reprc
2017-07-31 18:12:00 -07:00
J.C. Jones 0c69e5ac5a Fix #24: Refactor unwrap instances to be safe 2017-07-31 13:19:13 -07:00
Tim Taubert 5c49632b3d Let the C API generate and return random transaction IDs (instead of taking them as arguments) 2017-07-28 11:59:25 +02:00
J.C. Jones 6da667a37f Run rustfmt, and configure Travis to enforce rustfmt. 2017-07-27 10:00:53 -07:00
Tim Taubert 8f202ca539 Small cleanup in macos::Device::read() 2017-07-14 19:40:42 +02:00
Tim Taubert cd93c65733 Code cleanup and some reorganization 2017-07-14 16:23:10 +02:00
Tim Taubert 0027eaa5c8 Fixes #22: Add ability to check whether a device monitor is still alive 2017-07-14 15:34:40 +02:00
Tim Taubert b5f2de37bb Fixes #21: Update Windows platform manager to new API 2017-07-14 10:27:31 +02:00
Tim Taubert 3983d1c321 Let sign() take multiple key handles and return the one that signed 2017-07-11 16:19:22 +02:00
Tim Taubert 27f2b7b8c4 Add U2FKeyHandles to C API 2017-07-11 15:33:33 +02:00
Tim Taubert 9fb318a15e Move main.rs to examples/ 2017-07-11 14:29:54 +02:00
Tim Taubert 18ddea68dc Add utils shared between all platforms 2017-07-11 12:28:39 +02:00
Tim Taubert 100c5f6ef4 Update macOS platform manager and monitor APIs to work with callbacks 2017-07-11 12:01:46 +02:00
Tim Taubert eb312fa36e Implement proper WorkQueue and callbacks, update C API 2017-07-07 19:25:45 +02:00
Tim Taubert 89aec0f1bc Remove unused generic type param 2017-06-21 14:42:09 +02:00
Tim Taubert dc8cc7ffac macOS: Implement/fix sync platform API 2017-06-20 21:32:39 +02:00
Tim Taubert 4aa1a22ea4 Remove mach dependency 2017-06-20 21:32:24 +02:00
Tim Taubert a0c3a92d2f Remove nix and bitflags dependencies 2017-06-20 15:33:45 +02:00
Tim Taubert 217accc870 Add first rough C API 2017-06-20 12:03:09 +02:00
Tim Taubert 9fe604ebf6 Make U2FManager API sync 2017-06-20 12:02:25 +02:00
J.C. Jones 218a47b1e3 Fix #7 - Move U2F protocol functions out of lib.rs into u2fprotocol.rs 2017-06-12 18:30:15 +02:00
J.C. Jones f14df129c9 Reorder module/crate declarations 2017-06-12 13:48:27 +02:00
Tim Taubert d49013e701 Small cleanup for macOS monitor events 2017-05-23 20:30:40 +02:00
Tim Taubert e9779596d2 Initial Windows support 2017-05-22 21:43:34 +02:00
Tim Taubert a43886755d Small Linux cleanup 2017-05-22 18:49:23 +02:00
J.C. Jones a27c16aab1 Move the OSX hotplug check to be on the tail end of the device loop 2017-05-17 13:33:43 -07:00
J.C. Jones 6210b90cc2 Fix #16 - Improve logging
Pull in the log crate and move all the OSX println statements to be at appropriate
log levels.

This also pulls in `env_logger`, an implementation of a logger, that obeys an
environment variable RUST_LOG. I added some notes to README.md as to how to
use it.

Optimally, we don't need `env_logger` except for tests and the binary, but
we can't eliminate it from the library form until [this PR for cargo completes](https://github.com/rust-lang/cargo/issues/1982), so we might need to refactor it out of main.rs when this becomes a Gecko lib.

But maybe not? Anyway, it's easy to change down the line.
2017-05-17 12:16:08 -07:00
J.C. Jones a8e90c7a86 Fix #1 - Minimize races that might access removed devices on OSX
This patch changes the OSX runloop so that, before attempting to access a
device, it should peek and see if there are any pending Add/Remove events
from the Monitor, which runs in a different thread.

Another option, which might be safer, is to use an AtomicBoolean shared between
the Monitor and the OSX platform, named something like `events_waiting`. If I'm
understanding the channel properly though, this patch's method should be OK,
and doesn't push OSX's requirements out to other platforms.

Note that the way I'm doing this - using the TryIter.size_hint - is probably
somewhat inefficient, but this already has lots of milliseconds of sleep in it,
so I'm not overly worried.
2017-05-17 12:16:02 -07:00
J.C. Jones d6ac8b45a5 Add a test for ping_device 2017-05-17 10:11:03 -07:00
J.C. Jones 20d794b04a Fix #14: Don't send real data unnecessarily
When the state machine demands we call register() to cause blinks during a sign(),
this patch sets the challenge and application parameters to all zeroes. While
not necessary for security, it's what other implementations do.
2017-05-17 10:09:15 -07:00
J.C. Jones fb07a83df3 Fix #15: Resolve randomness in unit tests
The `init_device` and `ping_device` methods both need a random of some sort,
and since we want to test those methods, it seems reasonable to - like the
challenge parameters - make the randomness be supplied by the platform. This
also lets us potentially use different random sources per platform - which is
probably not a good idea, but ... maybe?

Anyway, this unbreaks the tests.
2017-05-17 09:14:22 -07:00
J.C. Jones dff5fec3f5 Cleanup OSX Device Boxed Pointer 2017-05-17 08:29:41 -07:00
Tim Taubert c498cee4db Clean up public API exposed by the u2fhid module 2017-05-17 16:10:48 +02:00
Tim Taubert b5dd3ad2ee ref #7: Moved U2FManager to src/manager.rs 2017-05-17 16:03:15 +02:00
Tim Taubert 60facaf0e9 Small follow-up / cleanup 2017-05-17 15:39:18 +02:00
Tim Taubert ced35bc803 Fixes #5 and #13: Use IOHID device matching instead of filtering manually 2017-05-17 15:35:55 +02:00
Tim Taubert 417e3355bd fixes #4: lib.rs::init_device must use a real nonce 2017-05-17 10:59:54 +02:00
Tim Taubert 25e09d6563 Speed up and simplify communication in macOS HID device monitor 2017-05-17 09:27:02 +02:00
Tim Taubert f155002621 Small cleanup for the macOS device monitor 2017-05-16 18:18:16 +02:00
Tim Taubert 9aacf0fc26 First steps towards a new U2FManager interface 2017-05-16 14:53:39 +02:00
Tim Taubert fc9aade869 Rewrite and reorganize most of the libudev code for Linux 2017-05-15 17:04:51 +02:00
J.C. Jones 365d7b962e Update the textual thread design 2017-05-12 13:49:37 -07:00
J.C. Jones 4e45151a5c Remove the find keys method 2017-05-12 08:57:48 -07:00
J.C. Jones f3c4e7922b Add sign, and avoid shutdown hangs 2017-05-11 16:28:48 -07:00
J.C. Jones 434abb0d25 More fix 2017-05-11 10:49:28 -07:00
J.C. Jones 9b5eeefd1e Set a common API for the 'main' method 2017-05-11 10:34:23 -07:00
J.C. Jones e4df17034d Only use callbacks to add/remove devices 2017-05-11 08:35:03 -07:00
J.C. Jones cf7325aa54 Remove unnecessary status functions 2017-05-11 08:16:44 -07:00
J.C. Jones 64c0f5353e Fix perform_job_for_key state transition 2017-05-10 22:43:39 -07:00
J.C. Jones c9bdc9a727 Add a status field to the U2FDevice trait 2017-05-10 22:21:44 -07:00
J.C. Jones e19941e126 Move devices to be initialized by main, not find_keys 2017-05-10 22:21:44 -07:00
J.C. Jones 0cc7762a87 Fix memory crash in OSX 2017-05-10 22:21:44 -07:00
J.C. Jones 89b0d9f182 Change the OSX model to use a single runloop 2017-05-10 22:21:44 -07:00
Tim Taubert 00e27c0df3 Don't depend on the byteorder crate to parse device usage information 2017-05-09 16:32:24 -07:00
Tim Taubert 13457548e9 Fix HID communication on Linux 2017-05-09 12:56:18 -07:00
J.C. Jones ef0f5ce55c Merge branch 'test_fixes' 2017-05-09 09:39:38 -07:00
Tim Taubert 41a81f3543 Fix U2F device detection on Linux 2017-05-09 09:35:35 -07:00
J.C. Jones da275b1586 Fix test: Continuation numbering starts at 0 2017-05-09 08:18:54 -07:00
J.C. Jones 684625bb25 Use multiple keys, but not dynamic changes
This rev can work with multiple simultaneous keys, but only for a single
operation at a time.

It also cannot handle dynamic changes.
2017-04-21 15:03:53 -07:00
J.C. Jones 0eb4a3aa8a Fix (almost) all warnings 2017-04-19 15:55:17 -07:00
J.C. Jones c6dedbeb6d Break up main 2017-04-19 15:21:34 -07:00
J.C. Jones 70aaab417a This commit can, in the trivial case, register and sign with a single
Security Key assuming:

1) There's only one plugged in
2) It doesn't get unplugged

It uses hardcoded values, but it works end-to-end.
2017-04-19 14:12:22 -07:00
J.C. Jones 9c45cdb480 Make Register work for at least a single token. 2017-04-18 17:21:51 -07:00
J.C. Jones c5922fad60
Initial OSX support 2017-03-31 14:19:42 -07:00
Kyle Machulis 7a06fda576 Linux module cleanup, commenting 2016-11-14 12:24:12 -08:00
Kyle Machulis 5e0e3b1ba2 Test cleanup 2016-11-09 11:45:56 -08:00
Kyle Machulis cd6db9d35d Fixed APDU test. 2016-11-08 14:43:33 -08:00
Kyle Machulis 46a7666311 Move consts to own file 2016-11-08 13:30:18 -08:00
Kyle Machulis 54a441682a Code cleanup 2016-11-07 16:59:51 -08:00
Kyle Machulis 1631bba1ab Multi-part chunk sending now works 2016-11-03 18:18:33 -07:00
Kyle Machulis 6f7fa3e6c6 Start work on multi-packet data formation 2016-11-03 15:57:02 -07:00
Kyle Machulis e02b92acef Create tests for init_device 2016-11-02 15:02:22 -07:00
Kyle Machulis 1269f0b17a Detect devices, send/recv function 2016-10-28 16:49:55 -07:00
Kyle Machulis d1be468f4b feat: Get hid descriptors on linux 2016-09-29 22:18:22 -07:00
Kyle Machulis a6cec4bbe7 Adding cargo defaults 2016-09-27 12:59:28 -07:00