mirror of
https://github.com/LordGrimmauld/yubi-oath-rs.git
synced 2025-03-03 21:34:40 +01:00
dependency cleanup
This commit is contained in:
parent
34f1c21bf0
commit
76073ac87f
7 changed files with 66 additions and 428 deletions
334
Cargo.lock
generated
334
Cargo.lock
generated
|
@ -17,56 +17,6 @@ version = "0.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b2d16507662817a6a20a9ea92df6652ee4f94f914589377d69f3b21bc5798a9"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79947af37f4177cfead1110013d678905c37501914fba0efea834c3fe9a8d60c"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "apdu-core"
|
||||
version = "0.4.0"
|
||||
|
@ -100,82 +50,12 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.2.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "755717a7de9ec452bf7f3f1a3099085deabd7f2962b861dae91ecd7a365903d2"
|
||||
dependencies = [
|
||||
"shlex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.5.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e77c3243bd94243c03672cb5154667347c457ca271254724f9f393aee1c05ff"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap-stdin"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1101d998d15574d862ee282bcb93e0cf2d192c2fb12338dec35daa91425769a9"
|
||||
dependencies = [
|
||||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.5.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.5.28"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf4ced95c6f4a675af3da73304b9ac4ed991640c36374e4b46795c49e17cf1ed"
|
||||
dependencies = [
|
||||
"heck 0.5.0",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5b63caa9aa9397e2d9480a9b13673856c78d8ac123288526c37d7839f2a86990"
|
||||
|
||||
[[package]]
|
||||
name = "cpufeatures"
|
||||
version = "0.2.17"
|
||||
|
@ -206,21 +86,6 @@ dependencies = [
|
|||
"subtle",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
|
||||
dependencies = [
|
||||
"foreign-types-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "foreign-types-shared"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
|
||||
|
||||
[[package]]
|
||||
name = "generic-array"
|
||||
version = "0.14.7"
|
||||
|
@ -237,12 +102,6 @@ version = "0.4.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||
|
||||
[[package]]
|
||||
name = "hmac"
|
||||
version = "0.12.1"
|
||||
|
@ -252,12 +111,6 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf"
|
||||
|
||||
[[package]]
|
||||
name = "iso7816-tlv"
|
||||
version = "0.4.4"
|
||||
|
@ -267,12 +120,6 @@ dependencies = [
|
|||
"untrusted",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
|
@ -292,65 +139,16 @@ dependencies = [
|
|||
"apdu-core",
|
||||
"base32",
|
||||
"base64",
|
||||
"byteorder",
|
||||
"clap",
|
||||
"clap-stdin",
|
||||
"hmac",
|
||||
"iso7816-tlv",
|
||||
"lazy_static",
|
||||
"once_cell",
|
||||
"openssl",
|
||||
"ouroboros",
|
||||
"pbkdf2",
|
||||
"pcsc",
|
||||
"regex",
|
||||
"sha1",
|
||||
"sha2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
|
||||
[[package]]
|
||||
name = "openssl"
|
||||
version = "0.10.70"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61cfb4e166a8bb8c9b55c500bc2308550148ece889be90f609377e58140f42c6"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
"once_cell",
|
||||
"openssl-macros",
|
||||
"openssl-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-macros"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "openssl-sys"
|
||||
version = "0.9.105"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b22d5b84be05a8d6947c7cb71f7c849aa0f112acd4bf51c2a7c1c988ac0a9dc"
|
||||
dependencies = [
|
||||
"cc",
|
||||
"libc",
|
||||
"pkg-config",
|
||||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ouroboros"
|
||||
version = "0.18.5"
|
||||
|
@ -368,13 +166,24 @@ version = "0.18.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c7028bdd3d43083f6d8d4d5187680d0d3560d54df4cc9d752005268b41e64d0"
|
||||
dependencies = [
|
||||
"heck 0.4.1",
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"proc-macro2-diagnostics",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pbkdf2"
|
||||
version = "0.12.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
|
||||
dependencies = [
|
||||
"digest",
|
||||
"hmac",
|
||||
"sha1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pcsc"
|
||||
version = "2.9.0"
|
||||
|
@ -482,24 +291,12 @@ dependencies = [
|
|||
"digest",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shlex"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
|
||||
|
||||
[[package]]
|
||||
name = "subtle"
|
||||
version = "2.6.1"
|
||||
|
@ -517,26 +314,6 @@ dependencies = [
|
|||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "2.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "2.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.17.0"
|
||||
|
@ -555,97 +332,12 @@ version = "0.9.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "yansi"
|
||||
version = "1.0.1"
|
||||
|
|
|
@ -2,17 +2,10 @@
|
|||
apdu-core = "0.4.0"
|
||||
base32 = "0.5.1"
|
||||
base64 = "0.22.1"
|
||||
byteorder = "1.5.0"
|
||||
clap = {version = "4.5.23", features = ["derive"]}
|
||||
clap-stdin = "0.6.0"
|
||||
hmac = "0.12.1"
|
||||
iso7816-tlv = "0.4.4"
|
||||
lazy_static = "1.5.0"
|
||||
once_cell = "1.20.2"
|
||||
openssl = "0.10.70"
|
||||
ouroboros = "0.18.5"
|
||||
# serde_json = "1.0.134"
|
||||
# serde = { version = "1.0", features = ["derive"] }
|
||||
pbkdf2 = { version = "0.12.2", features = ["sha1"] }
|
||||
pcsc = "2.9.0"
|
||||
regex = "1.11.1"
|
||||
sha1 = "0.10.6"
|
||||
|
|
15
src/args.rs
15
src/args.rs
|
@ -1,15 +0,0 @@
|
|||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
use clap::Parser;
|
||||
use clap_stdin::MaybeStdin;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[clap(name="ssg-sudo-shim", version=env!("CARGO_PKG_VERSION"),about=env!("CARGO_PKG_DESCRIPTION"), author=env!("CARGO_PKG_AUTHORS"))]
|
||||
pub struct Cli {
|
||||
/// The desktop file to search for
|
||||
pub cmd: MaybeStdin<String>,
|
||||
|
||||
/// save the local environment and reimport it in the ssh session
|
||||
#[clap(long, default_value_t = false)]
|
||||
pub keep_env: bool,
|
||||
}
|
|
@ -1,9 +1,6 @@
|
|||
#[crate_type = "lib"]
|
||||
use openssl::hash::MessageDigest;
|
||||
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
|
||||
use regex::Regex;
|
||||
use sha1::{Digest, Sha1};
|
||||
use sha2::{Sha256, Sha512};
|
||||
pub const INS_SELECT: u8 = 0xa4;
|
||||
pub const OATH_AID: [u8; 7] = [0xa0, 0x00, 0x00, 0x05, 0x27, 0x21, 0x01];
|
||||
|
||||
|
@ -21,10 +18,6 @@ pub enum ErrorResponse {
|
|||
NoSuchObject = 0x6984,
|
||||
}
|
||||
|
||||
lazy_static::lazy_static! {
|
||||
pub static ref TOTP_ID_PATTERN: Regex = Regex::new(r"^([A-Za-z0-9]+):([A-Za-z0-9]+):([A-Za-z0-9]+):([0-9]+)?:([0-9]+)$").unwrap();
|
||||
}
|
||||
|
||||
pub enum SuccessResponse {
|
||||
MoreData = 0x61,
|
||||
Okay = 0x9000,
|
||||
|
@ -74,11 +67,33 @@ pub enum HashAlgo {
|
|||
}
|
||||
|
||||
impl HashAlgo {
|
||||
pub fn get_message_digest(&self) -> openssl::hash::MessageDigest {
|
||||
// returns a function capable of hashing a byte array
|
||||
pub fn get_hash_fun(&self) -> impl Fn(&[u8]) -> Vec<u8> {
|
||||
match self {
|
||||
HashAlgo::Sha1 => MessageDigest::sha1(),
|
||||
HashAlgo::Sha256 => MessageDigest::sha256(),
|
||||
HashAlgo::Sha512 => MessageDigest::sha512(),
|
||||
HashAlgo::Sha1 => |m: &[u8]| {
|
||||
let mut hasher = Sha1::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
HashAlgo::Sha256 => |m: &[u8]| {
|
||||
let mut hasher = Sha256::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
HashAlgo::Sha512 => |m: &[u8]| {
|
||||
let mut hasher = Sha512::new();
|
||||
hasher.update(m);
|
||||
hasher.finalize().to_vec()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// returns digest output size in number of bytes
|
||||
pub fn digest_size(&self) -> usize {
|
||||
match self {
|
||||
HashAlgo::Sha1 => 20,
|
||||
HashAlgo::Sha256 => 32,
|
||||
HashAlgo::Sha512 => 64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +121,7 @@ impl OathCodeDisplay {
|
|||
pub fn new(bytes: &[u8; 5]) -> Self {
|
||||
Self {
|
||||
digits: bytes[0],
|
||||
code: BigEndian::read_u32(&bytes[1..5]),
|
||||
code: u32::from_be_bytes((&bytes[1..5]).try_into().unwrap()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
extern crate byteorder;
|
||||
mod constants;
|
||||
use constants::*;
|
||||
mod transaction;
|
||||
|
@ -6,25 +5,20 @@ use transaction::*;
|
|||
/// Utilities for interacting with YubiKey OATH/TOTP functionality
|
||||
extern crate pcsc;
|
||||
use base32::Alphabet;
|
||||
use openssl::hash::MessageDigest;
|
||||
use pbkdf2::pbkdf2_hmac_array;
|
||||
use regex::Regex;
|
||||
use sha1::Sha1;
|
||||
|
||||
use std::str::{self};
|
||||
|
||||
use base64::{engine::general_purpose, Engine as _};
|
||||
use hmac::{Hmac, Mac};
|
||||
use openssl::pkcs5::pbkdf2_hmac;
|
||||
|
||||
use std::cmp::Ordering;
|
||||
use std::hash::{Hash, Hasher};
|
||||
|
||||
use byteorder::{BigEndian, WriteBytesExt};
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub struct YubiKey<'a> {
|
||||
pub name: &'a str,
|
||||
}
|
||||
|
||||
pub fn parse_b32_key(key: String) -> u32 {
|
||||
let stripped = key.to_uppercase().replace(" ", "");
|
||||
let pad = 8 - (stripped.len() % 8);
|
||||
|
@ -146,6 +140,7 @@ fn _parse_cred_id(cred_id: &[u8], oath_type: OathType) -> (Option<String>, Strin
|
|||
};
|
||||
|
||||
if oath_type == OathType::Totp {
|
||||
let TOTP_ID_PATTERN = Regex::new(r"^((\d+)/)?(([^:]+):)?(.+)$").unwrap();
|
||||
if let Some(caps) = TOTP_ID_PATTERN.captures(&data) {
|
||||
let period_str = caps.get(2).map(|m| m.as_str()).unwrap_or("");
|
||||
let period = if !period_str.is_empty() {
|
||||
|
@ -163,27 +158,15 @@ fn _parse_cred_id(cred_id: &[u8], oath_type: OathType) -> (Option<String>, Strin
|
|||
return (None, data, DEFAULT_PERIOD.into());
|
||||
}
|
||||
} else {
|
||||
let (issuer, rest) = if let Some(pos) = data.find(':') {
|
||||
if data.chars().next() != Some(':') {
|
||||
let issuer = data[..pos].to_string();
|
||||
let rest = data[pos + 1..].to_string();
|
||||
(Some(issuer), rest)
|
||||
} else {
|
||||
(None, data)
|
||||
}
|
||||
} else {
|
||||
(None, data)
|
||||
};
|
||||
|
||||
return (issuer, rest, 0);
|
||||
let mut components = data.split(':').rev();
|
||||
let name = components.next().unwrap().to_string();
|
||||
let issuer = components.next().map(str::to_string);
|
||||
return (issuer, name, 0);
|
||||
}
|
||||
}
|
||||
|
||||
fn _get_device_id(salt: Vec<u8>) -> String {
|
||||
// Create SHA-256 hash of the salt
|
||||
let mut hasher = openssl::hash::Hasher::new(MessageDigest::sha256()).unwrap();
|
||||
hasher.update(salt.leak()).unwrap();
|
||||
let result = hasher.finish().unwrap();
|
||||
let result = HashAlgo::Sha256.get_hash_fun()(salt.leak());
|
||||
|
||||
// Get the first 16 bytes of the hash
|
||||
let hash_16_bytes = &result[..16];
|
||||
|
@ -198,36 +181,19 @@ fn _hmac_sha1(key: &[u8], message: &[u8]) -> Vec<u8> {
|
|||
}
|
||||
|
||||
fn _derive_key(salt: &[u8], passphrase: &str) -> Vec<u8> {
|
||||
let mut key = vec![0u8; 16]; // Allocate 16 bytes for the key
|
||||
pbkdf2_hmac(
|
||||
passphrase.as_bytes(),
|
||||
salt,
|
||||
1000,
|
||||
MessageDigest::sha1(),
|
||||
&mut key,
|
||||
)
|
||||
.unwrap();
|
||||
key
|
||||
pbkdf2_hmac_array::<Sha1, 16>(passphrase.as_bytes(), salt, 1000).to_vec()
|
||||
}
|
||||
|
||||
fn _hmac_shorten_key(key: &[u8], algo: MessageDigest) -> Vec<u8> {
|
||||
if key.len() > algo.block_size() {
|
||||
let mut hasher = openssl::hash::Hasher::new(algo).unwrap();
|
||||
hasher.update(key).unwrap();
|
||||
return hasher.finish().unwrap().to_vec();
|
||||
fn _hmac_shorten_key(key: &[u8], algo: HashAlgo) -> Vec<u8> {
|
||||
if key.len() > algo.digest_size() {
|
||||
algo.get_hash_fun()(key)
|
||||
} else {
|
||||
key.to_vec()
|
||||
}
|
||||
|
||||
key.to_vec()
|
||||
}
|
||||
|
||||
fn _get_challenge(timestamp: u32, period: u32) -> [u8; 8] {
|
||||
let time_step = timestamp / period;
|
||||
|
||||
let mut buffer = [0u8; 8];
|
||||
let mut cursor = &mut buffer[..];
|
||||
cursor.write_u64::<BigEndian>(time_step as u64).unwrap();
|
||||
|
||||
buffer
|
||||
return ((timestamp / period) as u64).to_be_bytes();
|
||||
}
|
||||
|
||||
fn format_code(credential: &OathCredential, timestamp: u64, truncated: &[u8]) -> OathCode {
|
||||
|
@ -345,23 +311,12 @@ impl<'a> OathSession<'a> {
|
|||
}
|
||||
|
||||
fn time_challenge(timestamp: Option<SystemTime>) -> Vec<u8> {
|
||||
let mut buf = Vec::new();
|
||||
let ts = match timestamp {
|
||||
Some(datetime) => {
|
||||
datetime
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
/ 30
|
||||
}
|
||||
None => {
|
||||
SystemTime::now()
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
/ 30
|
||||
}
|
||||
};
|
||||
buf.write_u64::<BigEndian>(ts).unwrap();
|
||||
buf
|
||||
(timestamp
|
||||
.unwrap_or_else(SystemTime::now)
|
||||
.duration_since(SystemTime::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs()
|
||||
/ 30)
|
||||
.to_be_bytes()
|
||||
.to_vec()
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
#[crate_type = "lib"]
|
||||
extern crate byteorder;
|
||||
use crate::lib_ykoath2::*;
|
||||
/// Utilities for interacting with YubiKey OATH/TOTP functionality
|
||||
extern crate pcsc;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
mod args;
|
||||
mod lib_ykoath2;
|
||||
|
||||
use lib_ykoath2::OathSession;
|
||||
|
|
Loading…
Add table
Reference in a new issue