using System; using System.Collections.Generic; using System.Linq; using System.Text; using Renci.SshNet.Common; using Renci.SshNet.Messages.Transport; using Renci.SshNet.Security; using Renci.SshNet.Sftp; namespace Renci.SshNet { /// /// Basic factory for creating new services. /// internal partial class ServiceFactory : IServiceFactory { /// /// Creates a . /// /// /// A . /// public IClientAuthentication CreateClientAuthentication() { return new ClientAuthentication(); } /// /// Creates a new with the specified . /// /// The to use for creating a new session. /// /// An for the specified . /// /// is null. public ISession CreateSession(ConnectionInfo connectionInfo) { return new Session(connectionInfo, this); } /// /// Creates a new in a given and with /// the specified operation timeout and encoding. /// /// The to create the in. /// The operation timeout. /// The encoding. /// /// An . /// public ISftpSession CreateSftpSession(ISession session, TimeSpan operationTimeout, Encoding encoding) { return new SftpSession(session, operationTimeout, encoding); } /// /// Create a new . /// /// /// A . /// public PipeStream CreatePipeStream() { return new PipeStream(); } /// /// Negotiates a key exchange algorithm, and creates a for the negotiated /// algorithm. /// /// A of the key exchange algorithms supported by the client where key is the name of the algorithm, and value is the type implementing this algorithm. /// The names of the key exchange algorithms supported by the SSH server. /// /// A that was negotiated between client and server. /// /// is null. /// is null. /// No key exchange algorithms are supported by both client and server. public IKeyExchange CreateKeyExchange(IDictionary clientAlgorithms, string[] serverAlgorithms) { if (clientAlgorithms == null) throw new ArgumentNullException("clientAlgorithms"); if (serverAlgorithms == null) throw new ArgumentNullException("serverAlgorithms"); // find an algorithm that is supported by both client and server var keyExchangeAlgorithmType = (from c in clientAlgorithms from s in serverAlgorithms where s == c.Key select c.Value).FirstOrDefault(); if (keyExchangeAlgorithmType == null) { throw new SshConnectionException("Failed to negotiate key exchange algorithm.", DisconnectReason.KeyExchangeFailed); } return keyExchangeAlgorithmType.CreateInstance(); } } }