Changed Private Key Regex to be more tolerant regarding new lines at end of key file (#1344)

This commit is contained in:
staecthSICKAG
2024-03-06 06:42:01 +01:00
committed by GitHub
parent e66a032308
commit 0876e88330
+1 -1
View File
@@ -64,7 +64,7 @@ namespace Renci.SshNet
/// </remarks>
public class PrivateKeyFile : IPrivateKeySource, IDisposable
{
private static readonly Regex PrivateKeyRegex = new Regex(@"^-+ *BEGIN (?<keyName>\w+( \w+)*) PRIVATE KEY *-+\r?\n((Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[A-F0-9]+)\r?\n\r?\n)|(Comment: ""?[^\r\n]*""?\r?\n))?(?<data>([a-zA-Z0-9/+=]{1,80}\r?\n)+)-+ *END \k<keyName> PRIVATE KEY *-+",
private static readonly Regex PrivateKeyRegex = new Regex(@"^-+ *BEGIN (?<keyName>\w+( \w+)*) PRIVATE KEY *-+\r?\n((Proc-Type: 4,ENCRYPTED\r?\nDEK-Info: (?<cipherName>[A-Z0-9-]+),(?<salt>[A-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 KEY *-+",
RegexOptions.Compiled | RegexOptions.Multiline | RegexOptions.ExplicitCapture);
private readonly List<HostAlgorithm> _hostAlgorithms = new List<HostAlgorithm>();