| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b30b11a commit bc99ada
12 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,15 @@ | |||
| 1 | + using Renci.SshNet.Security; | ||
| 2 | + | ||
| 3 | + namespace Renci.SshNet | ||
| 4 | + { | ||
| 5 | + /// <summary> | ||
| 6 | + /// Represents private key source interface. | ||
| 7 | + /// </summary> | ||
| 8 | + public interface IPrivateKeySource | ||
| 9 | + { | ||
| 10 | + /// <summary> | ||
| 11 | + /// Gets the host key. | ||
| 12 | + /// </summary> | ||
| 13 | + HostAlgorithm HostKey { get; } | ||
| 14 | + } | ||
| 15 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -103,7 +103,7 @@ public NetConfClient(string host, string username, string password) | |||
| 103 | 103 | /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception> | |
| 104 | 104 | /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception> | |
| 105 | 105 | [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")] | |
| 106 | - public NetConfClient(string host, int port, string username, params PrivateKeyFile[] keyFiles) | ||
| 106 | + public NetConfClient(string host, int port, string username, params IPrivateKeySource[] keyFiles) | ||
| 107 | 107 | : this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), true) | |
| 108 | 108 | { | |
| 109 | 109 | } | |
@@ -116,7 +116,7 @@ public NetConfClient(string host, int port, string username, params PrivateKeyFi | |||
| 116 | 116 | /// <param name="keyFiles">Authentication private key file(s) .</param> | |
| 117 | 117 | /// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <c>null</c>.</exception> | |
| 118 | 118 | /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception> | |
| 119 | - public NetConfClient(string host, string username, params PrivateKeyFile[] keyFiles) | ||
| 119 | + public NetConfClient(string host, string username, params IPrivateKeySource[] keyFiles) | ||
| 120 | 120 | : this(host, ConnectionInfo.DefaultPort, username, keyFiles) | |
| 121 | 121 | { | |
| 122 | 122 | } | |
@@ -163,7 +163,7 @@ internal NetConfClient(ConnectionInfo connectionInfo, bool ownsConnectionInfo, I | |||
| 163 | 163 | /// <value> | |
| 164 | 164 | /// The NetConf server capabilities. | |
| 165 | 165 | /// </value> | |
| 166 | - public XmlDocument ServerCapabilities | ||
| 166 | + public XmlDocument ServerCapabilities | ||
| 167 | 167 | { | |
| 168 | 168 | get { return _netConfSession.ServerCapabilities; } | |
| 169 | 169 | } | |
@@ -277,4 +277,4 @@ private INetConfSession CreateAndConnectNetConfSession() | |||
| 277 | 277 | } | |
| 278 | 278 | } | |
| 279 | 279 | } | |
| 280 | - } | ||
| 280 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,21 +28,21 @@ public override string Name | |||
| 28 | 28 | /// <summary> | |
| 29 | 29 | /// Gets the key files used for authentication. | |
| 30 | 30 | /// </summary> | |
| 31 | - public ICollection<PrivateKeyFile> KeyFiles { get; private set; } | ||
| 31 | + public ICollection<IPrivateKeySource> KeyFiles { get; private set; } | ||
| 32 | 32 | ||
| 33 | 33 | /// <summary> | |
| 34 | 34 | /// Initializes a new instance of the <see cref="PrivateKeyAuthenticationMethod"/> class. | |
| 35 | 35 | /// </summary> | |
| 36 | 36 | /// <param name="username">The username.</param> | |
| 37 | 37 | /// <param name="keyFiles">The key files.</param> | |
| 38 | 38 | /// <exception cref="ArgumentException"><paramref name="username"/> is whitespace or <c>null</c>.</exception> | |
| 39 | - public PrivateKeyAuthenticationMethod(string username, params PrivateKeyFile[] keyFiles) | ||
| 39 | + public PrivateKeyAuthenticationMethod(string username, params IPrivateKeySource[] keyFiles) | ||
| 40 | 40 | : base(username) | |
| 41 | 41 | { | |
| 42 | 42 | if (keyFiles == null) | |
| 43 | 43 | throw new ArgumentNullException("keyFiles"); | |
| 44 | 44 | ||
| 45 | - KeyFiles = new Collection<PrivateKeyFile>(keyFiles); | ||
| 45 | + KeyFiles = new Collection<IPrivateKeySource>(keyFiles); | ||
| 46 | 46 | } | |
| 47 | 47 | ||
| 48 | 48 | /// <summary> | |
@@ -250,4 +250,4 @@ protected override void SaveData() | |||
| 250 | 250 | } | |
| 251 | 251 | } | |
| 252 | 252 | } | |
| 253 | - } | ||
| 253 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -15,7 +15,7 @@ public class PrivateKeyConnectionInfo : ConnectionInfo, IDisposable | |||
| 15 | 15 | /// <summary> | |
| 16 | 16 | /// Gets the key files used for authentication. | |
| 17 | 17 | /// </summary> | |
| 18 | - public ICollection<PrivateKeyFile> KeyFiles { get; private set; } | ||
| 18 | + public ICollection<IPrivateKeySource> KeyFiles { get; private set; } | ||
| 19 | 19 | ||
| 20 | 20 | /// <summary> | |
| 21 | 21 | /// Initializes a new instance of the <see cref="PrivateKeyConnectionInfo"/> class. | |
@@ -40,7 +40,7 @@ public PrivateKeyConnectionInfo(string host, string username, params PrivateKeyF | |||
| 40 | 40 | /// <param name="port">Connection port.</param> | |
| 41 | 41 | /// <param name="username">Connection username.</param> | |
| 42 | 42 | /// <param name="keyFiles">Connection key files.</param> | |
| 43 | - public PrivateKeyConnectionInfo(string host, int port, string username, params PrivateKeyFile[] keyFiles) | ||
| 43 | + public PrivateKeyConnectionInfo(string host, int port, string username, params IPrivateKeySource[] keyFiles) | ||
| 44 | 44 | : this(host, port, username, ProxyTypes.None, string.Empty, 0, string.Empty, string.Empty, keyFiles) | |
| 45 | 45 | { | |
| 46 | 46 | } | |
@@ -55,7 +55,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, params P | |||
| 55 | 55 | /// <param name="proxyHost">The proxy host.</param> | |
| 56 | 56 | /// <param name="proxyPort">The proxy port.</param> | |
| 57 | 57 | /// <param name="keyFiles">The key files.</param> | |
| 58 | - public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles) | ||
| 58 | + public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params IPrivateKeySource[] keyFiles) | ||
| 59 | 59 | : this(host, port, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles) | |
| 60 | 60 | { | |
| 61 | 61 | } | |
@@ -71,7 +71,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTyp | |||
| 71 | 71 | /// <param name="proxyPort">The proxy port.</param> | |
| 72 | 72 | /// <param name="proxyUsername">The proxy username.</param> | |
| 73 | 73 | /// <param name="keyFiles">The key files.</param> | |
| 74 | - public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles) | ||
| 74 | + public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params IPrivateKeySource[] keyFiles) | ||
| 75 | 75 | : this(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles) | |
| 76 | 76 | { | |
| 77 | 77 | } | |
@@ -85,7 +85,7 @@ public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTyp | |||
| 85 | 85 | /// <param name="proxyHost">The proxy host.</param> | |
| 86 | 86 | /// <param name="proxyPort">The proxy port.</param> | |
| 87 | 87 | /// <param name="keyFiles">The key files.</param> | |
| 88 | - public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params PrivateKeyFile[] keyFiles) | ||
| 88 | + public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, params IPrivateKeySource[] keyFiles) | ||
| 89 | 89 | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, string.Empty, string.Empty, keyFiles) | |
| 90 | 90 | { | |
| 91 | 91 | } | |
@@ -100,7 +100,7 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy | |||
| 100 | 100 | /// <param name="proxyPort">The proxy port.</param> | |
| 101 | 101 | /// <param name="proxyUsername">The proxy username.</param> | |
| 102 | 102 | /// <param name="keyFiles">The key files.</param> | |
| 103 | - public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params PrivateKeyFile[] keyFiles) | ||
| 103 | + public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, params IPrivateKeySource[] keyFiles) | ||
| 104 | 104 | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, string.Empty, keyFiles) | |
| 105 | 105 | { | |
| 106 | 106 | } | |
@@ -116,7 +116,7 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy | |||
| 116 | 116 | /// <param name="proxyUsername">The proxy username.</param> | |
| 117 | 117 | /// <param name="proxyPassword">The proxy password.</param> | |
| 118 | 118 | /// <param name="keyFiles">The key files.</param> | |
| 119 | - public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles) | ||
| 119 | + public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params IPrivateKeySource[] keyFiles) | ||
| 120 | 120 | : this(host, DefaultPort, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, keyFiles) | |
| 121 | 121 | { | |
| 122 | 122 | } | |
@@ -133,10 +133,10 @@ public PrivateKeyConnectionInfo(string host, string username, ProxyTypes proxyTy | |||
| 133 | 133 | /// <param name="proxyUsername">The proxy username.</param> | |
| 134 | 134 | /// <param name="proxyPassword">The proxy password.</param> | |
| 135 | 135 | /// <param name="keyFiles">The key files.</param> | |
| 136 | - public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params PrivateKeyFile[] keyFiles) | ||
| 136 | + public PrivateKeyConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params IPrivateKeySource[] keyFiles) | ||
| 137 | 137 | : base(host, port, username, proxyType, proxyHost, proxyPort, proxyUsername, proxyPassword, new PrivateKeyAuthenticationMethod(username, keyFiles)) | |
| 138 | 138 | { | |
| 139 | - KeyFiles = new Collection<PrivateKeyFile>(keyFiles); | ||
| 139 | + KeyFiles = new Collection<IPrivateKeySource>(keyFiles); | ||
| 140 | 140 | } | |
| 141 | 141 | ||
| 142 | 142 | #region IDisposable Members | |
@@ -194,4 +194,4 @@ protected virtual void Dispose(bool disposing) | |||
| 194 | 194 | ||
| 195 | 195 | #endregion | |
| 196 | 196 | } | |
| 197 | - } | ||
| 197 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -63,7 +63,7 @@ namespace Renci.SshNet | |||
| 63 | 63 | /// </list> | |
| 64 | 64 | /// </para> | |
| 65 | 65 | /// </remarks> | |
| 66 | - public class PrivateKeyFile : IDisposable | ||
| 66 | + public class PrivateKeyFile : IPrivateKeySource, IDisposable | ||
| 67 | 67 | { | |
| 68 | 68 | 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 *-+", | |
| 69 | 69 | #if FEATURE_REGEX_COMPILE | |
@@ -79,6 +79,15 @@ public class PrivateKeyFile : IDisposable | |||
| 79 | 79 | /// </summary> | |
| 80 | 80 | public HostAlgorithm HostKey { get; private set; } | |
| 81 | 81 | ||
| 82 | + /// <summary> | ||
| 83 | + /// Initializes a new instance of the <see cref="PrivateKeyFile"/> class. | ||
| 84 | + /// </summary> | ||
| 85 | + /// <param name="key">The key.</param> | ||
| 86 | + public PrivateKeyFile(Key key) | ||
| 87 | + { | ||
| 88 | + HostKey = new KeyHostAlgorithm(key.ToString(), key); | ||
| 89 | + } | ||
| 90 | + | ||
| 82 | 91 | /// <summary> | |
| 83 | 92 | /// Initializes a new instance of the <see cref="PrivateKeyFile"/> class. | |
| 84 | 93 | /// </summary> | |
@@ -262,7 +271,7 @@ private void Open(Stream privateKey, string passPhrase) | |||
| 262 | 271 | ||
| 263 | 272 | if (decryptedLength > blobSize - 4) | |
| 264 | 273 | throw new SshException("Invalid passphrase."); | |
| 265 | - | ||
| 274 | + | ||
| 266 | 275 | if (keyType == "if-modn{sign{rsa-pkcs1-sha1},encrypt{rsa-pkcs1v2-oaep}}") | |
| 267 | 276 | { | |
| 268 | 277 | var exponent = reader.ReadBigIntWithBits();//e | |
@@ -515,8 +524,7 @@ private Key ParseOpenSshV1Key(byte[] keyFileData, string passPhrase) | |||
| 515 | 524 | throw new SshException("OpenSSH key type '" + keyType + "' is not supported."); | |
| 516 | 525 | } | |
| 517 | 526 | ||
| 518 | - //comment, we don't need this but we could log it, not sure if necessary | ||
| 519 | - var comment = privateKeyReader.ReadString(Encoding.UTF8); | ||
| 527 | + parsedKey.Comment = privateKeyReader.ReadString(Encoding.UTF8); | ||
| 520 | 528 | ||
| 521 | 529 | //The list of privatekey/comment pairs is padded with the bytes 1, 2, 3, ... | |
| 522 | 530 | //until the total length is a multiple of the cipher block size. | |
@@ -642,4 +650,4 @@ protected override void SaveData() | |||
| 642 | 650 | } | |
| 643 | 651 | } | |
| 644 | 652 | } | |
| 645 | - } | ||
| 653 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -142,7 +142,7 @@ public ScpClient(string host, string username, string password) | |||
| 142 | 142 | /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception> | |
| 143 | 143 | /// <exception cref="ArgumentOutOfRangeException"><paramref name="port"/> is not within <see cref="IPEndPoint.MinPort"/> and <see cref="IPEndPoint.MaxPort"/>.</exception> | |
| 144 | 144 | [SuppressMessage("Microsoft.Reliability", "CA2000:DisposeObjectsBeforeLosingScope", Justification = "Disposed in Dispose(bool) method.")] | |
| 145 | - public ScpClient(string host, int port, string username, params PrivateKeyFile[] keyFiles) | ||
| 145 | + public ScpClient(string host, int port, string username, params IPrivateKeySource[] keyFiles) | ||
| 146 | 146 | : this(new PrivateKeyConnectionInfo(host, port, username, keyFiles), true) | |
| 147 | 147 | { | |
| 148 | 148 | } | |
@@ -155,7 +155,7 @@ public ScpClient(string host, int port, string username, params PrivateKeyFile[] | |||
| 155 | 155 | /// <param name="keyFiles">Authentication private key file(s) .</param> | |
| 156 | 156 | /// <exception cref="ArgumentNullException"><paramref name="keyFiles"/> is <c>null</c>.</exception> | |
| 157 | 157 | /// <exception cref="ArgumentException"><paramref name="host"/> is invalid, -or- <paramref name="username"/> is <c>null</c> or contains only whitespace characters.</exception> | |
| 158 | - public ScpClient(string host, string username, params PrivateKeyFile[] keyFiles) | ||
| 158 | + public ScpClient(string host, string username, params IPrivateKeySource[] keyFiles) | ||
| 159 | 159 | : this(host, ConnectionInfo.DefaultPort, username, keyFiles) | |
| 160 | 160 | { | |
| 161 | 161 | } | |
@@ -466,4 +466,4 @@ private static SshException SecureExecutionRequestRejectedException() | |||
| 466 | 466 | throw new SshException("Secure copy execution request was rejected by the server. Please consult the server logs."); | |
| 467 | 467 | } | |
| 468 | 468 | } | |
| 469 | - } | ||
| 469 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,6 +99,15 @@ public ED25519Key() | |||
| 99 | 99 | { | |
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | + /// <summary> | ||
| 103 | + /// Initializes a new instance of the <see cref="ED25519Key"/> class. | ||
| 104 | + /// </summary> | ||
| 105 | + /// <param name="pk">pk data.</param> | ||
| 106 | + public ED25519Key(byte[] pk) | ||
| 107 | + { | ||
| 108 | + publicKey = pk.TrimLeadingZeros().Pad(Ed25519.PublicKeySizeInBytes); | ||
| 109 | + } | ||
| 110 | + | ||
| 102 | 111 | /// <summary> | |
| 103 | 112 | /// Initializes a new instance of the <see cref="ED25519Key"/> class. | |
| 104 | 113 | /// </summary> | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -39,12 +39,12 @@ public override bool Verify(byte[] input, byte[] signature) | |||
| 39 | 39 | // for 521 sig_size is 132 | |
| 40 | 40 | var sig_size = _key.KeyLength == 521 ? 132 : _key.KeyLength / 4; | |
| 41 | 41 | var ssh_data = new SshDataSignature(signature, sig_size); | |
| 42 | - #if NETSTANDARD2_0 | ||
| 43 | - return _key.Ecdsa.VerifyData(input, ssh_data.Signature, _key.HashAlgorithm); | ||
| 44 | - #else | ||
| 42 | + #if NETFRAMEWORK | ||
| 45 | 43 | var ecdsa = (ECDsaCng)_key.Ecdsa; | |
| 46 | 44 | ecdsa.HashAlgorithm = _key.HashAlgorithm; | |
| 47 | 45 | return ecdsa.VerifyData(input, ssh_data.Signature); | |
| 46 | + #else | ||
| 47 | + return _key.Ecdsa.VerifyData(input, ssh_data.Signature, _key.HashAlgorithm); | ||
| 48 | 48 | #endif | |
| 49 | 49 | } | |
| 50 | 50 | ||
@@ -57,12 +57,12 @@ public override bool Verify(byte[] input, byte[] signature) | |||
| 57 | 57 | /// </returns> | |
| 58 | 58 | public override byte[] Sign(byte[] input) | |
| 59 | 59 | { | |
| 60 | - #if NETSTANDARD2_0 | ||
| 61 | - var signed = _key.Ecdsa.SignData(input, _key.HashAlgorithm); | ||
| 62 | - #else | ||
| 60 | + #if NETFRAMEWORK | ||
| 63 | 61 | var ecdsa = (ECDsaCng)_key.Ecdsa; | |
| 64 | 62 | ecdsa.HashAlgorithm = _key.HashAlgorithm; | |
| 65 | 63 | var signed = ecdsa.SignData(input); | |
| 64 | + #else | ||
| 65 | + var signed = _key.Ecdsa.SignData(input, _key.HashAlgorithm); | ||
| 66 | 66 | #endif | |
| 67 | 67 | var ssh_data = new SshDataSignature(signed.Length); | |
| 68 | 68 | ssh_data.Signature = signed; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments