Skip to main content

oxdock_ssh_plugin/
lib.rs

1//! Ephemeral user-space SSH for OxDock scripts.
2//!
3//! This crate exposes an `SSH` host module through the [`Engine`]
4//! facade: `SSH_SERVE` spins up a loopback SSH server with ephemeral
5//! credentials held only in memory, while `SSH_DEQUEUE` exposes each
6//! session's metadata before `SSH_PUMP_CHANNEL` bridges it through
7//! explicit DSL pipes (`SSH_ACCEPT` combines both for simple loops).
8//! No OS users, no `sshd_config`, and no Docker are involved; killing
9//! the process removes every trace.
10//!
11//! [`Engine`]: oxdock_core::Engine
12
13mod auth;
14mod bridge;
15pub mod diagnostics;
16mod funcs;
17mod keys;
18mod pty;
19mod run;
20mod runtime;
21mod state;
22mod types;
23mod validate;
24
25pub use funcs::{module_with, module_with_endpoints};
26use oxdock_core::HostModule;
27pub use oxdock_process::DefaultProcessManager;
28
29pub use types::{SshServerTag, SshSessionTag};
30
31/// Generate a random password (256 bits, hex) for one server.
32/// Committed scripts and tests carry no usable credential: generate
33/// at runtime, hand the value to both sides, drop it after.
34pub fn generate_password() -> String {
35    use aes_gcm::aead::Generate;
36    use aes_gcm::{Aes256Gcm, Key};
37
38    let key = Key::<Aes256Gcm>::generate();
39    hex::encode(key)
40}
41
42/// The `SSH` host module with the default process manager.
43pub fn module() -> HostModule<DefaultProcessManager> {
44    module_with()
45}
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn generated_passwords_are_unique_hex() {
53        let a = generate_password();
54        let b = generate_password();
55        assert_eq!(a.len(), 64, "256 bits render as 64 hex chars");
56        assert!(
57            a.chars().all(|c| c.is_ascii_hexdigit()),
58            "hex only, safe in scripts and shells"
59        );
60        assert_ne!(a, b, "two draws must differ");
61    }
62}