diff --git a/Cargo.lock b/Cargo.lock index aa4109e..af49244 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1421,7 +1421,7 @@ dependencies = [ [[package]] name = "iroh-auth" -version = "0.1.1" +version = "0.1.2" dependencies = [ "anyhow", "hkdf", diff --git a/Cargo.toml b/Cargo.toml index 6f71c9b..c1c03c6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iroh-auth" -version = "0.1.1" +version = "0.1.2" edition = "2021" authors = ["rustonbsd "] description = "Authentication middleware for iroh" diff --git a/README.md b/README.md index d923973..9d87610 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/examples/basic.rs b/examples/basic.rs index e9717f1..d4a0e48 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -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) diff --git a/examples/gossip.rs b/examples/gossip.rs index ac5822c..a534e50 100644 --- a/examples/gossip.rs +++ b/examples/gossip.rs @@ -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(); diff --git a/src/lib.rs b/src/lib.rs index 8130504..d201d33 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -103,8 +103,10 @@ pub struct Authenticator { endpoint: Arc>>, } +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"; @@ -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)) @@ -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| { @@ -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| {