mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
[175686] Get rid of Platform CVS Dependency: Configure SSH through new IJschService and Prefs
This commit is contained in:
parent
8af84a782b
commit
69e3611f4f
11 changed files with 208 additions and 456 deletions
|
@ -25,24 +25,17 @@
|
||||||
<requires>
|
<requires>
|
||||||
<import plugin="org.eclipse.core.runtime"/>
|
<import plugin="org.eclipse.core.runtime"/>
|
||||||
<import plugin="org.eclipse.ui"/>
|
<import plugin="org.eclipse.ui"/>
|
||||||
|
<import plugin="com.jcraft.jsch" version="0.1.28" match="compatible"/>
|
||||||
|
<import plugin="org.eclipse.jsch.core"/>
|
||||||
<!-- Feature dependency due to bug 175004 (UM doesnt use plugins for "Select Required" -->
|
<!-- Feature dependency due to bug 175004 (UM doesnt use plugins for "Select Required" -->
|
||||||
<!-- But take care of bug 154505 (UM "Select Required" selects container features) -->
|
<!-- But take care of bug 154505 (UM "Select Required" selects container features) -->
|
||||||
<import feature="org.eclipse.rse.core" version="2.0.0" match="compatible"/>
|
|
||||||
<!--
|
<!--
|
||||||
|
<import feature="org.eclipse.rse.core" version="2.0.0" match="compatible"/>
|
||||||
|
-->
|
||||||
<import plugin="org.eclipse.rse.subsystems.files.core"/>
|
<import plugin="org.eclipse.rse.subsystems.files.core"/>
|
||||||
<import plugin="org.eclipse.rse.files.ui"/>
|
|
||||||
<import plugin="org.eclipse.rse.subsystems.shells.core"/>
|
<import plugin="org.eclipse.rse.subsystems.shells.core"/>
|
||||||
<import plugin="org.eclipse.rse.shells.ui"/>
|
|
||||||
<import plugin="org.eclipse.rse.services"/>
|
<import plugin="org.eclipse.rse.services"/>
|
||||||
<import plugin="org.eclipse.rse.ui"/>
|
<import plugin="org.eclipse.rse.ui"/>
|
||||||
-->
|
|
||||||
<!-- Bug 175108: Excplicit dependency on CVS for SSH -->
|
|
||||||
<!-- TM Site users can deselect SSH if they have Platform Only -->
|
|
||||||
<!-- Europa Users should be able to do "Select Required" -->
|
|
||||||
<import feature="org.eclipse.cvs" version="1.0.0" match="greaterOrEqual"/>
|
|
||||||
<!--
|
|
||||||
<import plugin="com.jcraft.jsch" version="0.1.28" match="compatible"/>
|
|
||||||
-->
|
|
||||||
</requires>
|
</requires>
|
||||||
|
|
||||||
<plugin
|
<plugin
|
||||||
|
|
|
@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.core.runtime,
|
||||||
org.eclipse.rse.core,
|
org.eclipse.rse.core,
|
||||||
org.eclipse.rse.ui,
|
org.eclipse.rse.ui,
|
||||||
org.eclipse.ui,
|
org.eclipse.ui,
|
||||||
com.jcraft.jsch;bundle-version="[0.1.28,2.0.0)"
|
com.jcraft.jsch;bundle-version="[0.1.28,1.0.0)",
|
||||||
|
org.eclipse.jsch.core
|
||||||
Eclipse-LazyStart: true
|
Eclipse-LazyStart: true
|
||||||
Export-Package: org.eclipse.rse.internal.connectorservice.ssh;x-friends:="org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh"
|
Export-Package: org.eclipse.rse.internal.connectorservice.ssh;x-friends:="org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh"
|
||||||
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006, 2007 Wind River Systems, Inc.
|
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,8 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Oberhuber (Wind River) - initial API and implementation
|
* Martin Oberhuber (Wind River) - initial API and implementation
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
|
* - copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.rse.internal.connectorservice.ssh;
|
package org.eclipse.rse.internal.connectorservice.ssh;
|
||||||
|
|
||||||
|
@ -16,44 +18,63 @@ import java.util.Date;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.Platform;
|
import org.eclipse.core.runtime.Platform;
|
||||||
import org.eclipse.jface.resource.ImageDescriptor;
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.jsch.core.IJSchService;
|
||||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.util.tracker.ServiceTracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The activator class controls the plug-in life cycle
|
* The activator class controls the plug-in life cycle
|
||||||
*/
|
*/
|
||||||
public class Activator extends AbstractUIPlugin {
|
public class Activator extends AbstractUIPlugin {
|
||||||
|
|
||||||
// The plug-in ID
|
|
||||||
public static final String PLUGIN_ID = "org.eclipse.rse.connectorservice.ssh"; //$NON-NLS-1$
|
public static final String PLUGIN_ID = "org.eclipse.rse.connectorservice.ssh"; //$NON-NLS-1$
|
||||||
|
|
||||||
// The shared instance
|
|
||||||
private static Activator plugin;
|
private static Activator plugin;
|
||||||
|
|
||||||
|
// ServiceTracker for IJschService
|
||||||
|
private ServiceTracker tracker;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The constructor
|
* The constructor
|
||||||
*/
|
*/
|
||||||
public Activator() {
|
public Activator() {
|
||||||
|
super();
|
||||||
plugin = this;
|
plugin = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
//---------------------------------------------------------------------------
|
||||||
* (non-Javadoc)
|
//<copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)>
|
||||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
//---------------------------------------------------------------------------
|
||||||
*/
|
|
||||||
public void start(BundleContext context) throws Exception {
|
public void start(BundleContext context) throws Exception {
|
||||||
super.start(context);
|
super.start(context);
|
||||||
|
tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
|
||||||
|
tracker.open();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
|
||||||
*/
|
|
||||||
public void stop(BundleContext context) throws Exception {
|
public void stop(BundleContext context) throws Exception {
|
||||||
plugin = null;
|
try {
|
||||||
super.stop(context);
|
SshConnectorService.shutdown();
|
||||||
|
tracker.close();
|
||||||
|
} finally {
|
||||||
|
plugin = null;
|
||||||
|
super.stop(context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an instance of IJSchService from the OSGi Registry.
|
||||||
|
* @return An instance of IJSchService, or <code>null</code> if no
|
||||||
|
* IJschService service is available.
|
||||||
|
*/
|
||||||
|
public IJSchService getJSchService() {
|
||||||
|
return (IJSchService)tracker.getService();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//</copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)>
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the shared instance
|
* Returns the shared instance
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Martin Oberhuber (Wind River) - extracted from various team.cvs plugins
|
* Martin Oberhuber (Wind River) - extracted from various team.cvs plugins
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.rse.internal.connectorservice.ssh;
|
package org.eclipse.rse.internal.connectorservice.ssh;
|
||||||
|
|
||||||
|
@ -17,23 +18,6 @@ package org.eclipse.rse.internal.connectorservice.ssh;
|
||||||
*/
|
*/
|
||||||
public interface ISshConstants {
|
public interface ISshConstants {
|
||||||
|
|
||||||
// These are from ISSHContants
|
|
||||||
public static final String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; //$NON-NLS-1$
|
|
||||||
public static final String KEY_PRIVATEKEY="CVSSSH2PreferencePage.PRIVATEKEY"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from ICVSUIConstants
|
|
||||||
public static final String PREF_USE_PROXY = "proxyEnabled"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_TYPE = "proxyType"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_HOST = "proxyHost"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_PORT = "proxyPort"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_AUTH = "proxyAuth"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from CVSProviderPlugin
|
|
||||||
public static final String PROXY_TYPE_HTTP = "HTTP"; //$NON-NLS-1$
|
|
||||||
public static final String PROXY_TYPE_SOCKS5 = "SOCKS5"; //$NON-NLS-1$
|
|
||||||
public static final String HTTP_DEFAULT_PORT="80"; //$NON-NLS-1$
|
|
||||||
public static final String SOCKS5_DEFAULT_PORT="1080"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from cvs.ui.IHelpContextIds
|
// These are from cvs.ui.IHelpContextIds
|
||||||
public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$
|
public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$
|
||||||
public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$
|
public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$
|
||||||
|
|
|
@ -8,45 +8,29 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Martin Oberhuber (Wind River) - initial API and implementation
|
* Martin Oberhuber (Wind River) - initial API and implementation
|
||||||
* David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies
|
* David Dykstal (IBM) - 168977: refactoring IConnectorService and ServerLauncher hierarchies
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
|
* - copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
|
||||||
package org.eclipse.rse.internal.connectorservice.ssh;
|
package org.eclipse.rse.internal.connectorservice.ssh;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.Socket;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.net.UnknownHostException;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
import org.eclipse.jface.operation.IRunnableContext;
|
import org.eclipse.jface.operation.IRunnableContext;
|
||||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
|
||||||
import org.eclipse.jface.window.Window;
|
import org.eclipse.jface.window.Window;
|
||||||
|
import org.eclipse.jsch.core.IJSchService;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.JSch;
|
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import com.jcraft.jsch.Proxy;
|
|
||||||
import com.jcraft.jsch.ProxyHTTP;
|
|
||||||
import com.jcraft.jsch.ProxySOCKS5;
|
|
||||||
import com.jcraft.jsch.Session;
|
import com.jcraft.jsch.Session;
|
||||||
import com.jcraft.jsch.SocketFactory;
|
|
||||||
import com.jcraft.jsch.UIKeyboardInteractive;
|
import com.jcraft.jsch.UIKeyboardInteractive;
|
||||||
import com.jcraft.jsch.UserInfo;
|
import com.jcraft.jsch.UserInfo;
|
||||||
|
|
||||||
|
@ -58,7 +42,6 @@ import org.eclipse.rse.core.subsystems.CommunicationsEvent;
|
||||||
import org.eclipse.rse.core.subsystems.IConnectorService;
|
import org.eclipse.rse.core.subsystems.IConnectorService;
|
||||||
import org.eclipse.rse.core.subsystems.SubSystemConfiguration;
|
import org.eclipse.rse.core.subsystems.SubSystemConfiguration;
|
||||||
import org.eclipse.rse.internal.services.ssh.ISshSessionProvider;
|
import org.eclipse.rse.internal.services.ssh.ISshSessionProvider;
|
||||||
import org.eclipse.rse.services.RemoteUtil;
|
|
||||||
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
import org.eclipse.rse.services.clientserver.messages.SystemMessage;
|
||||||
import org.eclipse.rse.ui.ISystemMessages;
|
import org.eclipse.rse.ui.ISystemMessages;
|
||||||
import org.eclipse.rse.ui.RSEUIPlugin;
|
import org.eclipse.rse.ui.RSEUIPlugin;
|
||||||
|
@ -72,7 +55,6 @@ public class SshConnectorService extends StandardConnectorService implements ISs
|
||||||
{
|
{
|
||||||
private static final int SSH_DEFAULT_PORT = 22;
|
private static final int SSH_DEFAULT_PORT = 22;
|
||||||
private static final int CONNECT_DEFAULT_TIMEOUT = 60; //seconds
|
private static final int CONNECT_DEFAULT_TIMEOUT = 60; //seconds
|
||||||
private static JSch jsch=new JSch();
|
|
||||||
private Session session;
|
private Session session;
|
||||||
private SessionLostHandler fSessionLostHandler;
|
private SessionLostHandler fSessionLostHandler;
|
||||||
|
|
||||||
|
@ -86,227 +68,53 @@ public class SshConnectorService extends StandardConnectorService implements ISs
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// <copied from org.eclipse.team.cvs.ssh2>
|
// <copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)>
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
private static String current_ssh_home = null;
|
|
||||||
private static String current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
static String SSH_HOME_DEFAULT = null;
|
|
||||||
static {
|
|
||||||
String ssh_dir_name = ".ssh"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// Windows doesn't like files or directories starting with a dot.
|
|
||||||
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
|
||||||
ssh_dir_name = "ssh"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
SSH_HOME_DEFAULT = System.getProperty("user.home"); //$NON-NLS-1$
|
|
||||||
if (SSH_HOME_DEFAULT != null) {
|
|
||||||
SSH_HOME_DEFAULT = SSH_HOME_DEFAULT + java.io.File.separator + ssh_dir_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IPreferenceStore fCvsSsh2PreferenceStore;
|
private static Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, IProgressMonitor monitor) throws JSchException {
|
||||||
static IPreferenceStore getCvsSsh2PreferenceStore() {
|
IJSchService service = Activator.getDefault().getJSchService();
|
||||||
if (fCvsSsh2PreferenceStore == null) {
|
if (service == null)
|
||||||
fCvsSsh2PreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ssh2"); //$NON-NLS-1$
|
return null;
|
||||||
}
|
Session session = service.createSession(hostname, port, username);
|
||||||
return fCvsSsh2PreferenceStore;
|
//session.setTimeout(getSshTimeoutInMillis());
|
||||||
|
session.setTimeout(0); //never time out on the session
|
||||||
|
if (password != null)
|
||||||
|
session.setPassword(password);
|
||||||
|
session.setUserInfo(wrapperUI);
|
||||||
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IPreferenceStore fCvsUIPreferenceStore;
|
static void shutdown() {
|
||||||
static IPreferenceStore getCvsUIPreferenceStore() {
|
//TODO: Store all Jsch sessions in a pool and disconnect them on shutdown
|
||||||
if (fCvsUIPreferenceStore == null) {
|
|
||||||
fCvsUIPreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ui"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return fCvsUIPreferenceStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load ssh prefs from Team/CVS for now.
|
|
||||||
// TODO do our own preference page.
|
|
||||||
static void loadSshPrefs(JSch jsch)
|
|
||||||
{
|
|
||||||
IPreferenceStore store = getCvsSsh2PreferenceStore();
|
|
||||||
String ssh_home = store.getString(ISshConstants.KEY_SSH2HOME);
|
|
||||||
String pkeys = store.getString(ISshConstants.KEY_PRIVATEKEY);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (ssh_home.length() == 0)
|
|
||||||
ssh_home = SSH_HOME_DEFAULT;
|
|
||||||
|
|
||||||
if (current_ssh_home == null || !current_ssh_home.equals(ssh_home)) {
|
|
||||||
loadKnownHosts(jsch, ssh_home);
|
|
||||||
current_ssh_home = ssh_home;
|
|
||||||
current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!current_pkeys.equals(pkeys)) {
|
|
||||||
java.io.File file;
|
|
||||||
String[] pkey = pkeys.split(","); //$NON-NLS-1$
|
|
||||||
String[] _pkey = current_pkeys.split(","); //$NON-NLS-1$
|
|
||||||
current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
for (int i = 0; i < pkey.length; i++) {
|
|
||||||
file = new java.io.File(pkey[i]);
|
|
||||||
if (!file.isAbsolute()) {
|
|
||||||
file = new java.io.File(ssh_home, pkey[i]);
|
|
||||||
}
|
|
||||||
if (file.exists()) {
|
|
||||||
boolean notyet = true;
|
|
||||||
for (int j = 0; j < _pkey.length; j++) {
|
|
||||||
if (pkey[i].equals(_pkey[j])) {
|
|
||||||
notyet = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (notyet)
|
|
||||||
jsch.addIdentity(file.getPath());
|
|
||||||
if (current_pkeys.length() == 0) {
|
|
||||||
current_pkeys = pkey[i];
|
|
||||||
} else {
|
|
||||||
current_pkeys += ("," + pkey[i]); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static void loadKnownHosts(JSch jsch, String ssh_home){
|
|
||||||
try {
|
|
||||||
java.io.File file;
|
|
||||||
file=new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$
|
|
||||||
jsch.setKnownHosts(file.getPath());
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String INFO_PROXY_USER = "org.eclipse.team.cvs.core.proxy.user"; //$NON-NLS-1$
|
|
||||||
private static final String INFO_PROXY_PASS = "org.eclipse.team.cvs.core.proxy.pass"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
static Proxy loadSshProxyPrefs() {
|
|
||||||
//TODO Use official Platform prefs when bug 154100 is fixed
|
|
||||||
IPreferenceStore store = getCvsUIPreferenceStore();
|
|
||||||
boolean useProxy = store.getBoolean(ISshConstants.PREF_USE_PROXY);
|
|
||||||
Proxy proxy = null;
|
|
||||||
if (useProxy) {
|
|
||||||
String _type = store.getString(ISshConstants.PREF_PROXY_TYPE);
|
|
||||||
String _host = store.getString(ISshConstants.PREF_PROXY_HOST);
|
|
||||||
String _port = store.getString(ISshConstants.PREF_PROXY_PORT);
|
|
||||||
|
|
||||||
boolean useAuth = store.getBoolean(ISshConstants.PREF_PROXY_AUTH);
|
|
||||||
String _user = ""; //$NON-NLS-1$
|
|
||||||
String _pass = ""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// Retrieve username and password from keyring.
|
|
||||||
if(useAuth){
|
|
||||||
Map authInfo = null;
|
|
||||||
try {
|
|
||||||
URL FAKE_URL = new URL("http://org.eclipse.team.cvs.proxy.auth");//$NON-NLS-1$
|
|
||||||
authInfo = Platform.getAuthorizationInfo(FAKE_URL, "proxy", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
} catch(MalformedURLException e) {
|
|
||||||
//should never happen
|
|
||||||
}
|
|
||||||
if (authInfo==null) authInfo=Collections.EMPTY_MAP;
|
|
||||||
_user=(String)authInfo.get(INFO_PROXY_USER);
|
|
||||||
_pass=(String)authInfo.get(INFO_PROXY_PASS);
|
|
||||||
if (_user==null) _user=""; //$NON-NLS-1$
|
|
||||||
if (_pass==null) _pass=""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
String proxyhost = _host + ":" + _port; //$NON-NLS-1$
|
|
||||||
if (_type.equals(ISshConstants.PROXY_TYPE_HTTP)) {
|
|
||||||
proxy = new ProxyHTTP(proxyhost);
|
|
||||||
if (useAuth) {
|
|
||||||
((ProxyHTTP) proxy).setUserPasswd(_user, _pass);
|
|
||||||
}
|
|
||||||
} else if (_type.equals(ISshConstants.PROXY_TYPE_SOCKS5)) {
|
|
||||||
proxy = new ProxySOCKS5(proxyhost);
|
|
||||||
if (useAuth) {
|
|
||||||
((ProxySOCKS5) proxy).setUserPasswd(_user, _pass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class SimpleSocketFactory implements SocketFactory {
|
|
||||||
InputStream in = null;
|
|
||||||
OutputStream out = null;
|
|
||||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
|
||||||
Socket socket = null;
|
|
||||||
socket = new Socket(host, port);
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
public InputStream getInputStream(Socket socket) throws IOException {
|
|
||||||
if (in == null)
|
|
||||||
in = socket.getInputStream();
|
|
||||||
return in;
|
|
||||||
}
|
|
||||||
public OutputStream getOutputStream(Socket socket) throws IOException {
|
|
||||||
if (out == null)
|
|
||||||
out = socket.getOutputStream();
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ResponsiveSocketFactory extends SimpleSocketFactory {
|
|
||||||
private IProgressMonitor monitor;
|
|
||||||
public ResponsiveSocketFactory(IProgressMonitor monitor) {
|
|
||||||
this.monitor = monitor;
|
|
||||||
}
|
|
||||||
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
|
||||||
Socket socket = null;
|
|
||||||
//Allows to cancel the socket creation operation if necessary.
|
|
||||||
//Waits for the timeout specified in CVS Preferences, maximum.
|
|
||||||
socket = RemoteUtil.createSocket(host, port, CONNECT_DEFAULT_TIMEOUT, monitor);
|
|
||||||
// Null out the monitor so we don't hold onto anything
|
|
||||||
// (i.e. the SSH2 session will keep a handle to the socket factory around
|
|
||||||
monitor = new NullProgressMonitor();
|
|
||||||
// Set the socket timeout
|
|
||||||
//socket.setSoTimeout(getSshTimeoutInMillis());
|
|
||||||
// We want blocking read() calls in ssh to never terminate
|
|
||||||
socket.setSoTimeout(0);
|
|
||||||
return socket;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// </copied from org.eclipse.team.cvs.ssh2>
|
// </copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)>
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
protected void internalConnect(IProgressMonitor monitor) throws Exception
|
protected void internalConnect(IProgressMonitor monitor) throws Exception
|
||||||
{
|
{
|
||||||
//We could share the preferences from ssh2, or use RSE
|
|
||||||
//ConnectorService Properties / Server Launcher Properties
|
|
||||||
|
|
||||||
//jsch.setKnownHosts("/home/foo/.ssh/known_hosts");
|
|
||||||
loadSshPrefs(jsch);
|
|
||||||
String host = getHostName();
|
String host = getHostName();
|
||||||
String user = getUserId();
|
String user = getUserId();
|
||||||
|
|
||||||
Proxy proxy = loadSshProxyPrefs();
|
|
||||||
session=jsch.getSession(user, host, SSH_DEFAULT_PORT);
|
|
||||||
if (proxy != null) {
|
|
||||||
session.setProxy(proxy);
|
|
||||||
}
|
|
||||||
//session.setTimeout(getSshTimeoutInMillis());
|
|
||||||
session.setTimeout(0); //never time out on the session
|
|
||||||
String password=""; //$NON-NLS-1$
|
String password=""; //$NON-NLS-1$
|
||||||
SystemSignonInformation ssi = getSignonInformation();
|
SystemSignonInformation ssi = getSignonInformation();
|
||||||
if (ssi!=null) {
|
if (ssi!=null) {
|
||||||
password = getSignonInformation().getPassword();
|
password = getSignonInformation().getPassword();
|
||||||
}
|
}
|
||||||
session.setPassword(password);
|
|
||||||
MyUserInfo userInfo = new MyUserInfo(user, password);
|
MyUserInfo userInfo = new MyUserInfo(user, password);
|
||||||
session.setUserInfo(userInfo);
|
|
||||||
session.setSocketFactory(new ResponsiveSocketFactory(monitor));
|
|
||||||
|
|
||||||
//java.util.Hashtable config=new java.util.Hashtable();
|
|
||||||
//config.put("StrictHostKeyChecking", "no");
|
|
||||||
//session.setConfig(config);
|
|
||||||
userInfo.aboutToConnect();
|
userInfo.aboutToConnect();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Activator.trace("SshConnectorService.connecting..."); //$NON-NLS-1$
|
session = createSession(user, password, host, SSH_DEFAULT_PORT,
|
||||||
|
userInfo, monitor);
|
||||||
|
|
||||||
|
//java.util.Hashtable config=new java.util.Hashtable();
|
||||||
|
//config.put("StrictHostKeyChecking", "no");
|
||||||
|
//session.setConfig(config);
|
||||||
|
userInfo.aboutToConnect();
|
||||||
|
|
||||||
|
Activator.trace("SshConnectorService.connecting..."); //$NON-NLS-1$
|
||||||
//wait for 60 sec maximum during connect
|
//wait for 60 sec maximum during connect
|
||||||
session.connect(CONNECT_DEFAULT_TIMEOUT * 1000);
|
session.connect(CONNECT_DEFAULT_TIMEOUT * 1000);
|
||||||
Activator.trace("SshConnectorService.connected"); //$NON-NLS-1$
|
Activator.trace("SshConnectorService.connected"); //$NON-NLS-1$
|
||||||
|
@ -314,6 +122,9 @@ public class SshConnectorService extends StandardConnectorService implements ISs
|
||||||
Activator.trace("SshConnectorService.connect failed: "+e.toString()); //$NON-NLS-1$
|
Activator.trace("SshConnectorService.connect failed: "+e.toString()); //$NON-NLS-1$
|
||||||
if (session.isConnected())
|
if (session.isConnected())
|
||||||
session.disconnect();
|
session.disconnect();
|
||||||
|
if(e.toString().indexOf("Auth cancel")>=0) { //$NON-NLS-1$
|
||||||
|
throw new OperationCanceledException();
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
userInfo.connectionMade();
|
userInfo.connectionMade();
|
||||||
|
|
|
@ -8,7 +8,7 @@ Bundle-Vendor: %providerName
|
||||||
Bundle-Localization: plugin
|
Bundle-Localization: plugin
|
||||||
Require-Bundle: org.eclipse.core.runtime,
|
Require-Bundle: org.eclipse.core.runtime,
|
||||||
org.eclipse.rse.services,
|
org.eclipse.rse.services,
|
||||||
com.jcraft.jsch;bundle-version="[0.1.28,2.0.0)"
|
com.jcraft.jsch;bundle-version="[0.1.28,1.0.0)"
|
||||||
Eclipse-LazyStart: true
|
Eclipse-LazyStart: true
|
||||||
Export-Package: org.eclipse.rse.internal.services.ssh;x-friends:="org.eclipse.rse.connectorservice.ssh,org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh",
|
Export-Package: org.eclipse.rse.internal.services.ssh;x-friends:="org.eclipse.rse.connectorservice.ssh,org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh",
|
||||||
org.eclipse.rse.internal.services.ssh.files;x-friends:="org.eclipse.rse.connectorservice.ssh,org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh",
|
org.eclipse.rse.internal.services.ssh.files;x-friends:="org.eclipse.rse.connectorservice.ssh,org.eclipse.rse.subsystems.files.ssh,org.eclipse.rse.subsystems.shells.ssh",
|
||||||
|
|
|
@ -2,8 +2,8 @@
|
||||||
<feature
|
<feature
|
||||||
id="org.eclipse.tm.terminal.ssh"
|
id="org.eclipse.tm.terminal.ssh"
|
||||||
label="%featureName"
|
label="%featureName"
|
||||||
provider-name="%providerName"
|
version="1.0.0.qualifier"
|
||||||
version="1.0.0.qualifier">
|
provider-name="%providerName">
|
||||||
|
|
||||||
<description>
|
<description>
|
||||||
%description
|
%description
|
||||||
|
@ -25,11 +25,8 @@
|
||||||
<import plugin="org.eclipse.ui"/>
|
<import plugin="org.eclipse.ui"/>
|
||||||
<import plugin="org.eclipse.core.runtime"/>
|
<import plugin="org.eclipse.core.runtime"/>
|
||||||
<import plugin="org.eclipse.tm.terminal"/>
|
<import plugin="org.eclipse.tm.terminal"/>
|
||||||
<!-- Bug 174796: Dont make dependency on jsch explicit in order to allow
|
<import plugin="com.jcraft.jsch" version="0.1.28" match="compatible"/>
|
||||||
installing the full Terminal feature (Serial, Telnet) on Platform
|
<import plugin="org.eclipse.jsch.core"/>
|
||||||
without CVS
|
|
||||||
<import plugin="com.jcraft.jsch"/>
|
|
||||||
-->
|
|
||||||
</requires>
|
</requires>
|
||||||
|
|
||||||
<plugin
|
<plugin
|
||||||
|
|
|
@ -8,7 +8,9 @@ Bundle-Localization: plugin
|
||||||
Require-Bundle: org.eclipse.ui,
|
Require-Bundle: org.eclipse.ui,
|
||||||
org.eclipse.core.runtime,
|
org.eclipse.core.runtime,
|
||||||
org.eclipse.tm.terminal,
|
org.eclipse.tm.terminal,
|
||||||
org.eclipse.ui,
|
com.jcraft.jsch;bundle-version="[0.1.28,1.0.0)",
|
||||||
com.jcraft.jsch;bundle-version="[0.1.28,2.0.0)"
|
org.eclipse.jsch.core
|
||||||
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
Bundle-RequiredExecutionEnvironment: J2SE-1.4
|
||||||
Export-Package: org.eclipse.tm.internal.terminal.ssh;x-internal:=true
|
Export-Package: org.eclipse.tm.internal.terminal.ssh;x-internal:=true
|
||||||
|
Bundle-Activator: org.eclipse.tm.internal.terminal.ssh.Activator
|
||||||
|
Eclipse-LazyStart: true
|
||||||
|
|
|
@ -0,0 +1,94 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2006, 2007 Wind River Systems, Inc. and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Martin Oberhuber (Wind River) - initial API and implementation
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
|
* - copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.tm.internal.terminal.ssh;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.Plugin;
|
||||||
|
import org.eclipse.jface.resource.ImageDescriptor;
|
||||||
|
import org.eclipse.jsch.core.IJSchService;
|
||||||
|
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.util.tracker.ServiceTracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The activator class controls the plug-in life cycle
|
||||||
|
*/
|
||||||
|
public class Activator extends Plugin {
|
||||||
|
|
||||||
|
public static final String PLUGIN_ID = "org.eclipse.tm.terminal.ssh"; //$NON-NLS-1$
|
||||||
|
private static Activator plugin;
|
||||||
|
|
||||||
|
// ServiceTracker for IJschService
|
||||||
|
private ServiceTracker tracker;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The constructor
|
||||||
|
*/
|
||||||
|
public Activator() {
|
||||||
|
super();
|
||||||
|
plugin = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//<copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)>
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
public void start(BundleContext context) throws Exception {
|
||||||
|
super.start(context);
|
||||||
|
tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
|
||||||
|
tracker.open();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop(BundleContext context) throws Exception {
|
||||||
|
try {
|
||||||
|
SshConnection.shutdown();
|
||||||
|
tracker.close();
|
||||||
|
} finally {
|
||||||
|
plugin = null;
|
||||||
|
super.stop(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an instance of IJSchService from the OSGi Registry.
|
||||||
|
* @return An instance of IJSchService, or <code>null</code> if no
|
||||||
|
* IJschService service is available.
|
||||||
|
*/
|
||||||
|
public IJSchService getJSchService() {
|
||||||
|
return (IJSchService)tracker.getService();
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
//</copied code from org.eclipse.team.cvs.ssh2/CVSSSH2Plugin (Copyright IBM)>
|
||||||
|
//---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the shared instance
|
||||||
|
*
|
||||||
|
* @return the shared instance
|
||||||
|
*/
|
||||||
|
public static Activator getDefault() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an image descriptor for the image file at the given
|
||||||
|
* plug-in relative path.
|
||||||
|
*
|
||||||
|
* @param path the path
|
||||||
|
* @return the image descriptor
|
||||||
|
*/
|
||||||
|
public static ImageDescriptor getImageDescriptor(String path) {
|
||||||
|
return AbstractUIPlugin.imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* Martin Oberhuber (Wind River) - extracted from various team.cvs plugins
|
* Martin Oberhuber (Wind River) - extracted from various team.cvs plugins
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.ssh;
|
package org.eclipse.tm.internal.terminal.ssh;
|
||||||
|
|
||||||
|
@ -17,23 +18,6 @@ package org.eclipse.tm.internal.terminal.ssh;
|
||||||
*/
|
*/
|
||||||
public interface ISshConstants {
|
public interface ISshConstants {
|
||||||
|
|
||||||
// These are from ISSHContants
|
|
||||||
public static final String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; //$NON-NLS-1$
|
|
||||||
public static final String KEY_PRIVATEKEY="CVSSSH2PreferencePage.PRIVATEKEY"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from ICVSUIConstants
|
|
||||||
public static final String PREF_USE_PROXY = "proxyEnabled"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_TYPE = "proxyType"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_HOST = "proxyHost"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_PORT = "proxyPort"; //$NON-NLS-1$
|
|
||||||
public static final String PREF_PROXY_AUTH = "proxyAuth"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from CVSProviderPlugin
|
|
||||||
public static final String PROXY_TYPE_HTTP = "HTTP"; //$NON-NLS-1$
|
|
||||||
public static final String PROXY_TYPE_SOCKS5 = "SOCKS5"; //$NON-NLS-1$
|
|
||||||
public static final String HTTP_DEFAULT_PORT="80"; //$NON-NLS-1$
|
|
||||||
public static final String SOCKS5_DEFAULT_PORT="1080"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// These are from cvs.ui.IHelpContextIds
|
// These are from cvs.ui.IHelpContextIds
|
||||||
public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$
|
public static final String CVSUIPREFIX = "org.eclipse.team.cvs.ui."; //$NON-NLS-1$
|
||||||
public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$
|
public static final String HELP_USER_VALIDATION_DIALOG = CVSUIPREFIX + "user_validation_dialog_context"; //$NON-NLS-1$
|
||||||
|
|
|
@ -8,36 +8,29 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Michael Scharf (Wind River) - initial API and implementation
|
* Michael Scharf (Wind River) - initial API and implementation
|
||||||
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
|
||||||
|
* Martin Oberhuber (Wind River) - [175686] Adapted to new IJSchService API
|
||||||
|
* - copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.tm.internal.terminal.ssh;
|
package org.eclipse.tm.internal.terminal.ssh;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InterruptedIOException;
|
import java.io.InterruptedIOException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Platform;
|
|
||||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
|
||||||
import org.eclipse.jface.dialogs.MessageDialog;
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
|
||||||
import org.eclipse.jface.window.Window;
|
import org.eclipse.jface.window.Window;
|
||||||
|
import org.eclipse.jsch.core.IJSchService;
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.tm.terminal.ITerminalControl;
|
import org.eclipse.tm.terminal.ITerminalControl;
|
||||||
import org.eclipse.tm.terminal.Logger;
|
import org.eclipse.tm.terminal.Logger;
|
||||||
import org.eclipse.tm.terminal.TerminalState;
|
import org.eclipse.tm.terminal.TerminalState;
|
||||||
import org.eclipse.ui.preferences.ScopedPreferenceStore;
|
|
||||||
|
|
||||||
import com.jcraft.jsch.Channel;
|
import com.jcraft.jsch.Channel;
|
||||||
import com.jcraft.jsch.ChannelShell;
|
import com.jcraft.jsch.ChannelShell;
|
||||||
import com.jcraft.jsch.JSch;
|
|
||||||
import com.jcraft.jsch.JSchException;
|
import com.jcraft.jsch.JSchException;
|
||||||
import com.jcraft.jsch.Proxy;
|
|
||||||
import com.jcraft.jsch.ProxyHTTP;
|
|
||||||
import com.jcraft.jsch.ProxySOCKS5;
|
|
||||||
import com.jcraft.jsch.Session;
|
import com.jcraft.jsch.Session;
|
||||||
import com.jcraft.jsch.UserInfo;
|
import com.jcraft.jsch.UserInfo;
|
||||||
|
|
||||||
|
@ -54,151 +47,28 @@ class SshConnection extends Thread {
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// <copied from org.eclipse.team.cvs.ssh2>
|
// <copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)>
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
private static String current_ssh_home = null;
|
|
||||||
private static String current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
static String SSH_HOME_DEFAULT = null;
|
|
||||||
static {
|
|
||||||
String ssh_dir_name = ".ssh"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// Windows doesn't like files or directories starting with a dot.
|
|
||||||
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
|
||||||
ssh_dir_name = "ssh"; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
SSH_HOME_DEFAULT = System.getProperty("user.home"); //$NON-NLS-1$
|
|
||||||
if (SSH_HOME_DEFAULT != null) {
|
|
||||||
SSH_HOME_DEFAULT = SSH_HOME_DEFAULT + java.io.File.separator + ssh_dir_name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static IPreferenceStore fCvsSsh2PreferenceStore;
|
private static Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, IProgressMonitor monitor) throws JSchException {
|
||||||
static IPreferenceStore getCvsSsh2PreferenceStore() {
|
IJSchService service = Activator.getDefault().getJSchService();
|
||||||
if (fCvsSsh2PreferenceStore == null) {
|
if (service == null)
|
||||||
fCvsSsh2PreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ssh2"); //$NON-NLS-1$
|
return null;
|
||||||
}
|
Session session = service.createSession(hostname, port, username);
|
||||||
return fCvsSsh2PreferenceStore;
|
//session.setTimeout(getSshTimeoutInMillis());
|
||||||
|
session.setTimeout(0); //never time out on the session
|
||||||
|
if (password != null)
|
||||||
|
session.setPassword(password);
|
||||||
|
session.setUserInfo(wrapperUI);
|
||||||
|
return session;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IPreferenceStore fCvsUIPreferenceStore;
|
static void shutdown() {
|
||||||
static IPreferenceStore getCvsUIPreferenceStore() {
|
//TODO: Store all Jsch sessions in a pool and disconnect them on shutdown
|
||||||
if (fCvsUIPreferenceStore == null) {
|
|
||||||
fCvsUIPreferenceStore = new ScopedPreferenceStore(new InstanceScope(),"org.eclipse.team.cvs.ui"); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
return fCvsUIPreferenceStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Load ssh prefs from Team/CVS for now.
|
|
||||||
// TODO do our own preference page.
|
|
||||||
static void loadSshPrefs(JSch jsch)
|
|
||||||
{
|
|
||||||
IPreferenceStore store = getCvsSsh2PreferenceStore();
|
|
||||||
String ssh_home = store.getString(ISshConstants.KEY_SSH2HOME);
|
|
||||||
String pkeys = store.getString(ISshConstants.KEY_PRIVATEKEY);
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (ssh_home.length() == 0)
|
|
||||||
ssh_home = SSH_HOME_DEFAULT;
|
|
||||||
|
|
||||||
if (current_ssh_home == null || !current_ssh_home.equals(ssh_home)) {
|
|
||||||
loadKnownHosts(jsch, ssh_home);
|
|
||||||
current_ssh_home = ssh_home;
|
|
||||||
current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!current_pkeys.equals(pkeys)) {
|
|
||||||
java.io.File file;
|
|
||||||
String[] pkey = pkeys.split(","); //$NON-NLS-1$
|
|
||||||
String[] _pkey = current_pkeys.split(","); //$NON-NLS-1$
|
|
||||||
current_pkeys = ""; //$NON-NLS-1$
|
|
||||||
for (int i = 0; i < pkey.length; i++) {
|
|
||||||
file = new java.io.File(pkey[i]);
|
|
||||||
if (!file.isAbsolute()) {
|
|
||||||
file = new java.io.File(ssh_home, pkey[i]);
|
|
||||||
}
|
|
||||||
if (file.exists()) {
|
|
||||||
boolean notyet = true;
|
|
||||||
for (int j = 0; j < _pkey.length; j++) {
|
|
||||||
if (pkey[i].equals(_pkey[j])) {
|
|
||||||
notyet = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (notyet)
|
|
||||||
jsch.addIdentity(file.getPath());
|
|
||||||
if (current_pkeys.length() == 0) {
|
|
||||||
current_pkeys = pkey[i];
|
|
||||||
} else {
|
|
||||||
current_pkeys += ("," + pkey[i]); //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void loadKnownHosts(JSch jsch, String ssh_home){
|
|
||||||
try {
|
|
||||||
java.io.File file;
|
|
||||||
file=new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$
|
|
||||||
jsch.setKnownHosts(file.getPath());
|
|
||||||
} catch (Exception e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final String INFO_PROXY_USER = "org.eclipse.team.cvs.core.proxy.user"; //$NON-NLS-1$
|
|
||||||
private static final String INFO_PROXY_PASS = "org.eclipse.team.cvs.core.proxy.pass"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
static Proxy loadSshProxyPrefs() {
|
|
||||||
//TODO Use official Platform prefs when bug 154100 is fixed
|
|
||||||
IPreferenceStore store = getCvsUIPreferenceStore();
|
|
||||||
boolean useProxy = store.getBoolean(ISshConstants.PREF_USE_PROXY);
|
|
||||||
Proxy proxy = null;
|
|
||||||
if (useProxy) {
|
|
||||||
String _type = store.getString(ISshConstants.PREF_PROXY_TYPE);
|
|
||||||
String _host = store.getString(ISshConstants.PREF_PROXY_HOST);
|
|
||||||
String _port = store.getString(ISshConstants.PREF_PROXY_PORT);
|
|
||||||
|
|
||||||
boolean useAuth = store.getBoolean(ISshConstants.PREF_PROXY_AUTH);
|
|
||||||
String _user = ""; //$NON-NLS-1$
|
|
||||||
String _pass = ""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// Retrieve username and password from keyring.
|
|
||||||
if(useAuth){
|
|
||||||
Map authInfo = null;
|
|
||||||
try {
|
|
||||||
URL FAKE_URL = new URL("http://org.eclipse.team.cvs.proxy.auth");//$NON-NLS-1$
|
|
||||||
authInfo = Platform.getAuthorizationInfo(FAKE_URL, "proxy", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
|
||||||
} catch(MalformedURLException e) {
|
|
||||||
//should never happen
|
|
||||||
}
|
|
||||||
if (authInfo==null) authInfo=Collections.EMPTY_MAP;
|
|
||||||
_user=(String)authInfo.get(INFO_PROXY_USER);
|
|
||||||
_pass=(String)authInfo.get(INFO_PROXY_PASS);
|
|
||||||
if (_user==null) _user=""; //$NON-NLS-1$
|
|
||||||
if (_pass==null) _pass=""; //$NON-NLS-1$
|
|
||||||
}
|
|
||||||
|
|
||||||
String proxyhost = _host + ":" + _port; //$NON-NLS-1$
|
|
||||||
if (_type.equals(ISshConstants.PROXY_TYPE_HTTP)) {
|
|
||||||
proxy = new ProxyHTTP(proxyhost);
|
|
||||||
if (useAuth) {
|
|
||||||
((ProxyHTTP) proxy).setUserPasswd(_user, _pass);
|
|
||||||
}
|
|
||||||
} else if (_type.equals(ISshConstants.PROXY_TYPE_SOCKS5)) {
|
|
||||||
proxy = new ProxySOCKS5(proxyhost);
|
|
||||||
if (useAuth) {
|
|
||||||
((ProxySOCKS5) proxy).setUserPasswd(_user, _pass);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return proxy;
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// </copied from org.eclipse.team.cvs.ssh2>
|
// </copied code from org.eclipse.team.cvs.ssh2/JSchSession (Copyright IBM)>
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
|
@ -209,15 +79,6 @@ class SshConnection extends Thread {
|
||||||
String password = fConn.getTelnetSettings().getPassword();
|
String password = fConn.getTelnetSettings().getPassword();
|
||||||
int port=fConn.getTelnetSettings().getPort();
|
int port=fConn.getTelnetSettings().getPort();
|
||||||
|
|
||||||
loadSshPrefs(fConn.getJsch());
|
|
||||||
Proxy proxy = loadSshProxyPrefs();
|
|
||||||
Session session=fConn.getJsch().getSession(user, host, port);
|
|
||||||
if (proxy != null) {
|
|
||||||
session.setProxy(proxy);
|
|
||||||
}
|
|
||||||
session.setTimeout(0); //never time out once connected
|
|
||||||
|
|
||||||
session.setPassword(password);
|
|
||||||
////Giving a connectionId could be the index into a local
|
////Giving a connectionId could be the index into a local
|
||||||
////Store where passwords are stored
|
////Store where passwords are stored
|
||||||
//String connectionId = host;
|
//String connectionId = host;
|
||||||
|
@ -226,13 +87,14 @@ class SshConnection extends Thread {
|
||||||
//}
|
//}
|
||||||
//UserInfo ui=new MyUserInfo(connectionId, user, password);
|
//UserInfo ui=new MyUserInfo(connectionId, user, password);
|
||||||
UserInfo ui=new MyUserInfo(null, user, password);
|
UserInfo ui=new MyUserInfo(null, user, password);
|
||||||
session.setUserInfo(ui);
|
|
||||||
|
|
||||||
// java.util.Hashtable config=new java.util.Hashtable();
|
Session session = createSession(user, password, host, port,
|
||||||
// config.put("StrictHostKeyChecking", "no");
|
ui, new NullProgressMonitor());
|
||||||
// session.setConfig(config);
|
|
||||||
|
|
||||||
//session.connect();
|
//java.util.Hashtable config=new java.util.Hashtable();
|
||||||
|
//config.put("StrictHostKeyChecking", "no");
|
||||||
|
//session.setConfig(config);
|
||||||
|
//ui.aboutToConnect();
|
||||||
session.connect(nTimeout); // making connection with timeout.
|
session.connect(nTimeout); // making connection with timeout.
|
||||||
|
|
||||||
ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
ChannelShell channel=(ChannelShell) session.openChannel("shell"); //$NON-NLS-1$
|
||||||
|
@ -250,7 +112,10 @@ class SshConnection extends Thread {
|
||||||
// when reading is done, we set the state to closed
|
// when reading is done, we set the state to closed
|
||||||
fControl.setState(TerminalState.CLOSED);
|
fControl.setState(TerminalState.CLOSED);
|
||||||
} catch (JSchException e) {
|
} catch (JSchException e) {
|
||||||
connectFailed(e.getMessage(),e.getMessage());
|
if(e.toString().indexOf("Auth cancel")<0) { //$NON-NLS-1$
|
||||||
|
//no error if user pressed cancel
|
||||||
|
connectFailed(e.getMessage(),e.getMessage());
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
connectFailed(e.getMessage(),e.getMessage());
|
connectFailed(e.getMessage(),e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
|
|
Loading…
Add table
Reference in a new issue