Skip to content

Commit

Permalink
[SSH] Added key size selection
Browse files Browse the repository at this point in the history
This implementation allows to select the key size of the generated key ranging from 2048-4096 bits incremented by 1024 bits. (DSA is limited to 3072 bits)
  • Loading branch information
axmanalad committed Nov 25, 2024
1 parent 28c0896 commit 57e2ce9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 to Generate:
UserInfoPrompter_0=SSH2 Message
UserInfoPrompter_1=SSH2 Message
KeyboardInteractiveDialog_0=Keyboard Interactive authentication for {0}: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
import org.eclipse.swt.custom.TableEditor;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
Expand All @@ -66,6 +68,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;
Expand All @@ -91,6 +94,10 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
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 DSA_KEY_SIZE = 3072;
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;
Expand All @@ -101,6 +108,7 @@ public class PreferencePage extends org.eclipse.jface.preference.PreferencePage
private Button ssh2HomeBrowse;
Button keyGenerateDSA;
Button keyGenerateRSA;
private Spinner keyGenerateSize;
private Button keyLoad;
private Button keyExport;
Button saveKeyPair;
Expand Down Expand Up @@ -305,6 +313,19 @@ private Control createKeyManagementPage(Composite parent){
gd.horizontalSpan=1;
keyLoad.setLayoutData(gd);

final Label keyGenerateSizeLabel=new Label(group, SWT.NONE);
keyGenerateSizeLabel.setText(Messages.CVSSSH2PreferencePage_148);
keyGenerateSize=new Spinner(group, SWT.BORDER);
keyGenerateSize.setValues(MIN_KEY_SIZE, MIN_KEY_SIZE, MAX_KEY_SIZE, MAX_KEY_SIZE_DIGIT_COUNT,
KEY_SIZE_INCREMENT, KEY_SIZE_INCREMENT);

keyGenerateSize.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
e.doit = false;
}
});

publicKeylabel=new Label(group, SWT.NONE);
publicKeylabel.setText(Messages.CVSSSH2PreferencePage_39);
gd=new GridData();
Expand Down Expand Up @@ -485,6 +506,8 @@ public void widgetSelected(SelectionEvent e){
if(e.widget==keyGenerateDSA){
type=KeyPair.DSA;
_type=IConstants.DSA;
if (keyGenerateSize.getSelection()>DSA_KEY_SIZE)
keyGenerateSize.setSelection(DSA_KEY_SIZE);
}
else if(e.widget==keyGenerateRSA){
type=KeyPair.RSA;
Expand All @@ -496,7 +519,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=keyGenerateSize.getSelection();
final JSchException[] _e=new JSchException[1];
BusyIndicator.showWhile(getShell().getDisplay(), () -> {
try {
Expand Down

0 comments on commit 57e2ce9

Please sign in to comment.