diff options
Diffstat (limited to 'bundles/org.eclipse.jsch.core/src/org')
4 files changed, 142 insertions, 5 deletions
diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/AbstractIdentityRepositoryFactory.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/AbstractIdentityRepositoryFactory.java new file mode 100644 index 000000000..462773539 --- /dev/null +++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/core/AbstractIdentityRepositoryFactory.java @@ -0,0 +1,30 @@ +/******************************************************************************* + * Copyright (c) 2014 JCraft,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: + * JCraft,Inc. - initial API and implementation + *******************************************************************************/ +package org.eclipse.jsch.core; + +import com.jcraft.jsch.IdentityRepository; + +/** + * This class abstracts the communications with the identity repository, + * and will be mainly used for ssh-agent. + * @since 1.2 + */ +public abstract class AbstractIdentityRepositoryFactory{ + /** + * This method will return an instance of + * <code>com.jcraft.com.jsch.IdentityRepository</code>. The ssh client will + * retrieve public keys from it, ask for signing data with a private key + * included in it. + * + * @return an instance of <code>IdentityRepository</code> + */ + public abstract IdentityRepository create(); +} diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IConstants.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IConstants.java index 872c79b31..964920ae0 100644 --- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IConstants.java +++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/IConstants.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2013 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation 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 @@ -55,6 +55,8 @@ public interface IConstants{ public static final String PREF_PREFERRED_AUTHENTICATION_METHODS="CVSSSH2PreferencePage.PREF_AUTH_METHODS"; //$NON-NLS-1$ public static final String PREF_PREFERRED_AUTHENTICATION_METHODS_ORDER="CVSSSH2PreferencePage.PREF_AUTH_METHODS_ORDER"; //$NON-NLS-1$ + public static final String PREF_PREFERRED_SSHAGENT="CVSSSH2PreferencePage.PREF_SSHAGENT"; //$NON-NLS-1$ + public static final String PREF_PREFERRED_KEYEXCHANGE_METHODS="CVSSSH2PreferencePage.PREF_KEX_METHODS"; //$NON-NLS-1$ public static final String PREF_PREFERRED_KEYEXCHANGE_METHODS_ORDER="CVSSSH2PreferencePage.PREF_KEX_METHODS_ORDER"; //$NON-NLS-1$ diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java index 92c22430f..df1427909 100644 --- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java +++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/JSchCorePlugin.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2008 IBM Corporation and others. + * Copyright (c) 2000, 2014 IBM Corporation 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 @@ -12,15 +12,18 @@ package org.eclipse.jsch.internal.core; import java.util.Hashtable; +import java.util.ArrayList; import org.eclipse.core.net.proxy.IProxyService; import org.eclipse.core.runtime.*; +import org.eclipse.jsch.core.AbstractIdentityRepositoryFactory; import org.eclipse.jsch.core.IJSchService; import org.eclipse.osgi.util.NLS; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; import org.osgi.util.tracker.ServiceTracker; +import com.jcraft.jsch.IdentityRepository; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; @@ -39,6 +42,7 @@ public class JSchCorePlugin extends Plugin{ private String current_pkeys=""; //$NON-NLS-1$ public static final String PT_AUTHENTICATOR="authenticator"; //$NON-NLS-1$ + public static final String PT_IDENTITYREPOSITORY="identityrepository"; //$NON-NLS-1$ private static JSchCorePlugin plugin; private ServiceTracker tracker; @@ -100,11 +104,86 @@ public class JSchCorePlugin extends Plugin{ } public synchronized JSch getJSch(){ - if(jsch==null) + if(jsch==null){ jsch=new JSch(); + setIdentityRepository(); + } return jsch; } + public synchronized void setIdentityRepository(){ + + IdentityRepository[] repositories = getPluggedInIdentityRepositries(); + String[] selected = Utils.getSelectedSSHAgent().split(","); //$NON-NLS-1$ + IdentityRepository irepo = null; + + for(int i=0; i<selected.length; i++){ + for(int j=0; j<repositories.length; j++){ + IdentityRepository _irepo = repositories[j]; + if(selected[i].equals(_irepo.getName()) && + _irepo.getStatus()==IdentityRepository.RUNNING){ + irepo = _irepo; + break; + } + } + if(irepo!=null) + break; + } + + if(irepo!=null){ + jsch.setIdentityRepository(irepo); + } + else{ + // set the internal default IdentityRepository + jsch.setIdentityRepository(null); + } + + } + + public IdentityRepository[] getPluggedInIdentityRepositries(){ + + IExtension[] extensions=Platform.getExtensionRegistry().getExtensionPoint( + JSchCorePlugin.ID, JSchCorePlugin.PT_IDENTITYREPOSITORY).getExtensions(); + + if(extensions.length==0) + return new IdentityRepository[0]; + + ArrayList tmp = new ArrayList(); + for(int i=0; i<extensions.length; i++){ + IExtension extension=extensions[i]; + IConfigurationElement[] configs=extension.getConfigurationElements(); + if(configs.length==0){ + JSchCorePlugin + .log( + IStatus.ERROR, + NLS + .bind( + "IdentityRepository {0} is missing required fields", (new Object[] {extension.getUniqueIdentifier()})), null);//$NON-NLS-1$ + continue; + } + try{ + IConfigurationElement config=configs[0]; + AbstractIdentityRepositoryFactory iirf = + (AbstractIdentityRepositoryFactory)config.createExecutableExtension("run");//$NON-NLS-1$ + tmp.add(iirf.create()); + } + catch(CoreException ex){ + JSchCorePlugin + .log( + IStatus.ERROR, + NLS + .bind( + "Unable to instantiate identity repository {0}", (new Object[] {extension.getUniqueIdentifier()})), ex);//$NON-NLS-1$ + } + } + + IdentityRepository[] repositories = new IdentityRepository[tmp.size()]; + for(int i=0; i<tmp.size(); i++){ + repositories[i]=(IdentityRepository)tmp.get(i); + } + return repositories; + } + public void loadKnownHosts(){ Preferences preferences=JSchCorePlugin.getPlugin().getPluginPreferences(); String ssh_home=preferences.getString(IConstants.KEY_SSH2HOME); diff --git a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java index 44a714399..e822a4606 100644 --- a/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java +++ b/bundles/org.eclipse.jsch.core/src/org/eclipse/jsch/internal/core/Utils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 IBM Corporation and others. + * Copyright (c) 2007, 2014 IBM Corporation 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 @@ -21,6 +21,7 @@ import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.InstanceScope; import org.osgi.service.prefs.BackingStoreException; +import com.jcraft.jsch.IdentityRepository; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Proxy; @@ -28,6 +29,7 @@ import com.jcraft.jsch.ProxyHTTP; import com.jcraft.jsch.ProxySOCKS5; import com.jcraft.jsch.Session; + /** * * @since 1.0 @@ -255,6 +257,18 @@ public class Utils{ IConstants.PREF_PREFERRED_AUTHENTICATION_METHODS, getDefaultAuthMethods(), null); } + public static String getAvailableSSHAgents(){ + IdentityRepository[] repositories = JSchCorePlugin.getPlugin().getPluggedInIdentityRepositries(); + String s=""; //$NON-NLS-1$ + for(int i=0; i<repositories.length; i++){ + IdentityRepository c = repositories[i]; + s+=c.getName(); + if(i+1<repositories.length) + s+=","; //$NON-NLS-1$ + } + return s; + } + public static String getMethodsOrder(){ IPreferencesService service = Platform.getPreferencesService(); return service.getString(JSchCorePlugin.ID, @@ -267,7 +281,19 @@ public class Utils{ IConstants.PREF_PREFERRED_AUTHENTICATION_METHODS, methods); service.getRootNode().node(InstanceScope.SCOPE).node(JSchCorePlugin.ID).put( IConstants.PREF_PREFERRED_AUTHENTICATION_METHODS_ORDER, order);} - + + public static String getSelectedSSHAgent(){ + IPreferencesService service = Platform.getPreferencesService(); + return service.getString(JSchCorePlugin.ID, + IConstants.PREF_PREFERRED_SSHAGENT, "", null); //$NON-NLS-1$ + } + + public static void setSelectedSSHAgents(String methods){ + IPreferencesService service=Platform.getPreferencesService(); + service.getRootNode().node(InstanceScope.SCOPE).node(JSchCorePlugin.ID).put( + IConstants.PREF_PREFERRED_SSHAGENT, methods); + } + public static String getEnabledPreferredKEXMethods(){ IPreferencesService service = Platform.getPreferencesService(); return service.getString(JSchCorePlugin.ID, |