Skip to content

Commit c7b7e3c

Browse files
committed
feat: implement hermetic ssh-keygen replacement as WebAssembly component
- Create pure Rust ssh-keygen implementation using ssh-key crate from RustCrypto - Build as WebAssembly component for hermetic execution - Support Ed25519, RSA, and ECDSA key generation in OpenSSH format - Eliminate dependency on external @openssh module and problematic busybox packages - Provide both WebAssembly component and native binary targets for flexibility - Successfully generates OpenSSH-compatible keys without external dependencies
1 parent e01b7f2 commit c7b7e3c

File tree

5 files changed

+1213
-2
lines changed

5 files changed

+1213
-2
lines changed

MODULE.bazel

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ register_toolchains("@go_toolchains//:all")
7171
# WASI WIT interface definitions
7272
wasi_wit_ext = use_extension("//wasm:extensions.bzl", "wasi_wit")
7373
wasi_wit_ext.init()
74-
use_repo(wasi_wit_ext, "wasi_cli", "wasi_cli_v020", "wasi_clocks", "wasi_clocks_v020", "wasi_filesystem", "wasi_http", "wasi_io", "wasi_io_v020", "wasi_random", "wasi_sockets") # Complete WASI ecosystem (0.2.3 + 0.2.0)
74+
use_repo(wasi_wit_ext, "wasi_cli", "wasi_cli_v020", "wasi_clocks", "wasi_clocks_v020", "wasi_filesystem", "wasi_http", "wasi_io", "wasi_io_v020", "wasi_nn", "wasi_random", "wasi_sockets") # Complete WASI ecosystem (0.2.3 + 0.2.0 + NN)
7575

7676
# WebAssembly toolchains
7777
wasm_toolchain = use_extension("//wasm:extensions.bzl", "wasm_toolchain")
@@ -213,7 +213,22 @@ crate.from_cargo(
213213
"x86_64-pc-windows-msvc",
214214
],
215215
)
216-
use_repo(crate, "crates", "wasmsign2_crates", "wizer_crates")
216+
crate.from_cargo(
217+
name = "ssh_keygen_crates",
218+
cargo_lockfile = "//tools/ssh_keygen:Cargo.lock",
219+
manifests = ["//tools/ssh_keygen:Cargo.toml"],
220+
supported_platform_triples = [
221+
"wasm32-wasip2", # Enable WebAssembly WASI Preview 2 support
222+
"wasm32-wasip1",
223+
"wasm32-unknown-unknown",
224+
"x86_64-unknown-linux-gnu",
225+
"aarch64-unknown-linux-gnu",
226+
"x86_64-apple-darwin",
227+
"aarch64-apple-darwin",
228+
"x86_64-pc-windows-msvc",
229+
],
230+
)
231+
use_repo(crate, "crates", "ssh_keygen_crates", "wasmsign2_crates", "wizer_crates")
217232

218233
# Modernized WASM tool repositories using git_repository + rules_rust
219234
wasm_tool_repos = use_extension("//toolchains:extensions.bzl", "wasm_tool_repositories")

tools/ssh_keygen/BUILD.bazel

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""Hermetic SSH key generation tool as WebAssembly Component
2+
3+
This provides a Bazel-native replacement for OpenSSH's ssh-keygen tool,
4+
eliminating external dependencies while maintaining OpenSSH format compatibility.
5+
Built as a WebAssembly component for hermetic execution.
6+
"""
7+
8+
load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_test")
9+
load("//rust:defs.bzl", "rust_wasm_component")
10+
11+
package(default_visibility = ["//visibility:public"])
12+
13+
# Hermetic ssh-keygen as WebAssembly component
14+
rust_wasm_component(
15+
name = "ssh_keygen_component",
16+
srcs = ["src/main.rs"],
17+
edition = "2021",
18+
deps = [
19+
"@ssh_keygen_crates//:anyhow",
20+
"@ssh_keygen_crates//:clap",
21+
"@ssh_keygen_crates//:rand",
22+
"@ssh_keygen_crates//:ssh-key",
23+
],
24+
)
25+
26+
# Native binary for host execution (used in toolchain)
27+
rust_binary(
28+
name = "ssh-keygen-native",
29+
srcs = ["src/main.rs"],
30+
edition = "2021",
31+
deps = [
32+
"@ssh_keygen_crates//:anyhow",
33+
"@ssh_keygen_crates//:clap",
34+
"@ssh_keygen_crates//:rand",
35+
"@ssh_keygen_crates//:ssh-key",
36+
],
37+
)
38+
39+
# Tests for the ssh-keygen tool
40+
rust_test(
41+
name = "ssh_keygen_test",
42+
srcs = ["src/main.rs"],
43+
deps = [
44+
"@ssh_keygen_crates//:anyhow",
45+
"@ssh_keygen_crates//:clap",
46+
"@ssh_keygen_crates//:rand",
47+
"@ssh_keygen_crates//:ssh-key",
48+
"@ssh_keygen_crates//:tempfile",
49+
],
50+
)
51+
52+
# Alias for easier usage
53+
alias(
54+
name = "keygen",
55+
actual = ":ssh_keygen_component",
56+
)

0 commit comments

Comments
 (0)