dalek-cryptography / curve25519-dalek

A pure-Rust implementation of group operations on Ristretto and Curve25519
Other
850 stars 416 forks source link

[docs request] how to serialize a public key in the format compatible with `~/.ssh/authorized_keys`? #634

Closed samuela closed 4 months ago

samuela commented 4 months ago

I'm attempting to more-or-less replicate the functionality of ssh-keygen with ed25519-dalek. I have poked around quite a bit but have not yet succeeding in generating a serialization of a public key that matches the format standard in ~/.ssh/authorized_keys: AAAAC3NzaC1lZDI1NTE5AAAA<xxxxxxxxxxxxx>.

Peeking at https://gist.github.com/thwarted/1024558 it looks like some DER serialization is necessary, but I have not yet found success generating a key that matches the expected format.

How does one accomplish this?

tarcieri commented 4 months ago

You can use the @RustCrypto ssh-key crate, which has a first-class integration with ed25519-dalek.

Specifically you might be interested in the ssh_key::PublicKey type. You can convert from ed25519_dalek::VerifyingKey using this From impl.

See also ssh_key::authorized_keys.

samuela commented 4 months ago

Awesome sauce, thanks @tarcieri !