Skip to content

Commit

Permalink
Add crate for DNS verification (#502)
Browse files Browse the repository at this point in the history
* add dns verification library

* rename library, add test

* schema test

* add builder

* add tests

* remove unused enum case

* use builder internally

* add all the logic to the builder, remove new function

* fix position in cargo.toml
  • Loading branch information
aumetra authored Mar 17, 2024
1 parent 43cfc17 commit b837e3b
Show file tree
Hide file tree
Showing 17 changed files with 680 additions and 82 deletions.
344 changes: 269 additions & 75 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ members = [
"lib/athena",
"lib/blowocking",
"lib/cursiv",
"lib/geomjeungja",
"lib/http-compat",
"lib/http-signatures",
"lib/just-retry",
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-activitypub/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
license.workspace = true

[dependencies]
async-trait = "0.1.77"
async-trait = "0.1.78"
autometrics = { version = "1.0.1", default-features = false }
base64-simd = "0.8.0"
diesel = "2.1.5"
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license.workspace = true
build = "build.rs"

[dependencies]
async-trait = "0.1.77"
async-trait = "0.1.78"
const_format = "0.2.32"
http = "1.1.0"
kitsune-db = { path = "../kitsune-db" }
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-observability/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
license.workspace = true

[dependencies]
async-trait = "0.1.77"
async-trait = "0.1.78"
http-body-util = "0.1.1"
http-compat = { path = "../../lib/http-compat" }
hyper = { version = "1.2.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-wasm-mrf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ license.workspace = true
build = "build.rs"

[dependencies]
async-trait = "0.1.77"
async-trait = "0.1.78"
derive_more = { version = "1.0.0-beta.6", features = ["from"] }
enum_dispatch = "0.3.12"
futures-util = { version = "0.3.30", default-features = false, features = [
Expand Down
2 changes: 1 addition & 1 deletion crates/kitsune-webfinger/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version.workspace = true
license.workspace = true

[dependencies]
async-trait = "0.1.77"
async-trait = "0.1.78"
autometrics = { version = "1.0.1", default-features = false }
futures-util = "0.3.30"
http = "1.1.0"
Expand Down
2 changes: 1 addition & 1 deletion kitsune/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ askama = { version = "0.12.1", features = [
"with-axum",
], default-features = false }
askama_axum = "0.4.0"
async-trait = "0.1.77"
async-trait = "0.1.78"
axum = { version = "0.7.4", features = ["macros", "multipart"] }
axum-extra = { version = "0.9.2", features = [
"cookie",
Expand Down
2 changes: 1 addition & 1 deletion lib/cursiv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tower = { version = "0.4.13", default-features = false }
zeroize = { version = "1.7.0", features = ["derive"] }

# `axum` feature
async-trait = { version = "0.1.77", optional = true }
async-trait = { version = "0.1.78", optional = true }
axum-core = { version = "0.4.3", optional = true }

[dev-dependencies]
Expand Down
25 changes: 25 additions & 0 deletions lib/geomjeungja/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
name = "geomjeungja"
authors.workspace = true
edition.workspace = true
version.workspace = true
license = "MIT OR Apache-2.0"

[dependencies]
async-trait = "0.1.78"
hickory-resolver = { version = "0.24.0", features = ["dns-over-rustls"] }
rand = "0.8.5"
serde = { version = "1.0.197", features = ["derive"] }
simdutf8 = { version = "0.1.4", features = ["aarch64_neon"] }
thiserror = "1.0.58"
tracing = "0.1.40"
typed-builder = "0.18.1"

[dev-dependencies]
insta = { version = "1.36.1", features = ["json"] }
rand_xorshift = "0.3.0"
serde_json = "1.0.114"
tokio = { version = "1.36.0", features = ["macros", "rt"] }

[lints]
workspace = true
1 change: 1 addition & 0 deletions lib/geomjeungja/LICENSE-APACHE-2.0
1 change: 1 addition & 0 deletions lib/geomjeungja/LICENSE-MIT
13 changes: 13 additions & 0 deletions lib/geomjeungja/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# geomjeungja

Domain verification via TXT records

## About

Geomjeungja is a small library for verifying domain ownership via the user setting a TXT record.
It is only compatible with Tokio at the moment but this might change in the future.

It ships with one default verification strategy. This strategy is for validating structures looking like this: `[key]=[value]`.
In case you need anything more complicated, consider implementing your own strategy.

A strategy is an asynchronous fallible operation with its own context that operates over an iterator of string slices that represent the TXT records.
33 changes: 33 additions & 0 deletions lib/geomjeungja/examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use geomjeungja::{Error, KeyValueStrategy, Verifier};

#[tokio::main(flavor = "current_thread")]
async fn main() {
// Create a verification strategy
let verification_strategy =
KeyValueStrategy::generate(&mut rand::thread_rng(), "kakunin".into());
let verifier = Verifier::builder()
.fqdn("aumetra.xyz".into())
.strategy(verification_strategy)
.build();

// Now we store that somewhere for later verification
let serialised_strategy = serde_json::to_string(verifier.strategy()).unwrap();

// --- SOME TIME LATER ---

// Now we can deserialise it because the user told us "yeah I set that"
let deserialised_strategy: KeyValueStrategy =
serde_json::from_str(&serialised_strategy).unwrap();

// Let's check if they didn't lie
let verifier = Verifier::builder()
.fqdn("aumetra.xyz".into())
.strategy(deserialised_strategy)
.build();

match verifier.verify().await {
Ok(()) => println!("Successfully verified. All good!"),
Err(Error::Unverified) => println!("TXT records didn't contain the KV pair :("),
Err(err) => eprintln!("Something errored out. Error: {err:?}"),
}
}
Loading

0 comments on commit b837e3b

Please sign in to comment.