mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 12:52:27 +00:00
frontend: use secret key for cookies
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -1387,6 +1387,9 @@ name = "hex"
|
|||||||
version = "0.4.3"
|
version = "0.4.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hkdf"
|
name = "hkdf"
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ quick-xml = { version = "0.37", features = [
|
|||||||
] }
|
] }
|
||||||
rust-embed = "8.5"
|
rust-embed = "8.5"
|
||||||
futures-core = "0.3.31"
|
futures-core = "0.3.31"
|
||||||
hex = "0.4.3"
|
hex = { version = "0.4.3", features = ["serde"] }
|
||||||
mime_guess = "2.0.5"
|
mime_guess = "2.0.5"
|
||||||
itertools = "0.13"
|
itertools = "0.13"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
|||||||
@@ -2,5 +2,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||||
pub struct FrontendConfig {
|
pub struct FrontendConfig {
|
||||||
secret_key: String,
|
#[serde(serialize_with = "hex::serde::serialize")]
|
||||||
|
#[serde(deserialize_with = "hex::serde::deserialize")]
|
||||||
|
pub secret_key: Vec<u8>,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,15 +62,19 @@ pub fn configure_frontend<AP: AuthenticationProvider, C: CalendarStore + ?Sized>
|
|||||||
cfg: &mut web::ServiceConfig,
|
cfg: &mut web::ServiceConfig,
|
||||||
auth_provider: Arc<AP>,
|
auth_provider: Arc<AP>,
|
||||||
store: Arc<C>,
|
store: Arc<C>,
|
||||||
|
frontend_config: FrontendConfig,
|
||||||
) {
|
) {
|
||||||
cfg.service(
|
cfg.service(
|
||||||
web::scope("")
|
web::scope("")
|
||||||
.wrap(AuthenticationMiddleware::new(auth_provider.clone()))
|
.wrap(AuthenticationMiddleware::new(auth_provider.clone()))
|
||||||
.wrap(
|
.wrap(
|
||||||
SessionMiddleware::builder(CookieSessionStore::default(), Key::from(&[0; 64]))
|
SessionMiddleware::builder(
|
||||||
.cookie_secure(true)
|
CookieSessionStore::default(),
|
||||||
.cookie_content_security(actix_session::config::CookieContentSecurity::Private)
|
Key::from(&frontend_config.secret_key),
|
||||||
.build(),
|
)
|
||||||
|
.cookie_secure(true)
|
||||||
|
.cookie_content_security(actix_session::config::CookieContentSecurity::Private)
|
||||||
|
.build(),
|
||||||
)
|
)
|
||||||
.app_data(Data::from(auth_provider))
|
.app_data(Data::from(auth_provider))
|
||||||
.app_data(Data::from(store.clone()))
|
.app_data(Data::from(store.clone()))
|
||||||
|
|||||||
15
src/app.rs
15
src/app.rs
@@ -2,7 +2,7 @@ use actix_web::body::MessageBody;
|
|||||||
use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse};
|
use actix_web::dev::{ServiceFactory, ServiceRequest, ServiceResponse};
|
||||||
use actix_web::middleware::NormalizePath;
|
use actix_web::middleware::NormalizePath;
|
||||||
use actix_web::{web, App};
|
use actix_web::{web, App};
|
||||||
use rustical_frontend::configure_frontend;
|
use rustical_frontend::{configure_frontend, FrontendConfig};
|
||||||
use rustical_store::auth::AuthenticationProvider;
|
use rustical_store::auth::AuthenticationProvider;
|
||||||
use rustical_store::{AddressbookStore, CalendarStore};
|
use rustical_store::{AddressbookStore, CalendarStore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
@@ -12,6 +12,7 @@ pub fn make_app<AS: AddressbookStore + ?Sized, CS: CalendarStore + ?Sized>(
|
|||||||
addr_store: Arc<AS>,
|
addr_store: Arc<AS>,
|
||||||
cal_store: Arc<CS>,
|
cal_store: Arc<CS>,
|
||||||
auth_provider: Arc<impl AuthenticationProvider>,
|
auth_provider: Arc<impl AuthenticationProvider>,
|
||||||
|
frontend_config: FrontendConfig,
|
||||||
) -> App<
|
) -> App<
|
||||||
impl ServiceFactory<
|
impl ServiceFactory<
|
||||||
ServiceRequest,
|
ServiceRequest,
|
||||||
@@ -38,9 +39,13 @@ pub fn make_app<AS: AddressbookStore + ?Sized, CS: CalendarStore + ?Sized>(
|
|||||||
rustical_carddav::configure_well_known(cfg, "/carddav".to_string())
|
rustical_carddav::configure_well_known(cfg, "/carddav".to_string())
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.service(
|
.service(web::scope("/frontend").configure(|cfg| {
|
||||||
web::scope("/frontend")
|
configure_frontend(
|
||||||
.configure(|cfg| configure_frontend(cfg, auth_provider.clone(), cal_store.clone())),
|
cfg,
|
||||||
)
|
auth_provider.clone(),
|
||||||
|
cal_store.clone(),
|
||||||
|
frontend_config,
|
||||||
|
)
|
||||||
|
}))
|
||||||
.service(web::redirect("/", "/frontend").see_other())
|
.service(web::redirect("/", "/frontend").see_other())
|
||||||
}
|
}
|
||||||
|
|||||||
15
src/main.rs
15
src/main.rs
@@ -50,10 +50,17 @@ async fn main() -> Result<()> {
|
|||||||
config::AuthConfig::Static(config) => StaticUserStore::new(config),
|
config::AuthConfig::Static(config) => StaticUserStore::new(config),
|
||||||
});
|
});
|
||||||
|
|
||||||
HttpServer::new(move || make_app(addr_store.clone(), cal_store.clone(), user_store.clone()))
|
HttpServer::new(move || {
|
||||||
.bind((config.http.host, config.http.port))?
|
make_app(
|
||||||
.run()
|
addr_store.clone(),
|
||||||
.await?;
|
cal_store.clone(),
|
||||||
|
user_store.clone(),
|
||||||
|
config.frontend.clone(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
.bind((config.http.host, config.http.port))?
|
||||||
|
.run()
|
||||||
|
.await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user