Skip to content

Commit 0613d3b

Browse files
axmanaladHannesWell
authored andcommitted
[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)
1 parent d5c652b commit 0613d3b

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/Messages.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public class Messages extends NLS{
9999
public static String CVSSSH2PreferencePage_145;
100100
public static String CVSSSH2PreferencePage_146;
101101
public static String CVSSSH2PreferencePage_147;
102+
public static String CVSSSH2PreferencePage_148;
102103
public static String KeyboardInteractiveDialog_0;
103104
public static String KeyboardInteractiveDialog_1;
104105
public static String KeyboardInteractiveDialog_2;

team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ CVSSSH2PreferencePage_144=Key Exchange &Methods
8989
CVSSSH2PreferencePage_145=MA&C Methods
9090
CVSSSH2PreferencePage_146=&SSH Agent
9191
CVSSSH2PreferencePage_147=Select preferred SSH Agent
92+
CVSSSH2PreferencePage_148=Key size:
9293
UserInfoPrompter_0=SSH2 Message
9394
UserInfoPrompter_1=SSH2 Message
9495
KeyboardInteractiveDialog_0=Keyboard Interactive authentication for {0}: {1}

team/bundles/org.eclipse.jsch.ui/src/org/eclipse/jsch/internal/ui/preference/PreferencePage.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import org.eclipse.swt.custom.TableEditor;
5454
import org.eclipse.swt.events.FocusEvent;
5555
import org.eclipse.swt.events.FocusListener;
56+
import org.eclipse.swt.events.KeyListener;
5657
import org.eclipse.swt.events.SelectionAdapter;
5758
import org.eclipse.swt.events.SelectionEvent;
5859
import org.eclipse.swt.graphics.Image;
@@ -66,6 +67,7 @@
6667
import org.eclipse.swt.widgets.FileDialog;
6768
import org.eclipse.swt.widgets.Label;
6869
import org.eclipse.swt.widgets.Shell;
70+
import org.eclipse.swt.widgets.Spinner;
6971
import org.eclipse.swt.widgets.Table;
7072
import org.eclipse.swt.widgets.TableColumn;
7173
import org.eclipse.swt.widgets.TableItem;
@@ -89,8 +91,11 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
8991
implements IWorkbenchPreferencePage{
9092

9193
private static final String SSH2_PREFERENCE_PAGE_CONTEXT="org.eclipse.jsch.ui.ssh2_preference_page_context"; //$NON-NLS-1$
92-
private static final int RSA_KEY_SIZE = 4096;
93-
private static final int DSA_KEY_SIZE = 3072;
94+
private static final int RSA_MAX_KEY_SIZE = 15360;
95+
private static final int DSA_MAX_KEY_SIZE = 3072;
96+
private static final int INITIAL_KEY_SIZE = 4096;
97+
private static final int MIN_KEY_SIZE = 2048;
98+
private static final int KEY_SIZE_INCREMENT = 1024;
9499

95100
private Label ssh2HomeLabel;
96101
private Label privateKeyLabel;
@@ -101,6 +106,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
101106
private Button ssh2HomeBrowse;
102107
Button keyGenerateDSA;
103108
Button keyGenerateRSA;
109+
private Spinner keySizeValue;
104110
private Button keyLoad;
105111
private Button keyExport;
106112
Button saveKeyPair;
@@ -305,6 +311,13 @@ private Control createKeyManagementPage(Composite parent){
305311
gd.horizontalSpan=1;
306312
keyLoad.setLayoutData(gd);
307313

314+
final Label keySizeValueLabel = new Label(group, SWT.NONE);
315+
keySizeValueLabel.setText(Messages.CVSSSH2PreferencePage_148);
316+
keySizeValue = new Spinner(group, SWT.BORDER);
317+
int maxKeySize = Math.max(DSA_MAX_KEY_SIZE, RSA_MAX_KEY_SIZE);
318+
keySizeValue.setValues(INITIAL_KEY_SIZE, MIN_KEY_SIZE, maxKeySize, 0, KEY_SIZE_INCREMENT, KEY_SIZE_INCREMENT);
319+
keySizeValue.addKeyListener(KeyListener.keyPressedAdapter(e -> e.doit = false));
320+
308321
publicKeylabel=new Label(group, SWT.NONE);
309322
publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39);
310323
gd=new GridData();
@@ -485,6 +498,9 @@ public void widgetSelected(SelectionEvent e){
485498
if(e.widget==keyGenerateDSA){
486499
type=KeyPair.DSA;
487500
_type=IConstants.DSA;
501+
if (keySizeValue.getSelection() > DSA_MAX_KEY_SIZE) {
502+
keySizeValue.setSelection(DSA_MAX_KEY_SIZE);
503+
}
488504
}
489505
else if(e.widget==keyGenerateRSA){
490506
type=KeyPair.RSA;
@@ -496,7 +512,7 @@ else if(e.widget==keyGenerateRSA){
496512

497513
final KeyPair[] _kpair=new KeyPair[1];
498514
final int __type=type;
499-
int keySize = type == KeyPair.RSA ? RSA_KEY_SIZE : DSA_KEY_SIZE;
515+
int keySize = keySizeValue.getSelection();
500516
final JSchException[] _e=new JSchException[1];
501517
BusyIndicator.showWhile(getShell().getDisplay(), () -> {
502518
try {

0 commit comments

Comments
 (0)