From 2f5c7e071500074f25b5debe10991d8b09437ae7 Mon Sep 17 00:00:00 2001 From: Alexander Manalad Date: Mon, 4 Nov 2024 21:48:58 -0800 Subject: [PATCH] [SSH] Added key size selection This implementation allows to select the key size of the generated key ranging from 2048-15360 bits incremented by 1024 bits. (DSA has a max limit of 3072 bits) --- .../eclipse/jsch/internal/ui/Messages.java | 1 + .../jsch/internal/ui/messages.properties | 1 + .../ui/preference/PreferencePage.java | 22 +++++++++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java index 0453c56f0a5..fde33f86be1 100644 --- a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java +++ b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java @@ -99,6 +99,7 @@ public class Messages extends NLS{ public static String CVSSSH2PreferencePage_145; public static String CVSSSH2PreferencePage_146; public static String CVSSSH2PreferencePage_147; + public static String CVSSSH2PreferencePage_148; public static String KeyboardInteractiveDialog_0; public static String KeyboardInteractiveDialog_1; public static String KeyboardInteractiveDialog_2; diff --git a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties index aa6a976f406..ff001ccc4ce 100644 --- a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties +++ b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties @@ -89,6 +89,7 @@ CVSSSH2PreferencePage_144=Key Exchange &Methods CVSSSH2PreferencePage_145=MA&C Methods CVSSSH2PreferencePage_146=&SSH Agent CVSSSH2PreferencePage_147=Select preferred SSH Agent +CVSSSH2PreferencePage_148=Key size: UserInfoPrompter_0=SSH2 Message UserInfoPrompter_1=SSH2 Message KeyboardInteractiveDialog_0=Keyboard Interactive authentication for {0}: {1} diff --git a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java index f536bec2f4a..60557889d6a 100644 --- a/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java +++ b/team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java @@ -53,6 +53,7 @@ import org.eclipse.swt.custom.TableEditor; import org.eclipse.swt.events.FocusEvent; import org.eclipse.swt.events.FocusListener; +import org.eclipse.swt.events.KeyListener; import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.graphics.Image; @@ -66,6 +67,7 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Spinner; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableColumn; import org.eclipse.swt.widgets.TableItem; @@ -89,8 +91,13 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage implements IWorkbenchPreferencePage{ private static final String SSH2_PREFERENCE_PAGE_CONTEXT="org.eclipse.jsch.ui.ssh2_preference_page_context"; //$NON-NLS-1$ - private static final int RSA_KEY_SIZE = 4096; + private static final int RSA_KEY_SIZE = 15360; private static final int DSA_KEY_SIZE = 3072; + private static final int INITIAL_KEY_SIZE = 4096; + private static final int MIN_KEY_SIZE = 2048; + private static final int MAX_KEY_SIZE = RSA_KEY_SIZE; + private static final int MAX_KEY_SIZE_DIGIT_COUNT = 0; + private static final int KEY_SIZE_INCREMENT = 1024; private Label ssh2HomeLabel; private Label privateKeyLabel; @@ -101,6 +108,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage private Button ssh2HomeBrowse; Button keyGenerateDSA; Button keyGenerateRSA; + private Spinner keySizeValue; private Button keyLoad; private Button keyExport; Button saveKeyPair; @@ -305,6 +313,13 @@ private Control createKeyManagementPage(Composite parent){ gd.horizontalSpan=1; keyLoad.setLayoutData(gd); + final Label keyGenerateSizeLabel = new Label(group, SWT.NONE); + keyGenerateSizeLabel.setText(Messages.CVSSSH2PreferencePage_148); + keySizeValue = new Spinner(group, SWT.BORDER); + keySizeValue.setValues(INITIAL_KEY_SIZE, MIN_KEY_SIZE, MAX_KEY_SIZE, MAX_KEY_SIZE_DIGIT_COUNT, + KEY_SIZE_INCREMENT, KEY_SIZE_INCREMENT); + keySizeValue.addKeyListener(KeyListener.keyPressedAdapter(e -> e.doit = false)); + publicKeylabel=new Label(group, SWT.NONE); publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39); gd=new GridData(); @@ -485,6 +500,9 @@ public void widgetSelected(SelectionEvent e){ if(e.widget==keyGenerateDSA){ type=KeyPair.DSA; _type=IConstants.DSA; + if (keySizeValue.getSelection() > DSA_KEY_SIZE) { + keySizeValue.setSelection(DSA_KEY_SIZE); + } } else if(e.widget==keyGenerateRSA){ type=KeyPair.RSA; @@ -496,7 +514,7 @@ else if(e.widget==keyGenerateRSA){ final KeyPair[] _kpair=new KeyPair[1]; final int __type=type; - int keySize = type == KeyPair.RSA ? RSA_KEY_SIZE : DSA_KEY_SIZE; + int keySize = keySizeValue.getSelection(); final JSchException[] _e=new JSchException[1]; BusyIndicator.showWhile(getShell().getDisplay(), () -> { try {