mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d59ae25eba | ||
|
|
d4daa35df6 | ||
|
|
ea43876410 | ||
|
|
18af1b9aa2 | ||
|
|
e69c75102c | ||
|
|
09f1bd20ae |
22
Cargo.lock
generated
22
Cargo.lock
generated
@@ -2999,7 +2999,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical"
|
name = "rustical"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"argon2",
|
"argon2",
|
||||||
@@ -3042,7 +3042,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_caldav"
|
name = "rustical_caldav"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-std",
|
"async-std",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3080,7 +3080,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_carddav"
|
name = "rustical_carddav"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -3112,7 +3112,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_dav"
|
name = "rustical_dav"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -3137,7 +3137,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_dav_push"
|
name = "rustical_dav_push"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -3163,7 +3163,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_frontend"
|
name = "rustical_frontend"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"askama",
|
"askama",
|
||||||
"askama_web",
|
"askama_web",
|
||||||
@@ -3196,7 +3196,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_ical"
|
name = "rustical_ical"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"axum",
|
"axum",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -3214,7 +3214,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_oidc"
|
name = "rustical_oidc"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"axum",
|
"axum",
|
||||||
@@ -3229,7 +3229,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_store"
|
name = "rustical_store"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -3263,7 +3263,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_store_sqlite"
|
name = "rustical_store_sqlite"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -3284,7 +3284,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustical_xml"
|
name = "rustical_xml"
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"quick-xml",
|
"quick-xml",
|
||||||
"thiserror 2.0.12",
|
"thiserror 2.0.12",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
members = ["crates/*"]
|
members = ["crates/*"]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.6.3"
|
version = "0.6.5"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
description = "A CalDAV server"
|
description = "A CalDAV server"
|
||||||
repository = "https://github.com/lennart-k/rustical"
|
repository = "https://github.com/lennart-k/rustical"
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ impl<C: CalendarStore, S: SubscriptionStore> ResourceService for CalendarResourc
|
|||||||
type Principal = Principal;
|
type Principal = Principal;
|
||||||
type PrincipalUri = CalDavPrincipalUri;
|
type PrincipalUri = CalDavPrincipalUri;
|
||||||
|
|
||||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy, webdav-push";
|
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, webdav-push";
|
||||||
|
|
||||||
async fn get_resource(
|
async fn get_resource(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -41,11 +41,6 @@ impl Resource for PrincipalResource {
|
|||||||
Resourcetype(&[
|
Resourcetype(&[
|
||||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "collection"),
|
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "collection"),
|
||||||
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "principal"),
|
ResourcetypeInner(Some(rustical_dav::namespace::NS_DAV), "principal"),
|
||||||
// https://github.com/apple/ccs-calendarserver/blob/13c706b985fb728b9aab42dc0fef85aae21921c3/doc/Extensions/caldav-proxy.txt
|
|
||||||
// ResourcetypeInner(
|
|
||||||
// Some(rustical_dav::namespace::NS_CALENDARSERVER),
|
|
||||||
// "calendar-proxy-write",
|
|
||||||
// ),
|
|
||||||
])
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ impl<AP: AuthenticationProvider, S: SubscriptionStore, CS: CalendarStore> Resour
|
|||||||
type Principal = Principal;
|
type Principal = Principal;
|
||||||
type PrincipalUri = CalDavPrincipalUri;
|
type PrincipalUri = CalDavPrincipalUri;
|
||||||
|
|
||||||
const DAV_HEADER: &str = "1, 3, access-control, calendar-access, calendar-proxy";
|
const DAV_HEADER: &str = "1, 3, access-control, calendar-access";
|
||||||
|
|
||||||
async fn get_resource(
|
async fn get_resource(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -56,9 +56,13 @@ pub async fn route_post_app_token<AP: AuthenticationProvider>(
|
|||||||
assert!(!name.is_empty());
|
assert!(!name.is_empty());
|
||||||
assert_eq!(user_id, user.id);
|
assert_eq!(user_id, user.id);
|
||||||
let token = generate_app_token();
|
let token = generate_app_token();
|
||||||
auth_provider
|
let mut token_id = auth_provider
|
||||||
.add_app_token(&user.id, name.to_owned(), token.clone())
|
.add_app_token(&user.id, name.to_owned(), token.clone())
|
||||||
.await?;
|
.await?;
|
||||||
|
// Get first 4 characters of token identifier
|
||||||
|
token_id.truncate(4);
|
||||||
|
// This will be a hint for the token validator which app token hash to verify against
|
||||||
|
let token = format!("{token_id}_{token}");
|
||||||
if apple {
|
if apple {
|
||||||
let profile = AppleConfig {
|
let profile = AppleConfig {
|
||||||
token_name: name,
|
token_name: name,
|
||||||
|
|||||||
@@ -149,8 +149,23 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
|||||||
user_id: &str,
|
user_id: &str,
|
||||||
token: &str,
|
token: &str,
|
||||||
) -> Result<Option<Principal>, Error> {
|
) -> Result<Option<Principal>, Error> {
|
||||||
|
#[instrument(skip(password))]
|
||||||
|
fn verify_password(password: &str, hash: &str) -> Result<(), password_auth::VerifyError> {
|
||||||
|
password_auth::verify_password(password, hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Allow to specify the token id to use to make validation faster
|
||||||
|
// Doesn't match the whole length of the token id to keep the length in bounds
|
||||||
|
// Example: asd_selgkh
|
||||||
|
// where the app token id starts with asd and its value is selgkh
|
||||||
|
let (token_id_prefix, token) = token.split_once('_').unwrap_or(("", token));
|
||||||
|
|
||||||
for app_token in &self.get_app_tokens(user_id).await? {
|
for app_token in &self.get_app_tokens(user_id).await? {
|
||||||
if password_auth::verify_password(token, app_token.token.as_ref()).is_ok() {
|
// Wrong token id
|
||||||
|
if !app_token.id.starts_with(token_id_prefix) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if verify_password(token, app_token.token.as_ref()).is_ok() {
|
||||||
return self.get_principal(user_id).await;
|
return self.get_principal(user_id).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -206,7 +221,10 @@ impl AuthenticationProvider for SqlitePrincipalStore {
|
|||||||
None,
|
None,
|
||||||
None,
|
None,
|
||||||
Params {
|
Params {
|
||||||
rounds: 10,
|
// The app token has a high entropy so we are quite safe from quessing attacks
|
||||||
|
// Also if an attacker got access to the hashes they'd have already gotten
|
||||||
|
// access to the whole database.
|
||||||
|
rounds: 2,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
&salt,
|
&salt,
|
||||||
|
|||||||
21
src/app.rs
21
src/app.rs
@@ -1,11 +1,13 @@
|
|||||||
use crate::config::NextcloudLoginConfig;
|
use crate::config::NextcloudLoginConfig;
|
||||||
use axum::Router;
|
use axum::Router;
|
||||||
use axum::body::Body;
|
use axum::body::{Body, HttpBody};
|
||||||
use axum::extract::Request;
|
use axum::extract::Request;
|
||||||
|
use axum::middleware::Next;
|
||||||
use axum::response::{Redirect, Response};
|
use axum::response::{Redirect, Response};
|
||||||
use axum::routing::{any, options};
|
use axum::routing::{any, options};
|
||||||
use axum_extra::TypedHeader;
|
use axum_extra::TypedHeader;
|
||||||
use headers::{HeaderMapExt, UserAgent};
|
use headers::{HeaderMapExt, UserAgent};
|
||||||
|
use http::header::CONNECTION;
|
||||||
use http::{HeaderValue, StatusCode};
|
use http::{HeaderValue, StatusCode};
|
||||||
use rustical_caldav::caldav_router;
|
use rustical_caldav::caldav_router;
|
||||||
use rustical_carddav::carddav_router;
|
use rustical_carddav::carddav_router;
|
||||||
@@ -178,4 +180,21 @@ pub fn make_app<AS: AddressbookStore, CS: CalendarStore, S: SubscriptionStore>(
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
.layer(axum::middleware::from_fn(
|
||||||
|
async |req: Request, next: Next| {
|
||||||
|
// Closes the connection if the request body might've not been fully consumed
|
||||||
|
// Otherwise subsequent requests reusing the connection might fail.
|
||||||
|
// See https://github.com/lennart-k/rustical/issues/77
|
||||||
|
let body_empty = req.body().is_end_stream();
|
||||||
|
let mut response = next.run(req).await;
|
||||||
|
if !body_empty
|
||||||
|
&& (response.status().is_server_error() || response.status().is_client_error())
|
||||||
|
{
|
||||||
|
response
|
||||||
|
.headers_mut()
|
||||||
|
.insert(CONNECTION, HeaderValue::from_static("close"));
|
||||||
|
}
|
||||||
|
response
|
||||||
|
},
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user