authenticator_ctap2_2021/
lib.rs

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#[macro_use]
6mod util;
7
8#[cfg(any(target_os = "linux"))]
9extern crate libudev;
10
11#[cfg(any(target_os = "freebsd"))]
12extern crate devd_rs;
13
14#[cfg(any(target_os = "macos"))]
15extern crate core_foundation;
16
17extern crate libc;
18#[macro_use]
19extern crate log;
20extern crate rand;
21extern crate runloop;
22
23#[macro_use]
24extern crate bitflags;
25
26pub mod authenticatorservice;
27mod consts;
28mod statemachine;
29mod u2fprotocol;
30mod u2ftypes;
31
32mod manager;
33pub use crate::manager::U2FManager;
34
35mod capi;
36pub use crate::capi::*;
37
38pub mod ctap2;
39pub use ctap2::attestation::AttestationObject;
40pub use ctap2::client_data::CollectedClientData;
41pub use ctap2::commands::client_pin::{Pin, PinError};
42pub use ctap2::commands::get_info::AuthenticatorInfo;
43pub use ctap2::AssertionObject;
44
45mod ctap2_capi;
46pub use crate::ctap2_capi::*;
47
48pub mod errors;
49pub mod statecallback;
50mod transport;
51mod virtualdevices;
52
53mod status_update;
54pub use status_update::*;
55
56mod crypto;
57pub use crypto::COSEAlgorithm;
58
59// Keep this in sync with the constants in u2fhid-capi.h.
60bitflags! {
61    pub struct RegisterFlags: u64 {
62        const REQUIRE_RESIDENT_KEY        = 1;
63        const REQUIRE_USER_VERIFICATION   = 2;
64        const REQUIRE_PLATFORM_ATTACHMENT = 4;
65    }
66}
67bitflags! {
68    pub struct SignFlags: u64 {
69        const REQUIRE_USER_VERIFICATION = 1;
70    }
71}
72bitflags! {
73    pub struct AuthenticatorTransports: u8 {
74        const USB = 1;
75        const NFC = 2;
76        const BLE = 4;
77    }
78}
79
80#[derive(Debug, Clone)]
81pub struct KeyHandle {
82    pub credential: Vec<u8>,
83    pub transports: AuthenticatorTransports,
84}
85
86pub type AppId = Vec<u8>;
87
88pub enum RegisterResult {
89    CTAP1(Vec<u8>, u2ftypes::U2FDeviceInfo),
90    CTAP2(AttestationObject, CollectedClientData),
91}
92
93pub enum SignResult {
94    CTAP1(AppId, Vec<u8>, Vec<u8>, u2ftypes::U2FDeviceInfo),
95    CTAP2(AssertionObject, CollectedClientData),
96}
97
98pub enum InfoResult {
99    CTAP2(AuthenticatorInfo),
100}
101
102pub type ResetResult = ();
103
104pub type Result<T> = std::result::Result<T, errors::AuthenticatorError>;
105
106#[cfg(test)]
107#[macro_use]
108extern crate assert_matches;
109
110#[cfg(fuzzing)]
111pub use consts::*;
112#[cfg(fuzzing)]
113pub use u2fprotocol::*;
114#[cfg(fuzzing)]
115pub use u2ftypes::*;