pub struct Challenge(/* private fields */);Expand description
A cryptographic challenge issued by the proxy server for authentication.
The server sends a random challenge to newly connected clients. Clients must sign this challenge with their private key to prove their identity without revealing the private key itself.
§Protocol Flow
- Client connects via WebSocket
- Server generates and sends
Challenge - Client signs challenge using
IdentityKeyPair - Client sends
ChallengeResponsewith signature - Server verifies signature to authenticate client
§Examples
Server-side challenge generation:
use ap_proxy_protocol::Challenge;
let challenge = Challenge::new();
// Send to client for signingClient-side challenge signing:
use ap_proxy_protocol::{Challenge, IdentityKeyPair};
let keypair = IdentityKeyPair::generate();
let response = challenge.sign(&keypair);
// Send response back to serverImplementations§
Source§impl Challenge
impl Challenge
Sourcepub fn new() -> Challenge
pub fn new() -> Challenge
Generate a new random challenge using cryptographically secure randomness.
Each challenge is 32 bytes of random data, providing sufficient entropy to prevent replay attacks and ensure uniqueness.
§Examples
use ap_proxy_protocol::Challenge;
let challenge = Challenge::new();
// Each call produces a different random challenge
assert_ne!(format!("{:?}", challenge), format!("{:?}", Challenge::new()));Sourcepub fn sign(&self, identity: &IdentityKeyPair) -> ChallengeResponse
pub fn sign(&self, identity: &IdentityKeyPair) -> ChallengeResponse
Sign this challenge using the provided identity key-pair.
§Examples
use ap_proxy_protocol::{Challenge, IdentityKeyPair};
let keypair = IdentityKeyPair::generate();
let challenge = Challenge::new();
let response = challenge.sign(&keypair);
// Verify the signature
let identity = keypair.identity();
assert!(response.verify(&challenge, &identity));Trait Implementations§
Source§impl<'de> Deserialize<'de> for Challenge
impl<'de> Deserialize<'de> for Challenge
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Challenge, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Challenge, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Challenge
impl Serialize for Challenge
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
Auto Trait Implementations§
impl Freeze for Challenge
impl RefUnwindSafe for Challenge
impl Send for Challenge
impl Sync for Challenge
impl Unpin for Challenge
impl UnsafeUnpin for Challenge
impl UnwindSafe for Challenge
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more