Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2007-03-03 21:04:55 +0000
committerMichael Valenta2007-03-03 21:04:55 +0000
commitf3afc89a8f4954f776d449260ac19ed5c68822f4 (patch)
treed26577aa58eca3a297cde686c93860504690cfe8 /bundles/org.eclipse.team.cvs.ssh2
parent621e92458663e722d3aa1bb013367f2629ebfdb0 (diff)
downloadeclipse.platform.team-f3afc89a8f4954f776d449260ac19ed5c68822f4.tar.gz
eclipse.platform.team-f3afc89a8f4954f776d449260ac19ed5c68822f4.tar.xz
eclipse.platform.team-f3afc89a8f4954f776d449260ac19ed5c68822f4.zip
Bug 170883 [SSH2] jsch connection preferences should be made public below "Internet" category
Diffstat (limited to 'bundles/org.eclipse.team.cvs.ssh2')
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/plugin.xml14
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java22
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2PreferencePage.java1219
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/ISSHContants.java39
-rw-r--r--bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java162
6 files changed, 44 insertions, 1416 deletions
diff --git a/bundles/org.eclipse.team.cvs.ssh2/META-INF/MANIFEST.MF b/bundles/org.eclipse.team.cvs.ssh2/META-INF/MANIFEST.MF
index a9a2a96d4..d5e0ef0d2 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.team.cvs.ssh2/META-INF/MANIFEST.MF
@@ -15,6 +15,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.1.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.2.0,4.0.0)",
org.eclipse.team.cvs.ssh;bundle-version="[3.2.0,4.0.0)",
org.eclipse.team.ui;bundle-version="[3.2.0,4.0.0)",
- com.jcraft.jsch;bundle-version="[0.1.18,2.0.0)"
+ com.jcraft.jsch;bundle-version="[0.1.18,2.0.0)",
+ org.eclipse.core.net;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.jsch.core;bundle-version="[1.0.0,2.0.0)"
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/bundles/org.eclipse.team.cvs.ssh2/plugin.xml b/bundles/org.eclipse.team.cvs.ssh2/plugin.xml
index cc666437e..f3651f29c 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/plugin.xml
+++ b/bundles/org.eclipse.team.cvs.ssh2/plugin.xml
@@ -32,18 +32,4 @@
</adapter>
</extension>
-
-<!-- =================================================================================== -->
-<!-- Extension Point: Preference page -->
-<!-- =================================================================================== -->
-<extension point="org.eclipse.ui.preferencePages">
- <page
- name="%ssh2PreferencePage.name"
- category="org.eclipse.team.cvs.ui.CVSPreferences"
- class="org.eclipse.team.internal.ccvs.ssh2.CVSSSH2PreferencePage"
- id="org.eclipse.team.cvs.ssh2.CVSSSH2Preferences">
- <keywordReference id="org.eclipse.team.cvs.ui.cvs.ext"/>
- </page>
-</extension>
-
</plugin>
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
index cc0f0c46b..50af4b83f 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2Plugin.java
@@ -12,9 +12,10 @@
package org.eclipse.team.internal.ccvs.ssh2;
import org.eclipse.core.runtime.Platform;
-import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jsch.core.IJSchService;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
public class CVSSSH2Plugin extends AbstractUIPlugin {
@@ -36,6 +37,8 @@ public class CVSSSH2Plugin extends AbstractUIPlugin {
}
}
+
+ private ServiceTracker tracker;
public CVSSSH2Plugin() {
super();
@@ -45,6 +48,7 @@ public class CVSSSH2Plugin extends AbstractUIPlugin {
public void stop(BundleContext context) throws Exception {
try {
JSchSession.shutdown();
+ tracker.close();
} finally {
super.stop(context);
}
@@ -53,18 +57,14 @@ public class CVSSSH2Plugin extends AbstractUIPlugin {
public static CVSSSH2Plugin getDefault() {
return plugin;
}
-
- private void initializeDefaultPreferences() {
- IPreferenceStore store = getPreferenceStore();
- store.setDefault(ISSHContants.KEY_SSH2HOME, SSH_HOME_DEFAULT);
- store.setDefault(ISSHContants.KEY_PRIVATEKEY, ISSHContants.PRIVATE_KEYS_DEFAULT);
- store.setDefault(ISSHContants.KEY_PROXY_TYPE, ISSHContants.HTTP);
- store.setDefault(ISSHContants.KEY_PROXY_PORT, ISSHContants.HTTP_DEFAULT_PORT);
- store.setDefault(ISSHContants.KEY_PROXY_AUTH, "false"); //$NON-NLS-1$
- }
public void start(BundleContext context) throws Exception {
super.start(context);
- initializeDefaultPreferences();
+ tracker = new ServiceTracker(getBundle().getBundleContext(), IJSchService.class.getName(), null);
+ tracker.open();
}
+
+ public IJSchService getJSchService() {
+ return (IJSchService)tracker.getService();
+ }
}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2PreferencePage.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2PreferencePage.java
deleted file mode 100644
index 4c956c891..000000000
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/CVSSSH2PreferencePage.java
+++ /dev/null
@@ -1,1219 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Atsuhiko Yamanaka, JCraft,Inc. - initial API and implementation.
- * IBM Corporation - ongoing maintenance
- * Sebastian Davids (sdavids@gmx.de) - Bug 54599 [SSH2] Export SSH Key ... Dialog does not standard margins
- *******************************************************************************/
-package org.eclipse.team.internal.ccvs.ssh2;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.IOException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Iterator;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.jface.dialogs.Dialog;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferencePage;
-import org.eclipse.jface.viewers.ColumnWeightData;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableLayout;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.custom.TableEditor;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.DirectoryDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.TabFolder;
-import org.eclipse.swt.widgets.TabItem;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.team.internal.ui.SWTUtils;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchPreferencePage;
-import org.eclipse.ui.PlatformUI;
-
-import com.jcraft.jsch.Channel;
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.HostKey;
-import com.jcraft.jsch.HostKeyRepository;
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-import com.jcraft.jsch.KeyPair;
-import com.jcraft.jsch.Session;
-import com.jcraft.jsch.SftpATTRS;
-import com.jcraft.jsch.SftpException;
-
-public class CVSSSH2PreferencePage extends PreferencePage
- implements IWorkbenchPreferencePage {
-
-// private DirectoryFieldEditor ssh2homeEditor;
-
- private static final String SSH2_PREFERENCE_PAGE_CONTEXT = "org.eclipse.team.cvs.ui.ssh2_preference_page_context"; //$NON-NLS-1$
-
- private Label ssh2HomeLabel;
- private Label privateKeyLabel;
- private Text ssh2HomeText;
- private Text privateKeyText;
- private Button privateKeyAdd;
-
-
- private Button ssh2HomeBrowse;
- private Button keyGenerateDSA;
- private Button keyGenerateRSA;
- private Button keyLoad;
- private Button keyExport;
- private Button saveKeyPair;
- private Label keyCommentLabel;
- private Text keyCommentText;
- private Label keyFingerPrintLabel;
- private Text keyFingerPrintText;
- private Label keyPassphrase1Label;
- private Text keyPassphrase1Text;
- private Label keyPassphrase2Label;
- private Text keyPassphrase2Text;
- private Label publicKeylabel;
- private Text publicKeyText;
- private KeyPair kpair=null;
- private String kpairComment;
-
- public static final String AUTH_SCHEME = "";//$NON-NLS-1$
- public static final URL FAKE_URL;
-
- static {
- URL temp = null;
- try{
- temp = new URL("http://org.eclipse.team.cvs.ssh2");//$NON-NLS-1$
- }catch (MalformedURLException e){}
- FAKE_URL = temp;
- }
-
- public CVSSSH2PreferencePage() {
-// super(GRID);
- IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();
- setPreferenceStore(store);
- setDescription(CVSSSH2Messages.CVSSSH2PreferencePage_18);
- }
-
- protected Control createContents(Composite parent) {
- Composite container = new Composite(parent, SWT.NULL);
- GridLayout layout = new GridLayout();
- container.setLayout(layout);
- initializeDialogUnits(container);
-
- TabFolder tabFolder = new TabFolder(container, SWT.NONE);
- tabFolder.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
- tabItem.setText(CVSSSH2Messages.CVSSSH2PreferencePage_19);
- tabItem.setControl(createGeneralPage(tabFolder));
-
- tabItem = new TabItem(tabFolder, SWT.NONE);
- tabItem.setText(CVSSSH2Messages.CVSSSH2PreferencePage_21);
- tabItem.setControl(createKeyManagementPage(tabFolder));
-
- tabItem = new TabItem(tabFolder, SWT.NONE);
- tabItem.setText(CVSSSH2Messages.CVSSSH2PreferencePage_133);
- tabItem.setControl(createHostKeyManagementPage(tabFolder));
-
- initControls();
-
- Dialog.applyDialogFont(parent);
- PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), SSH2_PREFERENCE_PAGE_CONTEXT);
- return container;
- }
-
- private Control createGeneralPage(Composite parent) {
- Composite group=new Composite(parent, SWT.NULL);
- GridLayout layout=new GridLayout();
- layout.numColumns=3;
- layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- group.setLayout(layout);
- GridData data = new GridData();
- data.horizontalAlignment = GridData.FILL;
- group.setLayoutData(data);
-
- ssh2HomeLabel=new Label(group, SWT.NONE);
- ssh2HomeLabel.setText(CVSSSH2Messages.CVSSSH2PreferencePage_23);
-
- ssh2HomeText=new Text(group, SWT.SINGLE | SWT.BORDER);
- ssh2HomeText.setFont(group.getFont());
- GridData gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=1;
- ssh2HomeText.setLayoutData(gd);
-
- ssh2HomeBrowse=new Button(group, SWT.NULL);
- ssh2HomeBrowse.setText(CVSSSH2Messages.CVSSSH2PreferencePage_24);
- gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan=1;
- ssh2HomeBrowse.setLayoutData(gd);
-
- createSpacer(group, 3);
-
- privateKeyLabel=new Label(group, SWT.NONE);
- privateKeyLabel.setText(CVSSSH2Messages.CVSSSH2PreferencePage_25);
-
- privateKeyText=new Text(group, SWT.SINGLE | SWT.BORDER);
- privateKeyText.setFont(group.getFont());
- gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=1;
- privateKeyText.setLayoutData(gd);
-
- privateKeyAdd=new Button(group, SWT.NULL);
- privateKeyAdd.setText(CVSSSH2Messages.CVSSSH2PreferencePage_26);
- gd=new GridData(GridData.HORIZONTAL_ALIGN_FILL);
- gd.horizontalSpan=1;
- privateKeyAdd.setLayoutData(gd);
-
- ssh2HomeBrowse.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- String home=ssh2HomeText.getText();
-
- if(!new File(home).exists()){
- while(true){
- int foo=home.lastIndexOf(java.io.File.separator, home.length());
- if(foo==-1)break;
- home=home.substring(0, foo);
- if(new File(home).exists())break;
- }
- }
-
- DirectoryDialog dd=new DirectoryDialog(getShell());
- dd.setFilterPath(home);
- dd.setMessage(CVSSSH2Messages.CVSSSH2PreferencePage_27);
- String dir=dd.open();
- if(dir==null){ // cancel
- return;
- }
- ssh2HomeText.setText(dir);
- }
- });
-
- privateKeyAdd.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- String home=ssh2HomeText.getText();
-
- FileDialog fd=new FileDialog(getShell(), SWT.OPEN|SWT.MULTI);
- fd.setFilterPath(home);
- Object o=fd.open();
- if(o==null){ // cancel
- return;
- }
- String[] files=fd.getFileNames();
- String keys=privateKeyText.getText();
- String dir=fd.getFilterPath();
- if(dir.equals(home)){dir="";} //$NON-NLS-1$
- else{dir+=java.io.File.separator;}
-
- for(int i=0; i<files.length; i++){
- String foo=files[i];
- if(keys.length()!=0)keys=keys+","; //$NON-NLS-1$
- keys=keys+dir+foo;
- }
- privateKeyText.setText(keys);
- }
- });
-
- return group;
- }
-
- private Control createKeyManagementPage(Composite parent) {
- int columnSpan=3;
- Composite group=new Composite(parent, SWT.NULL);
- GridLayout layout=new GridLayout();
- layout.numColumns=3;
- layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- group.setLayout(layout);
- GridData gd = new GridData();
- gd.horizontalAlignment = GridData.FILL;
- group.setLayoutData(gd);
-
- keyGenerateDSA=new Button(group, SWT.NULL);
- keyGenerateDSA.setText(CVSSSH2Messages.CVSSSH2PreferencePage_131);
- gd=new GridData();
- gd.horizontalSpan=1;
- keyGenerateDSA.setLayoutData(gd);
-
- keyGenerateRSA=new Button(group, SWT.NULL);
- keyGenerateRSA.setText(CVSSSH2Messages.CVSSSH2PreferencePage_132);
- gd=new GridData();
- gd.horizontalSpan=1;
- keyGenerateRSA.setLayoutData(gd);
-
- keyLoad=new Button(group, SWT.NULL);
- keyLoad.setText(CVSSSH2Messages.CVSSSH2PreferencePage_128);
- gd=new GridData();
- gd.horizontalSpan=1;
- keyLoad.setLayoutData(gd);
-
- publicKeylabel=new Label(group, SWT.NONE);
- publicKeylabel.setText(CVSSSH2Messages.CVSSSH2PreferencePage_39);
- gd=new GridData();
- gd.horizontalSpan=columnSpan;
- publicKeylabel.setLayoutData(gd);
-
- publicKeyText=new Text(group,SWT.MULTI|SWT.BORDER|SWT.V_SCROLL|SWT.WRAP);
- publicKeyText.setText(""); //$NON-NLS-1$
- publicKeyText.setEditable(false);
- gd=new GridData();
- gd.horizontalSpan=columnSpan;
- gd.horizontalAlignment = GridData.FILL;
- gd.verticalAlignment = GridData.FILL;
- gd.grabExcessHorizontalSpace = true;
- gd.grabExcessVerticalSpace = true;
- publicKeyText.setLayoutData(gd);
-
- keyFingerPrintLabel=new Label(group, SWT.NONE);
- keyFingerPrintLabel.setText(CVSSSH2Messages.CVSSSH2PreferencePage_41);
- keyFingerPrintText=new Text(group, SWT.SINGLE | SWT.BORDER);
- keyFingerPrintText.setFont(group.getFont());
- keyFingerPrintText.setEditable(false);
- gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=2;
- keyFingerPrintText.setLayoutData(gd);
-
- keyCommentLabel=new Label(group, SWT.NONE);
- keyCommentLabel.setText(CVSSSH2Messages.CVSSSH2PreferencePage_42);
- keyCommentText=new Text(group, SWT.SINGLE | SWT.BORDER);
- keyCommentText.setFont(group.getFont());
- gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=2;
- keyCommentText.setLayoutData(gd);
-
- keyCommentText.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e){
- if(kpair==null)return;
- try{
- ByteArrayOutputStream out=new ByteArrayOutputStream();
- kpair.writePublicKey(out, keyCommentText.getText());
- out.close();
- publicKeyText.setText(out.toString());
- }
- catch(IOException ee){}
- }});
-
- keyPassphrase1Label=new Label(group, SWT.NONE);
- keyPassphrase1Label.setText(CVSSSH2Messages.CVSSSH2PreferencePage_43);
- keyPassphrase1Text=new Text(group, SWT.SINGLE | SWT.BORDER);
- keyPassphrase1Text.setFont(group.getFont());
- keyPassphrase1Text.setEchoChar('*');
- gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=2;
- keyPassphrase1Text.setLayoutData(gd);
-
- keyPassphrase2Label=new Label(group, SWT.NONE);
- keyPassphrase2Label.setText(CVSSSH2Messages.CVSSSH2PreferencePage_44);
- keyPassphrase2Text=new Text(group, SWT.SINGLE | SWT.BORDER);
- keyPassphrase2Text.setFont(group.getFont());
- keyPassphrase2Text.setEchoChar('*');
- gd=new GridData(GridData.FILL_HORIZONTAL);
- gd.horizontalSpan=2;
- keyPassphrase2Text.setLayoutData(gd);
-
- keyPassphrase1Text.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e){
- String pass1=keyPassphrase1Text.getText();
- String pass2=keyPassphrase2Text.getText();
- if(kpair!=null && pass1.equals(pass2)){
- saveKeyPair.setEnabled(true);
- }
- else{
- saveKeyPair.setEnabled(false);
- }
- if(pass2.length()==0){
- setErrorMessage(null);
- return;
- }
- if(pass1.equals(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- }
- });
-
- keyPassphrase2Text.addModifyListener(new ModifyListener(){
- public void modifyText(ModifyEvent e){
- String pass1=keyPassphrase1Text.getText();
- String pass2=keyPassphrase2Text.getText();
- if(kpair!=null && pass1.equals(pass2)){
- saveKeyPair.setEnabled(true);
- }
- else{
- saveKeyPair.setEnabled(false);
- }
- if(pass2.length()<pass1.length()){
- if(pass1.startsWith(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- return;
- }
- if(pass1.equals(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- }
- });
-
- keyPassphrase2Text.addFocusListener(new FocusListener(){
- public void focusGained(FocusEvent e){
- String pass1=keyPassphrase1Text.getText();
- String pass2=keyPassphrase2Text.getText();
- if(pass2.length()<pass1.length()){
- if(pass1.startsWith(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- return;
- }
- if(pass1.equals(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- }
- public void focusLost(FocusEvent e){
- String pass1=keyPassphrase1Text.getText();
- String pass2=keyPassphrase2Text.getText();
- if(pass1.equals(pass2)){
- setErrorMessage(null);
- }
- else{
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_48);
- }
- }
- });
-
- Composite buttons=new Composite(group, SWT.NONE);
- layout=new GridLayout(2, true);
- layout.marginWidth=0;
- layout.marginHeight=0;
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- buttons.setLayout(layout);
- gd=new GridData(GridData.HORIZONTAL_ALIGN_END);
- gd.horizontalSpan=columnSpan;
- buttons.setLayoutData(gd);
-
- keyExport=new Button(buttons, SWT.NULL);
- keyExport.setText(CVSSSH2Messages.CVSSSH2PreferencePage_105);
- gd=new GridData(GridData.FILL_BOTH);
- keyExport.setLayoutData(gd);
-
- saveKeyPair=new Button(buttons, SWT.NULL);
- saveKeyPair.setText(CVSSSH2Messages.CVSSSH2PreferencePage_45);
- gd=new GridData(GridData.FILL_BOTH);
- saveKeyPair.setLayoutData(gd);
-
- SelectionAdapter keygenadapter=new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- JSch jsch=JSchSession.getJSch();
- boolean ok=true;
- String _type=""; //$NON-NLS-1$
-
- try{
- int type=0;
- if(e.widget==keyGenerateDSA){
- type=KeyPair.DSA;
- _type=ISSHContants.DSA;
- }
- else if(e.widget==keyGenerateRSA){
- type=KeyPair.RSA;
- _type=ISSHContants.RSA;
- }
- else{
- return;
- }
-
- final KeyPair[] _kpair=new KeyPair[1];
- final JSch _jsch=jsch;
- final int __type=type;
- final JSchException[] _e=new JSchException[1];
- BusyIndicator.showWhile(getShell().getDisplay(),
- new Runnable(){
- public void run(){
- try{
- _kpair[0]=KeyPair.genKeyPair(_jsch, __type);
- }catch(JSchException e){
- _e[0]=e;
- }
- }}
- );
- if(_e[0]!=null){
- throw _e[0];
- }
- kpair=_kpair[0];
-
- ByteArrayOutputStream out=new ByteArrayOutputStream();
- kpairComment=_type+"-1024"; //$NON-NLS-1$
- kpair.writePublicKey(out, kpairComment);
- out.close();
- publicKeyText.setText(out.toString());
- keyFingerPrintText.setText(kpair.getFingerPrint());
- keyCommentText.setText(kpairComment);
- keyPassphrase1Text.setText(""); //$NON-NLS-1$
- keyPassphrase2Text.setText(""); //$NON-NLS-1$
- updateControls();
- }
- catch(IOException ee){
- ok=false;
- }
- catch(JSchException ee){
- ok=false;
- }
- if(!ok){
- MessageDialog.openError(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_error,
- CVSSSH2Messages.CVSSSH2PreferencePage_47);
- }
- }
- };
- keyGenerateDSA.addSelectionListener(keygenadapter);
- keyGenerateRSA.addSelectionListener(keygenadapter);
-
- keyLoad.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- boolean ok=true;
- String home=ssh2HomeText.getText();
- FileDialog fd=new FileDialog(getShell(), SWT.OPEN);
- fd.setFilterPath(home);
- Object o=fd.open();
- if(o==null){ // cancel
- return;
- }
- String pkey=fd.getFileName();
- String pkeyab=(new File(fd.getFilterPath(), pkey)).getAbsolutePath();
- try{
- JSch jsch=JSchSession.getJSch();
- KeyPair _kpair=KeyPair.load(jsch, pkeyab);
- PassphrasePrompt prompt=null;
- while(_kpair.isEncrypted()){
- if(prompt==null){
- prompt=new PassphrasePrompt(NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_126, new String[] { pkey }));
- }
- Display.getDefault().syncExec(prompt);
- String passphrase=prompt.getPassphrase();
- if(passphrase==null) break;
- if(_kpair.decrypt(passphrase)){
- break;
- }
- MessageDialog.openError(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_error,
- NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_129, new String[] { pkey }));
- }
- if(_kpair.isEncrypted()){
- return;
- }
- kpair=_kpair;
- String _type=(kpair.getKeyType()==KeyPair.DSA)?ISSHContants.DSA:ISSHContants.RSA;
- ByteArrayOutputStream out=new ByteArrayOutputStream();
- kpairComment=_type+"-1024"; //$NON-NLS-1$
- kpair.writePublicKey(out, kpairComment);
- out.close();
- publicKeyText.setText(out.toString());
- keyFingerPrintText.setText(kpair.getFingerPrint());
- keyCommentText.setText(kpairComment);
- keyPassphrase1Text.setText(""); //$NON-NLS-1$
- keyPassphrase2Text.setText(""); //$NON-NLS-1$
- updateControls();
- }
- catch(IOException ee){
- ok=false;
- }
- catch(JSchException ee){
- ok=false;
- }
- if(!ok){
- MessageDialog.openError(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_error,
- CVSSSH2Messages.CVSSSH2PreferencePage_130);
- }
- }
- });
-
- keyExport.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- if(kpair==null)return;
-
- setErrorMessage(null);
-
- final String[] target=new String[1];
- final String title=CVSSSH2Messages.CVSSSH2PreferencePage_106;
- final String message=CVSSSH2Messages.CVSSSH2PreferencePage_107;
- Display.getDefault().syncExec(new Runnable(){
- public void run(){
- Display display=Display.getCurrent();
- Shell shell=new Shell(display);
- ExportDialog dialog=new ExportDialog(shell, title, message);
- dialog.open();
- shell.dispose();
- target[0]=dialog.getTarget();
- }});
- if(target[0]==null){
- return;
- }
- String user=""; //$NON-NLS-1$
- String host=""; //$NON-NLS-1$
- int port=22;
-
- if(target[0].indexOf('@')>0){
- user=target[0].substring(0, target[0].indexOf('@'));
- host=target[0].substring(target[0].indexOf('@')+1);
- }
- if(host.indexOf(':')>0){
- try{port=Integer.parseInt(host.substring(host.indexOf(':')+1));}
- catch(NumberFormatException ee) {
- port=-1;
- }
- host=host.substring(0, host.indexOf(':'));
- }
-
- if(user.length()==0 ||
- host.length()==0 ||
- port==-1){
- setErrorMessage(NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_108, new String[] { target[0] }));
- return;
- }
-
- String options=""; //$NON-NLS-1$
- try{
- ByteArrayOutputStream bos=new ByteArrayOutputStream();
- if(options.length()!=0){
- try{bos.write((options+" ").getBytes());} //$NON-NLS-1$
- catch(IOException eeee){}
- }
- kpair.writePublicKey(bos, kpairComment);
- bos.close();
- export_via_sftp(user, host, port,
- ".ssh/authorized_keys", //$NON-NLS-1$
- bos.toByteArray());
- }
- catch(IOException ee){
- }
- catch(JSchException ee){
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_111);
- }
- }});
-
- saveKeyPair.addSelectionListener(new SelectionAdapter(){
- public void widgetSelected(SelectionEvent e){
- if(kpair==null)return;
-
- String pass=keyPassphrase1Text.getText();
- /*
- if(!pass.equals(keyPassphrase2Text.getText())){
- setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$
- return;
- }
- */
- if(pass.length()==0){
- if(!MessageDialog.openConfirm(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_confirmation,
- CVSSSH2Messages.CVSSSH2PreferencePage_49
- )){
- return ;
- }
- }
-
- kpair.setPassphrase(pass);
-
- String home=ssh2HomeText.getText();
-
- File _home=new File(home);
-
- if(!_home.exists()){
- if(!MessageDialog.openConfirm(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_confirmation,
- NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_50, new String[] { home })
- )){
- return ;
- }
- if(!_home.mkdirs()){
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_100+home);
- return;
- }
- }
-
- FileDialog fd=new FileDialog(getShell(), SWT.SAVE);
- fd.setFilterPath(home);
- String file=(kpair.getKeyType()==KeyPair.RSA) ? "id_rsa" : "id_dsa"; //$NON-NLS-1$ //$NON-NLS-2$
- fd.setFileName(file);
- file=fd.open();
- if(file==null){ // cancel
- return;
- }
-
- if(new File(file).exists()){
- if(!MessageDialog.openConfirm(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_confirmation, //
- NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_53, new String[] { file })
- )){
- return;
- }
- }
-
- boolean ok=true;
- try{
- kpair.writePrivateKey(file);
- kpair.writePublicKey(file+".pub", kpairComment); //$NON-NLS-1$
- }
- catch(Exception ee){
- ok=false;
- }
-
- if(ok){
- MessageDialog.openInformation(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_information,
- CVSSSH2Messages.CVSSSH2PreferencePage_55+
- "\n"+ //$NON-NLS-1$
- CVSSSH2Messages.CVSSSH2PreferencePage_57+file+
- "\n"+ //$NON-NLS-1$
- CVSSSH2Messages.CVSSSH2PreferencePage_59+
- file+
- ".pub"); //$NON-NLS-1$
- }
- else{
- return;
- }
-
- // The generated key should be added to privateKeyText.
-
- String dir=fd.getFilterPath();
- File mypkey=new java.io.File(dir, fd.getFileName());
- String pkeys=privateKeyText.getText();
-
- // Check if the generated key has been included in pkeys?
- String[] pkeysa = pkeys.split(","); //$NON-NLS-1$
- for (int i = 0; i < pkeysa.length; i++) {
- File pkey = new java.io.File(pkeysa[i]);
- if (!pkey.isAbsolute()) {
- pkey = new java.io.File(home, pkeysa[i]);
- }
- if(pkey.equals(mypkey))
- return;
- }
-
- if(dir.equals(home)){dir="";} //$NON-NLS-1$
- else{dir+=java.io.File.separator;}
- if(pkeys.length()>0)
- pkeys+=","; //$NON-NLS-1$
- pkeys=pkeys+dir+fd.getFileName();
- privateKeyText.setText(pkeys);
- }
- });
-
- return group;
- }
-
- private TableViewer viewer;
- private Button removeHostKeyButton;
- class TableLabelProvider extends LabelProvider implements ITableLabelProvider {
- public String getColumnText(Object element, int columnIndex) {
- HostKey entry = (HostKey)element;
- switch (columnIndex) {
- case 0:
- return entry.getHost();
- case 1:
- return entry.getType();
- case 2:
- return entry.getFingerPrint(JSchSession.getJSch());
- default:
- return null;
- }
- }
- public Image getColumnImage(Object element, int columnIndex) {
- return null;
- }
- };
-
- private Control createHostKeyManagementPage(Composite parent) {
- Composite group=new Composite(parent, SWT.NULL);
- GridLayout layout=new GridLayout();
- layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- layout.numColumns = 2;
- group.setLayout(layout);
- GridData gd = new GridData();
- gd.horizontalAlignment = GridData.FILL;
- gd.verticalAlignment = GridData.FILL;
- group.setLayoutData(gd);
-
- Label label=new Label(group, SWT.NONE);
- label.setText(CVSSSH2Messages.CVSSSH2PreferencePage_139);
- gd=new GridData();
- gd.horizontalSpan=2;
- label.setLayoutData(gd);
-
- viewer = new TableViewer(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
- Table table = viewer.getTable();
- new TableEditor(table);
- table.setHeaderVisible(true);
- table.setLinesVisible(true);
- gd = new GridData(GridData.FILL_BOTH);
- gd.widthHint = convertWidthInCharsToPixels(30);
- /*
- * The hardcoded hint does not look elegant, but in reality
- * it does not make anything bound to this 100-pixel value,
- * because in any case the tree on the left is taller and
- * that's what really determines the height.
- */
- gd.heightHint = 100;
- table.setLayoutData(gd);
- table.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
- handleSelection();
- }
- });
- // Create the table columns
- new TableColumn(table, SWT.NULL);
- new TableColumn(table, SWT.NULL);
- new TableColumn(table, SWT.NULL);
- TableColumn[] columns = table.getColumns();
- columns[0].setText(CVSSSH2Messages.CVSSSH2PreferencePage_134);
- columns[1].setText(CVSSSH2Messages.CVSSSH2PreferencePage_135);
- columns[2].setText(CVSSSH2Messages.CVSSSH2PreferencePage_136);
- viewer.setColumnProperties(new String[] {
- CVSSSH2Messages.CVSSSH2PreferencePage_134, //
- CVSSSH2Messages.CVSSSH2PreferencePage_135, //
- CVSSSH2Messages.CVSSSH2PreferencePage_136});
- viewer.setLabelProvider(new TableLabelProvider());
- viewer.setContentProvider(new IStructuredContentProvider() {
- public void dispose() {
- }
- public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
- }
- public Object[] getElements(Object inputElement) {
- if (inputElement == null) return null;
- return (Object[])inputElement;
- }
- });
- TableLayout tl = new TableLayout();
- tl.addColumnData(new ColumnWeightData(30));
- tl.addColumnData(new ColumnWeightData(20));
- tl.addColumnData(new ColumnWeightData(70));
- table.setLayout(tl);
-
- Composite buttons = new Composite(group, SWT.NULL);
- buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
- layout = new GridLayout();
- layout.marginHeight=0;
- layout.marginWidth=0;
- buttons.setLayout(layout);
-
- removeHostKeyButton = new Button(buttons, SWT.PUSH);
- removeHostKeyButton.setText(CVSSSH2Messages.CVSSSH2PreferencePage_138);
- int buttonWidth= SWTUtils.calculateControlSize(SWTUtils.createDialogPixelConverter(parent), new Button [] { removeHostKeyButton });
- removeHostKeyButton.setLayoutData(SWTUtils.createGridData(buttonWidth, SWT.DEFAULT, SWT.END, SWT.CENTER, false, false));
- removeHostKeyButton.setEnabled(false);
- removeHostKeyButton.addListener(SWT.Selection, new Listener() {
- public void handleEvent(Event e) {
- removeHostKey();
- }
- });
-
- Dialog.applyDialogFont(parent);
-
- JSchSession.loadKnownHosts();
- HostKeyRepository hkr=JSchSession.getJSch().getHostKeyRepository();
- viewer.setInput(hkr.getHostKey());
- handleSelection();
-
- return group;
- }
-
- private void handleSelection() {
- boolean empty = viewer.getSelection().isEmpty();
- removeHostKeyButton.setEnabled(!empty);
- }
- private void removeHostKey(){
- IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
- HostKeyRepository hkr=JSchSession.getJSch().getHostKeyRepository();
- for (Iterator iterator = selection.iterator(); iterator.hasNext();) {
- HostKey hostkey = (HostKey) iterator.next();
- hkr.remove(hostkey.getHost(), hostkey.getType());
- viewer.remove(hostkey);
- }
- }
- private void export_via_sftp(String user, String host, int port, String target, byte[] pkey) throws JSchException{
- try{
-
- /*
- int i=0;
- String authorized_keys=target;
- String dir="";
- String separator="/";
- i=target.lastIndexOf("/");
- if(i<0){
- i=target.lastIndexOf("\\");
- if(i>=0){ separator="\\"; }
- }
- else{
- }
- if(i>=0){
- authorized_keys=target.substring(i+1);
- dir=target.substring(0, i+1);
- }
- */
-
- IProgressMonitor pm=new org.eclipse.core.runtime.NullProgressMonitor();
- Session session=JSchSession.getSession(null, user, "", host, port, pm).getSession(); //$NON-NLS-1$
- if(session.getServerVersion().indexOf("OpenSSH")==-1){ //$NON-NLS-1$
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_110);
- return;
- }
- Channel channel=session.openChannel("sftp"); //$NON-NLS-1$
- channel.connect();
- ChannelSftp c=(ChannelSftp)channel;
-
- /* String pwd=*/ c.pwd(); // Read off the channel
- SftpATTRS attr=null;
-
- try{ attr=c.stat(".ssh"); } //$NON-NLS-1$
- catch(SftpException ee){ }
- if(attr==null){
- try{ c.mkdir(".ssh"); } //$NON-NLS-1$
- catch(SftpException ee){
- setErrorMessage(ee.getMessage());
- return;
- }
- }
- try{ c.cd(".ssh"); } //$NON-NLS-1$
- catch(SftpException ee){
- setErrorMessage(ee.getMessage());
- return;
- }
-
- try{
- ByteArrayInputStream bis=new ByteArrayInputStream(pkey);
- c.put(bis, "authorized_keys", null, ChannelSftp.APPEND); //$NON-NLS-1$
- bis.close();
- checkPermission(c, "authorized_keys"); //$NON-NLS-1$
- checkPermission(c, "."); // .ssh //$NON-NLS-1$
- c.cd(".."); //$NON-NLS-1$
- checkPermission(c, "."); // home directory //$NON-NLS-1$
- }
- catch(SftpException ee){
- //setErrorMessage(debug+ee.message);
- }
-
- MessageDialog.openInformation(getShell(),
- CVSSSH2Messages.CVSSSH2PreferencePage_information,
- NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_109,
- (user+"@"+host+(port==22 ? "" : ":"+port)+":~/.ssh/authorized_keys"))); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-
- c.disconnect();
- //session.disconnect();
- }
- catch(IOException eee){
- setErrorMessage(eee.toString());
- }
- }
-
- private void checkPermission(ChannelSftp c, String path) throws SftpException{
- SftpATTRS attr=c.stat(path);
- int permissions=attr.getPermissions();
- if((permissions&00022)!=0){
- permissions&=~00022;
- c.chmod(permissions,path);
- }
- }
- private void updateControls() {
- boolean enable=(kpair!=null);
- publicKeylabel.setEnabled(enable);
- publicKeyText.setEnabled(enable);
- keyFingerPrintLabel.setEnabled(enable);
- keyFingerPrintText.setEnabled(enable);
- keyCommentLabel.setEnabled(enable);
- keyCommentText.setEnabled(enable);
- keyPassphrase1Label.setEnabled(enable);
- keyPassphrase1Text.setEnabled(enable);
- keyPassphrase2Label.setEnabled(enable);
- keyPassphrase2Text.setEnabled(enable);
- keyExport.setEnabled(enable);
- saveKeyPair.setEnabled(enable);
- }
-
- public void init(IWorkbench workbench) {
-// super.init(workbench);
-// initControls();
- }
-
- public void initialize() {
- initControls();
- }
-
- private void initControls(){
- IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();
- ssh2HomeText.setText(store.getString(ISSHContants.KEY_SSH2HOME));
- privateKeyText.setText(store.getString(ISSHContants.KEY_PRIVATEKEY));
- updateControls();
- }
- public boolean performOk() {
- boolean result = super.performOk();
- if (result) {
- setErrorMessage(null);
- String home = ssh2HomeText.getText();
- File _home = new File(home);
- if (!_home.exists()) {
- if (MessageDialog.openQuestion(getShell(), CVSSSH2Messages.CVSSSH2PreferencePage_question,
- NLS.bind(CVSSSH2Messages.CVSSSH2PreferencePage_99, new String[] { home })
- )) {
- if (!(_home.mkdirs())) {
- setErrorMessage(CVSSSH2Messages.CVSSSH2PreferencePage_100 + home);
- return false;
- }
- }
- }
-
- IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore();
- store.setValue(ISSHContants.KEY_SSH2HOME, home);
- store.setValue(ISSHContants.KEY_PRIVATEKEY, privateKeyText.getText());
- }
- CVSSSH2Plugin.getDefault().savePluginPreferences();
- return result;
- }
-
- public void performApply() {
- performOk();
- }
-
- protected void performDefaults(){
- super.performDefaults();
- IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore();
- store.setToDefault(ISSHContants.KEY_SSH2HOME);
- store.setToDefault(ISSHContants.KEY_PRIVATEKEY);
- store.setToDefault(ISSHContants.KEY_PROXY);
- store.setToDefault(ISSHContants.KEY_PROXY_TYPE);
- store.setToDefault(ISSHContants.KEY_PROXY_HOST);
- store.setToDefault(ISSHContants.KEY_PROXY_PORT);
- store.setToDefault(ISSHContants.KEY_PROXY_AUTH);
- initControls();
- updateControls();
- }
-
- protected void createSpacer(Composite composite, int columnSpan) {
- Label label=new Label(composite, SWT.NONE);
- GridData gd=new GridData();
- gd.horizontalSpan=columnSpan;
- label.setLayoutData(gd);
- }
-}
-
-class ExportDialog extends Dialog {
- protected Text field;
- protected String target=null;
- protected String title=null;
- protected String message=null;
-
- public ExportDialog(Shell parentShell, String title, String message) {
- super(parentShell);
- this.title=title;
- this.message=message;
- }
-
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(title);
- }
-
- public void create() {
- super.create();
- field.setFocus();
- }
-
- protected Control createDialogArea(Composite parent) {
- initializeDialogUnits(parent);
- Composite main=new Composite(parent, SWT.NONE);
- GridLayout layout=new GridLayout();
- layout.numColumns=2;
- layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- main.setLayout(layout);
- main.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- if (message!=null) {
- Label messageLabel=new Label(main, SWT.WRAP);
- messageLabel.setText(message);
- GridData data=new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan=2;
- messageLabel.setLayoutData(data);
- }
-
- createTargetFields(main);
- Dialog.applyDialogFont(main);
- return main;
- }
-
- protected void createTargetFields(Composite parent) {
- new Label(parent, SWT.NONE).setText(CVSSSH2Messages.CVSSSH2PreferencePage_125);
-
- field=new Text(parent, SWT.BORDER);
- GridData data=new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
- field.setLayoutData(data);
- }
-
- public String getTarget() {
- return target;
- }
-
- protected void okPressed() {
- String _target=field.getText();
- if(_target==null || _target.length()==0){
- return;
- }
- target=_target;
- super.okPressed();
- }
-
- protected void cancelPressed() {
- target=null;
- super.cancelPressed();
- }
-}
-
-class PassphrasePrompt implements Runnable{
- private String message;
- private String passphrase;
- PassphrasePrompt(String message){
- this.message=message;
- }
- public void run(){
- Display display=Display.getCurrent();
- Shell shell=new Shell(display);
- PassphraseDialog dialog=new PassphraseDialog(shell, message);
- dialog.open();
- shell.dispose();
- passphrase=dialog.getPassphrase();
- }
- public String getPassphrase(){
- return passphrase;
- }
-}
-
-class PassphraseDialog extends Dialog {
- protected Text passphraseField;
- protected String passphrase = null;
- protected String message = null;
-
- public PassphraseDialog(Shell parentShell, String message) {
- super(parentShell);
- this.message = message;
- }
-
- protected void configureShell(Shell newShell) {
- super.configureShell(newShell);
- newShell.setText(message);
- }
-
- public void create() {
- super.create();
- passphraseField.setFocus();
- }
-
- protected Control createDialogArea(Composite parent) {
- initializeDialogUnits(parent);
- Composite main=new Composite(parent, SWT.NONE);
-
- GridLayout layout=new GridLayout();
- layout.numColumns=3;
- layout.marginHeight=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
- layout.marginWidth=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
- layout.verticalSpacing=convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
- layout.horizontalSpacing=convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
- main.setLayout(layout);
- main.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- if (message!=null) {
- Label messageLabel=new Label(main, SWT.WRAP);
- messageLabel.setText(message);
- GridData data=new GridData(GridData.FILL_HORIZONTAL);
- data.horizontalSpan=3;
- messageLabel.setLayoutData(data);
- }
-
- createPassphraseFields(main);
- Dialog.applyDialogFont(main);
- return main;
- }
-
- protected void createPassphraseFields(Composite parent) {
- new Label(parent, SWT.NONE).setText(CVSSSH2Messages.CVSSSH2PreferencePage_127);
- passphraseField=new Text(parent, SWT.BORDER);
- GridData data=new GridData(GridData.FILL_HORIZONTAL);
- data.widthHint=convertHorizontalDLUsToPixels(IDialogConstants.ENTRY_FIELD_WIDTH);
- passphraseField.setLayoutData(data);
- passphraseField.setEchoChar('*');
-
- new Label(parent, SWT.NONE);
- }
-
- public String getPassphrase() {
- return passphrase;
- }
-
- protected void okPressed() {
- String _passphrase = passphraseField.getText();
- if(_passphrase==null || _passphrase.length()==0){
- return;
- }
- passphrase=_passphrase;
- super.okPressed();
- }
- protected void cancelPressed() {
- passphrase=null;
- super.cancelPressed();
- }
-}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/ISSHContants.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/ISSHContants.java
deleted file mode 100644
index f7d8359b6..000000000
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/ISSHContants.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.team.internal.ccvs.ssh2;
-
-
-/**
- * Defines the constants used by the SSH2 Plugin
- */
-public interface ISSHContants {
-
- public static String KEY_PROXY="CVSSSH2PreferencePage.PROXY"; //$NON-NLS-1$
- public static String KEY_PROXY_TYPE="CVSSSH2PreferencePage.PROXY_TYPE"; //$NON-NLS-1$
- public static String KEY_PROXY_HOST="CVSSSH2PreferencePage.PROXY_HOST"; //$NON-NLS-1$
- public static String KEY_PROXY_PORT="CVSSSH2PreferencePage.PROXY_PORT"; //$NON-NLS-1$
- public static String KEY_PROXY_AUTH="CVSSSH2PreferencePage.PROXY_AUTH"; //$NON-NLS-1$
- public static String KEY_PROXY_USER="CVSSSH2PreferencePage.PROXY_USER"; //$NON-NLS-1$
- public static String KEY_PROXY_PASS="CVSSSH2PreferencePage.PROXY_PASS"; //$NON-NLS-1$
- public static String KEY_SSH2HOME="CVSSSH2PreferencePage.SSH2HOME"; //$NON-NLS-1$
- public static String KEY_KEYFILE="CVSSSH2PreferencePage.KEYFILE"; //$NON-NLS-1$
- public static String KEY_PRIVATEKEY="CVSSSH2PreferencePage.PRIVATEKEY"; //$NON-NLS-1$
-
- static String SOCKS5="SOCKS5"; //$NON-NLS-1$
- static String HTTP="HTTP"; //$NON-NLS-1$
- static String HTTP_DEFAULT_PORT="80"; //$NON-NLS-1$
- static String SOCKS5_DEFAULT_PORT="1080"; //$NON-NLS-1$
- static String PRIVATE_KEYS_DEFAULT="id_dsa,id_rsa"; //$NON-NLS-1$
-
- static String DSA="DSA"; //$NON-NLS-1$
- static String RSA="RSA"; //$NON-NLS-1$
-
-}
diff --git a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
index e56c4db05..f26dcb6c3 100644
--- a/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
+++ b/bundles/org.eclipse.team.cvs.ssh2/src/org/eclipse/team/internal/ccvs/ssh2/JSchSession.java
@@ -11,27 +11,36 @@
*******************************************************************************/
package org.eclipse.team.internal.ccvs.ssh2;
-import java.io.*;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Enumeration;
-import java.util.Hashtable;
-import org.eclipse.core.runtime.*;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.team.internal.ccvs.core.*;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jsch.core.IJSchService;
+import org.eclipse.team.internal.ccvs.core.CVSException;
+import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
+import org.eclipse.team.internal.ccvs.core.IUserAuthenticator;
+import org.eclipse.team.internal.ccvs.core.IUserInfo;
import org.eclipse.team.internal.ccvs.core.connection.CVSRepositoryLocation;
import org.eclipse.team.internal.ccvs.core.util.Util;
-import com.jcraft.jsch.*;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+import com.jcraft.jsch.Session;
+import com.jcraft.jsch.SocketFactory;
+import com.jcraft.jsch.UIKeyboardInteractive;
+import com.jcraft.jsch.UserInfo;
class JSchSession {
private static final int SSH_DEFAULT_PORT = 22;
private static JSch jsch=new JSch();
private static java.util.Hashtable pool = new java.util.Hashtable();
-
- private static String current_ssh_home = null;
- private static String current_pkeys = ""; //$NON-NLS-1$
+
private final Session session;
private final UserInfo prompter;
private final ICVSRepositoryLocation location;
@@ -349,52 +358,7 @@ class JSchSession {
if (port == ICVSRepositoryLocation.USE_DEFAULT_PORT)
port = getPort(location);
-
- IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore();
- String ssh_home = store.getString(ISSHContants.KEY_SSH2HOME);
- String pkeys = store.getString(ISSHContants.KEY_PRIVATEKEY);
-
- try {
- if (current_ssh_home == null || !current_ssh_home.equals(ssh_home)) {
- loadKnownHosts();
- current_ssh_home = ssh_home;
- }
-
- if (ssh_home.length() == 0)
- ssh_home = CVSSSH2Plugin.SSH_HOME_DEFAULT;
-
- 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) {
- }
-
String key = getPoolKey(username, hostname, port);
try {
@@ -405,61 +369,29 @@ class JSchSession {
}
if (jschSession == null) {
- boolean useProxy = CVSProviderPlugin.getPlugin().isUseProxy();
- Proxy proxy = null;
- if (useProxy) {
- String _type = CVSProviderPlugin.getPlugin().getProxyType();
- String _host = CVSProviderPlugin.getPlugin().getProxyHost();
- String _port = CVSProviderPlugin.getPlugin().getProxyPort();
-
- boolean useAuth = CVSProviderPlugin.getPlugin().isUseProxyAuth();
- String _user = ""; //$NON-NLS-1$
- String _pass = ""; //$NON-NLS-1$
-
- // Retrieve username and password from keyring.
- if(useAuth){
- _user=CVSProviderPlugin.getPlugin().getProxyUser();
- _pass=CVSProviderPlugin.getPlugin().getProxyPassword();
- }
-
- String proxyhost = _host + ":" + _port; //$NON-NLS-1$
- if (_type.equals(CVSProviderPlugin.PROXY_TYPE_HTTP)) {
- proxy = new ProxyHTTP(proxyhost);
- if (useAuth) {
- ((ProxyHTTP) proxy).setUserPasswd(_user, _pass);
- }
- } else if (_type.equals(CVSProviderPlugin.PROXY_TYPE_SOCKS5)) {
- proxy = new ProxySOCKS5(proxyhost);
- if (useAuth) {
- ((ProxySOCKS5) proxy).setUserPasswd(_user, _pass);
- }
- } else {
- proxy = null;
- }
- }
-
MyUserInfo ui = new MyUserInfo(username, password, location);
UserInfoTimer wrapperUI = new UserInfoTimer(ui);
ui.aboutToConnect();
Session session = null;
try {
- session = createSession(username, password, hostname, port, new JSchSession.ResponsiveSocketFacory(monitor), proxy, wrapperUI);
+ session = createSession(username, password, hostname, port, wrapperUI, monitor);
} catch (JSchException e) {
if (isAuthenticationFailure(e) && wrapperUI.hasPromptExceededTimeout()) {
// Try again since the previous prompt may have obtained the proper credentials from the user
- session = createSession(username, password, hostname, port, new JSchSession.ResponsiveSocketFacory(monitor), proxy, wrapperUI);
+ session = createSession(username, password, hostname, port, wrapperUI, monitor);
} else {
throw e;
}
}
+ if (session == null)
+ throw new JSchException("The JSch service is not available");
ui.connectionMade();
JSchSession schSession = new JSchSession(session, location, wrapperUI);
pool.put(key, schSession);
return schSession;
- } else {
- return jschSession;
- }
+ }
+ return jschSession;
} catch (JSchException e) {
pool.remove(key);
if(e.toString().indexOf("Auth cancel")!=-1){ //$NON-NLS-1$
@@ -469,35 +401,16 @@ class JSchSession {
}
}
- private static Session createSession(String username, String password, String hostname, int port, SocketFactory socketFactory, Proxy proxy, UserInfo wrapperUI) throws JSchException {
- Session session = jsch.getSession(username, hostname, port);
- if (proxy != null) {
- session.setProxy(proxy);
- }
+ private static Session createSession(String username, String password, String hostname, int port, UserInfo wrapperUI, IProgressMonitor monitor) throws JSchException {
+ IJSchService service = CVSSSH2Plugin.getDefault().getJSchService();
+ if (service == null)
+ return null;
+ Session session = service.createSession(hostname, port, username);
session.setTimeout(getCVSTimeoutInMillis());
if (password != null)
session.setPassword(password);
session.setUserInfo(wrapperUI);
- session.setSocketFactory(socketFactory);
-
- // TODO following lines should be deleted after
- // improvements on the prompt for keyboard-interactive(KI) auth method.
- // Without following lines, in establishing SSH session to some sshd(for example,
- // running on dev.eclipse.org), KI will be tryed at first instead of password auth method and
- // the GUI for KI prompt will not allow to save given password in current implementation.
- Hashtable config=new Hashtable();
- config.put("PreferredAuthentications", //$NON-NLS-1$
- "gssapi-with-mic,publickey,password,keyboard-interactive"); //$NON-NLS-1$
- session.setConfig(config);
-
- // This is where the server is contacted and authentication occurs
- try {
- session.connect();
- } catch (JSchException e) {
- if (session.isConnected())
- session.disconnect();
- throw e;
- }
+ service.connect(session, getCVSTimeoutInMillis(), monitor);
return session;
}
@@ -516,21 +429,6 @@ class JSchSession {
return port;
}
- static void loadKnownHosts(){
- IPreferenceStore store = CVSSSH2Plugin.getDefault().getPreferenceStore();
- String ssh_home = store.getString(ISSHContants.KEY_SSH2HOME);
-
- if (ssh_home.length() == 0)
- ssh_home = CVSSSH2Plugin.SSH_HOME_DEFAULT;
-
- try {
- java.io.File file;
- file=new java.io.File(ssh_home, "known_hosts"); //$NON-NLS-1$
- jsch.setKnownHosts(file.getPath());
- } catch (Exception e) {
- }
- }
-
static void shutdown() {
if (jsch != null && pool.size() > 0) {
for (Enumeration e = pool.elements(); e.hasMoreElements(); ) {

Back to the top