Skip to content

Commit

Permalink
fix newline characters in PuTTY key file comment (#1550)
Browse files Browse the repository at this point in the history
  • Loading branch information
Varorbc authored Dec 4, 2024
1 parent 3b4f2cf commit ee054f4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/Renci.SshNet/PrivateKeyFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ namespace Renci.SshNet
public partial class PrivateKeyFile : IPrivateKeySource, IDisposable
{
private const string PrivateKeyPattern = @"^-+ *BEGIN (?<keyName>\w+( \w+)*) *-+\r?\n((Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[a-fA-F0-9]+)\r?\n\r?\n)|(Comment: ""?[^\r\n]*""?\r?\n))?(?<data>([a-zA-Z0-9/+=]{1,80}\r?\n)+)(\r?\n)?-+ *END \k<keyName> *-+";
private const string PuTTYPrivateKeyPattern = @"^(?<keyName>PuTTY-User-Key-File)-(?<version>\d+): (?<algorithmName>[\w-]+)\r?\nEncryption: (?<encryptionType>[\w-]+)\r?\nComment: (?<comment>.*)\r?\nPublic-Lines: \d+\r?\n(?<publicKey>(([a-zA-Z0-9/+=]{1,64})\r?\n)+)(Key-Derivation: (?<argon2Type>\w+)\r?\nArgon2-Memory: (?<argon2Memory>\d+)\r?\nArgon2-Passes: (?<argon2Passes>\d+)\r?\nArgon2-Parallelism: (?<argon2Parallelism>\d+)\r?\nArgon2-Salt: (?<argon2Salt>[a-fA-F0-9]+)\r?\n)?Private-Lines: \d+\r?\n(?<data>(([a-zA-Z0-9/+=]{1,64})\r?\n)+)+Private-MAC: (?<mac>[a-fA-F0-9]+)";
private const string PuTTYPrivateKeyPattern = @"^(?<keyName>PuTTY-User-Key-File)-(?<version>\d+): (?<algorithmName>[\w-]+)\r?\nEncryption: (?<encryptionType>[\w-]+)\r?\nComment: (?<comment>.*?)\r?\nPublic-Lines: \d+\r?\n(?<publicKey>(([a-zA-Z0-9/+=]{1,64})\r?\n)+)(Key-Derivation: (?<argon2Type>\w+)\r?\nArgon2-Memory: (?<argon2Memory>\d+)\r?\nArgon2-Passes: (?<argon2Passes>\d+)\r?\nArgon2-Parallelism: (?<argon2Parallelism>\d+)\r?\nArgon2-Salt: (?<argon2Salt>[a-fA-F0-9]+)\r?\n)?Private-Lines: \d+\r?\n(?<data>(([a-zA-Z0-9/+=]{1,64})\r?\n)+)+Private-MAC: (?<mac>[a-fA-F0-9]+)";
private const string CertificatePattern = @"(?<type>[-\w]+@openssh\.com)\s(?<data>[a-zA-Z0-9\/+=]*)(\s+(?<comment>.*))?";

#if NET7_0_OR_GREATER
Expand Down
42 changes: 21 additions & 21 deletions test/Data/Key.PuTTY2.RSA.Encrypted.12345.ppk
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: Key.OPENSSH.RSA
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQDtbs6KCLsePWaxraXweKYs/NqBWYT8Kx4w
oJHE8xO1ZO+hl0y3uF+S2FYDuHbRruhJJ4fa3sWp46lU0YVi9FXcFVawpkkxFx0m
JMJkCMffytiT3Re9neYqso3/d9xCyHg6I+dapPodKqDXiiJXxQ+1TCcTrmyRZLG/
G34QuVWkKobm8TY78Y0MpATsXNi3q9CKEwVIAEGqO9q7SaNfTTYpiIIyvq+CXxdi
QMDifn4nJBJDHOed+sv3dmhqq6NE/ZtPlSFeBvOvwcXC6pAa9REQJlNMjwGK//q0
4if3HaERo3q/EMu1dz30TZ3o1bpx2uLBoYUniOBVYMTmZTTTpd09
AAAAB3NzaC1yc2EAAAABJQAAAQEAhV8n1KDNo6N3dkNbIf8PhKNxxb68Sgy9abub
6Q17ozTKKFOVyKTy2Du3ZJ03ep8J3/4OzCbmH88KKcp3MtdWCX6DhEB8Tt7MMcL4
7KgLQoHshe+DH09XmdYBmPNCdT6mqOB3UaoEzHDUspP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3UzrJvGp2nwPzj4qokCZKFhPYNYiCY16V0LaBRoE3mQ
Private-MAC: 191817999553b67a7516223647e90e0b17db8918
7aKnXgEFpI13WMiMB/Fxh4TZU56/tVDjrSFZOacypsS8DMdw+ovbblDRD9tzv0XO
1tRuV0K/IIkHu7PrszeWzq3MS1QMmOyOYePZtzIfEyAOBSjR4humXZKw7JZE313u
Lea/o4PgaDJAVtWTsF42o+0bNmYL3NIUNawTb+t61hVk8cEwJm2evo/ZzLE9uCeR
X6n8MJ41p/6803oCg6o7V2Qwk9Zadv6UzQDv1fLB18ZjD40FfyEWDe1jWbIZ0H1r
4XS8MIdAVXwkhqMhwzzXPtT9CdEFHY5tR0L3mKq7TrcRwJTuUbct5uHe7HeoeNWN
NjCxj9MazAMaqGe43q/FwPPXbYY7OvImFcUWFJO/k9ysVqxg5HlgLBvsl9gtXGRz
kaQgHP+2iM9GjxlJcCbviE7yD92zbfbR5moIeINqFa7TMlXGWCteJ00qyh3RbUVb
D1yJnBzKJ7S7Y3a4T861d4d5OHVhPVBpcGB43FZC0h6qChqZ0eZtRx4J6e+f/32n
6g4yvja/0nGUkrHvutfOYV0hTShGYXrIKxgBu7NYxgHdQnUnxq0e2kF9xtskXZVb
pk6ZaDbNHQW7AvUebJFnoPCPjvF8UVFJ2jimsro4PECViH3Sj9PoFpLMBmWVomtz
+EXkrISVIdudQVZPXtDp3/oRuW5Zfj5hfrxG9lsuxxtXJoBBXVVhxOVpCAzyw6lI
KN5ZdDry7GuPMDp3JBdqtAOrz2p9Z2XJp3NCgwuNjPu3qGngH/DGHi1ZA6rhzyHk
3tT96ww6Lmgiza1/d+DGNgYiRWB0aF5+Gj4ixb6jIv/OhCxHPL8dEN1HxxwanrUp
vGbhRv5xDWdf7eYuGyCUnkrlNjC7jvEOQNwx6KxLGzLcSdbIRmwmtjbbWNFk6qJv
Private-MAC: 63bf8fb4565012276cdf442031308b2157b79f67

0 comments on commit ee054f4

Please sign in to comment.