/// <summary> /// Initializes a new instance of the <see cref="ConnectionInfo" /> class. /// </summary> /// <param name="host">Connection host.</param> /// <param name="port">Connection port.</param> /// <param name="username">Connection username.</param> /// <param name="proxyType">Type of the proxy.</param> /// <param name="proxyHost">The proxy host.</param> /// <param name="proxyPort">The proxy port.</param> /// <param name="proxyUsername">The proxy username.</param> /// <param name="proxyPassword">The proxy password.</param> /// <param name="authenticationMethods">The authentication methods.</param> /// <exception cref="ArgumentNullException"><paramref name="host"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException"><paramref name="username" /> is <c>null</c>, a zero-length string or contains only whitespace characters.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="port" /> is not within <see cref="F:System.Net.IPEndPoint.MinPort" /> and <see cref="F:System.Net.IPEndPoint.MaxPort" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="proxyType"/> is not <see cref="ProxyTypes.None"/> and <paramref name="proxyHost" /> is <c>null</c>.</exception> /// <exception cref="ArgumentOutOfRangeException"><paramref name="proxyType"/> is not <see cref="ProxyTypes.None"/> and <paramref name="proxyPort" /> is not within <see cref="F:System.Net.IPEndPoint.MinPort" /> and <see cref="F:System.Net.IPEndPoint.MaxPort" />.</exception> /// <exception cref="ArgumentNullException"><paramref name="authenticationMethods"/> is <c>null</c>.</exception> /// <exception cref="ArgumentException">No <paramref name="authenticationMethods"/> specified.</exception> public ConnectionInfo(string host, int port, string username, ProxyTypes proxyType, string proxyHost, int proxyPort, string proxyUsername, string proxyPassword, params AuthenticationMethod[] authenticationMethods) { if (host == null) { throw new ArgumentNullException("host"); } port.ValidatePort("port"); if (username == null) { throw new ArgumentNullException("username"); } if (username.All(char.IsWhiteSpace)) { throw new ArgumentException("Cannot be empty or contain only whitespace.", "username"); } if (proxyType != ProxyTypes.None) { if (proxyHost == null) { throw new ArgumentNullException("proxyHost"); } proxyPort.ValidatePort("proxyPort"); } if (authenticationMethods == null) { throw new ArgumentNullException("authenticationMethods"); } if (authenticationMethods.Length == 0) { throw new ArgumentException("At least one authentication method should be specified.", "authenticationMethods"); } // Set default connection values Timeout = DefaultTimeout; ChannelCloseTimeout = DefaultChannelCloseTimeout; RetryAttempts = 10; MaxSessions = 10; Encoding = Encoding.UTF8; KeyExchangeAlgorithms = new Dictionary <string, Type> { { "curve25519-sha256", typeof(KeyExchangeECCurve25519) }, { "*****@*****.**", typeof(KeyExchangeECCurve25519) }, { "ecdh-sha2-nistp256", typeof(KeyExchangeECDH256) }, { "ecdh-sha2-nistp384", typeof(KeyExchangeECDH384) }, { "ecdh-sha2-nistp521", typeof(KeyExchangeECDH521) }, { "diffie-hellman-group-exchange-sha256", typeof(KeyExchangeDiffieHellmanGroupExchangeSha256) }, { "diffie-hellman-group-exchange-sha1", typeof(KeyExchangeDiffieHellmanGroupExchangeSha1) }, { "diffie-hellman-group16-sha512", typeof(KeyExchangeDiffieHellmanGroup16Sha512) }, { "diffie-hellman-group14-sha256", typeof(KeyExchangeDiffieHellmanGroup14Sha256) }, { "diffie-hellman-group14-sha1", typeof(KeyExchangeDiffieHellmanGroup14Sha1) }, { "diffie-hellman-group1-sha1", typeof(KeyExchangeDiffieHellmanGroup1Sha1) }, }; Encryptions = new Dictionary <string, CipherInfo> { { "aes256-ctr", new CipherInfo(256, (key, iv) => new AesCipher(key, new CtrCipherMode(iv), null)) }, { "3des-cbc", new CipherInfo(192, (key, iv) => new TripleDesCipher(key, new CbcCipherMode(iv), null)) }, { "aes128-cbc", new CipherInfo(128, (key, iv) => new AesCipher(key, new CbcCipherMode(iv), null)) }, { "aes192-cbc", new CipherInfo(192, (key, iv) => new AesCipher(key, new CbcCipherMode(iv), null)) }, { "aes256-cbc", new CipherInfo(256, (key, iv) => new AesCipher(key, new CbcCipherMode(iv), null)) }, { "blowfish-cbc", new CipherInfo(128, (key, iv) => new BlowfishCipher(key, new CbcCipherMode(iv), null)) }, { "twofish-cbc", new CipherInfo(256, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), null)) }, { "twofish192-cbc", new CipherInfo(192, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), null)) }, { "twofish128-cbc", new CipherInfo(128, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), null)) }, { "twofish256-cbc", new CipherInfo(256, (key, iv) => new TwofishCipher(key, new CbcCipherMode(iv), null)) }, ////{"serpent256-cbc", typeof(CipherSerpent256CBC)}, ////{"serpent192-cbc", typeof(...)}, ////{"serpent128-cbc", typeof(...)}, { "arcfour", new CipherInfo(128, (key, iv) => new Arc4Cipher(key, false)) }, { "arcfour128", new CipherInfo(128, (key, iv) => new Arc4Cipher(key, true)) }, { "arcfour256", new CipherInfo(256, (key, iv) => new Arc4Cipher(key, true)) }, ////{"idea-cbc", typeof(...)}, { "cast128-cbc", new CipherInfo(128, (key, iv) => new CastCipher(key, new CbcCipherMode(iv), null)) }, ////{"*****@*****.**", typeof(...)}, { "aes128-ctr", new CipherInfo(128, (key, iv) => new AesCipher(key, new CtrCipherMode(iv), null)) }, { "aes192-ctr", new CipherInfo(192, (key, iv) => new AesCipher(key, new CtrCipherMode(iv), null)) }, }; HmacAlgorithms = new Dictionary <string, HashInfo> { { "hmac-sha1", new HashInfo(20 * 8, CryptoAbstraction.CreateHMACSHA1) }, { "hmac-sha1-96", new HashInfo(20 * 8, key => CryptoAbstraction.CreateHMACSHA1(key, 96)) }, { "hmac-sha2-256", new HashInfo(32 * 8, CryptoAbstraction.CreateHMACSHA256) }, { "hmac-sha2-256-96", new HashInfo(32 * 8, key => CryptoAbstraction.CreateHMACSHA256(key, 96)) }, { "hmac-sha2-512", new HashInfo(64 * 8, CryptoAbstraction.CreateHMACSHA512) }, { "hmac-sha2-512-96", new HashInfo(64 * 8, key => CryptoAbstraction.CreateHMACSHA512(key, 96)) }, //{"*****@*****.**", typeof(HMacSha1)}, { "hmac-ripemd160", new HashInfo(160, CryptoAbstraction.CreateHMACRIPEMD160) }, { "*****@*****.**", new HashInfo(160, CryptoAbstraction.CreateHMACRIPEMD160) }, //{"none", typeof(...)}, }; HostKeyAlgorithms = new Dictionary <string, Func <byte[], KeyHostAlgorithm> > { { "ssh-ed25519", data => new KeyHostAlgorithm("ssh-ed25519", new ED25519Key(), data) }, #if FEATURE_ECDSA { "ecdsa-sha2-nistp256", data => new KeyHostAlgorithm("ecdsa-sha2-nistp256", new EcdsaKey(), data) }, { "ecdsa-sha2-nistp384", data => new KeyHostAlgorithm("ecdsa-sha2-nistp384", new EcdsaKey(), data) }, { "ecdsa-sha2-nistp521", data => new KeyHostAlgorithm("ecdsa-sha2-nistp521", new EcdsaKey(), data) }, #endif { "ssh-rsa", data => new KeyHostAlgorithm("ssh-rsa", new RsaKey(), data) }, { "ssh-dss", data => new KeyHostAlgorithm("ssh-dss", new DsaKey(), data) }, //{"x509v3-sign-rsa", () => { ... }, //{"x509v3-sign-dss", () => { ... }, //{"spki-sign-rsa", () => { ... }, //{"spki-sign-dss", () => { ... }, //{"pgp-sign-rsa", () => { ... }, //{"pgp-sign-dss", () => { ... }, }; CompressionAlgorithms = new Dictionary <string, Type> { //{"*****@*****.**", typeof(ZlibOpenSsh)}, //{"zlib", typeof(Zlib)}, { "none", null }, }; ChannelRequests = new Dictionary <string, RequestInfo> { { EnvironmentVariableRequestInfo.Name, new EnvironmentVariableRequestInfo() }, { ExecRequestInfo.Name, new ExecRequestInfo() }, { ExitSignalRequestInfo.Name, new ExitSignalRequestInfo() }, { ExitStatusRequestInfo.Name, new ExitStatusRequestInfo() }, { PseudoTerminalRequestInfo.Name, new PseudoTerminalRequestInfo() }, { ShellRequestInfo.Name, new ShellRequestInfo() }, { SignalRequestInfo.Name, new SignalRequestInfo() }, { SubsystemRequestInfo.Name, new SubsystemRequestInfo() }, { WindowChangeRequestInfo.Name, new WindowChangeRequestInfo() }, { X11ForwardingRequestInfo.Name, new X11ForwardingRequestInfo() }, { XonXoffRequestInfo.Name, new XonXoffRequestInfo() }, { EndOfWriteRequestInfo.Name, new EndOfWriteRequestInfo() }, { KeepAliveRequestInfo.Name, new KeepAliveRequestInfo() }, }; Host = host; Port = port; Username = username; ProxyType = proxyType; ProxyHost = proxyHost; ProxyPort = proxyPort; ProxyUsername = proxyUsername; ProxyPassword = proxyPassword; AuthenticationMethods = authenticationMethods; }
public void Test_HMac_Sha256_96_Connection() { var connectionInfo = new PasswordConnectionInfo(Resources.HOST, int.Parse(Resources.PORT), Resources.USERNAME, Resources.PASSWORD); connectionInfo.HmacAlgorithms.Clear(); connectionInfo.HmacAlgorithms.Add("hmac-sha2-256-96", new HashInfo(32 * 8, (key) => CryptoAbstraction.CreateHMACSHA256(key, 96))); using (var client = new SshClient(connectionInfo)) { client.Connect(); client.Disconnect(); } }