diff options
| author | Fuwn <[email protected]> | 2022-06-13 04:10:53 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-06-13 04:10:53 +0000 |
| commit | 0736c56990e2203efa090774eb6217f8bd93fa6c (patch) | |
| tree | 11a47f69ef078a293de14fdd99198e240efe6fd7 /examples | |
| parent | refactor: fix qualifications (diff) | |
| download | windmark-0736c56990e2203efa090774eb6217f8bd93fa6c.tar.xz windmark-0736c56990e2203efa090774eb6217f8bd93fa6c.zip | |
feat(router): allow access to client certs
Pretty happy to finally get this one over with...
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/windmark.rs | 23 |
1 files changed, 20 insertions, 3 deletions
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<dyn std::error::Error>> { ) }) }); - // 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<String, openssl::error::ErrorStack> { + 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 } |