security(server): use SysRng directly for bootstrap token generation
Replace make_rng()/StdRng with UnwrapErr(SysRng) to eliminate the PRNG intermediate layer and make OS entropy derivation explicit and unambiguous. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1
server/Cargo.lock
generated
1
server/Cargo.lock
generated
@@ -771,6 +771,7 @@ dependencies = [
|
|||||||
"proptest",
|
"proptest",
|
||||||
"prost-types",
|
"prost-types",
|
||||||
"rand 0.10.1",
|
"rand 0.10.1",
|
||||||
|
"rand_core 0.10.1",
|
||||||
"rcgen",
|
"rcgen",
|
||||||
"restructed",
|
"restructed",
|
||||||
"rstest",
|
"rstest",
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ mutants = "0.0.4"
|
|||||||
prost = "0.14.3"
|
prost = "0.14.3"
|
||||||
prost-types = { version = "0.14.3", features = ["chrono"] }
|
prost-types = { version = "0.14.3", features = ["chrono"] }
|
||||||
rand = "0.10.1"
|
rand = "0.10.1"
|
||||||
|
rand_core = "0.10.1"
|
||||||
rcgen = { version = "0.14.7", features = [ "aws_lc_rs", "pem", "x509-parser", "zeroize" ], default-features = false }
|
rcgen = { version = "0.14.7", features = [ "aws_lc_rs", "pem", "x509-parser", "zeroize" ], default-features = false }
|
||||||
rstest = "0.26.1"
|
rstest = "0.26.1"
|
||||||
rustls = { version = "0.23.40", features = ["aws-lc-rs", "logging", "prefer-post-quantum", "std"], default-features = false }
|
rustls = { version = "0.23.40", features = ["aws-lc-rs", "logging", "prefer-post-quantum", "std"], default-features = false }
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ diesel_migrations = { version = "2.3.2", features = ["sqlite"] }
|
|||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
tokio-stream.workspace = true
|
tokio-stream.workspace = true
|
||||||
rand.workspace = true
|
rand.workspace = true
|
||||||
|
rand_core.workspace = true
|
||||||
rcgen.workspace = true
|
rcgen.workspace = true
|
||||||
chrono.workspace = true
|
chrono.workspace = true
|
||||||
kameo.workspace = true
|
kameo.workspace = true
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use arbiter_proto::{BOOTSTRAP_PATH, home_path};
|
|||||||
use diesel::QueryDsl;
|
use diesel::QueryDsl;
|
||||||
use diesel_async::RunQueryDsl;
|
use diesel_async::RunQueryDsl;
|
||||||
use kameo::{Actor, messages};
|
use kameo::{Actor, messages};
|
||||||
use rand::{RngExt, distr::Alphanumeric, make_rng, rngs::StdRng};
|
use rand::{RngExt, distr::Alphanumeric, rngs::SysRng};
|
||||||
|
use rand_core::UnwrapErr;
|
||||||
use subtle::ConstantTimeEq as _;
|
use subtle::ConstantTimeEq as _;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
use zeroize::Zeroizing;
|
use zeroize::Zeroizing;
|
||||||
@@ -12,9 +13,7 @@ use zeroize::Zeroizing;
|
|||||||
const TOKEN_LENGTH: usize = 64;
|
const TOKEN_LENGTH: usize = 64;
|
||||||
|
|
||||||
pub async fn generate_token() -> Result<String, std::io::Error> {
|
pub async fn generate_token() -> Result<String, std::io::Error> {
|
||||||
let rng: StdRng = make_rng();
|
let token = UnwrapErr(SysRng).sample_iter(Alphanumeric).take(TOKEN_LENGTH).fold(
|
||||||
|
|
||||||
let token = rng.sample_iter(Alphanumeric).take(TOKEN_LENGTH).fold(
|
|
||||||
String::default(),
|
String::default(),
|
||||||
|mut accum, char| {
|
|mut accum, char| {
|
||||||
accum += char.to_string().as_str();
|
accum += char.to_string().as_str();
|
||||||
|
|||||||
Reference in New Issue
Block a user