Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.2.0 #30

Merged
merged 95 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
8c02764
docs: wip updating docker documatations
junkurihara Jan 19, 2024
f1a8019
docs: draft completed. needs review
junkurihara Jan 19, 2024
632db46
docs: update docker-otel readme
junkurihara Jan 19, 2024
898d9b1
docs: typo
junkurihara Jan 19, 2024
00953af
Merge pull request #12 from junkurihara/docs/docker
junkurihara Jan 19, 2024
f21b641
[ci skip] Update README.md
junkurihara Jan 19, 2024
d221070
chore: deps
junkurihara Jan 23, 2024
74d16c3
chore(deps): update derive_builder requirement in /modoh-bin
dependabot[bot] Jan 23, 2024
a5d5ae2
chore(deps): update derive_builder requirement from 0.12.0 to 0.13.0
dependabot[bot] Jan 23, 2024
7535596
Merge pull request #13 from junkurihara/dependabot/cargo/modoh-bin/de…
junkurihara Jan 23, 2024
aee90f1
Merge pull request #14 from junkurihara/dependabot/cargo/derive_build…
junkurihara Jan 23, 2024
4a94225
chore(deps): bump kaisugi/action-regex-match from 1.0.0 to 1.0.1
dependabot[bot] Feb 1, 2024
ca3d4a7
Merge pull request #15 from junkurihara/dependabot/github_actions/kai…
junkurihara Feb 1, 2024
3c521e7
deps
junkurihara Feb 13, 2024
a88bff1
refactor
junkurihara Feb 16, 2024
c8a87fa
deps
junkurihara Feb 19, 2024
8b5cb8a
add configuration options for httpsig
junkurihara Feb 19, 2024
1680854
add comment
junkurihara Feb 19, 2024
bca8847
wip
junkurihara Feb 20, 2024
d3f75e0
wip: dh being implemented
junkurihara Feb 21, 2024
bb4e0e6
wip: dh being implemented
junkurihara Feb 21, 2024
17339b7
deps
junkurihara Feb 22, 2024
86ca854
wip: change strategy to support both dh-based and simple asymmetric sig
junkurihara Feb 22, 2024
152aa72
wip: should we make httpsig mod separeted?
junkurihara Feb 22, 2024
b8077a8
wip: split modoh-proto from lib
junkurihara Feb 22, 2024
f197b10
wip: dh proto
junkurihara Feb 26, 2024
ea7a886
wip: serialize and deserialized mixed config vector
junkurihara Feb 26, 2024
8c81529
refactor: change name
junkurihara Feb 26, 2024
70e0151
wip: implementing message signature into modoh
junkurihara Feb 26, 2024
b08d95a
refactor
junkurihara Feb 28, 2024
71e5d5f
feat: add unstable build actions
junkurihara Feb 28, 2024
9c30fb8
Merge branch 'develop' into feat/httpsig
junkurihara Feb 28, 2024
40aeb9c
refactor: make httpsig rotator split from target
junkurihara Feb 28, 2024
e738932
fix: fix github actions build target branch
junkurihara Feb 28, 2024
4dca9a8
Merge branch 'develop' into feat/httpsig
junkurihara Feb 28, 2024
e0529ae
refactor
junkurihara Feb 28, 2024
4fb9770
update config structure
junkurihara Feb 28, 2024
6e01e46
wip: implement refetcher service for httpsig public keys
junkurihara Feb 28, 2024
77f3358
wip: refactor the api handling key rotation for httpsig
junkurihara Feb 28, 2024
efa5214
wip: implement trie based structure for domain-keyid maps
junkurihara Feb 29, 2024
1ef409e
wip: api for signing (just design args)
junkurihara Mar 1, 2024
e905dfe
wip: implemented DHKeX based signing at relay. TODO: PK based. also v…
junkurihara Mar 1, 2024
27c9318
wip: implemented PK based signing
junkurihara Mar 4, 2024
41b73a6
deps
junkurihara Mar 5, 2024
0a832e6
deps
junkurihara Mar 5, 2024
ac68954
add dh key verification
junkurihara Mar 5, 2024
e448072
wip: almost done for httpsig verification
junkurihara Mar 5, 2024
75e3295
debug messages
junkurihara Mar 6, 2024
f9b3b0a
update encoding method for nonce
junkurihara Mar 6, 2024
1d368af
instrument
junkurihara Mar 6, 2024
550c250
deps: otel
junkurihara Mar 6, 2024
ed735c3
fix: fix bug for into_iter for httpsigconfigs
junkurihara Mar 6, 2024
dd5198e
feat: store previous public keys for DH Kex to fill the time gap betw…
junkurihara Mar 7, 2024
ebaeb26
fix: change key map to use the latest dh key for signing
junkurihara Mar 7, 2024
b638b72
feat: implement transitional signing
junkurihara Mar 9, 2024
8d874a1
tmp: defined new struct of keys with generation. todo: change keyid t…
junkurihara Mar 11, 2024
63a9034
chore(deps): bump softprops/action-gh-release from 1 to 2
dependabot[bot] Mar 11, 2024
5088f6d
Merge pull request #26 from junkurihara/dependabot/github_actions/sof…
junkurihara Mar 12, 2024
1f5c309
refactor: split handler.rs
junkurihara Mar 13, 2024
99513ad
refactor: change comments
junkurihara Mar 13, 2024
fc366b5
refactor: update api of signing considering multiple signatures for g…
junkurihara Mar 13, 2024
c29a097
feat: verifier with transition margin and force refeching
junkurihara Mar 14, 2024
ad1b93f
Merge pull request #25 from junkurihara/tmp/httpsig-transitional-margin
junkurihara Mar 14, 2024
12a12bd
fix: add notifier
junkurihara Mar 14, 2024
f48fe3f
feat: add ignore_verification_result_for_allowed_source_ips
junkurihara Mar 14, 2024
d002fa9
wip: initial commit for httpsig pk-registry
junkurihara Mar 19, 2024
8385a63
wip add constants
junkurihara Mar 19, 2024
9f5b78e
wip
junkurihara Mar 19, 2024
64f6674
feat: add feature to host registry markdown on https
junkurihara Mar 22, 2024
2acd289
refactor
junkurihara Mar 25, 2024
445ad4e
chore: deps
junkurihara Mar 25, 2024
aac943f
feat: add reader for registry
junkurihara Mar 25, 2024
c4292bb
chore: add comments
junkurihara Mar 25, 2024
5cf279a
add comment
junkurihara Mar 26, 2024
a0361b7
feat: add registry service
junkurihara Mar 27, 2024
a47fae8
Merge pull request #27 from junkurihara/tmp/httpsig-pk-registry
junkurihara Mar 27, 2024
9fb4106
fix test
junkurihara Mar 27, 2024
a3127ab
feat: exclude my hostname from fetch httpsig pk endpoint
junkurihara Mar 27, 2024
91cb45e
deps
junkurihara Mar 29, 2024
688c6a8
chore: deps
junkurihara Apr 8, 2024
59eb3f2
chore: bump deps
junkurihara Apr 12, 2024
1b4609f
chore: deps hyper-rustls
junkurihara Apr 15, 2024
f98b532
chore(deps): bump ubuntu from 22.04 to 24.04 in /docker
dependabot[bot] Apr 26, 2024
5d9b944
chore: deps
junkurihara Apr 30, 2024
0790fbe
Merge pull request #28 from junkurihara/dependabot/docker/docker/ubun…
junkurihara Apr 30, 2024
ad95ad5
Merge remote-tracking branch 'origin/develop' into feat/httpsig
junkurihara Apr 30, 2024
b558c08
Merge remote-tracking branch 'origin/develop' into feat/httpsig
junkurihara Apr 30, 2024
32b24cd
remove version from docker-compose.yml
junkurihara Apr 30, 2024
db668e4
update structure image with httpsig
junkurihara May 9, 2024
3edae3a
docs: wip - adding httpsig config options
junkurihara May 9, 2024
f46cebb
docs: wip
junkurihara May 9, 2024
3ef1c51
chore: refactor
junkurihara May 9, 2024
c792aa6
docs: add documents for http-message-signature in readme
junkurihara May 9, 2024
6fdf250
fix: wrong docs for docker env options + chore: deps
junkurihara May 16, 2024
3150ff8
Merge pull request #24 from junkurihara/feat/httpsig
junkurihara May 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name: Nightly and release build
on:
push:
branches:
- "feat/*"
- "develop"
pull_request:
types: [closed]
Expand Down Expand Up @@ -75,13 +76,27 @@ jobs:
cache-to: type=gha,mode=max,scope=modoh-server-nightly
labels: ${{ steps.meta.outputs.labels }}

- name: Unstable build and push x86_64 for 'feat/*' branches (for development purposes)
if: ${{ startsWith(github.ref_name, 'feat/') && (github.event_name == 'push') }}
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ env.GHCR }}/${{ env.GHCR_IMAGE_NAME }}:unstable
${{ env.DH_REGISTRY_NAME }}:unstable
file: ./docker/Dockerfile
cache-from: type=gha,scope=modoh-server-unstable
cache-to: type=gha,mode=max,scope=modoh-server-unstable
labels: ${{ steps.meta.outputs.labels }}

dispatch_release:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref == 'develop' && github.event.pull_request.base.ref == 'main' && github.event.pull_request.merged == true }}
needs: docker_build_and_push
steps:
- name: check pull_request title
uses: kaisugi/action-regex-match@v1.0.0
uses: kaisugi/action-regex-match@v1.0.1
id: regex-match
with:
text: ${{ github.event.pull_request.title }}
Expand All @@ -102,7 +117,7 @@ jobs:

- name: release
if: ${{ steps.regex-match.outputs.match != ''}}
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: /tmp/modoh-server-x86_64-unknown-linux-gnu.tar.gz
name: ${{ github.event.pull_request.title }}
Expand Down
32 changes: 30 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
[workspace]
[workspace.package]
version = "0.2.0"
authors = ["Jun Kurihara"]
homepage = "https://github.com/junkurihara/modoh-server"
repository = "https://github.com/junkurihara/modoh-server"
license = "MIT"
readme = "./README.md"
categories = [
"asynchronous",
"network-programming",
"command-line-utilities",
"web-programming::http-server",
]
keywords = [
"dns",
"https",
"dns-over-https",
"doh",
"oblivious-dns-over-https",
"odoh",
"mutualized-oblivious-dns",
"mutualized-odoh",
"modoh",
"relay",
"authorization",
]
edition = "2021"
publish = false

members = ["modoh-bin", "modoh-lib"]
[workspace]
members = ["modoh-bin", "modoh-lib", "httpsig-wire-proto", "httpsig-registry"]
exclude = ["submodules/hyper-tls"]
resolver = "2"

Expand Down
182 changes: 170 additions & 12 deletions README.md

Large diffs are not rendered by default.

Binary file modified assets/modoh-structure.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/observability.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docker-otel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Example Construction of Opentelemetry and its Related Servers for Observability

Here is an example of docker containers for the observability of `modoh-server`, conjunctively configured with its container in [`../docker/`](../docker/) directory.

![Example for Observability](../assets/observability.jpg)

This example consists of the following containers:

- [`opentelemetry-collector`](https://github.com/open-telemetry/opentelemetry-collector): Receives and aggregates OTLP gRPC messages from `modoh-server`. In this example, it is collocated with `modoh-server` in a virtual local network. You need to update [`./otel-config.yml`](./otel-config.yml) as your setting.
- [`Jaeger`](https://www.jaegertracing.io/): Receives trace information via OTLP gRPC from `opentelemetry-collector`, and visualize the trace on the web ([`http://localhost:16686`](http://localhost:16686)). Currently `Jaeger` in our setting uses a non-persistent in-memory storage.
- [`Grafana mimir`](https://github.com/grafana/mimir): Receives metrics information via Prometheus Remote Write protocol from `opentelemetry-collector`. This is responsible to aggregate and store the metric information in a long-term storage like object storage services. Update [`./mimir.yml`](./mimir.yml) and [`./mimir-alertmanager-fallback.yml`](./mimir-alertmanager-fallback.yml) if needed.
- [`Grafana`](https://grafana.com/): Retrieves Prometheus metrics from `Grafana mimir` and visualize the metrics information on the web ([`http://localhost:3000`](http://localhost:3000)).
- [`Rclone`](https://rclone.org/): Serves an S3 compatible object storage backed by a certain cloud storage service like Dropbox. This is connected from `Grafana mimir` to store the metrics data. `rclone.conf` requires to be configured. (See the [Rclone docs](https://rclone.org/docs/))

For the detailed configurations for these containers, please refer to [`./docker-compose.yml`](./docker-compose.yml) and its mounting configuration files. Of course, the [`./docker-compose.yml`](./docker-compose.yml) itself should be updated according to your environment.
1 change: 1 addition & 0 deletions docker-otel/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ services:
image: jaegertracing/all-in-one:latest
container_name: jaeger
restart: unless-stopped
command: ["--memory.max-traces", "4096"] # limits the memory used by the in-memory storage
ports:
- 127.0.0.1:16686:16686 # frontend
expose:
Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ubuntu:22.04 AS base
FROM ubuntu:24.04 AS base

SHELL ["/bin/sh", "-x", "-c"]
ENV SERIAL 2
Expand Down
26 changes: 26 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Docker container of `modoh-server`

## Environment Variables

We have several container-specific environment variables, which doesn't relates the behavior of `modoh-server`.

- `HOST_USER` (default: `user`): User name executing `rpxy` inside the container.
- `HOST_UID` (default: `900`): `UID` of `HOST_USER`.
- `HOST_GID` (default: `900`): `GID` of `HOST_USER`
- `LOG_LEVEL=debug|info|warn|error` (default: `info`): Log level
- `LOG_TO_FILE=true|false` (default: `false`): Enable logging to the log file `/modoh/log/modoh-server.log` using `logrotate`. You should mount `/modoh/log` via docker volume option if enabled. The log dir and file will be owned by the `HOST_USER` with `HOST_UID:HOST_GID` on the host machine. Hence, `HOST_USER`, `HOST_UID` and `HOST_GID` should be the same as ones of the user who executes the `modoh-server` container on the host.
- `DISABLE_OTEL`: If explicitly set to `true`, `--trace` and `--metrics` are disabled in the execute option. (default: `false`)
- `OTEL_ENDPOINT`: Set the gRPC endpoint of `opentelemetry-collector`. (default: `http://localhost:4317` but no collector is contained in the `modoh-server` docker container.)

See [`./docker-compose.yml`](./docker-compose.yml) for the detailed configuration of the above environment variables.

## Volumes

At least, the configured `config.toml` file (or its contained directory) must be mounted:

- case 1: only `config.toml` is directly mounted as `/etc/modoh-server.toml`. Then, the *hot-reload function is disabled* due to the limitation of docker.
- case 2: `path/to/config_dir/` containing `config.toml` is mounted as `/modoh/config`. Then `modoh-server` can tracks changes of the configuration file.

In addition to the configuration file/directory, the list of up-to-date CDN IP addresses should be mounted and set in the `config.toml`. See [`../modoh-server.toml`](../modoh-server.toml) and [`./docker-compose.yml`](./docker-compose.yml).

You may also need to mount the log directory (`/modoh/log`).
4 changes: 2 additions & 2 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
version: "3.9"
services:
modoh-server:
image: jqtype/modoh-server:latest # ghcr.io/junkurihara/modoh-server:latest also works
Expand All @@ -20,7 +19,8 @@ services:
- HOST_UID=501
- HOST_GID=501
# - WATCH=true
- OTLP_ENDPOINT=http://otel-collector:4317 # opentelemetry is enabled if specified the OTLP_ENDPOINT
# - DISABLE_OTEL=true # opentelemetry is disabled if DISABLE_OTEL=true (default: false)
- OTLP_ENDPOINT=http://otel-collector:4317 # opentelemetry endpoint (default: http://localhost:4317)
tty: false
privileged: true
volumes:
Expand Down
37 changes: 37 additions & 0 deletions httpsig-registry/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "httpsig-registry"
description = "Handler for endpoints that serves wire-formatted HTTPSig public keys"
version.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
license.workspace = true
readme.workspace = true
categories.workspace = true
keywords.workspace = true
edition.workspace = true
publish.workspace = true

[dependencies]
anyhow = { version = "1.0.83" }
thiserror = { version = "1.0.60" }
pulldown-cmark = { version = "0.10.3", default-features = false }
http = { version = "1.1.0" }
indexmap = { version = "2.2.6" }
minisign-verify = { version = "0.2.1" }
reqwest = { version = "0.12.4", default-features = false, features = [
"rustls-tls",
"http2",
"hickory-dns",
] }
futures = { version = "0.3.30", default-features = false, features = [
"std",
"async-await",
] }
tokio = { version = "1.37.0", features = [
"net",
"rt-multi-thread",
"time",
"sync",
"macros",
] }
13 changes: 13 additions & 0 deletions httpsig-registry/registry-sample/httpsig-endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# List of endpoints serving wire-formatted HTTPSig public keys for MODoH

## modoh01.typeq.org

Below is the list of target domain names that are handled under the public keys of the above endpoint (For DHKex). Wildcard for prefix, i.e., `*.example.com` is acceptable. If not specified, it is identical to the endpoint domain.

- modoh01.typeq.org

## modoh02.typeq.org

## modoh03.typeq.org

## dnsauth.typeq.org
4 changes: 4 additions & 0 deletions httpsig-registry/registry-sample/httpsig-endpoints.md.minisig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
untrusted comment: signature from rsign secret key
RUQm8wdk0lJP8EHUuBcr5PqdYYiBqC7XVePhn4VByqvpWUHcEQ8RQ4DUA6WS11deeQmVqj6nX4IwDSpol6YaP4wxN1CyAbMu4QI=
trusted comment: timestamp:1711525202 file:httpsig-endpoints.md prehashed
l+/B9UT3aI65PbBVCl/ptq6jSbDj0bd/aT3C0F0dFfdoj32N/bjw7T9Hj8v2UKzb6lfx6mvUPM23j3pbtur9BA==
1 change: 1 addition & 0 deletions httpsig-registry/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const HTTPSIG_CONFIGS_PATH: &str = "/.well-known/httpsigconfigs";
18 changes: 18 additions & 0 deletions httpsig-registry/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use thiserror::Error;

/// Describes things that can go wrong in registry handling
#[derive(Debug, Error)]
pub enum ModohRegistryError {
/// Url parse error
#[error("Url parse error")]
FailToParseUrl,
/// IO error
#[error("IO error")]
Io(#[from] std::io::Error),
/// Reqwest error
#[error("Reqwest error")]
Reqwest(#[from] reqwest::Error),
/// Minisign error
#[error("Minisign error")]
Minisign(#[from] minisign_verify::Error),
}
Empty file.
117 changes: 117 additions & 0 deletions httpsig-registry/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
mod constants;
mod error;
mod http_client;
mod parse_md;

use crate::{constants::HTTPSIG_CONFIGS_PATH, error::ModohRegistryError};
use minisign_verify::{PublicKey, Signature};
use std::{borrow::Cow, str::FromStr};

/* ------------------------------------------------ */
#[derive(Clone, Debug)]
/// HTTP message signatures enabled domain information
pub struct HttpSigDomainInfo {
/// Configs endpoint
pub configs_endpoint_uri: http::Uri,
/// Domain name
pub dh_signing_target_domain: String,
}
impl HttpSigDomainInfo {
/// Create a new HttpSigDomainInfo
pub fn new<'a, T: Into<Cow<'a, str>>>(configs_endpoint_domain: T, dh_signing_target_domain: Option<String>) -> Self {
let configs_endpoint_uri: http::Uri = format!("https://{}{}", configs_endpoint_domain.into(), HTTPSIG_CONFIGS_PATH)
.parse()
.unwrap();
let dh_signing_target_domain =
dh_signing_target_domain.unwrap_or_else(|| configs_endpoint_uri.authority().unwrap().to_string());
Self {
configs_endpoint_uri,
dh_signing_target_domain,
}
}

/// Create a new HttpSigDomainInfo by fetching endpoint list in markdown format from `file://<abs_path>` or `https://<domain>/<path>`
pub async fn new_from_registry_md<'a, T1, T2>(registry_uri: T1, minisign_base64_pk: T2) -> Result<Vec<Self>, ModohRegistryError>
where
T1: Into<Cow<'a, str>>,
T2: Into<Cow<'a, str>>,
{
// let registry_uri = registry_uri.into();
let reqwest_uri = reqwest::Url::from_str(&registry_uri.into()).map_err(|_| ModohRegistryError::FailToParseUrl)?;
if !reqwest_uri.path().ends_with(".md") {
return Err(ModohRegistryError::FailToParseUrl);
}
let (markdown_input, markdown_minisig_input) = match reqwest_uri.scheme() {
"file" => {
let markdown_path = reqwest_uri.to_file_path().map_err(|_| ModohRegistryError::FailToParseUrl)?;
let markdown_sig_path = markdown_path.with_extension("md.minisig");
let markdown_input = std::fs::read_to_string(markdown_path)?;
let markdown_minisig_input = std::fs::read_to_string(markdown_sig_path)?;
(markdown_input, markdown_minisig_input)
}
"https" => {
let mut reqwest_minisig_uri = reqwest_uri.clone();
reqwest_minisig_uri.set_path(&format!("{}.minisig", reqwest_uri.path()));
let client = reqwest::Client::new();
let futs = vec![client.get(reqwest_uri).send(), client.get(reqwest_minisig_uri).send()];
let res = futures::future::join_all(futs)
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()?;
let texts = futures::future::join_all(res.into_iter().map(|v| v.text()))
.await
.into_iter()
.collect::<Result<Vec<_>, _>>()?;
(texts[0].clone(), texts[1].clone())
}
_ => return Err(ModohRegistryError::FailToParseUrl),
};

let minisign_pk = minisign_base64_pk.into();
let pk = PublicKey::from_base64(&minisign_pk)?;
let sig = Signature::decode(&markdown_minisig_input)?;
pk.verify(markdown_input.as_bytes(), &sig, false)?;

let parsed = parse_md::parse_md(markdown_input);
Ok(parsed)
}
}

/* ------------------------------------------------ */
#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let minisign_pk = "RWQm8wdk0lJP8AyGtShi96d72ZzkZnGX9gxR0F5EIWmMW2N25SDfzbrt";
let file_path = std::path::PathBuf::from("./registry-sample/httpsig-endpoints.md");
let file_path_minisig = std::path::PathBuf::from("./registry-sample/httpsig-endpoints.md.minisig");
let markdown_input = std::fs::read_to_string(file_path).unwrap();
let markdown_minisig_input = std::fs::read_to_string(file_path_minisig).unwrap();
let pk = PublicKey::from_base64(minisign_pk).unwrap();
let sig = Signature::decode(&markdown_minisig_input).unwrap();
let res = pk.verify(markdown_input.as_bytes(), &sig, false);
assert!(res.is_ok());

let parsed = parse_md::parse_md(markdown_input);
println!("{:#?}", parsed);
}

#[tokio::test]
async fn test_from_uri() {
let minisign_pk = "RWQm8wdk0lJP8AyGtShi96d72ZzkZnGX9gxR0F5EIWmMW2N25SDfzbrt";

let abs_path = std::path::PathBuf::from("./registry-sample/httpsig-endpoints.md")
.canonicalize()
.unwrap();
let string_path = format!("file://{}", abs_path.to_str().unwrap());
let res = HttpSigDomainInfo::new_from_registry_md(string_path, minisign_pk).await;
println!("from file:\n{:#?}", res);

let https_path = "https://filedn.com/lVEKDQEKcCIhnH516GYdXu0/modoh_httpsig_dev/httpsig-endpoints.md";
let res = HttpSigDomainInfo::new_from_registry_md(https_path, minisign_pk).await;
println!("from https:\n{:#?}", res);
assert!(res.is_ok());
}
}
Loading