Compare commits
9 Commits
0.2.6
...
luks2_toke
Author | SHA1 | Date | |
---|---|---|---|
c1a82b9ae6
|
|||
f774580c9c
|
|||
0b19760175
|
|||
2ec8679c47
|
|||
65e1dead8b
|
|||
478fb5e036
|
|||
1547f5e199
|
|||
5c0364587e
|
|||
9307503bdc
|
104
Cargo.lock
generated
104
Cargo.lock
generated
@@ -55,9 +55,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "backtrace-sys"
|
name = "backtrace-sys"
|
||||||
version = "0.1.35"
|
version = "0.1.36"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118"
|
checksum = "78848718ee1255a2485d1309ad9cdecfc2e7d0362dd11c6829364c6b35ae1bc7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
"libc",
|
"libc",
|
||||||
@@ -111,9 +111,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.50"
|
version = "1.0.52"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
|
checksum = "c3d87b23d6a92cd03af510a5ade527033f6aa6fa92161e2d5863a907d4c5e31d"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cexpr"
|
name = "cexpr"
|
||||||
@@ -247,9 +247,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ctap_hmac"
|
name = "ctap_hmac"
|
||||||
version = "0.4.1"
|
version = "0.4.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6b22457233b74539c53c10658eb3effb7c3d50907276dab6b5fbd8391d2b4351"
|
checksum = "c5fec79b66e3a7bc6a7ace0f4c98f0748892b36d3c5c317fadfce0344fd185dc"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"cbor-codec",
|
"cbor-codec",
|
||||||
@@ -287,7 +287,7 @@ dependencies = [
|
|||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"strsim 0.9.3",
|
"strsim 0.9.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -298,7 +298,7 @@ checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"darling_core",
|
"darling_core",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -311,7 +311,7 @@ dependencies = [
|
|||||||
"derive_builder_core",
|
"derive_builder_core",
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -323,7 +323,7 @@ dependencies = [
|
|||||||
"darling",
|
"darling",
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -363,13 +363,13 @@ checksum = "030a733c8287d6213886dd487564ff5c8f6aae10278b3588ed177f9d18f8d231"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
"synstructure",
|
"synstructure",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "fido2luks"
|
name = "fido2luks"
|
||||||
version = "0.2.6"
|
version = "0.2.8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ctap_hmac",
|
"ctap_hmac",
|
||||||
"failure",
|
"failure",
|
||||||
@@ -377,6 +377,9 @@ dependencies = [
|
|||||||
"libcryptsetup-rs",
|
"libcryptsetup-rs",
|
||||||
"ring",
|
"ring",
|
||||||
"rpassword",
|
"rpassword",
|
||||||
|
"serde",
|
||||||
|
"serde_derive",
|
||||||
|
"serde_json",
|
||||||
"structopt",
|
"structopt",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -415,9 +418,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.10"
|
version = "0.1.12"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e"
|
checksum = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
@@ -463,20 +466,21 @@ checksum = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.68"
|
version = "0.2.69"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "dea0c0405123bba743ee3f91f49b1c7cfb684eef0da0a50110f758ccf24cdff0"
|
checksum = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libcryptsetup-rs"
|
name = "libcryptsetup-rs"
|
||||||
version = "0.2.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0177fd0ec022a5adb247e13e3238309913c28102a811227ad5de6a55697f152"
|
checksum = "286a440a894fafd96c841b61c73e2053ff5b4d456820b3e04f7e88c4e8636a6b"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"either",
|
"either",
|
||||||
"libc",
|
"libc",
|
||||||
"libcryptsetup-rs-sys",
|
"libcryptsetup-rs-sys",
|
||||||
"pkg-config",
|
"pkg-config",
|
||||||
|
"semver",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
@@ -577,26 +581,26 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error"
|
name = "proc-macro-error"
|
||||||
version = "0.4.12"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "18f33027081eba0a6d8aba6d1b1c3a3be58cbb12106341c2d5759fcd9b5277e7"
|
checksum = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro-error-attr",
|
"proc-macro-error-attr",
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "proc-macro-error-attr"
|
name = "proc-macro-error-attr"
|
||||||
version = "0.4.12"
|
version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "8a5b4b77fdb63c1eca72173d68d24501c54ab1269409f6b672c85deb18af69de"
|
checksum = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
"syn-mid",
|
"syn-mid",
|
||||||
"version_check",
|
"version_check",
|
||||||
]
|
]
|
||||||
@@ -781,17 +785,11 @@ dependencies = [
|
|||||||
"rand_core 0.3.1",
|
"rand_core 0.3.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_syscall"
|
|
||||||
version = "0.1.56"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "regex"
|
name = "regex"
|
||||||
version = "1.3.6"
|
version = "1.3.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f6946991529684867e47d86474e3a6d0c0ab9b82d5821e314b1ede31fa3a4b3"
|
checksum = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aho-corasick",
|
"aho-corasick",
|
||||||
"memchr",
|
"memchr",
|
||||||
@@ -860,9 +858,9 @@ checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ryu"
|
name = "ryu"
|
||||||
version = "1.0.3"
|
version = "1.0.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "535622e6be132bccd223f4bb2b8ac8d53cda3c7a6394944d3b2b33fb974f9d76"
|
checksum = "ed3d612bc64430efeb3f7ee6ef26d590dce0c43249217bddc62112540c7941e1"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
@@ -891,6 +889,17 @@ version = "1.0.106"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
|
checksum = "36df6ac6412072f67cf767ebbde4133a5b2e88e76dc6187fa7104cd16f783399"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.106"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e549e3abf4fb8621bd1609f11dfc9f5e50320802273b12f3811a67e6716ea6c"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.10",
|
||||||
|
"quote 1.0.3",
|
||||||
|
"syn 1.0.18",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_json"
|
name = "serde_json"
|
||||||
version = "1.0.51"
|
version = "1.0.51"
|
||||||
@@ -922,9 +931,9 @@ checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "structopt"
|
name = "structopt"
|
||||||
version = "0.3.12"
|
version = "0.3.14"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c8faa2719539bbe9d77869bfb15d4ee769f99525e707931452c97b693b3f159d"
|
checksum = "863246aaf5ddd0d6928dfeb1a9ca65f505599e4e1b399935ef7e75107516b4ef"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@@ -933,15 +942,15 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "structopt-derive"
|
name = "structopt-derive"
|
||||||
version = "0.4.5"
|
version = "0.4.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3f88b8e18c69496aad6f9ddf4630dd7d585bcaf765786cb415b9aec2fe5a0430"
|
checksum = "d239ca4b13aee7a2142e6795cbd69e457665ff8037aed33b3effdc430d2f927a"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"heck",
|
"heck",
|
||||||
"proc-macro-error",
|
"proc-macro-error",
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -957,9 +966,9 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.17"
|
version = "1.0.18"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "0df0eb663f387145cab623dea85b09c2c5b4b0aef44e945d928e682fce71bb03"
|
checksum = "410a7488c0a728c7ceb4ad59b9567eb4053d02e8cc7f5c0e0eeeb39518369213"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
@@ -974,7 +983,7 @@ checksum = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -985,7 +994,7 @@ checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2 1.0.10",
|
"proc-macro2 1.0.10",
|
||||||
"quote 1.0.3",
|
"quote 1.0.3",
|
||||||
"syn 1.0.17",
|
"syn 1.0.18",
|
||||||
"unicode-xid 0.2.0",
|
"unicode-xid 0.2.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1018,12 +1027,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.1.42"
|
version = "0.1.43"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
|
checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall",
|
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -1105,9 +1113,9 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi-util"
|
name = "winapi-util"
|
||||||
version = "0.1.4"
|
version = "0.1.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fa515c5163a99cc82bab70fd3bfdd36d827be85de63737b40fcef2ce084a436e"
|
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fido2luks"
|
name = "fido2luks"
|
||||||
version = "0.2.6"
|
version = "0.2.8"
|
||||||
authors = ["shimunn <shimun@shimun.net>"]
|
authors = ["shimunn <shimun@shimun.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
@@ -14,13 +14,16 @@ categories = ["command-line-utilities"]
|
|||||||
license-file = "LICENSE"
|
license-file = "LICENSE"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
ctap_hmac = { version="0.4.1", features = ["request_multiple"] }
|
ctap_hmac = { version="0.4.2", features = ["request_multiple"] }
|
||||||
hex = "0.3.2"
|
hex = "0.3.2"
|
||||||
ring = "0.13.5"
|
ring = "0.13.5"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
rpassword = "4.0.1"
|
rpassword = "4.0.1"
|
||||||
structopt = "0.3.2"
|
structopt = "0.3.2"
|
||||||
libcryptsetup-rs = "0.2.0"
|
libcryptsetup-rs = "0.4.0"
|
||||||
|
serde_json = "1.0.51"
|
||||||
|
serde_derive = "1.0.106"
|
||||||
|
serde = "1.0.106"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
91
src/cli.rs
91
src/cli.rs
@@ -120,6 +120,14 @@ impl SecretGeneration {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn obtain_secret(&self, password_query: &str) -> Fido2LuksResult<[u8; 32]> {
|
pub fn obtain_secret(&self, password_query: &str) -> Fido2LuksResult<[u8; 32]> {
|
||||||
|
self.obtain_secret_and_credential(password_query)
|
||||||
|
.map(|(secret, _)| secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn obtain_secret_and_credential(
|
||||||
|
&self,
|
||||||
|
password_query: &str,
|
||||||
|
) -> Fido2LuksResult<([u8; 32], FidoCredential)> {
|
||||||
let mut salt = [0u8; 32];
|
let mut salt = [0u8; 32];
|
||||||
match self.password_helper {
|
match self.password_helper {
|
||||||
PasswordHelper::Stdin if !self.verify_password.unwrap_or(true) => {
|
PasswordHelper::Stdin if !self.verify_password.unwrap_or(true) => {
|
||||||
@@ -138,7 +146,7 @@ impl SecretGeneration {
|
|||||||
|
|
||||||
while let Ok(el) = start.elapsed() {
|
while let Ok(el) = start.elapsed() {
|
||||||
if el > timeout {
|
if el > timeout {
|
||||||
Err(error::Fido2LuksError::NoAuthenticatorError)?;
|
return Err(error::Fido2LuksError::NoAuthenticatorError);
|
||||||
}
|
}
|
||||||
if get_devices()
|
if get_devices()
|
||||||
.map(|devices| !devices.is_empty())
|
.map(|devices| !devices.is_empty())
|
||||||
@@ -158,10 +166,9 @@ impl SecretGeneration {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let credentials = credentials.iter().collect::<Vec<_>>();
|
let credentials = credentials.iter().collect::<Vec<_>>();
|
||||||
Ok(assemble_secret(
|
let (secret, credential) =
|
||||||
&perform_challenge(&credentials[..], &salt, timeout - start.elapsed().unwrap())?,
|
perform_challenge(&credentials[..], &salt, timeout - start.elapsed().unwrap())?;
|
||||||
&salt,
|
Ok((assemble_secret(&secret, &salt), credential.clone()))
|
||||||
))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +227,9 @@ pub enum Command {
|
|||||||
/// Will wipe all other keys
|
/// Will wipe all other keys
|
||||||
#[structopt(short = "e", long = "exclusive")]
|
#[structopt(short = "e", long = "exclusive")]
|
||||||
exclusive: bool,
|
exclusive: bool,
|
||||||
|
/// Will add an token to your LUKS 2 header, including the credential id
|
||||||
|
#[structopt(short = "t", long = "token")]
|
||||||
|
token: bool,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
existing_secret: OtherSecret,
|
existing_secret: OtherSecret,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
@@ -235,6 +245,9 @@ pub enum Command {
|
|||||||
/// Add the password and keep the key
|
/// Add the password and keep the key
|
||||||
#[structopt(short = "a", long = "add-password")]
|
#[structopt(short = "a", long = "add-password")]
|
||||||
add_password: bool,
|
add_password: bool,
|
||||||
|
// /// Will add an token to your LUKS 2 header, including the credential id
|
||||||
|
// #[structopt(short = "t", long = "token")]
|
||||||
|
// token: bool,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
replacement: OtherSecret,
|
replacement: OtherSecret,
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
@@ -254,6 +267,15 @@ pub enum Command {
|
|||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
secret_gen: SecretGeneration,
|
secret_gen: SecretGeneration,
|
||||||
},
|
},
|
||||||
|
/// Open the LUKS device using information embedded into the LUKS 2 header
|
||||||
|
#[structopt(name = "open-token")]
|
||||||
|
OpenToken {
|
||||||
|
#[structopt(env = "FIDO2LUKS_DEVICE")]
|
||||||
|
device: PathBuf,
|
||||||
|
#[structopt(env = "FIDO2LUKS_MAPPER_NAME")]
|
||||||
|
name: String,
|
||||||
|
salt: String,
|
||||||
|
},
|
||||||
/// Generate a new FIDO credential
|
/// Generate a new FIDO credential
|
||||||
#[structopt(name = "credential")]
|
#[structopt(name = "credential")]
|
||||||
Credential {
|
Credential {
|
||||||
@@ -287,27 +309,29 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
.patch(&args, Some(false))
|
.patch(&args, Some(false))
|
||||||
.obtain_secret("Password")?;
|
.obtain_secret("Password")?;
|
||||||
if *binary {
|
if *binary {
|
||||||
stdout.write(&secret[..])?;
|
stdout.write_all(&secret[..])?;
|
||||||
} else {
|
} else {
|
||||||
stdout.write(hex::encode(&secret[..]).as_bytes())?;
|
stdout.write_all(hex::encode(&secret[..]).as_bytes())?;
|
||||||
}
|
}
|
||||||
Ok(stdout.flush()?)
|
Ok(stdout.flush()?)
|
||||||
}
|
}
|
||||||
Command::AddKey {
|
Command::AddKey {
|
||||||
device,
|
device,
|
||||||
exclusive,
|
exclusive,
|
||||||
|
token,
|
||||||
existing_secret,
|
existing_secret,
|
||||||
ref secret_gen,
|
ref secret_gen,
|
||||||
luks_settings,
|
luks_settings,
|
||||||
} => {
|
} => {
|
||||||
let secret_gen = secret_gen.patch(&args, None);
|
let secret_gen = secret_gen.patch(&args, None);
|
||||||
let old_secret = existing_secret.obtain(&secret_gen, false, "Existing password")?;
|
let old_secret = existing_secret.obtain(&secret_gen, false, "Existing password")?;
|
||||||
let secret = secret_gen.obtain_secret("Password")?;
|
let (secret, credential) = secret_gen.obtain_secret_and_credential("Password")?;
|
||||||
let added_slot = luks::add_key(
|
let added_slot = luks::add_key(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
&secret,
|
&secret,
|
||||||
&old_secret[..],
|
&old_secret[..],
|
||||||
luks_settings.kdf_time.or(Some(10)),
|
luks_settings.kdf_time.or(Some(10)),
|
||||||
|
Some(&credential.id[..]).filter(|_| *token),
|
||||||
)?;
|
)?;
|
||||||
if *exclusive {
|
if *exclusive {
|
||||||
let destroyed = luks::remove_keyslots(&device, &[added_slot])?;
|
let destroyed = luks::remove_keyslots(&device, &[added_slot])?;
|
||||||
@@ -329,6 +353,7 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
Command::ReplaceKey {
|
Command::ReplaceKey {
|
||||||
device,
|
device,
|
||||||
add_password,
|
add_password,
|
||||||
|
//token,
|
||||||
replacement,
|
replacement,
|
||||||
ref secret_gen,
|
ref secret_gen,
|
||||||
luks_settings,
|
luks_settings,
|
||||||
@@ -337,9 +362,21 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
let secret = secret_gen.obtain_secret("Password")?;
|
let secret = secret_gen.obtain_secret("Password")?;
|
||||||
let new_secret = replacement.obtain(&secret_gen, true, "Replacement password")?;
|
let new_secret = replacement.obtain(&secret_gen, true, "Replacement password")?;
|
||||||
let slot = if *add_password {
|
let slot = if *add_password {
|
||||||
luks::add_key(device, &new_secret[..], &secret, luks_settings.kdf_time)
|
luks::add_key(
|
||||||
|
device,
|
||||||
|
&new_secret[..],
|
||||||
|
&secret,
|
||||||
|
luks_settings.kdf_time,
|
||||||
|
None,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
luks::replace_key(device, &new_secret[..], &secret, luks_settings.kdf_time)
|
luks::replace_key(
|
||||||
|
device,
|
||||||
|
&new_secret[..],
|
||||||
|
&secret,
|
||||||
|
luks_settings.kdf_time,
|
||||||
|
None,
|
||||||
|
)
|
||||||
}?;
|
}?;
|
||||||
println!(
|
println!(
|
||||||
"Added to password to device {}, slot: {}",
|
"Added to password to device {}, slot: {}",
|
||||||
@@ -363,14 +400,11 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
{
|
{
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
match e {
|
match e {
|
||||||
Fido2LuksError::WrongSecret if retries > 0 => (),
|
Fido2LuksError::WrongSecret if retries > 0 => {}
|
||||||
Fido2LuksError::AuthenticatorError { ref cause }
|
Fido2LuksError::AuthenticatorError { ref cause }
|
||||||
if cause.kind() == FidoErrorKind::Timeout && retries > 0 =>
|
if cause.kind() == FidoErrorKind::Timeout && retries > 0 => {}
|
||||||
{
|
|
||||||
()
|
|
||||||
}
|
|
||||||
|
|
||||||
e => break Err(e)?,
|
e => return Err(e),
|
||||||
}
|
}
|
||||||
retries -= 1;
|
retries -= 1;
|
||||||
eprintln!("{}", e);
|
eprintln!("{}", e);
|
||||||
@@ -379,6 +413,31 @@ pub fn run_cli() -> Fido2LuksResult<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: utilise salt
|
||||||
|
Command::OpenToken {
|
||||||
|
device,
|
||||||
|
name,
|
||||||
|
salt: _,
|
||||||
|
} => luks::open_container_token(
|
||||||
|
device,
|
||||||
|
&name[..],
|
||||||
|
Box::new(|creds| {
|
||||||
|
let (secret, cred) = SecretGeneration {
|
||||||
|
credential_ids: CommaSeparated(
|
||||||
|
creds
|
||||||
|
.iter()
|
||||||
|
.map(|c| HexEncoded::from_str(&c[..]).unwrap())
|
||||||
|
.collect(),
|
||||||
|
),
|
||||||
|
salt: InputSalt::String("".into()),
|
||||||
|
password_helper: Default::default(),
|
||||||
|
await_authenticator: 100,
|
||||||
|
verify_password: None,
|
||||||
|
}
|
||||||
|
.obtain_secret_and_credential("Password")?;
|
||||||
|
Ok((secret, hex::encode(cred.id)))
|
||||||
|
}),
|
||||||
|
),
|
||||||
Command::Connected => match get_devices() {
|
Command::Connected => match get_devices() {
|
||||||
Ok(ref devs) if !devs.is_empty() => {
|
Ok(ref devs) if !devs.is_empty() => {
|
||||||
println!("Found {} devices", devs.len());
|
println!("Found {} devices", devs.len());
|
||||||
|
@@ -24,7 +24,7 @@ impl Default for InputSalt {
|
|||||||
|
|
||||||
impl From<&str> for InputSalt {
|
impl From<&str> for InputSalt {
|
||||||
fn from(s: &str) -> Self {
|
fn from(s: &str) -> Self {
|
||||||
let mut parts = s.split(":").into_iter();
|
let mut parts = s.split(':');
|
||||||
match parts.next() {
|
match parts.next() {
|
||||||
Some("ask") | Some("Ask") => InputSalt::AskPassword,
|
Some("ask") | Some("Ask") => InputSalt::AskPassword,
|
||||||
Some("file") => InputSalt::File {
|
Some("file") => InputSalt::File {
|
||||||
@@ -87,6 +87,7 @@ impl InputSalt {
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum PasswordHelper {
|
pub enum PasswordHelper {
|
||||||
Script(String),
|
Script(String),
|
||||||
|
#[allow(dead_code)]
|
||||||
Systemd,
|
Systemd,
|
||||||
Stdin,
|
Stdin,
|
||||||
}
|
}
|
||||||
@@ -134,7 +135,7 @@ impl PasswordHelper {
|
|||||||
Systemd => unimplemented!(),
|
Systemd => unimplemented!(),
|
||||||
Stdin => Ok(util::read_password("Password", true)?),
|
Stdin => Ok(util::read_password("Password", true)?),
|
||||||
Script(password_helper) => {
|
Script(password_helper) => {
|
||||||
let mut helper_parts = password_helper.split(" ");
|
let mut helper_parts = password_helper.split(' ');
|
||||||
|
|
||||||
let password = Command::new((&mut helper_parts).next().unwrap())
|
let password = Command::new((&mut helper_parts).next().unwrap())
|
||||||
.args(helper_parts)
|
.args(helper_parts)
|
||||||
|
@@ -7,7 +7,7 @@ use ctap::{
|
|||||||
};
|
};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
const RP_ID: &'static str = "fido2luks";
|
const RP_ID: &str = "fido2luks";
|
||||||
|
|
||||||
pub fn make_credential_id(name: Option<&str>) -> Fido2LuksResult<FidoCredential> {
|
pub fn make_credential_id(name: Option<&str>) -> Fido2LuksResult<FidoCredential> {
|
||||||
let mut request = FidoCredentialRequestBuilder::default().rp_id(RP_ID);
|
let mut request = FidoCredentialRequestBuilder::default().rp_id(RP_ID);
|
||||||
@@ -24,11 +24,11 @@ pub fn make_credential_id(name: Option<&str>) -> Fido2LuksResult<FidoCredential>
|
|||||||
)?)
|
)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn perform_challenge(
|
pub fn perform_challenge<'a>(
|
||||||
credentials: &[&FidoCredential],
|
credentials: &'a [&'a FidoCredential],
|
||||||
salt: &[u8; 32],
|
salt: &[u8; 32],
|
||||||
timeout: Duration,
|
timeout: Duration,
|
||||||
) -> Fido2LuksResult<[u8; 32]> {
|
) -> Fido2LuksResult<([u8; 32], &'a FidoCredential)> {
|
||||||
let request = FidoAssertionRequestBuilder::default()
|
let request = FidoAssertionRequestBuilder::default()
|
||||||
.rp_id(RP_ID)
|
.rp_id(RP_ID)
|
||||||
.credentials(credentials)
|
.credentials(credentials)
|
||||||
@@ -37,13 +37,13 @@ pub fn perform_challenge(
|
|||||||
let get_assertion = |device: &mut FidoDevice| {
|
let get_assertion = |device: &mut FidoDevice| {
|
||||||
device.get_hmac_assertion(&request, &util::sha256(&[&salt[..]]), None)
|
device.get_hmac_assertion(&request, &util::sha256(&[&salt[..]]), None)
|
||||||
};
|
};
|
||||||
let (_, (secret, _)) = request_multiple_devices(
|
let (credential, (secret, _)) = request_multiple_devices(
|
||||||
get_devices()?
|
get_devices()?
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.map(|device| (device, &get_assertion)),
|
.map(|device| (device, &get_assertion)),
|
||||||
Some(timeout),
|
Some(timeout),
|
||||||
)?;
|
)?;
|
||||||
Ok(secret)
|
Ok((secret, credential))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_devices() -> Fido2LuksResult<Vec<FidoDevice>> {
|
pub fn get_devices() -> Fido2LuksResult<Vec<FidoDevice>> {
|
||||||
@@ -52,7 +52,7 @@ pub fn get_devices() -> Fido2LuksResult<Vec<FidoDevice>> {
|
|||||||
match FidoDevice::new(&di) {
|
match FidoDevice::new(&di) {
|
||||||
Err(e) => match e.kind() {
|
Err(e) => match e.kind() {
|
||||||
FidoErrorKind::ParseCtap | FidoErrorKind::DeviceUnsupported => (),
|
FidoErrorKind::ParseCtap | FidoErrorKind::DeviceUnsupported => (),
|
||||||
err => Err(FidoError::from(err))?,
|
err => return Err(FidoError::from(err).into()),
|
||||||
},
|
},
|
||||||
Ok(dev) => devices.push(dev),
|
Ok(dev) => devices.push(dev),
|
||||||
}
|
}
|
||||||
|
38
src/error.rs
38
src/error.rs
@@ -13,11 +13,13 @@ pub enum Fido2LuksError {
|
|||||||
AuthenticatorError { cause: ctap::FidoError },
|
AuthenticatorError { cause: ctap::FidoError },
|
||||||
#[fail(display = "no authenticator found, please ensure your device is plugged in")]
|
#[fail(display = "no authenticator found, please ensure your device is plugged in")]
|
||||||
NoAuthenticatorError,
|
NoAuthenticatorError,
|
||||||
#[fail(display = "luks err")]
|
#[fail(display = " {}", cause)]
|
||||||
LuksError {
|
CryptsetupError {
|
||||||
cause: libcryptsetup_rs::LibcryptErr,
|
cause: libcryptsetup_rs::LibcryptErr,
|
||||||
},
|
},
|
||||||
#[fail(display = "no authenticator found, please ensure your device is plugged in")]
|
#[fail(display = "{}", cause)]
|
||||||
|
LuksError { cause: LuksError },
|
||||||
|
#[fail(display = "{}", cause)]
|
||||||
IoError { cause: io::Error },
|
IoError { cause: io::Error },
|
||||||
#[fail(display = "supplied secret isn't valid for this device")]
|
#[fail(display = "supplied secret isn't valid for this device")]
|
||||||
WrongSecret,
|
WrongSecret,
|
||||||
@@ -46,7 +48,35 @@ pub enum AskPassError {
|
|||||||
Mismatch,
|
Mismatch,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Fail)]
|
||||||
|
pub enum LuksError {
|
||||||
|
#[fail(display = "This feature requires to the LUKS device to be formatted as LUKS 2")]
|
||||||
|
Luks2Required,
|
||||||
|
#[fail(display = "Invalid token: {}", _0)]
|
||||||
|
InvalidToken(String),
|
||||||
|
#[fail(display = "No token found")]
|
||||||
|
NoToken,
|
||||||
|
#[fail(display = "The device already exists")]
|
||||||
|
DeviceExists,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LuksError {
|
||||||
|
pub fn activate(e: LibcryptErr) -> Fido2LuksError {
|
||||||
|
match e {
|
||||||
|
LibcryptErr::IOError(ref io) => match io.raw_os_error() {
|
||||||
|
Some(1) if io.kind() == ErrorKind::PermissionDenied => Fido2LuksError::WrongSecret,
|
||||||
|
Some(17) => Fido2LuksError::LuksError {
|
||||||
|
cause: LuksError::DeviceExists,
|
||||||
|
},
|
||||||
|
_ => return Fido2LuksError::CryptsetupError { cause: e },
|
||||||
|
},
|
||||||
|
_ => Fido2LuksError::CryptsetupError { cause: e },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
use libcryptsetup_rs::LibcryptErr;
|
use libcryptsetup_rs::LibcryptErr;
|
||||||
|
use std::io::ErrorKind;
|
||||||
use std::string::FromUtf8Error;
|
use std::string::FromUtf8Error;
|
||||||
use Fido2LuksError::*;
|
use Fido2LuksError::*;
|
||||||
|
|
||||||
@@ -62,7 +92,7 @@ impl From<LibcryptErr> for Fido2LuksError {
|
|||||||
LibcryptErr::IOError(e) if e.raw_os_error().iter().any(|code| code == &1i32) => {
|
LibcryptErr::IOError(e) if e.raw_os_error().iter().any(|code| code == &1i32) => {
|
||||||
WrongSecret
|
WrongSecret
|
||||||
}
|
}
|
||||||
_ => LuksError { cause: e },
|
_ => CryptsetupError { cause: e },
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
203
src/luks.rs
203
src/luks.rs
@@ -1,23 +1,45 @@
|
|||||||
use crate::error::*;
|
use crate::error::*;
|
||||||
|
|
||||||
use libcryptsetup_rs::{CryptActivateFlags, CryptDevice, CryptInit, EncryptionFormat, KeyslotInfo};
|
use libcryptsetup_rs::{
|
||||||
|
CryptActivateFlags, CryptDevice, CryptInit, CryptTokenInfo, EncryptionFormat, KeyslotInfo,
|
||||||
|
TokenInput,
|
||||||
|
};
|
||||||
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
fn load_device_handle<P: AsRef<Path>>(path: P) -> Fido2LuksResult<CryptDevice> {
|
fn load_device_handle<P: AsRef<Path>>(path: P) -> Fido2LuksResult<CryptDevice> {
|
||||||
let mut device = CryptInit::init(path.as_ref())?;
|
let mut device = CryptInit::init(path.as_ref())?;
|
||||||
//TODO: determine luks version some way other way than just trying
|
device.context_handle().load::<()>(None, None)?;
|
||||||
let mut load = |format| device.context_handle().load::<()>(format, None).map(|_| ());
|
|
||||||
vec![EncryptionFormat::Luks2, EncryptionFormat::Luks1]
|
|
||||||
.into_iter()
|
|
||||||
.fold(None, |res, format| match res {
|
|
||||||
Some(Ok(())) => res,
|
|
||||||
Some(e) => Some(e.or(load(format))),
|
|
||||||
None => Some(load(format)),
|
|
||||||
})
|
|
||||||
.unwrap()?;
|
|
||||||
Ok(device)
|
Ok(device)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn check_luks2(device: &mut CryptDevice) -> Fido2LuksResult<()> {
|
||||||
|
match device.format_handle().get_type()? {
|
||||||
|
EncryptionFormat::Luks2 => Ok(()),
|
||||||
|
_ => Err(Fido2LuksError::LuksError {
|
||||||
|
cause: LuksError::Luks2Required,
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
struct Fido2LuksToken {
|
||||||
|
#[serde(rename = "type")]
|
||||||
|
type_: String,
|
||||||
|
credential: Vec<String>,
|
||||||
|
keyslots: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Fido2LuksToken {
|
||||||
|
fn new(credential_id: impl AsRef<[u8]>, slot: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
type_: "fido2luks\0".into(), // Doubles as c style string
|
||||||
|
credential: vec![hex::encode(credential_id)],
|
||||||
|
keyslots: vec![slot.to_string()],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn open_container<P: AsRef<Path>>(path: P, name: &str, secret: &[u8]) -> Fido2LuksResult<()> {
|
pub fn open_container<P: AsRef<Path>>(path: P, name: &str, secret: &[u8]) -> Fido2LuksResult<()> {
|
||||||
let mut device = load_device_handle(path)?;
|
let mut device = load_device_handle(path)?;
|
||||||
device
|
device
|
||||||
@@ -27,41 +49,157 @@ pub fn open_container<P: AsRef<Path>>(path: P, name: &str, secret: &[u8]) -> Fid
|
|||||||
.map_err(|_e| Fido2LuksError::WrongSecret)
|
.map_err(|_e| Fido2LuksError::WrongSecret)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn open_container_token<P: AsRef<Path>>(
|
||||||
|
path: P,
|
||||||
|
name: &str,
|
||||||
|
secret: Box<dyn Fn(Vec<String>) -> Fido2LuksResult<([u8; 32], String)>>,
|
||||||
|
) -> Fido2LuksResult<()> {
|
||||||
|
let mut device = load_device_handle(path)?;
|
||||||
|
check_luks2(&mut device)?;
|
||||||
|
|
||||||
|
let mut creds = HashMap::new();
|
||||||
|
for i in 0..256 {
|
||||||
|
let status = device.token_handle().status(i)?;
|
||||||
|
match status {
|
||||||
|
CryptTokenInfo::Inactive => break,
|
||||||
|
CryptTokenInfo::Internal(s)
|
||||||
|
| CryptTokenInfo::InternalUnknown(s)
|
||||||
|
| CryptTokenInfo::ExternalUnknown(s)
|
||||||
|
| CryptTokenInfo::External(s)
|
||||||
|
if &s != "fido2luks" =>
|
||||||
|
{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
let json = device.token_handle().json_get(i)?;
|
||||||
|
let info: Fido2LuksToken =
|
||||||
|
serde_json::from_value(json.clone()).map_err(|_| Fido2LuksError::LuksError {
|
||||||
|
cause: LuksError::InvalidToken(json.to_string()),
|
||||||
|
})?;
|
||||||
|
let slots = || {
|
||||||
|
info.keyslots
|
||||||
|
.iter()
|
||||||
|
.filter_map(|slot| slot.parse::<u32>().ok())
|
||||||
|
};
|
||||||
|
for cred in info.credential.iter().cloned() {
|
||||||
|
creds
|
||||||
|
.entry(cred)
|
||||||
|
.or_insert_with(|| slots().collect::<HashSet<u32>>())
|
||||||
|
.extend(slots());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if creds.is_empty() {
|
||||||
|
return Err(Fido2LuksError::LuksError {
|
||||||
|
cause: LuksError::NoToken,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let (secret, credential) = secret(creds.keys().cloned().collect())?;
|
||||||
|
let slots = creds.get(&credential).unwrap();
|
||||||
|
let slots = slots
|
||||||
|
.iter()
|
||||||
|
.cloned()
|
||||||
|
.map(Option::Some)
|
||||||
|
.chain(std::iter::once(None).take(slots.is_empty() as usize));
|
||||||
|
for slot in slots {
|
||||||
|
match device
|
||||||
|
.activate_handle()
|
||||||
|
.activate_by_passphrase(Some(name), slot, &secret, CryptActivateFlags::empty())
|
||||||
|
.map(|_slot| ())
|
||||||
|
.map_err(LuksError::activate)
|
||||||
|
{
|
||||||
|
Err(Fido2LuksError::WrongSecret) => (),
|
||||||
|
res => return res,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(Fido2LuksError::WrongSecret)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn add_key<P: AsRef<Path>>(
|
pub fn add_key<P: AsRef<Path>>(
|
||||||
path: P,
|
path: P,
|
||||||
secret: &[u8],
|
secret: &[u8],
|
||||||
old_secret: &[u8],
|
old_secret: &[u8],
|
||||||
iteration_time: Option<u64>,
|
iteration_time: Option<u64>,
|
||||||
|
credential_id: Option<&[u8]>,
|
||||||
) -> Fido2LuksResult<u32> {
|
) -> Fido2LuksResult<u32> {
|
||||||
let mut device = load_device_handle(path)?;
|
let mut device = load_device_handle(path)?;
|
||||||
if let Some(millis) = iteration_time {
|
if let Some(millis) = iteration_time {
|
||||||
device.settings_handle().set_iteration_time(millis)
|
device.settings_handle().set_iteration_time(millis)
|
||||||
}
|
}
|
||||||
let slot = device
|
let slot = device
|
||||||
.keyslot_handle(None)
|
.keyslot_handle()
|
||||||
.add_by_passphrase(old_secret, secret)?;
|
.add_by_passphrase(None, old_secret, secret)?;
|
||||||
|
if let Some(id) = credential_id {
|
||||||
|
/* if let e @ Err(_) = check_luks2(&mut device) {
|
||||||
|
//rollback
|
||||||
|
device.keyslot_handle(Some(slot)).destroy()?;
|
||||||
|
return e.map(|_| 0u32);
|
||||||
|
}*/
|
||||||
|
device.token_handle().json_set(TokenInput::AddToken(
|
||||||
|
&serde_json::to_value(&Fido2LuksToken::new(id, slot)).unwrap(),
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(slot)
|
Ok(slot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn find_token(
|
||||||
|
device: &mut CryptDevice,
|
||||||
|
slot: u32,
|
||||||
|
) -> Fido2LuksResult<Option<(u32, Fido2LuksToken)>> {
|
||||||
|
for i in 0..256 {
|
||||||
|
let status = device.token_handle().status(i)?;
|
||||||
|
match status {
|
||||||
|
CryptTokenInfo::Inactive => break,
|
||||||
|
CryptTokenInfo::Internal(s)
|
||||||
|
| CryptTokenInfo::InternalUnknown(s)
|
||||||
|
| CryptTokenInfo::ExternalUnknown(s)
|
||||||
|
| CryptTokenInfo::External(s)
|
||||||
|
if &s != "fido2luks" =>
|
||||||
|
{
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
};
|
||||||
|
let json = device.token_handle().json_get(i)?;
|
||||||
|
let info: Fido2LuksToken =
|
||||||
|
serde_json::from_value(json.clone()).map_err(|_| Fido2LuksError::LuksError {
|
||||||
|
cause: LuksError::InvalidToken(json.to_string()),
|
||||||
|
})?;
|
||||||
|
if info.keyslots.contains(&slot.to_string()) {
|
||||||
|
return Ok(Some((i, info)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(None)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn remove_keyslots<P: AsRef<Path>>(path: P, exclude: &[u32]) -> Fido2LuksResult<u32> {
|
pub fn remove_keyslots<P: AsRef<Path>>(path: P, exclude: &[u32]) -> Fido2LuksResult<u32> {
|
||||||
let mut device = load_device_handle(path)?;
|
let mut device = load_device_handle(path)?;
|
||||||
let mut handle;
|
|
||||||
let mut destroyed = 0;
|
let mut destroyed = 0;
|
||||||
//TODO: detect how many keyslots there are instead of trying within a given range
|
let mut tokens = Vec::new();
|
||||||
for slot in 0..1024 {
|
for slot in 0..256 {
|
||||||
handle = device.keyslot_handle(Some(slot));
|
match device.keyslot_handle().status(slot)? {
|
||||||
match handle.status()? {
|
|
||||||
KeyslotInfo::Inactive => continue,
|
KeyslotInfo::Inactive => continue,
|
||||||
KeyslotInfo::Active if !exclude.contains(&slot) => {
|
KeyslotInfo::Active | KeyslotInfo::ActiveLast if !exclude.contains(&slot) => {
|
||||||
handle.destroy()?;
|
if let Ok(_) = check_luks2(&mut device) {
|
||||||
|
if let Some((token, _)) = dbg!(find_token(&mut device, slot))? {
|
||||||
|
tokens.push(token);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
device.keyslot_handle().destroy(slot)?;
|
||||||
destroyed += 1;
|
destroyed += 1;
|
||||||
}
|
}
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
match handle.status()? {
|
|
||||||
KeyslotInfo::ActiveLast => break,
|
KeyslotInfo::ActiveLast => break,
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
if device.keyslot_handle().status(slot)? == KeyslotInfo::ActiveLast {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for token in tokens.iter() {
|
||||||
|
device
|
||||||
|
.token_handle()
|
||||||
|
.json_set(TokenInput::RemoveToken(*token))?;
|
||||||
}
|
}
|
||||||
Ok(destroyed)
|
Ok(destroyed)
|
||||||
}
|
}
|
||||||
@@ -71,13 +209,26 @@ pub fn replace_key<P: AsRef<Path>>(
|
|||||||
secret: &[u8],
|
secret: &[u8],
|
||||||
old_secret: &[u8],
|
old_secret: &[u8],
|
||||||
iteration_time: Option<u64>,
|
iteration_time: Option<u64>,
|
||||||
|
credential_id: Option<&[u8]>,
|
||||||
) -> Fido2LuksResult<u32> {
|
) -> Fido2LuksResult<u32> {
|
||||||
let mut device = load_device_handle(path)?;
|
let mut device = load_device_handle(path)?;
|
||||||
// Set iteration time not sure wether this applies to luks2 as well
|
// Set iteration time not sure wether this applies to luks2 as well
|
||||||
if let Some(millis) = iteration_time {
|
if let Some(millis) = iteration_time {
|
||||||
device.settings_handle().set_iteration_time(millis)
|
device.settings_handle().set_iteration_time(millis)
|
||||||
}
|
}
|
||||||
Ok(device
|
let slot = device
|
||||||
.keyslot_handle(None)
|
.keyslot_handle()
|
||||||
.change_by_passphrase(None, None, old_secret, secret)? as u32)
|
.change_by_passphrase(None, None, old_secret, secret)? as u32;
|
||||||
|
if let Some(id) = credential_id {
|
||||||
|
if check_luks2(&mut device).is_ok() {
|
||||||
|
let token = find_token(&mut device, slot)?.map(|(t, _)| t);
|
||||||
|
if let Some(token) = token {
|
||||||
|
device.token_handle().json_set(TokenInput::ReplaceToken(
|
||||||
|
token,
|
||||||
|
&serde_json::to_value(&Fido2LuksToken::new(id, slot)).unwrap(),
|
||||||
|
))?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(slot)
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
extern crate ctap_hmac as ctap;
|
extern crate ctap_hmac as ctap;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate serde_derive;
|
||||||
use crate::cli::*;
|
use crate::cli::*;
|
||||||
use crate::config::*;
|
use crate::config::*;
|
||||||
use crate::device::*;
|
use crate::device::*;
|
||||||
|
@@ -4,7 +4,7 @@ use std::fs::File;
|
|||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
pub fn sha256<'a>(messages: &[&[u8]]) -> [u8; 32] {
|
pub fn sha256(messages: &[&[u8]]) -> [u8; 32] {
|
||||||
let mut digest = digest::Context::new(&digest::SHA256);
|
let mut digest = digest::Context::new(&digest::SHA256);
|
||||||
for m in messages.iter() {
|
for m in messages.iter() {
|
||||||
digest.update(m);
|
digest.update(m);
|
||||||
@@ -23,7 +23,7 @@ pub fn read_password(q: &str, verify: bool) -> Fido2LuksResult<String> {
|
|||||||
{
|
{
|
||||||
Err(Fido2LuksError::AskPassError {
|
Err(Fido2LuksError::AskPassError {
|
||||||
cause: AskPassError::Mismatch,
|
cause: AskPassError::Mismatch,
|
||||||
})?
|
})
|
||||||
}
|
}
|
||||||
pass => Ok(pass),
|
pass => Ok(pass),
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user