Repository navigation
feat: add ECDSA key generation to bssh-keygen and default to P-384 - #370
Conversation
OpenSSH switched ssh-keygen's default key type to ECDSA P-384, and bssh-keygen could not generate software ECDSA keys at all. This follows upstream. - New keygen::ecdsa module (exposed as keygen::generate_ecdsa) generates P-256, P-384, and P-521 keys through ssh-key's PrivateKey::random, with the same OpenSSH encoding, 0600 private file, and .pub layout as the Ed25519 generator. Unsupported sizes fail before any file is written. - The duplicated write_private_key helper now lives once in keygen/mod.rs, and RSA bit validation is exposed as rsa::validate_bits. RSA and Ed25519 output is unchanged. - bssh-keygen defaults -t to ecdsa and writes ~/.ssh/id_ecdsa. -b is now optional and resolved per type (ECDSA 384, RSA 4096, ignored for Ed25519), and is validated before the overwrite prompt, directory creation, or any file write. - Man page, README, quick start, security guide, and CHANGELOG describe the new type and call out the default change. Tests: ecdsa unit tests (round trip per curve, 0600 mode, invalid sizes, ssh-keygen -l when available), binary tests through the real bssh-keygen CLI, and a publickey authentication test against BsshServer with a listed and an unlisted P-384 key. Closes #369
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
Ed25519 and RSA generators changed only by moving the identical |
Security and performance reviewNo CRITICAL or HIGH findings, so no fixes were pushed. Verified locally: Checked and fine: Introduced by this PR (LOW)
Pre-existing, not worsened (follow-up candidates)
|
docs/README.md still labeled plain bssh-keygen as Ed25519. It now names the ECDSA P-384 default at ~/.ssh/id_ecdsa and adds an explicit -t ed25519 example. tests/keygen_ecdsa_auth_test.rs connected with the default client config, so each run appended a [127.0.0.1]:<port> line to the real ~/.ssh/known_hosts. It now connects through connect_with_ssh_config with a tempdir known_hosts file and /dev/null as the global file. Validation: cargo fmt --check, cargo clippy --lib --tests -D warnings, cargo test --test keygen_ecdsa_auth_test, --test keygen_cli_ecdsa_test and --lib keygen pass. The count of ^\[127\.0\.0\.1\]: lines in ~/.ssh/known_hosts was 98 before and after the test run. Refs #369
Summary
OpenSSH changed ssh-keygen's default key type to ECDSA P-384 (openbsd/src c7d9309). bssh-keygen follows: it can now generate software ECDSA keys, and plain
bssh-keygenwrites anecdsa-sha2-nistp384key to~/.ssh/id_ecdsa.keygen::generate_ecdsa(newsrc/keygen/ecdsa.rs) generates P-256, P-384, and P-521 keys via ssh-key'sPrivateKey::random, with the same encoding, 0600 private file, and.publayout as the Ed25519 generator. No new crates.write_private_keynow lives once insrc/keygen/mod.rs. RSA, Ed25519, and sk output is unchanged.-tdefaults toecdsa.-bis optional and resolved per type (ECDSA 384, RSA 4096, ignored for Ed25519), and is validated before the overwrite prompt,.sshor parent directory creation, or any write.docs/README.md), quick start, security guide, and CHANGELOG updated. The CHANGELOG lists the default change under a separate Behavior Changes heading: scripts relying on the old default must pass-t ed25519.User-visible: the default output file changes from
id_ed25519toid_ecdsa.bssh-server gen-host-keykeeps its Ed25519 default, and the existing RSA-bsize bug is left for a separate issue, as scoped.The CLI unit tests
test_cli_defaultsandcli_software_key_defaultswere updated because they assert the old default and the oldu32type ofbits.Test plan
cargo test --lib keygen(33 passed, including the ECDSA round trip per curve, 0600 mode, invalid sizes 0/224/2048/4096 leave no file, andssh-keygen -lreporting256/384/521 ... (ECDSA))cargo test --test keygen_cli_ecdsa_test(7 passed): the real binary withHOME=<tmp>and-y -qwrites~/.ssh/id_ecdsaas P-384,-t ecdsa -b 4096exits non-zero without creating files or prompting,-t ECDSA,-b 256/521, Ed25519 ignores-b,-Ois rejected for ecdsacargo test --test keygen_ecdsa_auth_test: a generated P-384 key authenticates againstBsshServer::run_atthrough the bssh client, and an unlisted P-384 key fails withKeyAuthFailed. The client uses a tempdir known_hosts file, so running the test never writes to the developer's~/.ssh/known_hostscargo test --bin bssh-keygen(16 passed),cargo clippy --lib --tests -- -D warnings,cargo fmt --checkcargo test --lib(1988 passed) andcargo test --tests -- --skip integration_test(all binaries passed) run locallybssh-keygenoutput is read byssh-keygen -las384 ... (ECDSA),-t rsawithout-bstill writes 4096 bits,-t ecdsa -b 4096exits 1 with the size errorCloses #369