| 25 | const CLUSTER_SECRET_LEN: usize = 32; |
| 26 | |
| 27 | pub fn create(data_dir: &Path, for_node: u64, ttl: Duration) -> Result<(), String> { |
| 28 | let secret_path = data_dir.join("tls").join("cluster_secret.bin"); |
| 29 | let secret = read_cluster_secret(&secret_path)?; |
| 30 | |
| 31 | let expiry = SystemTime::now() |
| 32 | .duration_since(UNIX_EPOCH) |
| 33 | .map_err(|e| format!("system clock before UNIX epoch: {e}"))? |
| 34 | + ttl; |
| 35 | let expiry_secs = expiry.as_secs(); |
| 36 | |
| 37 | let hex = tok::issue_token(&secret, for_node, expiry_secs) |
| 38 | .map_err(|e| format!("issue token: {e}"))?; |
| 39 | |
| 40 | println!("join token (expires at unix {expiry_secs}):"); |
| 41 | println!("{hex}"); |
| 42 | println!(); |
| 43 | println!("usage on joiner:"); |
| 44 | println!(" NODEDB_JOIN_TOKEN={hex} nodedb <config.toml>"); |
| 45 | Ok(()) |
| 46 | } |
| 47 | |
| 48 | fn read_cluster_secret(path: &Path) -> Result<[u8; CLUSTER_SECRET_LEN], String> { |
| 49 | let bytes = |