Skip to content

Commit 2f5c7e0

Browse files
committed
[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 4712d12 commit 2f5c7e0

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
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: 20 additions & 2 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,13 @@ 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;
94+
private static final int RSA_KEY_SIZE = 15360;
9395
private static final int DSA_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 MAX_KEY_SIZE = RSA_KEY_SIZE;
99+
private static final int MAX_KEY_SIZE_DIGIT_COUNT = 0;
100+
private static final int KEY_SIZE_INCREMENT = 1024;
94101

95102
private Label ssh2HomeLabel;
96103
private Label privateKeyLabel;
@@ -101,6 +108,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
101108
private Button ssh2HomeBrowse;
102109
Button keyGenerateDSA;
103110
Button keyGenerateRSA;
111+
private Spinner keySizeValue;
104112
private Button keyLoad;
105113
private Button keyExport;
106114
Button saveKeyPair;
@@ -305,6 +313,13 @@ private Control createKeyManagementPage(Composite parent){
305313
gd.horizontalSpan=1;
306314
keyLoad.setLayoutData(gd);
307315

316+
final Label keyGenerateSizeLabel = new Label(group, SWT.NONE);
317+
keyGenerateSizeLabel.setText(Messages.CVSSSH2PreferencePage_148);
318+
keySizeValue = new Spinner(group, SWT.BORDER);
319+
keySizeValue.setValues(INITIAL_KEY_SIZE, MIN_KEY_SIZE, MAX_KEY_SIZE, MAX_KEY_SIZE_DIGIT_COUNT,
320+
KEY_SIZE_INCREMENT, KEY_SIZE_INCREMENT);
321+
keySizeValue.addKeyListener(KeyListener.keyPressedAdapter(e -> e.doit = false));
322+
308323
publicKeylabel=new Label(group, SWT.NONE);
309324
publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39);
310325
gd=new GridData();
@@ -485,6 +500,9 @@ public void widgetSelected(SelectionEvent e){
485500
if(e.widget==keyGenerateDSA){
486501
type=KeyPair.DSA;
487502
_type=IConstants.DSA;
503+
if (keySizeValue.getSelection() > DSA_KEY_SIZE) {
504+
keySizeValue.setSelection(DSA_KEY_SIZE);
505+
}
488506
}
489507
else if(e.widget==keyGenerateRSA){
490508
type=KeyPair.RSA;
@@ -496,7 +514,7 @@ else if(e.widget==keyGenerateRSA){
496514

497515
final KeyPair[] _kpair=new KeyPair[1];
498516
final int __type=type;
499-
int keySize = type == KeyPair.RSA ? RSA_KEY_SIZE : DSA_KEY_SIZE;
517+
int keySize = keySizeValue.getSelection();
500518
final JSchException[] _e=new JSchException[1];
501519
BusyIndicator.showWhile(getShell().getDisplay(), () -> {
502520
try {

0 commit comments

Comments
 (0)