diff --git a/assets/webpage/_astro/delete.6228aab6.css b/assets/webpage/_astro/delete.6228aab6.css new file mode 100644 index 0000000..3021a74 --- /dev/null +++ b/assets/webpage/_astro/delete.6228aab6.css @@ -0,0 +1 @@ +*,:before,:after{box-sizing:border-box;border-width:0;border-style:solid;border-color:#e5e7eb}:before,:after{--tw-content: ""}html{line-height:1.5;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4;font-family:ui-sans-serif,system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Arial,Noto Sans,sans-serif,"Apple Color Emoji","Segoe UI Emoji",Segoe UI Symbol,"Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){-webkit-text-decoration:underline dotted;text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;font-weight:inherit;line-height:inherit;color:inherit;margin:0;padding:0}button,select{text-transform:none}button,[type=button],[type=reset],[type=submit]{-webkit-appearance:button;background-color:transparent;background-image:none}:-moz-focusring{outline:auto}:-moz-ui-invalid{box-shadow:none}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}blockquote,dl,dd,h1,h2,h3,h4,h5,h6,hr,figure,p,pre{margin:0}fieldset{margin:0;padding:0}legend{padding:0}ol,ul,menu{list-style:none;margin:0;padding:0}textarea{resize:vertical}input::-moz-placeholder,textarea::-moz-placeholder{opacity:1;color:#9ca3af}input::placeholder,textarea::placeholder{opacity:1;color:#9ca3af}button,[role=button]{cursor:pointer}:disabled{cursor:default}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}[hidden]{display:none}[type=text],[type=email],[type=url],[type=password],[type=number],[type=date],[type=datetime-local],[type=month],[type=search],[type=tel],[type=time],[type=week],[multiple],textarea,select{-webkit-appearance:none;-moz-appearance:none;appearance:none;background-color:#fff;border-color:#6b7280;border-width:1px;border-radius:0;padding:.5rem .75rem;font-size:1rem;line-height:1.5rem;--tw-shadow: 0 0 #0000}[type=text]:focus,[type=email]:focus,[type=url]:focus,[type=password]:focus,[type=number]:focus,[type=date]:focus,[type=datetime-local]:focus,[type=month]:focus,[type=search]:focus,[type=tel]:focus,[type=time]:focus,[type=week]:focus,[multiple]:focus,textarea:focus,select:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow);border-color:#2563eb}input::-moz-placeholder,textarea::-moz-placeholder{color:#6b7280;opacity:1}input::placeholder,textarea::placeholder{color:#6b7280;opacity:1}::-webkit-datetime-edit-fields-wrapper{padding:0}::-webkit-date-and-time-value{min-height:1.5em}::-webkit-datetime-edit,::-webkit-datetime-edit-year-field,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute-field,::-webkit-datetime-edit-second-field,::-webkit-datetime-edit-millisecond-field,::-webkit-datetime-edit-meridiem-field{padding-top:0;padding-bottom:0}select{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");background-position:right .5rem center;background-repeat:no-repeat;background-size:1.5em 1.5em;padding-right:2.5rem;-webkit-print-color-adjust:exact;print-color-adjust:exact}[multiple]{background-image:initial;background-position:initial;background-repeat:unset;background-size:initial;padding-right:.75rem;-webkit-print-color-adjust:unset;print-color-adjust:unset}[type=checkbox],[type=radio]{-webkit-appearance:none;-moz-appearance:none;appearance:none;padding:0;-webkit-print-color-adjust:exact;print-color-adjust:exact;display:inline-block;vertical-align:middle;background-origin:border-box;-webkit-user-select:none;-moz-user-select:none;user-select:none;flex-shrink:0;height:1rem;width:1rem;color:#2563eb;background-color:#fff;border-color:#6b7280;border-width:1px;--tw-shadow: 0 0 #0000}[type=checkbox]{border-radius:0}[type=radio]{border-radius:100%}[type=checkbox]:focus,[type=radio]:focus{outline:2px solid transparent;outline-offset:2px;--tw-ring-inset: var(--tw-empty, );--tw-ring-offset-width: 2px;--tw-ring-offset-color: #fff;--tw-ring-color: #2563eb;--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(2px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow)}[type=checkbox]:checked,[type=radio]:checked{border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}[type=checkbox]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3cpath d='M12.207 4.793a1 1 0 010 1.414l-5 5a1 1 0 01-1.414 0l-2-2a1 1 0 011.414-1.414L6.5 9.086l4.293-4.293a1 1 0 011.414 0z'/%3e%3c/svg%3e")}[type=radio]:checked{background-image:url("data:image/svg+xml,%3csvg viewBox='0 0 16 16' fill='white' xmlns='http://www.w3.org/2000/svg'%3e%3ccircle cx='8' cy='8' r='3'/%3e%3c/svg%3e")}[type=checkbox]:checked:hover,[type=checkbox]:checked:focus,[type=radio]:checked:hover,[type=radio]:checked:focus{border-color:transparent;background-color:currentColor}[type=checkbox]:indeterminate{background-image:url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 16 16'%3e%3cpath stroke='white' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M4 8h8'/%3e%3c/svg%3e");border-color:transparent;background-color:currentColor;background-size:100% 100%;background-position:center;background-repeat:no-repeat}[type=checkbox]:indeterminate:hover,[type=checkbox]:indeterminate:focus{border-color:transparent;background-color:currentColor}[type=file]{background:unset;border-color:inherit;border-width:0;border-radius:0;padding:0;font-size:unset;line-height:inherit}[type=file]:focus{outline:1px solid ButtonText;outline:1px auto -webkit-focus-ring-color}*,:before,:after{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }::backdrop{--tw-border-spacing-x: 0;--tw-border-spacing-y: 0;--tw-translate-x: 0;--tw-translate-y: 0;--tw-rotate: 0;--tw-skew-x: 0;--tw-skew-y: 0;--tw-scale-x: 1;--tw-scale-y: 1;--tw-pan-x: ;--tw-pan-y: ;--tw-pinch-zoom: ;--tw-scroll-snap-strictness: proximity;--tw-ordinal: ;--tw-slashed-zero: ;--tw-numeric-figure: ;--tw-numeric-spacing: ;--tw-numeric-fraction: ;--tw-ring-inset: ;--tw-ring-offset-width: 0px;--tw-ring-offset-color: #fff;--tw-ring-color: rgb(59 130 246 / .5);--tw-ring-offset-shadow: 0 0 #0000;--tw-ring-shadow: 0 0 #0000;--tw-shadow: 0 0 #0000;--tw-shadow-colored: 0 0 #0000;--tw-blur: ;--tw-brightness: ;--tw-contrast: ;--tw-grayscale: ;--tw-hue-rotate: ;--tw-invert: ;--tw-saturate: ;--tw-sepia: ;--tw-drop-shadow: ;--tw-backdrop-blur: ;--tw-backdrop-brightness: ;--tw-backdrop-contrast: ;--tw-backdrop-grayscale: ;--tw-backdrop-hue-rotate: ;--tw-backdrop-invert: ;--tw-backdrop-opacity: ;--tw-backdrop-saturate: ;--tw-backdrop-sepia: }.mt-3{margin-top:.75rem}.mt-4{margin-top:1rem}.mt-6{margin-top:1.5rem}.flex{display:flex}.h-full{height:100%}.w-full{width:100%}.max-w-full{max-width:100%}.resize-none{resize:none}.flex-row{flex-direction:row}.flex-col{flex-direction:column}.items-center{align-items:center}.space-x-6>:not([hidden])~:not([hidden]){--tw-space-x-reverse: 0;margin-right:calc(1.5rem * var(--tw-space-x-reverse));margin-left:calc(1.5rem * calc(1 - var(--tw-space-x-reverse)))}.self-end{align-self:flex-end}.px-8{padding-left:2rem;padding-right:2rem}.py-4{padding-top:1rem;padding-bottom:1rem}.font-mono{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,Liberation Mono,Courier New,monospace}.text-lg{font-size:1.125rem;line-height:1.75rem}.text-xl{font-size:1.25rem;line-height:1.75rem}.font-bold{font-weight:700}.focus\:rounded-lg:focus{border-radius:.5rem}.button{--tw-bg-opacity: 1;background-color:rgb(240 253 250 / var(--tw-bg-opacity));padding:1rem}.button:hover{--tw-drop-shadow: drop-shadow(0 4px 3px rgb(0 0 0 / .07)) drop-shadow(0 2px 2px rgb(0 0 0 / .06));filter:var(--tw-blur) var(--tw-brightness) var(--tw-contrast) var(--tw-grayscale) var(--tw-hue-rotate) var(--tw-invert) var(--tw-saturate) var(--tw-sepia) var(--tw-drop-shadow);border-radius:.5rem}.round,.button{--tw-border-opacity: 1;border-color:rgb(0 0 0 / var(--tw-border-opacity));border-width:1px;border-top-right-radius:.5rem;border-bottom-left-radius:.5rem;transition-property:all;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s} diff --git a/assets/webpage/delete/index.html b/assets/webpage/delete/index.html new file mode 100644 index 0000000..0f0806e --- /dev/null +++ b/assets/webpage/delete/index.html @@ -0,0 +1,20 @@ + + + + + + Submit a key + + + +
+
+
+ + + +
+
+
+ + \ No newline at end of file diff --git a/assets/webpage/index.html b/assets/webpage/index.html new file mode 100644 index 0000000..cfd1c83 --- /dev/null +++ b/assets/webpage/index.html @@ -0,0 +1,20 @@ + + + + + + Manage keys + + + +
+
+

What would you like to do?

+ +
+
+ + \ No newline at end of file diff --git a/assets/webpage/submit/index.html b/assets/webpage/submit/index.html new file mode 100644 index 0000000..3be1b3f --- /dev/null +++ b/assets/webpage/submit/index.html @@ -0,0 +1,20 @@ + + + + + + Submit a key + + + +
+
+
+ + + +
+
+
+ + \ No newline at end of file diff --git a/example.config.toml b/example.config.toml index d0d98cc..e12b8f9 100644 --- a/example.config.toml +++ b/example.config.toml @@ -13,4 +13,4 @@ smtp_password = "verysecurepassword" smtp_port = 465 smtp_tls = "Tls" mail_from = "key-submission@example.org" -mail_subject = "Confirm this action" \ No newline at end of file +mail_subject = "Please confirm to %a your public key" \ No newline at end of file diff --git a/src/confirmation.rs b/src/confirmation.rs index b0e3466..8eeb2fb 100644 --- a/src/confirmation.rs +++ b/src/confirmation.rs @@ -105,6 +105,13 @@ pub fn confirm_action(token: &str) -> Result<(Action, String), Error> { pub fn send_confirmation_email(address: &str, action: &Action, token: &str) -> Result<(), Error> { debug!("Sending email to {}", address); let template = fs::read_to_string(Path::new("assets").join("mail-template.html")).unwrap(); + let mut url = SETTINGS + .external_url + .join("api/") + .unwrap() + .join("confirm") + .unwrap(); + url.set_query(Some(&format!("token={}", token))); let email = Message::builder() .from(match SETTINGS.mail_settings.mail_from.parse() { Ok(mailbox) => mailbox, @@ -129,18 +136,7 @@ pub fn send_confirmation_email(address: &str, action: &Action, token: &str) -> R .header(ContentType::TEXT_HTML) .body( template - .replace( - "{{%u}}", - SETTINGS - .external_url - .join("api/") - .unwrap() - .join("confirm/") - .unwrap() - .join(token) - .unwrap() - .as_ref(), - ) + .replace("{{%u}}", url.as_ref()) .replace("{{%a}}", &action.to_string().to_lowercase()), ); diff --git a/src/errors.rs b/src/errors.rs index 059eb31..4e323e8 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -3,33 +3,33 @@ use thiserror::Error; #[derive(Error, Debug, Clone, Copy)] pub enum Error { - #[error("(0x00) Cert is invalid")] + #[error("(0x01) Cert is invalid")] InvalidCert, - #[error("(0x01) Error while parsing cert")] + #[error("(0x02) Error while parsing cert")] ParseCert, - #[error("(0x02) Error while parsing an E-Mail address")] + #[error("(0x03) Error while parsing an E-Mail address")] ParseEmail, - #[error("(0x03) There is no pending request associated to this token")] + #[error("(0x04) There is no pending request associated to this token")] MissingPending, - #[error("(0x04) Requested key does not exist")] + #[error("(0x05) Requested key does not exist")] MissingKey, - #[error("(0x05) No E-Mail found in the certificate")] + #[error("(0x06) No E-Mail found in the certificate")] MissingMail, - #[error("(0x06) Error while sending the E-Mail")] + #[error("(0x07) Error while sending the E-Mail")] SendMail, - #[error("(0x07) rror while serializing data")] + #[error("(0x08) rror while serializing data")] SerializeData, - #[error("(0x08) Error while deserializing data")] + #[error("(0x09) Error while deserializing data")] DeserializeData, - #[error("(0x09) The file is inaccessible")] + #[error("(0x0A) The file is inaccessible")] Inaccessible, - #[error("(0x0A) Error while adding a key to the wkd")] + #[error("(0x0B) Error while adding a key to the wkd")] AddingKey, - #[error("(0x0B) Error while generating the wkd path")] + #[error("(0x0C) Error while generating the wkd path")] PathGeneration, - #[error("(0x0C) Error while generating the email")] + #[error("(0x0D) Error while generating the email")] MailGeneration, - #[error("(0x0D) Wrong email domain")] + #[error("(0x0E) Wrong email domain")] WrongDomain, } diff --git a/src/main.rs b/src/main.rs index 427c032..69e072c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,18 +23,18 @@ use utils::init_logger; const PENDING_FOLDER: &str = "pending"; #[derive(Deserialize, Debug)] -struct Pem { +struct Key { key: String, } #[derive(Deserialize, Debug)] struct Token { - value: String, + token: String, } #[derive(Deserialize, Debug)] struct Email { - address: String, + email: String, } #[actix_web::main] @@ -67,7 +67,7 @@ async fn main() -> std::io::Result<()> { } #[post("/api/submit")] -async fn submit(pem: web::Form) -> Result { +async fn submit(pem: web::Form) -> Result { let cert = parse_pem(&pem.key)?; let email = get_email_from_cert(&cert)?; is_email_allowed(&email)?; @@ -75,24 +75,24 @@ async fn submit(pem: web::Form) -> Result { store_pending_addition(pem.key.clone(), &email, &token)?; send_confirmation_email(&email, &Action::Add, &token)?; info!("User {} submitted a key!", &email); - Ok(String::from("Key submitted successfully!")) + Ok(String::from("(0x00) Key submitted successfully!")) } -#[get("/api/confirm/{value}")] -async fn confirm(token: web::Path) -> Result { - let (action, email) = confirm_action(&token.value)?; +#[get("/api/confirm")] +async fn confirm(token: web::Query) -> Result { + let (action, email) = confirm_action(&token.token)?; match action { Action::Add => info!("Key for user {} was added successfully!", email), Action::Delete => info!("Key for user {} was deleted successfully!", email), } - Ok(String::from("Confirmation successful!")) + Ok(String::from("(0x00) Confirmation successful!")) } -#[get("/api/delete/{address}")] -async fn delete(email: web::Path) -> Result { +#[get("/api/delete")] +async fn delete(email: web::Query) -> Result { let token = gen_random_token(); - store_pending_deletion(email.address.clone(), &token)?; - send_confirmation_email(&email.address, &Action::Delete, &token)?; - info!("User {} requested the deletion of his key!", email.address); - Ok(String::from("Deletion request submitted successfully!")) + store_pending_deletion(email.email.clone(), &token)?; + send_confirmation_email(&email.email, &Action::Delete, &token)?; + info!("User {} requested the deletion of his key!", email.email); + Ok(String::from("(0x00) Deletion request submitted successfully!")) } diff --git a/src/management.rs b/src/management.rs index d44ba78..cf35b0f 100644 --- a/src/management.rs +++ b/src/management.rs @@ -5,7 +5,7 @@ use crate::PENDING_FOLDER; use crate::{errors::Error, utils::get_filename}; use chrono::Utc; -use log::{debug, warn}; +use log::{debug, error, warn}; use serde::{Deserialize, Serialize}; use std::{fmt::Display, fs, path::Path}; @@ -74,10 +74,13 @@ pub fn store_pending_addition(pem: String, email: &str, token: &str) -> Result<( } pub fn store_pending_deletion(email: String, token: &str) -> Result<(), Error> { - match key_exists(&email) { - Err(Error::PathGeneration) => debug!("Error while generating path for user {}", email), - Err(Error::MissingKey) => debug!("There is no key for user {}", email), - _ => (), + if let Err(error) = key_exists(&email) { + match error { + Error::PathGeneration => debug!("Error while generating path for user {}", email), + Error::MissingKey => debug!("There is no key for user {}", email), + _ => error!("An unexpected error occoured!"), + } + return Err(error); } let pending = Pending::build_delete(email.clone()); store_pending(&pending, token)?;