ssh/
constant.rs

1/// The client version
2pub(crate) const CLIENT_VERSION: &str = "SSH-2.0-SSH_RS-0.5.0";
3pub(crate) const SSH_MAGIC: &[u8] = b"SSH-";
4
5/// The constant strings that used for ssh communication
6#[allow(dead_code)]
7pub(crate) mod ssh_str {
8    /// Pre-auth msg
9    pub const SSH_USERAUTH: &str = "ssh-userauth";
10    /// Authenticate msg
11    pub const SSH_CONNECTION: &str = "ssh-connection";
12    /// Authenticate with public key
13    pub const PUBLIC_KEY: &str = "publickey";
14    /// Authenticate with password
15    pub const PASSWORD: &str = "password";
16    /// Session level msg
17    pub const SESSION: &str = "session";
18    /// Open a Shell
19    pub const SHELL: &str = "shell";
20    /// Execute a command
21    pub const EXEC: &str = "exec";
22    /// SCP
23    pub const SCP: &str = "scp";
24    /// Request a pesudo-terminal
25    pub const PTY_REQ: &str = "pty-req";
26    /// The xterm style that used for the pty
27    pub const XTERM_VAR: &str = "xterm-256color";
28}
29
30#[allow(dead_code)]
31pub(crate) mod permission {
32    /// The default permission for directories
33    pub const DIR: &str = "775";
34    /// The default permission for files
35    pub const FILE: &str = "664";
36}
37
38/// Some constants that used when scp
39#[cfg(feature = "scp")]
40#[allow(dead_code)]
41pub(crate) mod scp {
42    /// Scp from our to the remote
43    pub const SOURCE: &str = "-f";
44    /// Scp from the remote to our
45    pub const SINK: &str = "-t";
46    /// Recursive scp for a dir
47    pub const RECURSIVE: &str = "-r";
48    /// Show details
49    pub const VERBOSE: &str = "-v";
50    /// Keep the modification, access time and permission the same with the origin
51    pub const PRESERVE_TIMES: &str = "-p";
52    /// Show not progress bar
53    pub const QUIET: &str = "-q";
54    /// Limit the bandwidth usage
55    pub const LIMIT: &str = "-l";
56
57    /// Indicate the modification, access time of the file we recieve
58    /// "T1647767946 0 1647767946 0\n";
59    pub const T: u8 = b'T';
60    /// Indicate that we are recieving a directory
61    /// "D0775 0 dirName\n"
62    pub const D: u8 = b'D';
63    /// Indicate that we are recieving a file
64    /// "C0664 200 fileName.js\n"
65    pub const C: u8 = b'C';
66    /// Indicate that current directory is done
67    /// "D\n"
68    pub const E: u8 = b'E';
69
70    /// The end flag of current operation
71    // '\0'
72    pub const END: u8 = 0;
73    /// Exceptions occur
74    pub const ERR: u8 = 1;
75    /// Exceptions that cannot recover
76    pub const FATAL_ERR: u8 = 2;
77}
78
79#[allow(dead_code)]
80pub(crate) mod size {
81    pub const FILE_CHUNK: usize = 30000;
82    /// The max size of one packet
83    pub const BUF_SIZE: usize = 32768;
84    /// The default window size of the flow-control
85    pub const LOCAL_WINDOW_SIZE: u32 = 2097152;
86}
87
88/// <https://www.rfc-editor.org/rfc/rfc4254#section-9>
89#[allow(dead_code)]
90pub(crate) mod ssh_connection_code {
91    pub const GLOBAL_REQUEST: u8 = 80;
92    pub const REQUEST_SUCCESS: u8 = 81;
93    pub const REQUEST_FAILURE: u8 = 82;
94    pub const CHANNEL_OPEN: u8 = 90;
95    pub const CHANNEL_OPEN_CONFIRMATION: u8 = 91;
96    pub const CHANNEL_OPEN_FAILURE: u8 = 92;
97    pub const CHANNEL_WINDOW_ADJUST: u8 = 93;
98    pub const CHANNEL_DATA: u8 = 94;
99    pub const CHANNEL_EXTENDED_DATA: u8 = 95;
100    pub const CHANNEL_EOF: u8 = 96;
101    pub const CHANNEL_CLOSE: u8 = 97;
102    pub const CHANNEL_REQUEST: u8 = 98;
103    pub const CHANNEL_SUCCESS: u8 = 99;
104    pub const CHANNEL_FAILURE: u8 = 100;
105}
106
107/// <https://www.rfc-editor.org/rfc/rfc4254#section-5.1>
108#[allow(dead_code)]
109pub(crate) mod ssh_channel_fail_code {
110    pub const ADMINISTRATIVELY_PROHIBITED: u32 = 1;
111    pub const CONNECT_FAILED: u32 = 2;
112    pub const UNKNOWN_CHANNEL_TYPE: u32 = 3;
113    pub const RESOURCE_SHORTAGE: u32 = 4;
114}
115
116/// <https://www.rfc-editor.org/rfc/rfc4253#section-12>
117#[allow(dead_code)]
118pub(crate) mod ssh_transport_code {
119    pub const DISCONNECT: u8 = 1;
120    pub const IGNORE: u8 = 2;
121    pub const UNIMPLEMENTED: u8 = 3;
122    pub const DEBUG: u8 = 4;
123    pub const SERVICE_REQUEST: u8 = 5;
124    pub const SERVICE_ACCEPT: u8 = 6;
125    pub const KEXINIT: u8 = 20;
126    pub const NEWKEYS: u8 = 21;
127    pub const KEXDH_INIT: u8 = 30;
128    pub const KEXDH_REPLY: u8 = 31;
129}
130
131/// <https://www.rfc-editor.org/rfc/rfc4253#section-11.1>
132#[allow(dead_code)]
133pub(crate) mod ssh_disconnection_code {
134    pub const HOST_NOT_ALLOWED_TO_CONNECT: u8 = 1;
135    pub const PROTOCOL_ERROR: u8 = 2;
136    pub const KEY_EXCHANGE_FAILED: u8 = 3;
137    pub const RESERVED: u8 = 4;
138    pub const MAC_ERROR: u8 = 5;
139    pub const COMPRESSION_ERROR: u8 = 6;
140    pub const SERVICE_NOT_AVAILABLE: u8 = 7;
141    pub const PROTOCOL_VERSION_NOT_SUPPORTED: u8 = 8;
142    pub const HOST_KEY_NOT_VERIFIABLE: u8 = 9;
143    pub const CONNECTION_LOST: u8 = 10;
144    pub const BY_APPLICATION: u8 = 11;
145    pub const TOO_MANY_CONNECTIONS: u8 = 12;
146    pub const AUTH_CANCELLED_BY_USER: u8 = 13;
147    pub const NO_MORE_AUTH_METHODS_AVAILABLE: u8 = 14;
148    pub const ILLEGAL_USER_NAME: u8 = 15;
149}
150
151/// <https://www.rfc-editor.org/rfc/rfc4252#section-6>
152#[allow(dead_code)]
153pub(crate) mod ssh_user_auth_code {
154    pub const REQUEST: u8 = 50;
155    pub const FAILURE: u8 = 51;
156    pub const SUCCESS: u8 = 52;
157    pub const BANNER: u8 = 53;
158    pub const PK_OK: u8 = 60;
159}
160
161/// The magic that used when doing hash after kex
162pub(crate) const ALPHABET: [u8; 6] = [b'A', b'B', b'C', b'D', b'E', b'F'];