6 Commits
Author SHA1 Message Date
nelsbrock fe984f2e43 release version 0.2.1 2025-11-01 09:42:39 +01:00
nelsbrock b1450070d1 use a bounded channel and fix panic in race condition 2025-11-01 09:40:42 +01:00
nelsbrock 241fecd8a7 release version 0.2.0 2025-10-25 19:32:59 +02:00
nelsbrock 273c1059a2 fix README.md 2025-10-25 19:28:58 +02:00
nelsbrock 1f659c33a7 stop gracefully on ctrl-c 2025-10-25 18:54:40 +02:00
nelsbrock 561a4d220b add --stop-after option 2025-10-25 13:53:38 +02:00
5 changed files with 243 additions and 180 deletions
Generated
+129 -112
View File
@@ -10,9 +10,9 @@ checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
name = "aho-corasick"
version = "1.1.3"
version = "1.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301"
dependencies = [
"memchr",
]
@@ -193,6 +193,15 @@ dependencies = [
"generic-array 0.14.9",
]
[[package]]
name = "block2"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5"
dependencies = [
"objc2",
]
[[package]]
name = "buffered-reader"
version = "1.4.0"
@@ -231,9 +240,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.2.41"
version = "1.2.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7"
checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3"
dependencies = [
"find-msvc-tools",
"shlex",
@@ -254,6 +263,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chrono"
version = "0.4.42"
@@ -280,9 +295,9 @@ dependencies = [
[[package]]
name = "clap"
version = "4.5.50"
version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623"
checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5"
dependencies = [
"clap_builder",
"clap_derive",
@@ -290,9 +305,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.50"
version = "4.5.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0"
checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a"
dependencies = [
"anstream",
"anstyle",
@@ -364,6 +379,17 @@ dependencies = [
"typenum",
]
[[package]]
name = "ctrlc"
version = "3.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790"
dependencies = [
"dispatch2",
"nix",
"windows-sys 0.61.2",
]
[[package]]
name = "digest"
version = "0.10.7"
@@ -396,6 +422,18 @@ dependencies = [
"winapi",
]
[[package]]
name = "dispatch2"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec"
dependencies = [
"bitflags",
"block2",
"libc",
"objc2",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
@@ -469,10 +507,11 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]]
name = "fingerprunk"
version = "0.1.0"
version = "0.2.1"
dependencies = [
"anyhow",
"clap",
"ctrlc",
"fancy-regex",
"num-integer",
"num_cpus",
@@ -488,9 +527,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]]
name = "flate2"
version = "1.1.4"
version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9"
checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
dependencies = [
"crc32fast",
"miniz_oxide",
@@ -508,9 +547,9 @@ dependencies = [
[[package]]
name = "generic-array"
version = "1.3.4"
version = "1.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985a5578ebdb02351d484a77fb27e7cb79272f1ba9bc24692d8243c3cfe40660"
checksum = "eaf57c49a95fd1fe24b90b3033bee6dc7e8f1288d51494cb44e627c295e38542"
dependencies = [
"rustversion",
"typenum",
@@ -591,9 +630,9 @@ dependencies = [
[[package]]
name = "icu_collections"
version = "2.0.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47"
checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43"
dependencies = [
"displaydoc",
"potential_utf",
@@ -604,9 +643,9 @@ dependencies = [
[[package]]
name = "icu_locale_core"
version = "2.0.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a"
checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6"
dependencies = [
"displaydoc",
"litemap",
@@ -617,11 +656,10 @@ dependencies = [
[[package]]
name = "icu_normalizer"
version = "2.0.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979"
checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599"
dependencies = [
"displaydoc",
"icu_collections",
"icu_normalizer_data",
"icu_properties",
@@ -632,42 +670,38 @@ dependencies = [
[[package]]
name = "icu_normalizer_data"
version = "2.0.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3"
checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a"
[[package]]
name = "icu_properties"
version = "2.0.1"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b"
checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99"
dependencies = [
"displaydoc",
"icu_collections",
"icu_locale_core",
"icu_properties_data",
"icu_provider",
"potential_utf",
"zerotrie",
"zerovec",
]
[[package]]
name = "icu_properties_data"
version = "2.0.1"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632"
checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899"
[[package]]
name = "icu_provider"
version = "2.0.0"
version = "2.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af"
checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614"
dependencies = [
"displaydoc",
"icu_locale_core",
"stable_deref_trait",
"tinystr",
"writeable",
"yoke",
"zerofrom",
@@ -732,9 +766,9 @@ dependencies = [
[[package]]
name = "js-sys"
version = "0.3.81"
version = "0.3.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305"
checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65"
dependencies = [
"once_cell",
"wasm-bindgen",
@@ -804,9 +838,9 @@ checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039"
[[package]]
name = "litemap"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956"
checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77"
[[package]]
name = "lock_api"
@@ -884,6 +918,18 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
[[package]]
name = "nix"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]]
name = "nom"
version = "7.1.3"
@@ -922,6 +968,21 @@ dependencies = [
"libc",
]
[[package]]
name = "objc2"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05"
dependencies = [
"objc2-encode",
]
[[package]]
name = "objc2-encode"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33"
[[package]]
name = "once_cell"
version = "1.21.3"
@@ -995,9 +1056,9 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "potential_utf"
version = "0.1.3"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a"
checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77"
dependencies = [
"zerovec",
]
@@ -1010,9 +1071,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]]
name = "proc-macro2"
version = "1.0.101"
version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [
"unicode-ident",
]
@@ -1176,35 +1237,6 @@ dependencies = [
"xxhash-rust",
]
[[package]]
name = "serde"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
dependencies = [
"serde_core",
]
[[package]]
name = "serde_core"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.228"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "sha1collisiondetection"
version = "0.3.4"
@@ -1212,7 +1244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f606421e4a6012877e893c399822a4ed4b089164c5969424e1b9d1e66e6964b"
dependencies = [
"digest",
"generic-array 1.3.4",
"generic-array 1.3.5",
]
[[package]]
@@ -1271,9 +1303,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]]
name = "syn"
version = "2.0.107"
version = "2.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b"
checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
dependencies = [
"proc-macro2",
"quote",
@@ -1366,9 +1398,9 @@ dependencies = [
[[package]]
name = "tinystr"
version = "0.8.1"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b"
checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869"
dependencies = [
"displaydoc",
"zerovec",
@@ -1382,9 +1414,9 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
[[package]]
name = "unicode-ident"
version = "1.0.19"
version = "1.0.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d"
checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
[[package]]
name = "unicode-xid"
@@ -1443,9 +1475,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen"
version = "0.2.104"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d"
checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60"
dependencies = [
"cfg-if",
"once_cell",
@@ -1454,25 +1486,11 @@ dependencies = [
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-backend"
version = "0.2.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19"
dependencies = [
"bumpalo",
"log",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-macro"
version = "0.2.104"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119"
checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -1480,22 +1498,22 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
version = "0.2.104"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7"
checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc"
dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
[[package]]
name = "wasm-bindgen-shared"
version = "0.2.104"
version = "0.2.105"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1"
checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76"
dependencies = [
"unicode-ident",
]
@@ -1763,9 +1781,9 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "writeable"
version = "0.6.1"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb"
checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9"
[[package]]
name = "xxhash-rust"
@@ -1775,11 +1793,10 @@ checksum = "fdd20c5420375476fbd4394763288da7eb0cc0b8c11deed431a91562af7335d3"
[[package]]
name = "yoke"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc"
checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954"
dependencies = [
"serde",
"stable_deref_trait",
"yoke-derive",
"zerofrom",
@@ -1787,9 +1804,9 @@ dependencies = [
[[package]]
name = "yoke-derive"
version = "0.8.0"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6"
checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d"
dependencies = [
"proc-macro2",
"quote",
@@ -1820,9 +1837,9 @@ dependencies = [
[[package]]
name = "zerotrie"
version = "0.2.2"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595"
checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851"
dependencies = [
"displaydoc",
"yoke",
@@ -1831,9 +1848,9 @@ dependencies = [
[[package]]
name = "zerovec"
version = "0.11.4"
version = "0.11.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b"
checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002"
dependencies = [
"yoke",
"zerofrom",
@@ -1842,9 +1859,9 @@ dependencies = [
[[package]]
name = "zerovec-derive"
version = "0.11.1"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f"
checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3"
dependencies = [
"proc-macro2",
"quote",
+2 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "fingerprunk"
version = "0.1.0"
version = "0.2.1"
authors = ["Niklas Elsbrock <mail@nelsbrock.de>"]
edition = "2024"
description = "CLI tool for brute-forcing OpenPGP keys with cool fingerprints"
@@ -12,6 +12,7 @@ categories = ["command-line-utilities"]
[dependencies]
anyhow = "1.0.100"
clap = { version = "4.5.50", features = ["derive"] }
ctrlc = "3.5.0"
fancy-regex = "0.16.2"
num-integer = "0.1.46"
num_cpus = "1.17.0"
+8 -8
View File
@@ -51,7 +51,7 @@ Also see <https://en.wikipedia.org/wiki/Hexspeak> for some further examples of "
### How long does it take?
On my machine with an AMD Ryzen 7 5800X processor, Fingerprunk is able to generate and check about
41000 keys per second. This means that for finding a fingerprint with a string of *n* specific
43500 keys per second. This means that for finding a fingerprint with a string of *n* specific
hexadecimal digits at a specific place, I could expect the following runtimes until finding the
first key:
@@ -60,15 +60,15 @@ first key:
| 1 | 16 = 16¹ | < 0.1 secs |
| 2 | 256 = 16² | < 0.1 secs |
| 3 | 4096 = 16³ | 0.1 secs |
| 4 | 65536 = 16⁴ | 1.6 secs |
| 5 | 1048576 = 16⁵ | 26 secs |
| 6 | 16777216 = 16⁶ | 7 mins |
| 4 | 65536 = 16⁴ | 1.5 secs |
| 5 | 1048576 = 16⁵ | 24 secs |
| 6 | 16777216 = 16⁶ | 6 mins |
| 7 | 268435456 = 16⁷ | 2 hours |
| 8 | 4294967296 = 16⁸ | 1 days |
| 9 | 68719476736 = 16⁹ | 19 days |
| 10 | 1099511627776 = 16¹⁰ | 310 days |
| 11 | 17592186044416 = 16¹¹ | 14 years |
| 12 | 281474976710656 = 16¹² | 218 years |
| 9 | 68719476736 = 16⁹ | 18 days |
| 10 | 1099511627776 = 16¹⁰ | 293 days |
| 11 | 17592186044416 = 16¹¹ | 13 years |
| 12 | 281474976710656 = 16¹² | 205 years |
As you can see, anything above 10 fixed digits is pretty much unfeasible, at least with a normal
personal computer.
+94 -57
View File
@@ -2,10 +2,11 @@
use std::{
fmt::{self, Write},
io::{self},
io,
num::NonZeroU64,
sync::{
atomic::{AtomicU64, Ordering},
mpsc::{self, Receiver},
atomic::{AtomicBool, AtomicU64, Ordering},
mpsc,
},
thread,
time::{Duration, Instant},
@@ -27,16 +28,25 @@ use sequoia_openpgp::{
type SecretKey = Key<SecretParts, PrimaryRole>;
#[allow(clippy::large_enum_variant)]
enum Message {
Key(SecretKey),
Stop,
}
#[derive(Clone, Debug)]
pub struct Config {
pub regex: Regex,
pub status_enabled: bool,
pub stop_after: Option<NonZeroU64>,
pub password: Option<Password>,
}
#[derive(Debug)]
pub struct Fingerprunk {
config: Config,
started_instant: Instant,
stop: AtomicBool,
counter_tried: AtomicU64,
counter_found: AtomicU64,
}
@@ -52,55 +62,90 @@ impl Fingerprunk {
pub fn new_from_config(config: Config) -> Self {
Self {
config,
started_instant: Instant::now(),
stop: AtomicBool::new(false),
counter_tried: AtomicU64::new(0),
counter_found: AtomicU64::new(0),
}
}
pub fn run(self) {
let (tx, rx) = mpsc::channel();
pub fn run(mut self) -> anyhow::Result<()> {
self.started_instant = Instant::now();
let (sender, receiver) = mpsc::sync_channel(16);
{
let sender = sender.clone();
ctrlc::set_handler(move || {
let _ = sender.send(Message::Stop);
})?;
}
thread::scope(|scope| {
const THREAD_SPAWN_EXPECT_MSG: &str = "should be able to spawn thread";
let ref_self = &self;
if self.config.status_enabled {
thread::Builder::new()
.name("status_displayer".to_string())
.spawn_scoped(scope, move || ref_self.status_displayer_thread())
.expect(THREAD_SPAWN_EXPECT_MSG);
}
let status_displayer = if self.config.status_enabled {
Some(
thread::Builder::new()
.name("status_displayer".to_string())
.spawn_scoped(scope, move || ref_self.status_displayer_thread())?,
)
} else {
None
};
for num in 0..num_cpus::get() {
let tx = tx.clone();
let sender = sender.clone();
thread::Builder::new()
.name(format!("worker-{num:03}"))
.spawn_scoped(scope, move || ref_self.worker_thread(tx))
.expect(THREAD_SPAWN_EXPECT_MSG);
.spawn_scoped(scope, move || ref_self.worker_thread(sender))?;
}
thread::Builder::new()
.name("finalizer".to_string())
.spawn_scoped(scope, move || ref_self.finalizer_thread(rx))
.expect(THREAD_SPAWN_EXPECT_MSG);
});
let mut stdout = io::stdout().lock();
// Receive and process messages from the workers and the ctrl-c handler
for message in receiver {
match message {
Message::Key(key) => {
let cert = self.key_to_cert(&key)?;
self.serialize_cert(cert, &mut stdout)?;
// Increase "found" counter and stop if enough matches have been found
let prev = self.counter_found.fetch_add(1, Ordering::Relaxed);
if self.config.stop_after.is_some_and(|s| prev + 1 == s.get()) {
break;
}
}
Message::Stop => break,
}
}
// Ask all other threads to stop
self.stop.store(true, Ordering::Relaxed);
// Unpark the status displayer thread, if existant
if let Some(status_displayer) = status_displayer {
status_displayer.thread().unpark();
}
Ok(())
})
}
fn worker_thread(&self, matches_tx: mpsc::Sender<SecretKey>) {
fn worker_thread(&self, sender: mpsc::SyncSender<Message>) {
let mut fingerprint_hex = String::with_capacity(20 * 2);
loop {
while !self.stop.load(Ordering::Relaxed) {
let key =
Key4::generate_ecc(true, Curve::Ed25519).expect("should be able to generate key");
fingerprint_hex.clear();
write!(fingerprint_hex, "{:X}", key.fingerprint())
.expect("should write into string without error");
if self.check_fingerprint(&fingerprint_hex) {
matches_tx
.send(Key::V4(key))
.expect("should be able to send key");
// The channel might already be closed here if we're stopping.
// That is fine, so we just ignore the error.
let _ = sender.send(Message::Key(Key::V4(key)));
}
self.counter_tried.fetch_add(1, Ordering::Relaxed);
}
@@ -114,21 +159,6 @@ impl Fingerprunk {
.expect("should check regex without error")
}
fn finalizer_thread(&self, matches_rx: Receiver<SecretKey>) {
let mut stdout = io::stdout().lock();
for key in matches_rx {
let cert = self
.key_to_cert(&key)
.expect("should be able to create certificate");
self.serialize_cert(cert, &mut stdout)
.expect("should be able to serialize certificate");
self.counter_found.fetch_add(1, Ordering::Relaxed);
}
}
fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> {
let sig = SignatureBuilder::new(SignatureType::DirectKey)
.set_hash_algo(HashAlgorithm::SHA512)
@@ -181,6 +211,21 @@ impl Fingerprunk {
}
fn status_displayer_thread(&self) {
const UPDATE_INTERVAL: Duration = Duration::from_millis(250);
eprint!("\n\n\n\n\n");
while !self.stop.load(Ordering::Relaxed) {
self.print_status();
// We are parking the thread instead of sleeping so we can unpark it when we want to
// stop the program.
thread::park_timeout(UPDATE_INTERVAL);
}
self.print_status();
}
fn print_status(&self) {
struct DurationDhms(Duration);
impl fmt::Display for DurationDhms {
@@ -194,28 +239,20 @@ impl Fingerprunk {
}
}
const UPDATE_INTERVAL: Duration = Duration::from_millis(250);
const FORMAT_WIDTH: usize = 12;
let start = Instant::now();
eprint!("\n\n\n\n\n");
loop {
let duration = DurationDhms(start.elapsed());
let keys = self.counter_tried.load(Ordering::Relaxed);
let keys_per_sec = keys as f64 / duration.0.as_secs_f64();
let found = self.counter_found.load(Ordering::Relaxed);
eprint!(
"\x1b[F\x1b[F\x1b[F\x1b[F\x1b[F\
let duration = DurationDhms(self.started_instant.elapsed());
let keys = self.counter_tried.load(Ordering::Relaxed);
let keys_per_sec = keys as f64 / duration.0.as_secs_f64();
let found = self.counter_found.load(Ordering::Relaxed);
eprint!(
"\x1b[F\x1b[F\x1b[F\x1b[F\x1b[F\
Time: {duration}\n\
Tried: {keys: >w$} keys\n\
Rate: {keys_per_sec: >w$.0} keys/s\n\
---\n\
Found: {found: >w$} keys\n",
w = FORMAT_WIDTH
);
thread::sleep(UPDATE_INTERVAL);
}
w = FORMAT_WIDTH
);
}
}
+10 -2
View File
@@ -1,4 +1,7 @@
use std::io::{self, IsTerminal};
use std::{
io::{self, IsTerminal},
num::NonZeroU64,
};
use anyhow::{Context as AnyhowContext, anyhow};
use clap::{ArgAction, Parser, ValueEnum};
@@ -26,6 +29,10 @@ struct Args {
#[arg(long, value_enum, default_value_t)]
status: StatusEnabled,
/// Stop once the specified number of matching keys has been found.
#[arg(long)]
stop_after: Option<NonZeroU64>,
/// Prompt for a password and use it to encrypt found keys.
///
/// By default, found keys are printed to stdout unencrypted. Use this if you actually plan to
@@ -78,10 +85,11 @@ fn main() -> anyhow::Result<()> {
let config = fingerprunk::Config {
regex: args.regex,
status_enabled: args.status.evaluate(),
stop_after: args.stop_after,
password,
};
Fingerprunk::new_from_config(config).run();
Fingerprunk::new_from_config(config).run()?;
Ok(())
}