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-15360 bits incremented by 1024 bits. (DSA has a max limit of 3072 bits)
  • Loading branch information
axmanalad committed Nov 12, 2024
1 parent 4712d12 commit 2f5c7e0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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:
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,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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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 {
Expand Down

0 comments on commit 2f5c7e0

Please sign in to comment.