1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Made bakashrot-cert write a certificate and its key both or neither, Refused a clock before 1970 at start, Noted the replication limits in the example config

- bakashrot-cert ca and issue write nothing when either file of the
  pair is there already, and remove the certificate again when its key
  can't be written.
- The server refuses to start with a clock before 1970 (pushed_at 0);
  set back that far while running isn't checked, noted in
  known-issues.md.
- The example config says to keep sync_interval under 5 min (idle links
  are closed) and what a replicated attachment can be resumed past
  (read back and hashed in 30 s). Both left as they are, why in
  known-issues.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-16 11:02:08 +01:00
parent 39ba7fce6c
commit 764bc3652a
7 changed files with 104 additions and 21 deletions
+24
View File
@@ -72,6 +72,7 @@ impl Server {
/// Reads the server's certificates and CRL, opens its database, starts
/// its writer. Errors say which file and why.
pub fn start(config: Config) -> Result<Server, String> {
check_clock(SystemTime::now())?;
let server = &config.server;
let ca = read(&server.ca)?;
let certificate = read(&server.certificate)?;
@@ -307,6 +308,15 @@ fn load_revocations(path: Option<&Path>, ca: &str) -> Result<Revocations, String
Revocations::load(&read(path)?, ca).map_err(|error| format!("{}: {error}", path.display()))
}
/// Refuses a clock before 1970: messages would be stamped `pushed_at` 0,
/// which readers refuse.
fn check_clock(now: SystemTime) -> Result<(), String> {
match now.duration_since(UNIX_EPOCH) {
Ok(_) => Ok(()),
Err(_) => Err("the system's clock is before 1970: set it right first".into()),
}
}
/// Now, in ms since 1970 UTC: when a message is pushed.
fn now() -> u64 {
SystemTime::now()
@@ -319,3 +329,17 @@ fn stamp(path: &Path) -> Option<(SystemTime, u64)> {
let metadata = std::fs::metadata(path).ok()?;
Some((metadata.modified().ok()?, metadata.len()))
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_clock_before_1970_is_refused() {
assert!(check_clock(UNIX_EPOCH).is_ok());
assert!(check_clock(SystemTime::now()).is_ok());
let before = UNIX_EPOCH - Duration::from_secs(1);
let error = check_clock(before).unwrap_err();
assert!(error.contains("before 1970"), "{error}");
}
}