From 0736c56990e2203efa090774eb6217f8bd93fa6c Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 13 Jun 2022 04:10:53 +0000 Subject: feat(router): allow access to client certs Pretty happy to finally get this one over with... --- examples/windmark.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'examples') diff --git a/examples/windmark.rs b/examples/windmark.rs index 0c5b13b..eaf7b43 100644 --- a/examples/windmark.rs +++ b/examples/windmark.rs @@ -199,9 +199,26 @@ async fn main() -> Result<(), Box> { ) }) }); - // router.mount("", Box::new(|_| { - // Response::Success("hi".into()) - // })); + router.mount( + "/secret", + Box::new(|context| { + if let Some(certificate) = context.certificate { + Response::Success(format!("Your public key: {}.", { + (|| -> Result { + Ok(format!( + "{:?}", + certificate.public_key()?.rsa()?.public_key_to_pem()? + )) + })() + .unwrap_or_else(|_| "Unknown".to_string()) + },)) + } else { + Response::ClientCertificateRequired( + "This is a secret route! Identify yourself!".to_string(), + ) + } + }), + ); router.run().await } -- cgit v1.2.3