From 8c6067f20a107cca2342bfc024b1b19eedf7bb4c Mon Sep 17 00:00:00 2001 From: Hendrik Eeckhaut Date: Mon, 22 Jan 2024 11:45:46 +0100 Subject: [PATCH] Add button to easily use PSE hosted notary server's certificate --- src/components/pem_input.rs | 44 ++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/components/pem_input.rs b/src/components/pem_input.rs index 7f0f7c5..9bfb7e7 100644 --- a/src/components/pem_input.rs +++ b/src/components/pem_input.rs @@ -1,4 +1,4 @@ -use elliptic_curve::pkcs8::DecodePublicKey; +use elliptic_curve::{pkcs8::DecodePublicKey, PublicKey}; #[allow(unused_imports)] use gloo::console::log; @@ -17,6 +17,12 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEBv36FI4ZFszJa0DQFJ3wWCXvVLFr cRzMG5kaTeHGoSzDu6cFqx3uEWYpFGo6C0EOUgf+mEgbktLrXocv5yHzKg== -----END PUBLIC KEY-----"; +// from https://notary.pse.dev/info +pub const NOTARY_PSE_PEM: &str = "-----BEGIN PUBLIC KEY----- +MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAExpX/4R4z40gI6C/j9zAM39u58LJu +3Cx5tXTuqhhu/tirnBi5GniMmspOTEsps4ANnPLpMmMSfhJ+IFHbc3qVOA== +-----END PUBLIC KEY-----"; + #[function_component(PemInputComponent)] pub fn pem_input_component(Props { pem_callback }: &Props) -> Html { let input_value = use_state(|| DEFAULT_PEM.to_string()); @@ -47,6 +53,34 @@ pub fn pem_input_component(Props { pem_callback }: &Props) -> Html { }) }; + let notary_pse_dev = { + let input_value = input_value.clone(); + let callback = pem_callback.clone(); + let invalid_input = invalid_input.clone(); + + Callback::from(move |_| { + let public_key = p256::PublicKey::from_public_key_pem(NOTARY_PSE_PEM) + .expect("should be a valid public key"); + input_value.set(NOTARY_PSE_PEM.into()); + invalid_input.set(None); + callback.emit(public_key); + }) + }; + + let default = { + let input_value = input_value.clone(); + let callback = pem_callback.clone(); + let invalid_input = invalid_input.clone(); + + Callback::from(move |_| { + let public_key = p256::PublicKey::from_public_key_pem(DEFAULT_PEM) + .expect("should be a valid public key"); + input_value.set(DEFAULT_PEM.into()); + invalid_input.set(None); + callback.emit(public_key); + }) + }; + // Toggling styles based on the presence of an error let style = if invalid_input.is_none() { "text-sm text-white border-gray-600 focus:ring-blue-500 focus:border-blue-500" @@ -69,6 +103,14 @@ pub fn pem_input_component(Props { pem_callback }: &Props) -> Html { if let Some(error_message) = invalid_input.as_ref() {

{error_message}

} +
+ + +