vw_small

Hardened fork of Vaultwarden (https://github.com/dani-garcia/vaultwarden) with fewer features.
git clone https://git.philomathiclife.com/repos/vw_small
Log | Files | Refs | README

commit a0ece3754b8315ec0d220168f2dc31a2c88ffce1
parent 4cec502f7b9987d2d552060db5acd076ff988aa7
Author: Daniel GarcĂ­a <dani-garcia@users.noreply.github.com>
Date:   Fri, 27 Dec 2019 18:37:14 +0100

Formatting

Diffstat:
Mrustfmt.toml | 1+
Msrc/api/admin.rs | 4++--
Msrc/api/core/mod.rs | 7+++----
Msrc/api/core/two_factor/duo.rs | 8++------
Msrc/api/core/two_factor/email.rs | 7+------
Msrc/api/core/two_factor/yubikey.rs | 6+-----
Msrc/api/icons.rs | 2+-
Msrc/api/web.rs | 11++++-------
Msrc/auth.rs | 8++------
Msrc/config.rs | 27+++++++--------------------
Msrc/crypto.rs | 2+-
Msrc/error.rs | 2+-
Msrc/mail.rs | 14++++----------
13 files changed, 30 insertions(+), 69 deletions(-)

diff --git a/rustfmt.toml b/rustfmt.toml @@ -1 +1,2 @@ +version = "Two" max_width = 120 diff --git a/src/api/admin.rs b/src/api/admin.rs @@ -110,7 +110,7 @@ struct AdminTemplateData { users: Vec<Value>, config: Value, can_backup: bool, - logged_in: bool + logged_in: bool, } impl AdminTemplateData { @@ -121,7 +121,7 @@ impl AdminTemplateData { users, config: CONFIG.prepare_json(), can_backup: *CAN_BACKUP, - logged_in: true + logged_in: true, } } diff --git a/src/api/core/mod.rs b/src/api/core/mod.rs @@ -149,11 +149,10 @@ fn hibp_breach(username: String) -> JsonResult { use reqwest::{header::USER_AGENT, Client}; if let Some(api_key) = crate::CONFIG.hibp_api_key() { - let hibp_client = Client::builder() - .use_sys_proxy() - .build()?; + let hibp_client = Client::builder().use_sys_proxy().build()?; - let res = hibp_client.get(&url) + let res = hibp_client + .get(&url) .header(USER_AGENT, user_agent) .header("hibp-api-key", api_key) .send()?; diff --git a/src/api/core/two_factor/duo.rs b/src/api/core/two_factor/duo.rs @@ -16,11 +16,7 @@ use crate::error::MapResult; use crate::CONFIG; pub fn routes() -> Vec<Route> { - routes![ - get_duo, - activate_duo, - activate_duo_put, - ] + routes![get_duo, activate_duo, activate_duo_put,] } #[derive(Serialize, Deserialize)] @@ -171,7 +167,7 @@ fn activate_duo(data: JsonUpcase<EnableDuoData>, headers: Headers, conn: DbConn) let type_ = TwoFactorType::Duo; let twofactor = TwoFactor::new(user.uuid.clone(), type_, data_str); twofactor.save(&conn)?; - + _generate_recover_code(&mut user, &conn); Ok(Json(json!({ diff --git a/src/api/core/two_factor/email.rs b/src/api/core/two_factor/email.rs @@ -18,12 +18,7 @@ use chrono::{Duration, NaiveDateTime, Utc}; use std::ops::Add; pub fn routes() -> Vec<Route> { - routes![ - get_email, - send_email_login, - send_email, - email, - ] + routes![get_email, send_email_login, send_email, email,] } #[derive(Deserialize)] diff --git a/src/api/core/two_factor/yubikey.rs b/src/api/core/two_factor/yubikey.rs @@ -16,11 +16,7 @@ use crate::error::{Error, MapResult}; use crate::CONFIG; pub fn routes() -> Vec<Route> { - routes![ - generate_yubikey, - activate_yubikey, - activate_yubikey_put, - ] + routes![generate_yubikey, activate_yubikey, activate_yubikey_put,] } #[derive(Deserialize, Debug)] diff --git a/src/api/icons.rs b/src/api/icons.rs @@ -391,7 +391,7 @@ fn download_icon(domain: &str) -> Result<Vec<u8>, Error> { break; } } - _ => warn!("data uri is invalid") + _ => warn!("data uri is invalid"), }; } else { match get_page_with_cookies(&icon.href, &cookie_str) { diff --git a/src/api/web.rs b/src/api/web.rs @@ -7,12 +7,12 @@ use rocket::Route; use rocket_contrib::json::Json; use serde_json::Value; -use crate::util::Cached; use crate::error::Error; +use crate::util::Cached; use crate::CONFIG; pub fn routes() -> Vec<Route> { - // If addding more routes here, consider also adding them to + // If addding more routes here, consider also adding them to // crate::utils::LOGGED_ROUTES to make sure they appear in the log if CONFIG.web_vault_enabled() { routes![web_index, app_id, web_files, attachments, alive, static_files] @@ -23,9 +23,7 @@ pub fn routes() -> Vec<Route> { #[get("/")] fn web_index() -> Cached<Option<NamedFile>> { - Cached::short(NamedFile::open( - Path::new(&CONFIG.web_vault_folder()).join("index.html"), - ).ok()) + Cached::short(NamedFile::open(Path::new(&CONFIG.web_vault_folder()).join("index.html")).ok()) } #[get("/app-id.json")] @@ -79,4 +77,4 @@ fn static_files(filename: String) -> Result<Content<&'static [u8]>, Error> { "identicon.js" => Ok(Content(ContentType::JavaScript, include_bytes!("../static/scripts/identicon.js"))), _ => err!("Image not found"), } -} -\ No newline at end of file +} diff --git a/src/auth.rs b/src/auth.rs @@ -156,9 +156,7 @@ pub struct DeleteJWTClaims { pub sub: String, } -pub fn generate_delete_claims( - uuid: String, -) -> DeleteJWTClaims { +pub fn generate_delete_claims(uuid: String) -> DeleteJWTClaims { let time_now = Utc::now().naive_utc(); DeleteJWTClaims { nbf: time_now.timestamp(), @@ -180,9 +178,7 @@ pub struct VerifyEmailJWTClaims { pub sub: String, } -pub fn generate_verify_email_claims( - uuid: String, -) -> DeleteJWTClaims { +pub fn generate_verify_email_claims(uuid: String) -> DeleteJWTClaims { let time_now = Utc::now().naive_utc(); DeleteJWTClaims { nbf: time_now.timestamp(), diff --git a/src/config.rs b/src/config.rs @@ -378,7 +378,6 @@ make_config! { fn validate_config(cfg: &ConfigItems) -> Result<(), Error> { let db_url = cfg.database_url.to_lowercase(); - if cfg!(feature = "sqlite") && (db_url.starts_with("mysql:") || db_url.starts_with("postgresql:")) { err!("`DATABASE_URL` is meant for MySQL or Postgres, while this server is meant for SQLite") } @@ -447,12 +446,7 @@ impl Config { validate_config(&config)?; Ok(Config { - inner: RwLock::new(Inner { - templates: load_templates(&config.templates_folder), - config, - _env, - _usr, - }), + inner: RwLock::new(Inner { templates: load_templates(&config.templates_folder), config, _env, _usr }), }) } @@ -500,9 +494,8 @@ impl Config { let e: Vec<&str> = email.rsplitn(2, '@').collect(); if e.len() != 2 || e[0].is_empty() || e[1].is_empty() { warn!("Failed to parse email address '{}'", email); - return false + return false; } - self.signups_domains_whitelist().split(',').any(|d| d == e[0]) } @@ -634,9 +627,7 @@ impl HelperDef for CaseHelper { rc: &mut RenderContext<'reg>, out: &mut dyn Output, ) -> HelperResult { - let param = h - .param(0) - .ok_or_else(|| RenderError::new("Param not found for helper \"case\""))?; + let param = h.param(0).ok_or_else(|| RenderError::new("Param not found for helper \"case\""))?; let value = param.value().clone(); if h.params().iter().skip(1).any(|x| x.value() == &value) { @@ -658,14 +649,10 @@ impl HelperDef for JsEscapeHelper { _: &mut RenderContext<'reg>, out: &mut dyn Output, ) -> HelperResult { - let param = h - .param(0) - .ok_or_else(|| RenderError::new("Param not found for helper \"js_escape\""))?; - - let value = param - .value() - .as_str() - .ok_or_else(|| RenderError::new("Param for helper \"js_escape\" is not a String"))?; + let param = h.param(0).ok_or_else(|| RenderError::new("Param not found for helper \"js_escape\""))?; + + let value = + param.value().as_str().ok_or_else(|| RenderError::new("Param for helper \"js_escape\" is not a String"))?; let escaped_value = value.replace('\\', "").replace('\'', "\\x22").replace('\"', "\\x27"); let quoted_value = format!("&quot;{}&quot;", escaped_value); diff --git a/src/crypto.rs b/src/crypto.rs @@ -2,9 +2,9 @@ // PBKDF2 derivation // +use crate::error::Error; use ring::{digest, hmac, pbkdf2}; use std::num::NonZeroU32; -use crate::error::Error; static DIGEST_ALG: &digest::Algorithm = &digest::SHA256; const OUTPUT_LEN: usize = digest::SHA256_OUTPUT_LEN; diff --git a/src/error.rs b/src/error.rs @@ -94,7 +94,7 @@ impl std::fmt::Debug for Error { } else { write!(f, "{}. {}", self.message, s) } - }, + } ErrorKind::JsonError(_) => write!(f, "{}", self.message), _ => unreachable!(), }, diff --git a/src/mail.rs b/src/mail.rs @@ -8,7 +8,7 @@ use percent_encoding::{percent_encode, NON_ALPHANUMERIC}; use quoted_printable::encode_to_str; use crate::api::EmptyResult; -use crate::auth::{encode_jwt, generate_invite_claims, generate_delete_claims, generate_verify_email_claims}; +use crate::auth::{encode_jwt, generate_delete_claims, generate_invite_claims, generate_verify_email_claims}; use crate::error::Error; use crate::CONFIG; use chrono::NaiveDateTime; @@ -96,9 +96,7 @@ pub fn send_password_hint(address: &str, hint: Option<String>) -> EmptyResult { } pub fn send_delete_account(address: &str, uuid: &str) -> EmptyResult { - let claims = generate_delete_claims( - uuid.to_string(), - ); + let claims = generate_delete_claims(uuid.to_string()); let delete_token = encode_jwt(&claims); let (subject, body_html, body_text) = get_text( @@ -115,9 +113,7 @@ pub fn send_delete_account(address: &str, uuid: &str) -> EmptyResult { } pub fn send_verify_email(address: &str, uuid: &str) -> EmptyResult { - let claims = generate_verify_email_claims( - uuid.to_string(), - ); + let claims = generate_verify_email_claims(uuid.to_string()); let verify_email_token = encode_jwt(&claims); let (subject, body_html, body_text) = get_text( @@ -145,9 +141,7 @@ pub fn send_welcome(address: &str) -> EmptyResult { } pub fn send_welcome_must_verify(address: &str, uuid: &str) -> EmptyResult { - let claims = generate_verify_email_claims( - uuid.to_string(), - ); + let claims = generate_verify_email_claims(uuid.to_string()); let verify_email_token = encode_jwt(&claims); let (subject, body_html, body_text) = get_text(