Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Private Key] Add support for PuTTY private key file format (V3 and V2) #1543

Merged
merged 3 commits into from
Dec 2, 2024

Conversation

scott-xu
Copy link
Collaborator

@scott-xu scott-xu commented Nov 21, 2024

This PR adds support for PuTTY private key file format (V3 and V2) described in https://tartarus.org/~simon/putty-snapshots/htmldoc/AppendixC.html

Close #341
Close #431
Close #434
Close #510

Notes:

  1. PuTTY private key file format V1 is not included because

    PPK version 1 was a badly designed format, only used during initial development, and not recommended for production use.

  2. The Argon2 algorithm is from latest BouncyCastle beta version. It may subject to change, then we need to change accordingly. (Hope not). Also hope BouncyCastle makes a formal release before SSH.NET next release. Update: BouncyCastle 2.5.0 is released.

@scott-xu scott-xu marked this pull request as ready for review November 22, 2024 04:41
@scott-xu scott-xu changed the title [Private Key] Add support for PuTTY private key [Private Key] Add support for PuTTY private key file format (V3 and V2) Nov 22, 2024
switch (keyType)
{
case "ssh-ed25519":
parsedKey = new ED25519Key(privateKeyReader.ReadBignum2());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ED25519Key class does not have a constructor with both publicKeyData and privateKeyData. The current implementation is to generate public key from private key. Should we add a new constructor?

public ED25519Key(byte[] privateKeyData)
{
PrivateKey = new byte[Ed25519.SecretKeySize];
PublicKey = new byte[Ed25519.PublicKeySize];
Buffer.BlockCopy(privateKeyData, 0, PrivateKey, 0, Ed25519.SecretKeySize);
Ed25519.GeneratePublicKey(privateKeyData, 0, PublicKey, 0);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems ok as it is, but I don't mind

Copy link
Collaborator

@Rob-Hague Rob-Hague left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, will wait for a stable BC release

src/Renci.SshNet/PrivateKeyFile.PuTTY.cs Show resolved Hide resolved
switch (keyType)
{
case "ssh-ed25519":
parsedKey = new ED25519Key(privateKeyReader.ReadBignum2());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems ok as it is, but I don't mind

src/Renci.SshNet/PrivateKeyFile.PuTTY.cs Outdated Show resolved Hide resolved
@Rob-Hague
Copy link
Collaborator

ooh a flaky test

@Rob-Hague Rob-Hague merged commit 3b4f2cf into sshnet:develop Dec 2, 2024
2 of 3 checks passed
@scott-xu scott-xu deleted the privatekey-putty branch December 2, 2024 22:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants