Compare commits

...

2 Commits

Author SHA1 Message Date
Oystein Kristoffer Tveit 680f39ee27
WIP 2024-04-29 18:41:36 +02:00
Oystein Kristoffer Tveit 0c889e226b
Add flake.nix 2024-04-29 18:37:41 +02:00
5 changed files with 326 additions and 21 deletions

196
Cargo.lock generated
View File

@ -80,6 +80,15 @@ version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f538837af36e6f6a9be0faa67f9a314f8119e4e4b5867c6ab40ed60360142519"
[[package]]
name = "arrayvec"
version = "0.4.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd9fd44efafa8690358b7408d253adf110036b88f55672a933f01d616ad9b1b9"
dependencies = [
"nodrop",
]
[[package]]
name = "autocfg"
version = "1.2.0"
@ -94,7 +103,7 @@ checksum = "26b05800d2e817c8b3b4b54abd461726265fa9789ae34330622f2db9ee696f9d"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"cfg-if 1.0.0",
"libc",
"miniz_oxide",
"object",
@ -134,6 +143,12 @@ version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d32a725bc159af97c3e629873bb9f88fb8cf8a4867175f76dc987815ea07c83b"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
[[package]]
name = "cfg-if"
version = "1.0.0"
@ -168,10 +183,10 @@ version = "4.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
"heck 0.5.0",
"proc-macro2 1.0.81",
"quote 1.0.36",
"syn 2.0.60",
]
[[package]]
@ -244,6 +259,44 @@ dependencies = [
"log",
]
[[package]]
name = "errno"
version = "0.2.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1"
dependencies = [
"errno-dragonfly",
"libc",
"winapi",
]
[[package]]
name = "errno-dragonfly"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf"
dependencies = [
"cc",
"libc",
]
[[package]]
name = "file-descriptors"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24ae4625507f29129d657453e2e32da40cb9c77584bdbda1a89dee7f73c13f81"
dependencies = [
"arrayvec",
"bitflags",
"cfg-if 0.1.10",
"errno",
"libc",
"likely",
"memchr",
"strum",
"strum_macros",
]
[[package]]
name = "fnv"
version = "1.0.7"
@ -271,9 +324,9 @@ version = "0.3.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.81",
"quote 1.0.36",
"syn 2.0.60",
]
[[package]]
@ -319,7 +372,7 @@ version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"wasi",
]
@ -330,6 +383,15 @@ version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]]
name = "heck"
version = "0.5.0"
@ -387,6 +449,12 @@ version = "0.2.153"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd"
[[package]]
name = "likely"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a376724c7528c066bb67f2e958a9ce95f1dee26a57e614f64a9e7b15ea0bb9f5"
[[package]]
name = "lock_api"
version = "0.4.11"
@ -429,6 +497,12 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "nodrop"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb"
[[package]]
name = "num_cpus"
version = "1.16.0"
@ -464,7 +538,7 @@ version = "0.9.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"libc",
"redox_syscall",
"smallvec",
@ -495,6 +569,15 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid",
]
[[package]]
name = "proc-macro2"
version = "1.0.81"
@ -504,13 +587,22 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
"proc-macro2 1.0.81",
]
[[package]]
@ -599,7 +691,7 @@ version = "0.10.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba"
dependencies = [
"cfg-if",
"cfg-if 1.0.0",
"cpufeatures",
"digest",
]
@ -644,14 +736,43 @@ version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "strum"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6b3fc98c482ff9bb37a6db6a6491218c4c82bec368bd5682033e5b96b969143"
[[package]]
name = "strum_macros"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6969d7021d96b53b12b774d4f412026f1debe7f168a0b8c59e93b4c1e850a05f"
dependencies = [
"heck 0.3.3",
"proc-macro2 0.4.30",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid",
]
[[package]]
name = "syn"
version = "2.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.81",
"quote 1.0.36",
"unicode-ident",
]
@ -670,9 +791,9 @@ version = "1.0.59"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1cd413b5d558b4c5bf3680e324a6fa5014e7b7c067a51e69dbdf47eb7148b66"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.81",
"quote 1.0.36",
"syn 2.0.60",
]
[[package]]
@ -715,9 +836,9 @@ version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.81",
"quote 1.0.36",
"syn 2.0.60",
]
[[package]]
@ -778,6 +899,18 @@ dependencies = [
"tinyvec",
]
[[package]]
name = "unicode-segmentation"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "url"
version = "2.5.0"
@ -813,6 +946,28 @@ version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-sys"
version = "0.48.0"
@ -959,6 +1114,7 @@ dependencies = [
"anyhow",
"clap",
"env_logger",
"file-descriptors",
"futures-util",
"log",
"tokio",

View File

@ -3,6 +3,8 @@ name = "woossh"
version = "0.1.0"
edition = "2021"
license = "GPL-3.0+"
description = "A websocket tunnel for SSH"
repository = "https://git.pvv.ntnu.no/oysteikt/woossh"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -10,12 +12,16 @@ license = "GPL-3.0+"
anyhow = "1.0.82"
clap = { version = "4.5.4", features = ["derive"] }
env_logger = "0.11.3"
file-descriptors = { version = "0.9.1", optional = true }
futures-util = "0.3.30"
log = "0.4.21"
tokio = { version = "1.37.0", features = ["full"] }
tokio-tungstenite = "0.21.0"
tungstenite = "0.21.0"
[features]
socket-activation = ["dep:file-descriptors"]
[[bin]]
name = "wssh"
path = "src/main.rs"

66
flake.lock Normal file
View File

@ -0,0 +1,66 @@
{
"nodes": {
"fenix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
],
"rust-analyzer-src": "rust-analyzer-src"
},
"locked": {
"lastModified": 1714285404,
"narHash": "sha256-MmoQIO+KRiH3UnH0myAp2Fgi84rmpROMfw9VIbqrjHA=",
"owner": "nix-community",
"repo": "fenix",
"rev": "94be183087845937b0fd77281c37d0796572b899",
"type": "github"
},
"original": {
"owner": "nix-community",
"repo": "fenix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1714253743,
"narHash": "sha256-mdTQw2XlariysyScCv2tTE45QSU9v/ezLcHJ22f0Nxc=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "58a1abdbae3217ca6b702f03d3b35125d88a2994",
"type": "github"
},
"original": {
"owner": "NixOS",
"ref": "nixos-unstable",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"fenix": "fenix",
"nixpkgs": "nixpkgs"
}
},
"rust-analyzer-src": {
"flake": false,
"locked": {
"lastModified": 1714217560,
"narHash": "sha256-zttBYGaoHpZfqWHQ8OI5f9OkGHCHb8tDBMySwsYNa2U=",
"owner": "rust-lang",
"repo": "rust-analyzer",
"rev": "f216be4a0746142c5f30835b254871256a7637b8",
"type": "github"
},
"original": {
"owner": "rust-lang",
"ref": "nightly",
"repo": "rust-analyzer",
"type": "github"
}
}
},
"root": "root",
"version": 7
}

67
flake.nix Normal file
View File

@ -0,0 +1,67 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
fenix.url = "github:nix-community/fenix";
fenix.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = { self, nixpkgs, fenix }:
let
systems = [
"x86_64-linux"
"aarch64-linux"
"x86_64-darwin"
"aarch64-darwin"
];
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: let
toolchain = fenix.packages.${system}.complete;
pkgs = import nixpkgs {
inherit system;
overlays = [
(_: super: let pkgs = fenix.inputs.nixpkgs.legacyPackages.${system}; in fenix.overlays.default pkgs pkgs)
];
};
in f system pkgs toolchain);
in {
apps = forAllSystems (system: pkgs: _: let
mkApp = program: {
type = "app";
program = "${pkgs.lib.getExe program}";
};
in {
default = mkApp self.packages.${system}.default;
});
devShell = forAllSystems (system: pkgs: toolchain: pkgs.mkShell {
packages = [
(toolchain.withComponents [
"cargo" "rustc" "rustfmt" "clippy"
])
];
RUST_SRC_PATH = "${toolchain.rust-src}/lib/rustlib/src/rust/";
});
overlays.default = final: prev: self.packages.${final.system};
packages = (forAllSystems (system: pkgs: _: {
default = let
cargo-toml = pkgs.lib.importTOML ./Cargo.toml;
in pkgs.rustPlatform.buildRustPackage rec {
pname = cargo-toml.package.name;
version = cargo-toml.package.version;
src = ./.;
cargoSha256 = "sha256-ykcbKz8NnSw1uP8ajBVr/PGZKrDJvjFKpaFOyKoEGTc=";
meta = with pkgs.lib; {
description = cargo-toml.package.description;
homepage = cargo-toml.package.repository;
license = licenses.mit;
platforms = systems;
mainProgram = (pkgs.lib.head cargo-toml.bin).name;
};
};
}));
};
}

View File

@ -56,6 +56,8 @@ async fn main() -> anyhow::Result<()> {
match args.command {
SubCommand::Connect(args) => connect(args).await,
SubCommand::Server(args) => server(args).await,
#[cfg(feature = "socket_activation")]
SubCommand::SocketActivation => socket_activation().await,
}
}
@ -210,4 +212,12 @@ async fn handle_client(stream: TcpStream, ssh_socket: String) -> anyhow::Result<
tokio::try_join!(stdin_receiver, stdout_forwarder)?;
Ok(())
}
}
// --------------------------------------------------------- //
#[cfg(feature = "socket_activation")]
async fn socket_activation() -> anyhow::Result<()> {
let raw_connection = unsafe { std::net::TcpStream::from_raw_fd(3) };
Ok(())
}