| 1 |
/* This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
| 4 |
|
| 5 |
#![allow(clippy::large_enum_variant)] |
| 6 |
#![allow(clippy::upper_case_acronyms)] |
| 7 |
#![allow(clippy::bool_to_int_with_if)] |
| 8 |
|
| 9 |
#[macro_use] |
| 10 |
mod util; |
| 11 |
|
| 12 |
#[cfg(target_os = "linux")] |
| 13 |
extern crate libudev; |
| 14 |
|
| 15 |
#[cfg(target_os = "freebsd")] |
| 16 |
extern crate devd_rs; |
| 17 |
|
| 18 |
#[cfg(target_os = "macos")] |
| 19 |
extern crate core_foundation; |
| 20 |
|
| 21 |
extern crate libc; |
| 22 |
#[macro_use] |
| 23 |
extern crate log; |
| 24 |
extern crate rand; |
| 25 |
extern crate runloop; |
| 26 |
|
| 27 |
#[macro_use] |
| 28 |
extern crate bitflags; |
| 29 |
|
| 30 |
mod consts; |
| 31 |
mod manager; |
| 32 |
mod statemachine; |
| 33 |
mod status_update; |
| 34 |
mod transport; |
| 35 |
mod u2ftypes; |
| 36 |
|
| 37 |
pub mod authenticatorservice; |
| 38 |
pub mod crypto; |
| 39 |
pub mod ctap2; |
| 40 |
pub mod errors; |
| 41 |
pub mod statecallback; |
| 42 |
pub use ctap2::attestation::AttestationObject; |
| 43 |
pub use ctap2::commands::bio_enrollment::BioEnrollmentResult; |
| 44 |
pub use ctap2::commands::client_pin::{Pin, PinError}; |
| 45 |
pub use ctap2::commands::credential_management::CredentialManagementResult; |
| 46 |
pub use ctap2::commands::get_assertion::{Assertion, GetAssertionResult}; |
| 47 |
pub use ctap2::commands::get_info::AuthenticatorInfo; |
| 48 |
pub use ctap2::commands::make_credentials::MakeCredentialsResult; |
| 49 |
use serde::Serialize; |
| 50 |
pub use statemachine::StateMachine; |
| 51 |
pub use status_update::{ |
| 52 |
BioEnrollmentCmd, CredManagementCmd, InteractiveRequest, InteractiveUpdate, StatusPinUv, |
| 53 |
StatusUpdate, |
| 54 |
}; |
| 55 |
pub use transport::{FidoDevice, FidoDeviceIO, FidoProtocol, VirtualFidoDevice}; |
| 56 |
|
| 57 |
// Keep this in sync with the constants in u2fhid-capi.h. |
| 58 |
bitflags! { |
| 59 |
pub struct RegisterFlags: u64 { |
| 60 |
const REQUIRE_RESIDENT_KEY = 1; |
| 61 |
const REQUIRE_USER_VERIFICATION = 2; |
| 62 |
const REQUIRE_PLATFORM_ATTACHMENT = 4; |
| 63 |
} |
| 64 |
} |
| 65 |
bitflags! { |
| 66 |
pub struct SignFlags: u64 { |
| 67 |
const REQUIRE_USER_VERIFICATION = 1; |
| 68 |
} |
| 69 |
} |
| 70 |
bitflags! { |
| 71 |
pub struct AuthenticatorTransports: u8 { |
| 72 |
const USB = 1; |
| 73 |
const NFC = 2; |
| 74 |
const BLE = 4; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
#[derive(Debug, Clone)] |
| 79 |
pub struct KeyHandle { |
| 80 |
pub credential: Vec<u8>, |
| 81 |
pub transports: AuthenticatorTransports, |
| 82 |
} |
| 83 |
|
| 84 |
pub type AppId = Vec<u8>; |
| 85 |
|
| 86 |
pub type RegisterResult = MakeCredentialsResult; |
| 87 |
pub type SignResult = GetAssertionResult; |
| 88 |
|
| 89 |
#[derive(Debug, Serialize)] |
| 90 |
pub enum ManageResult { |
| 91 |
Success, |
| 92 |
CredManagement(CredentialManagementResult), |
| 93 |
BioEnrollment(BioEnrollmentResult), |
| 94 |
} |
| 95 |
|
| 96 |
pub type ResetResult = (); |
| 97 |
|
| 98 |
impl From<ResetResult> for ManageResult { |
| 99 |
fn from(_value: ResetResult) -> Self { |
| 100 |
ManageResult::Success |
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
pub type Result<T> = std::result::Result<T, errors::AuthenticatorError>; |
| 105 |
|
| 106 |
#[cfg(test)] |
| 107 |
#[macro_use] |
| 108 |
extern crate assert_matches; |
| 109 |
|
| 110 |
#[cfg(fuzzing)] |
| 111 |
pub use consts::*; |
| 112 |
#[cfg(fuzzing)] |
| 113 |
pub use u2ftypes::*; |