Spiegel von
https://github.com/dani-garcia/vaultwarden.git
synchronisiert 2024-11-26 05:50:29 +01:00
Implemented basic support for prelogin and notification negotiation
Dieser Commit ist enthalten in:
Ursprung
c91f80c456
Commit
8d1ee859f2
5 geänderte Dateien mit 63 neuen und 0 gelöschten Zeilen
|
@ -275,3 +275,31 @@ fn password_hint(data: JsonUpcase<PasswordHintData>, conn: DbConn) -> EmptyResul
|
||||||
None => Ok(()),
|
None => Ok(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
struct PreloginData {
|
||||||
|
Email: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/accounts/prelogin", data = "<data>")]
|
||||||
|
fn prelogin(data: JsonUpcase<PreloginData>, conn: DbConn) -> JsonResult {
|
||||||
|
let data: PreloginData = data.into_inner().data;
|
||||||
|
|
||||||
|
match User::find_by_mail(&data.Email, &conn) {
|
||||||
|
Some(user) => {
|
||||||
|
let kdf_type = 0; // PBKDF2: 0
|
||||||
|
|
||||||
|
let _server_iter = user.password_iterations;
|
||||||
|
let client_iter = 5000; // TODO: Make iterations user configurable
|
||||||
|
|
||||||
|
|
||||||
|
Ok(Json(json!({
|
||||||
|
"Kdf": kdf_type,
|
||||||
|
"KdfIterations": client_iter
|
||||||
|
})))
|
||||||
|
},
|
||||||
|
None => err!("Invalid user"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ pub fn routes() -> Vec<Route> {
|
||||||
delete_account,
|
delete_account,
|
||||||
revision_date,
|
revision_date,
|
||||||
password_hint,
|
password_hint,
|
||||||
|
prelogin,
|
||||||
|
|
||||||
sync,
|
sync,
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,13 @@ pub(crate) mod core;
|
||||||
mod icons;
|
mod icons;
|
||||||
mod identity;
|
mod identity;
|
||||||
mod web;
|
mod web;
|
||||||
|
mod notifications;
|
||||||
|
|
||||||
pub use self::core::routes as core_routes;
|
pub use self::core::routes as core_routes;
|
||||||
pub use self::icons::routes as icons_routes;
|
pub use self::icons::routes as icons_routes;
|
||||||
pub use self::identity::routes as identity_routes;
|
pub use self::identity::routes as identity_routes;
|
||||||
pub use self::web::routes as web_routes;
|
pub use self::web::routes as web_routes;
|
||||||
|
pub use self::notifications::routes as notifications_routes;
|
||||||
|
|
||||||
use rocket::response::status::BadRequest;
|
use rocket::response::status::BadRequest;
|
||||||
use rocket_contrib::Json;
|
use rocket_contrib::Json;
|
||||||
|
|
31
src/api/notifications.rs
Normale Datei
31
src/api/notifications.rs
Normale Datei
|
@ -0,0 +1,31 @@
|
||||||
|
use rocket::Route;
|
||||||
|
use rocket_contrib::Json;
|
||||||
|
|
||||||
|
use db::DbConn;
|
||||||
|
use api::JsonResult;
|
||||||
|
use auth::Headers;
|
||||||
|
|
||||||
|
pub fn routes() -> Vec<Route> {
|
||||||
|
routes![negotiate]
|
||||||
|
}
|
||||||
|
|
||||||
|
#[post("/hub/negotiate")]
|
||||||
|
fn negotiate(_headers: Headers, _conn: DbConn) -> JsonResult {
|
||||||
|
use data_encoding::BASE64URL;
|
||||||
|
use crypto;
|
||||||
|
|
||||||
|
// Store this in db?
|
||||||
|
let conn_id = BASE64URL.encode(&crypto::get_random(vec![0u8; 16]));
|
||||||
|
|
||||||
|
// TODO: Implement transports
|
||||||
|
// Rocket WS support: https://github.com/SergioBenitez/Rocket/issues/90
|
||||||
|
// Rocket SSE support: https://github.com/SergioBenitez/Rocket/issues/33
|
||||||
|
Ok(Json(json!({
|
||||||
|
"connectionId": conn_id,
|
||||||
|
"availableTransports":[
|
||||||
|
// {"transport":"WebSockets", "transferFormats":["Text","Binary"]},
|
||||||
|
// {"transport":"ServerSentEvents", "transferFormats":["Text"]},
|
||||||
|
// {"transport":"LongPolling", "transferFormats":["Text","Binary"]}
|
||||||
|
]
|
||||||
|
})))
|
||||||
|
}
|
|
@ -45,6 +45,7 @@ fn init_rocket() -> Rocket {
|
||||||
.mount("/api", api::core_routes())
|
.mount("/api", api::core_routes())
|
||||||
.mount("/identity", api::identity_routes())
|
.mount("/identity", api::identity_routes())
|
||||||
.mount("/icons", api::icons_routes())
|
.mount("/icons", api::icons_routes())
|
||||||
|
.mount("/notifications", api::notifications_routes())
|
||||||
.manage(db::init_pool())
|
.manage(db::init_pool())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Laden …
In neuem Issue referenzieren