Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iroh-auth"
version = "0.1.1"
version = "0.1.2"
edition = "2021"
authors = ["rustonbsd <rustonbsd@mailfence.com>"]
description = "Authentication middleware for iroh"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async fn main() -> Result<(), String> {

// 4. Register the auth protocol handler
let router = Router::builder(endpoint)
.accept(Authenticator::ALPN, auth.clone())
.accept(iroh_auth::ALPN, auth.clone())

// Register your actual application protocols here
.accept(b"/my-app/1.0", MyProtocolHandler)
Expand Down
2 changes: 1 addition & 1 deletion examples/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ async fn main() -> Result<(), String> {

// 4. Register the auth protocol handler
let router = Router::builder(endpoint)
.accept(Authenticator::ALPN, auth.clone())
.accept(iroh_auth::ALPN, auth.clone())

// Register your actual application protocols here
.accept(b"/my-app/1.0", MyProtocolHandler)
Expand Down
2 changes: 1 addition & 1 deletion examples/gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn main() -> Result<(), String> {

let router = Router::builder(endpoint)
// #4 Add Authenticator to the router
.accept(Authenticator::ALPN, auth.clone())
.accept(iroh_auth::ALPN, auth.clone())
.accept(iroh_gossip::ALPN, gossip.clone())
.spawn();

Expand Down
10 changes: 6 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ pub struct Authenticator {
endpoint: Arc<Mutex<Option<iroh::Endpoint>>>,
}

pub const ALPN: &[u8] = b"/iroh/auth/0.1";

impl Authenticator {
pub const ALPN: &'static [u8] = b"/iroh/auth/0.1";
pub const ALPN: &'static [u8] = ALPN;
const ACCEPT_CONTEXT: &'static [u8] = b"iroh-auth-accept";
const OPEN_CONTEXT: &'static [u8] = b"iroh-auth-open";

Expand Down Expand Up @@ -144,7 +146,7 @@ impl Authenticator {
.ok_or(AuthenticatorError::EndpointNotSet)
}

pub fn is_authenticated(&self, id: &PublicKey) -> bool {
fn is_authenticated(&self, id: &PublicKey) -> bool {
self.authenticated
.lock()
.map(|set| set.contains(id))
Expand Down Expand Up @@ -184,7 +186,7 @@ impl Authenticator {
/// Accept an incoming connection and perform SPAKE2 authentication.
/// On success, adds the remote ID to the authenticated set.
/// Returns Ok(()) on success, or an AuthenticatorError on failure.
pub async fn auth_accept(&self, conn: Connection) -> Result<(), AuthenticatorError> {
async fn auth_accept(&self, conn: Connection) -> Result<(), AuthenticatorError> {
let remote_id = conn.remote_id();
debug!("accepting auth connection from {}", remote_id);
let (mut send, mut recv) = conn.accept_bi().await.map_err(|err| {
Expand Down Expand Up @@ -254,7 +256,7 @@ impl Authenticator {
/// Open an outgoing connection and perform SPAKE2 authentication.
/// On success, adds the remote ID to the authenticated set.
/// Returns Ok(()) on success, or an AuthenticatorError on failure.
pub async fn auth_open(&self, conn: Connection) -> Result<(), AuthenticatorError> {
async fn auth_open(&self, conn: Connection) -> Result<(), AuthenticatorError> {
let remote_id = conn.remote_id();
debug!("opening auth connection to {}", remote_id);
let (mut send, mut recv) = conn.open_bi().await.map_err(|err| {
Expand Down