mirror of
https://github.com/nelsbrock/fingerprunk.git
synced 2026-08-15 00:16:47 +02:00
Compare commits
3
Commits
4388ae2c5c
...
6c7a0b7461
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6c7a0b7461
|
||
|
|
6620aa898d
|
||
|
|
bbc17385a7
|
@@ -13,8 +13,9 @@ cargo install fingerprunk
|
|||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Let's say you want to find keys whose fingerprints begin with `C0FFEE` and store them `secret.asc`.
|
Let's say you want to find keys whose fingerprints begin with `C0FFEE` and store them
|
||||||
The regex for this is `^C0FFEE`. Now, simply use the following command to start the search:
|
at `secret.asc`. The regex for this is `^C0FFEE`. Now, simply use the following command to start
|
||||||
|
the search:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
fingerprunk -r '^C0FFEE' >> secret.asc
|
fingerprunk -r '^C0FFEE' >> secret.asc
|
||||||
@@ -49,25 +50,25 @@ Also see <https://en.wikipedia.org/wiki/Hexspeak> for some further examples of "
|
|||||||
|
|
||||||
### How long does it take?
|
### How long does it take?
|
||||||
|
|
||||||
On my machine with an AMD Ryzen 7 5800X Processor, Fingerprunk is able to generate and check about
|
On my machine with an AMD Ryzen 7 5800X processor, Fingerprunk is able to generate and check about
|
||||||
43300 keys per second. This means that for finding a fingerprint with a string of *n* specific
|
41000 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
|
hexadecimal digits at a specific place, I could expect the following runtimes until finding the
|
||||||
first key:
|
first key:
|
||||||
|
|
||||||
| *n* | expected tries | expected time |
|
| *n* | estimate tries | estimate time |
|
||||||
| --: | --------------: | ------------: |
|
| --: | ---------------------: | ------------: |
|
||||||
| *n* | 16ⁿ | 43300s / 16ⁿ |
|
| 1 | 16 = 16¹ | < 0.1 secs |
|
||||||
| 2 | 256 | 0.0059 secs |
|
| 2 | 256 = 16² | < 0.1 secs |
|
||||||
| 3 | 4096 | 0.0946 secs |
|
| 3 | 4096 = 16³ | 0.1 secs |
|
||||||
| 4 | 65536 | 1.5 secs |
|
| 4 | 65536 = 16⁴ | 1.6 secs |
|
||||||
| 5 | 1028576 | 24 secs |
|
| 5 | 1048576 = 16⁵ | 26 secs |
|
||||||
| 6 | 16777216 | 6.5 mins |
|
| 6 | 16777216 = 16⁶ | 7 mins |
|
||||||
| 7 | 268435456 | 103 mins |
|
| 7 | 268435456 = 16⁷ | 2 hours |
|
||||||
| 8 | 4294967296 | 27 hours |
|
| 8 | 4294967296 = 16⁸ | 1 days |
|
||||||
| 9 | 68719476736 | 18 days |
|
| 9 | 68719476736 = 16⁹ | 19 days |
|
||||||
| 10 | 1099511627776 | 293 days |
|
| 10 | 1099511627776 = 16¹⁰ | 310 days |
|
||||||
| 11 | 17592186044416 | 13 years |
|
| 11 | 17592186044416 = 16¹¹ | 14 years |
|
||||||
| 12 | 281474976710656 | 206 years |
|
| 12 | 281474976710656 = 16¹² | 218 years |
|
||||||
|
|
||||||
As you can see, anything above 8 or 9 fixed digits is pretty much unfeasible, at least with
|
As you can see, anything above 10 fixed digits is pretty much unfeasible, at least with a normal
|
||||||
a normal personal computer.
|
personal computer.
|
||||||
+32
-9
@@ -14,7 +14,7 @@ use std::{
|
|||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use num_integer::Integer;
|
use num_integer::Integer;
|
||||||
use sequoia_openpgp::{
|
use sequoia_openpgp::{
|
||||||
Cert, Packet,
|
Cert, Packet, armor,
|
||||||
crypto::Password,
|
crypto::Password,
|
||||||
packet::{
|
packet::{
|
||||||
Key,
|
Key,
|
||||||
@@ -22,7 +22,7 @@ use sequoia_openpgp::{
|
|||||||
prelude::SignatureBuilder,
|
prelude::SignatureBuilder,
|
||||||
},
|
},
|
||||||
serialize::Serialize,
|
serialize::Serialize,
|
||||||
types::{HashAlgorithm, SignatureType, SymmetricAlgorithm},
|
types::{Curve, HashAlgorithm, SignatureType, SymmetricAlgorithm},
|
||||||
};
|
};
|
||||||
|
|
||||||
type SecretKey = Key<SecretParts, PrimaryRole>;
|
type SecretKey = Key<SecretParts, PrimaryRole>;
|
||||||
@@ -92,7 +92,8 @@ impl Fingerprunk {
|
|||||||
let mut fingerprint_hex = String::with_capacity(20 * 2);
|
let mut fingerprint_hex = String::with_capacity(20 * 2);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let key = Key4::generate_ed25519().expect("should be able to generate key");
|
let key =
|
||||||
|
Key4::generate_ecc(true, Curve::Ed25519).expect("should be able to generate key");
|
||||||
fingerprint_hex.clear();
|
fingerprint_hex.clear();
|
||||||
write!(fingerprint_hex, "{:X}", key.fingerprint())
|
write!(fingerprint_hex, "{:X}", key.fingerprint())
|
||||||
.expect("should write into string without error");
|
.expect("should write into string without error");
|
||||||
@@ -117,17 +118,16 @@ impl Fingerprunk {
|
|||||||
let mut stdout = io::stdout().lock();
|
let mut stdout = io::stdout().lock();
|
||||||
|
|
||||||
for key in matches_rx {
|
for key in matches_rx {
|
||||||
let result = self
|
let cert = self
|
||||||
.key_to_cert(&key)
|
.key_to_cert(&key)
|
||||||
.and_then(|cert| cert.as_tsk().armored().serialize(&mut stdout));
|
.expect("should be able to create certificate");
|
||||||
|
|
||||||
|
self.serialize_cert(cert, &mut stdout)
|
||||||
|
.expect("should be able to serialize certificate");
|
||||||
|
|
||||||
if let Err(err) = result {
|
|
||||||
eprintln!("Error: {err}");
|
|
||||||
} else {
|
|
||||||
self.counter_found.fetch_add(1, Ordering::Relaxed);
|
self.counter_found.fetch_add(1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> {
|
fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> {
|
||||||
let sig = SignatureBuilder::new(SignatureType::DirectKey)
|
let sig = SignatureBuilder::new(SignatureType::DirectKey)
|
||||||
@@ -157,6 +157,29 @@ impl Fingerprunk {
|
|||||||
Cert::try_from(vec![secret_key_packet, Packet::from(sig)])
|
Cert::try_from(vec![secret_key_packet, Packet::from(sig)])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn serialize_cert(&self, cert: Cert, to: impl io::Write) -> anyhow::Result<()> {
|
||||||
|
let mut comments = cert.armor_headers();
|
||||||
|
comments.push(format!(
|
||||||
|
"Generated with Fingerprunk. Regex: {}",
|
||||||
|
self.config.regex
|
||||||
|
));
|
||||||
|
|
||||||
|
let headers: Vec<_> = comments
|
||||||
|
.into_iter()
|
||||||
|
.map(|s| ("Comment".to_string(), s))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let mut writer = armor::Writer::with_headers(to, armor::Kind::SecretKey, headers)?;
|
||||||
|
|
||||||
|
// Set the profile to RFC4880 because we generate v4 keys.
|
||||||
|
writer.set_profile(sequoia_openpgp::Profile::RFC4880)?;
|
||||||
|
|
||||||
|
cert.serialize(&mut writer)?;
|
||||||
|
writer.finalize()?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn status_displayer_thread(&self) {
|
fn status_displayer_thread(&self) {
|
||||||
struct DurationDhms(Duration);
|
struct DurationDhms(Duration);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user