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

[Breaking] Drop support for RSA PKCS#1 PEM keys in favor of the OpenSSH format. #272

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,12 +521,9 @@ class SshConnectionClosedException : SshConnectionException

This section lists the currently supported algorithms. If you would like support for other algorithms, you can request it with an issue in the repository. If the requested algorithm is considered insecure by current practice, it is unlikely to be added.

Supported private key formats:
- RSA in `RSA PRIVATE KEY`
- RSA, ECDSA, ED25519 in `OPENSSH PRIVATE KEY` (`openssh-key-v1`)

Supported private key encryption cyphers:
- OpenSSH Keys `OPENSSH PRIVATE KEY` (`openssh-key-v1`)
Supported private key formats*:
- RSA, ECDSA, ED25519 in `OPENSSH PRIVATE KEY` (`openssh-key-v1`) with encryption:
- none
- aes[128|192|256]-[cbc|ctr]
- aes[128|256]-gcm@openssh.com
- chacha20-poly1305@openssh.com
Expand Down Expand Up @@ -569,6 +566,8 @@ Authentications:
- gssapi-with-mic (`KerberosCredential`)
- none (`NoCredential`)

*: Please convert your keys (using `ssh-keygen`, `PuttyGen`, ...) to a supported format rather than suggesting the library should support an additional format. If you can motivate why the library should support a additional format, open an issue to request support.

## Design

* Since SSH is a network protocol, the APIs are asynchronous and implemented using C# `async` and .NET's `Task`/`ValueTask`.
Expand Down
41 changes: 0 additions & 41 deletions src/Tmds.Ssh/PrivateKeyParser.RsaPkcs1.cs

This file was deleted.

2 changes: 0 additions & 2 deletions src/Tmds.Ssh/PrivateKeyParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ internal static PrivateKey ParsePrivateKey(ReadOnlyMemory<char> rawKey, Func<str

switch (keyFormat)
{
case "-----BEGIN RSA PRIVATE KEY-----":
return ParseRsaPkcs1PemKey(keyData, metadata);
case "-----BEGIN OPENSSH PRIVATE KEY-----":
return ParseOpenSshKey(keyData, passwordPrompt);
default:
Expand Down
26 changes: 0 additions & 26 deletions test/Tmds.Ssh.Tests/PrivateKeyCredentialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,32 +73,6 @@ public async Task CtorWithRawKey()
Assert.NotNull(privateKey);
}

[Fact]
public async Task Pkcs1RsaKey()
{
await RunWithKeyConversion(_sshServer.TestUserIdentityFile, async (string localKey) =>
{
await EncryptSshKey(localKey, "PEM", null, null);
return new PrivateKeyCredential(localKey);
}, async (c) => await c.ConnectAsync());
}

[Fact]
public async Task FailPkcs1EncryptedRsaKey()
{
await RunWithKeyConversion(_sshServer.TestUserIdentityFile, async (string localKey) =>
{
await EncryptSshKey(localKey, "PEM", null, null);
await RunBinary("openssl", "pkey", "-in", localKey, "-inform", "PEM", "-out", $"{localKey}.rsa", "-traditional", "-aes256", "-passout", $"pass:{TestPassword}");
File.Move($"{localKey}.rsa", localKey, overwrite: true);
return new PrivateKeyCredential(localKey, TestPassword);
}, async (SshClient client) =>
{
var exc = await Assert.ThrowsAnyAsync<ConnectFailedException>(() => client.ConnectAsync());
Assert.IsType<PrivateKeyLoadException>(exc.InnerException);
});
}

[Theory]
[InlineData(null)]
[InlineData("aes128-cbc")]
Expand Down