Skip to content

Commit

Permalink
feat: request for the fingerprint anytime an http url is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
therishidesai committed Dec 23, 2024
1 parent 3453eb2 commit 71c9ac1
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 32 deletions.
55 changes: 54 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
crate2nix.url = "github:nix-community/crate2nix";
fenix.url = "github:nix-community/fenix";
crate2nix.url = "github:nix-community/crate2nix";
};

outputs = inputs@{ flake-utils, crate2nix, ... }:
Expand Down
10 changes: 3 additions & 7 deletions moq-relay/src/web.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{net, sync::Arc};

Check warning on line 1 in moq-relay/src/web.rs

View workflow job for this annotation

GitHub Actions / Native Checks

unused import: `sync::Arc`

Check warning on line 1 in moq-relay/src/web.rs

View workflow job for this annotation

GitHub Actions / Native Checks

unused import: `sync::Arc`

Check warning on line 1 in moq-relay/src/web.rs

View workflow job for this annotation

GitHub Actions / Native Checks

unused import: `sync::Arc`

use axum::{extract::State, http::Method, response::IntoResponse, routing::get, Router};
use hyper_serve::tls_rustls::RustlsAcceptor;
use hyper_serve::accept::DefaultAcceptor;
use tower_http::cors::{Any, CorsLayer};

pub struct WebConfig {
Expand All @@ -13,7 +13,7 @@ pub struct WebConfig {
// TODO remove this when Chrome adds support for self-signed certificates using WebTransport
pub struct Web {
app: Router,
server: hyper_serve::Server<RustlsAcceptor>,
server: hyper_serve::Server<DefaultAcceptor>,
}

impl Web {
Expand All @@ -22,16 +22,12 @@ impl Web {
// TODO serve all of them so we can support multiple signature algorithms.
let fingerprint = config.tls.fingerprints.first().expect("missing certificate").clone();

let mut tls = config.tls.server.expect("missing server configuration");
tls.alpn_protocols = vec![b"h2".to_vec(), b"http/1.1".to_vec()];
let tls = hyper_serve::tls_rustls::RustlsConfig::from_config(Arc::new(tls));

let app = Router::new()
.route("/fingerprint", get(serve_fingerprint))
.layer(CorsLayer::new().allow_origin(Any).allow_methods([Method::GET]))
.with_state(fingerprint);

let server = hyper_serve::bind_rustls(config.bind, tls);
let server = hyper_serve::bind(config.bind);

Self { app, server }
}
Expand Down
4 changes: 2 additions & 2 deletions moq-web/src/demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>

<body>
<moq-video src="https://localhost:4443/demo/bbb" />
<moq-video src="http://localhost:4443/test-zed" />
</body>

</html>
</html>
19 changes: 9 additions & 10 deletions moq-web/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,22 @@ use url::Url;

use crate::{Error, Result};

pub async fn connect(addr: &Url) -> Result<moq_transfork::Session> {
pub async fn connect(addr: &mut Url) -> Result<moq_transfork::Session> {
tracing::info!("connecting to: {}", addr);

if addr.scheme() != "https" {
return Err(Error::InvalidUrl);
}

let client = web_transport::Client::new().congestion_control(web_transport::CongestionControl::LowLatency);

// TODO Unfortunately, WebTransport doesn't work correctly with self-signed certificates.
// Until that gets fixed, we need to perform a HTTP request to fetch the certificate hashes.
let client = match addr.host_str() {
Some("localhost") => {
let client = match addr.scheme() {
"http" => {
// TODO Unfortunately, WebTransport doesn't work correctly with self-signed certificates.
// Until that gets fixed, we need to perform a HTTP request to fetch the certificate hashes.
let fingerprint = fingerprint(addr).await?;
// convert the URL back to https for WebTransport
let _ = addr.set_scheme("https");
client.server_certificate_hashes(vec![fingerprint])
}
_ => client,
"https" => client,
_ => return Err(Error::InvalidUrl),
};

let session = client.connect(addr).await?;
Expand Down
2 changes: 1 addition & 1 deletion moq-web/src/watch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl WatchBackend {
}

async fn run(&mut self) -> Result<()> {
let session = super::session::connect(&self.src).await?;
let session = super::session::connect(&mut self.src).await?;
let path = self.src.path_segments().ok_or(Error::InvalidUrl)?.collect();
let mut broadcast = moq_karp::BroadcastConsumer::new(session, path);

Expand Down
43 changes: 33 additions & 10 deletions nix/shell.nix
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
{ self, nixpkgs, flake-utils, ... }:
{ self, nixpkgs, flake-utils, fenix, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
in
with pkgs;
{
devShells.default = mkShell {
nativeBuildInputs = [
pkg-config
libressl
cargo
ffmpeg
];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
devShells = {
default = with pkgs; mkShell {
nativeBuildInputs = [
pkg-config
libressl
cargo
rustfmt
ffmpeg
];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
};

web =
let
rustToolchain = with fenix.packages.${system};
combine [
latest.rustc
latest.cargo
targets.wasm32-unknown-unknown.latest.rust-std
];
in
with pkgs;
mkShell {
nativeBuildInputs = [
bun
go
nodejs_23
biome
rustToolchain
wasm-pack
];
};
};
}
)

0 comments on commit 71c9ac1

Please sign in to comment.