/// <exception cref="NSch.JSchException"></exception> public override Session GetSession(string user, string pass, string host, int port , CredentialsProvider credentialsProvider, FS fs) { lock (this) { if (config == null) { config = OpenSshConfig.Get(fs); } OpenSshConfig.Host hc = config.Lookup(host); host = hc.GetHostName(); if (port <= 0) { port = hc.GetPort(); } if (user == null) { user = hc.GetUser(); } Session session = CreateSession(hc, user, host, port, fs); if (pass != null) { session.SetPassword(pass); } string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking(); if (strictHostKeyCheckingPolicy != null) { session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy); } string pauth = hc.GetPreferredAuthentications(); if (pauth != null) { session.SetConfig("PreferredAuthentications", pauth); } if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive ())) { session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider) ); } Configure(hc, session); return(session); } }
/// <exception cref="NGit.Errors.TransportException"></exception> public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider , FS fs, int tms) { lock (this) { string user = uri.GetUser(); string pass = uri.GetPass(); string host = uri.GetHost(); int port = uri.GetPort(); try { if (config == null) { config = OpenSshConfig.Get(fs); } OpenSshConfig.Host hc = config.Lookup(host); host = hc.GetHostName(); if (port <= 0) { port = hc.GetPort(); } if (user == null) { user = hc.GetUser(); } Session session = CreateSession(credentialsProvider, fs, user, pass, host, port, hc); int retries = 0; while (!session.IsConnected() && retries < 3) { try { retries++; session.Connect(tms); } catch (JSchException e) { session.Disconnect(); session = null; // if authentication failed maybe credentials changed at the // remote end therefore reset credentials and retry if (credentialsProvider != null && e.InnerException == null && e.Message.Equals("Auth fail" ) && retries < 3) { credentialsProvider.Reset(uri); session = CreateSession(credentialsProvider, fs, user, pass, host, port, hc); } else { throw; } } } return(new JschSession(session, uri)); } catch (JSchException je) { Exception c = je.InnerException; if (c is UnknownHostException) { throw new TransportException(uri, JGitText.Get().unknownHost); } if (c is ConnectException) { throw new TransportException(uri, c.Message); } throw new TransportException(uri, je.Message, je); } } }
/// <exception cref="NGit.Errors.TransportException"></exception> public override RemoteSession GetSession(URIish uri, CredentialsProvider credentialsProvider , FS fs, int tms) { lock (this) { string user = uri.GetUser(); string pass = uri.GetPass(); string host = uri.GetHost(); int port = uri.GetPort(); try { if (config == null) { config = OpenSshConfig.Get(fs); } OpenSshConfig.Host hc = config.Lookup(host); host = hc.GetHostName(); if (port <= 0) { port = hc.GetPort(); } if (user == null) { user = hc.GetUser(); } Session session = CreateSession(hc, user, host, port, fs); if (pass != null) { session.SetPassword(pass); } string strictHostKeyCheckingPolicy = hc.GetStrictHostKeyChecking(); if (strictHostKeyCheckingPolicy != null) { session.SetConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy); } string pauth = hc.GetPreferredAuthentications(); if (pauth != null) { session.SetConfig("PreferredAuthentications", pauth); } if (credentialsProvider != null && (!hc.IsBatchMode() || !credentialsProvider.IsInteractive ())) { session.SetUserInfo(new CredentialsProviderUserInfo(session, credentialsProvider) ); } Configure(hc, session); if (!session.IsConnected()) { session.Connect(tms); } return(new JschSession(session, uri)); } catch (JSchException je) { Exception c = je.InnerException; if (c is UnknownHostException) { throw new TransportException(uri, JGitText.Get().unknownHost); } if (c is ConnectException) { throw new TransportException(uri, c.Message); } throw new TransportException(uri, je.Message, je); } } }