5353import org .eclipse .swt .custom .TableEditor ;
5454import org .eclipse .swt .events .FocusEvent ;
5555import org .eclipse .swt .events .FocusListener ;
56+ import org .eclipse .swt .events .KeyListener ;
5657import org .eclipse .swt .events .SelectionAdapter ;
5758import org .eclipse .swt .events .SelectionEvent ;
5859import org .eclipse .swt .graphics .Image ;
6667import org .eclipse .swt .widgets .FileDialog ;
6768import org .eclipse .swt .widgets .Label ;
6869import org .eclipse .swt .widgets .Shell ;
70+ import org .eclipse .swt .widgets .Spinner ;
6971import org .eclipse .swt .widgets .Table ;
7072import org .eclipse .swt .widgets .TableColumn ;
7173import 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