Add SSH key pair generation - #11
Conversation
| /// The objects of this class are NOT thread safe and must NOT be used to running multiple operations | ||
| /// at the same time. If you need such functionality, create multiple MFTSftpConnection (and by doing that | ||
| /// establish multiple SFTP connections). | ||
| /// A newly generated SSH key pair. |
There was a problem hiding this comment.
By adding new class here, you separated the comment above (starting line 66) from the function (MFTSftpConnection) it refers to. This needs to be fixed.
Also, these new classes could be moved to a new file as then are not directly related to MFTSftpConnection implemented in this file.
There was a problem hiding this comment.
Appreciate the fast review of both PR's
I will adjust this PR, so it's corrected and not writing them into the existing MFTSftpConnection when not needing too.
Thank you will get back to me you asap
There was a problem hiding this comment.
Moved the new classes to their own file, mft/MFTKeyGenerator.swift. MFTSftpConnection.swift is back to how it was and does not show up in the diff at all now, so the comment is back where it should be.
Added the file to both the mft and mft ios targets, both build fine here.
846b07a to
4f6d22c
Compare
Adds MFTKeyGenerator, which generates an SSH key pair locally, with no connection needed: the key material is made before there is anything to connect to. Ed25519, RSA 4096 and ECDSA P-256 are supported, and the private half is encrypted when a passphrase is given. The pair comes back as an MFTKeyPair holding the PEM wrapped private key and a single authorized_keys line for the public half. Ed25519 private keys come out in OpenSSH format, RSA and ECDSA ones in PKCS#8. The RSA modulus size goes through an ssh_pki_ctx, since libssh otherwise defaults to 3072 bits. These types live in their own file rather than in MFTSftpConnection.swift, having nothing to do with an established connection.
4f6d22c to
4bbcae4
Compare
|
Thanks for contributing! |
Adds
MFTKeyGenerator, for generating an SSH key pair locally. No connection isinvolved: this is key material made before there is anything to connect to, so
an app can offer "generate a key" without first having a server to talk to.
Ed25519, RSA 4096 and ECDSA P-256 are supported. The pair comes back as an
MFTKeyPairholding the PEM wrapped private key and a singleauthorized_keysline for the public half, so the public half can be shown or copied directly.
Passing a passphrase encrypts the private half.
Two details worth flagging:
ssh_pki_ctx. Passing a nullcontext to
ssh_pki_generate_keyleaves libssh at its 3072 bit default, so.rsa4096would otherwise quietly produce a 3072 bit key.PKCS#8. That is libssh's behaviour; it is documented on the property rather
than normalised.
Everything is
@objcexposed, matching the rest of the framework.Verified by generating all three types, writing them out, and checking them with
ssh-keygen: the reported sizes are 256 / 4096 / 256, each public line matchesthe one
ssh-keygen -yderives from the corresponding private key, and apassphrase protected key fails to load with the wrong passphrase and succeeds
with the right one.