mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 09:22:26 +00:00
frontend: Generate random secret by default
This commit is contained in:
@@ -1,5 +1,14 @@
|
|||||||
|
use rand::RngCore;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
pub fn generate_frontend_secret() -> [u8; 64] {
|
||||||
|
let mut rng = rand::thread_rng();
|
||||||
|
|
||||||
|
let mut secret = [0u8; 64];
|
||||||
|
rng.fill_bytes(&mut secret);
|
||||||
|
secret
|
||||||
|
}
|
||||||
|
|
||||||
fn default_true() -> bool {
|
fn default_true() -> bool {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@@ -9,6 +18,7 @@ fn default_true() -> bool {
|
|||||||
pub struct FrontendConfig {
|
pub struct FrontendConfig {
|
||||||
#[serde(serialize_with = "hex::serde::serialize")]
|
#[serde(serialize_with = "hex::serde::serialize")]
|
||||||
#[serde(deserialize_with = "hex::serde::deserialize")]
|
#[serde(deserialize_with = "hex::serde::deserialize")]
|
||||||
|
#[serde(default = "generate_frontend_secret")]
|
||||||
pub secret_key: [u8; 64],
|
pub secret_key: [u8; 64],
|
||||||
#[serde(default = "default_true")]
|
#[serde(default = "default_true")]
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ mod routes;
|
|||||||
pub const ROUTE_NAME_HOME: &str = "frontend_home";
|
pub const ROUTE_NAME_HOME: &str = "frontend_home";
|
||||||
pub const ROUTE_USER_NAMED: &str = "frontend_user_named";
|
pub const ROUTE_USER_NAMED: &str = "frontend_user_named";
|
||||||
|
|
||||||
pub use config::FrontendConfig;
|
pub use config::{FrontendConfig, generate_frontend_secret};
|
||||||
|
|
||||||
pub fn generate_app_token() -> String {
|
pub fn generate_app_token() -> String {
|
||||||
rand::thread_rng()
|
rand::thread_rng()
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ use argon2::password_hash::SaltString;
|
|||||||
use clap::{Parser, ValueEnum};
|
use clap::{Parser, ValueEnum};
|
||||||
use password_hash::PasswordHasher;
|
use password_hash::PasswordHasher;
|
||||||
use pbkdf2::Params;
|
use pbkdf2::Params;
|
||||||
use rand::{RngCore, rngs::OsRng};
|
use rand::rngs::OsRng;
|
||||||
use rustical_frontend::FrontendConfig;
|
use rustical_frontend::{FrontendConfig, generate_frontend_secret};
|
||||||
|
|
||||||
use crate::config::{
|
use crate::config::{
|
||||||
Config, DataStoreConfig, DavPushConfig, HttpConfig, SqliteDataStoreConfig, TracingConfig,
|
Config, DataStoreConfig, DavPushConfig, HttpConfig, SqliteDataStoreConfig, TracingConfig,
|
||||||
@@ -15,14 +15,6 @@ pub mod principals;
|
|||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
pub struct GenConfigArgs {}
|
pub struct GenConfigArgs {}
|
||||||
|
|
||||||
pub fn generate_frontend_secret() -> [u8; 64] {
|
|
||||||
let mut rng = rand::thread_rng();
|
|
||||||
|
|
||||||
let mut secret = [0u8; 64];
|
|
||||||
rng.fill_bytes(&mut secret);
|
|
||||||
secret
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
pub fn cmd_gen_config(_args: GenConfigArgs) -> anyhow::Result<()> {
|
||||||
let config = Config {
|
let config = Config {
|
||||||
http: HttpConfig::default(),
|
http: HttpConfig::default(),
|
||||||
|
|||||||
@@ -131,13 +131,10 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{
|
use crate::{app::make_app, config::NextcloudLoginConfig, get_data_stores};
|
||||||
app::make_app, commands::generate_frontend_secret, config::NextcloudLoginConfig,
|
|
||||||
get_data_stores,
|
|
||||||
};
|
|
||||||
use actix_web::{http::StatusCode, test::TestRequest};
|
use actix_web::{http::StatusCode, test::TestRequest};
|
||||||
use rustical_frontend::FrontendConfig;
|
|
||||||
use rustical_frontend::nextcloud_login::NextcloudFlows;
|
use rustical_frontend::nextcloud_login::NextcloudFlows;
|
||||||
|
use rustical_frontend::{FrontendConfig, generate_frontend_secret};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Reference in New Issue
Block a user