⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cvsssh2preferencepage.java

📁 This archive file is for Eclipse 2.1.* and Eclipse 3.0 M5(or previous) users
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
    		try{    			ByteArrayOutputStream out=new ByteArrayOutputStream();    			kpair.writePublicKey(out, keyCommentText.getText());    			out.close();    			publicKeyText.setText(out.toString());    		}    		catch(IOException ee){}    }});    keyPassphrase1Label=new Label(group, SWT.NONE);    keyPassphrase1Label.setText(Policy.bind("CVSSSH2PreferencePage.43")); //$NON-NLS-1$    keyPassphrase1Text=new Text(group, SWT.SINGLE | SWT.BORDER);    keyPassphrase1Text.setFont(group.getFont());    keyPassphrase1Text.setEchoChar('*');    gd=new GridData(GridData.FILL_HORIZONTAL);    gd.horizontalSpan=2;    keyPassphrase1Text.setLayoutData(gd);    keyPassphrase2Label=new Label(group, SWT.NONE);    keyPassphrase2Label.setText(Policy.bind("CVSSSH2PreferencePage.44")); //$NON-NLS-1$    keyPassphrase2Text=new Text(group, SWT.SINGLE | SWT.BORDER);    keyPassphrase2Text.setFont(group.getFont());    keyPassphrase2Text.setEchoChar('*');    gd=new GridData(GridData.FILL_HORIZONTAL);    gd.horizontalSpan=2;    keyPassphrase2Text.setLayoutData(gd);    keyPassphrase1Text.addModifyListener(new ModifyListener(){	public void modifyText(ModifyEvent e){	  String pass1=keyPassphrase1Text.getText();	  String pass2=keyPassphrase2Text.getText();	  if(kpair!=null && pass1.equals(pass2)){	    saveKeyPair.setEnabled(true);	  }	  else{	    saveKeyPair.setEnabled(false);	  }	  if(pass2.length()==0){	    setErrorMessage(null);	    return;	  }	  if(pass1.equals(pass2)){	    setErrorMessage(null);	  }	  else{	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	  }	}      });       keyPassphrase2Text.addModifyListener(new ModifyListener(){	public void modifyText(ModifyEvent e){	  String pass1=keyPassphrase1Text.getText();	  String pass2=keyPassphrase2Text.getText();	  if(kpair!=null && pass1.equals(pass2)){	    saveKeyPair.setEnabled(true);	  }	  else{	    saveKeyPair.setEnabled(false);	  }	  if(pass2.length()<pass1.length()){	    if(pass1.startsWith(pass2)){	      setErrorMessage(null);	    }	    else{	      setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	    }	    return;	  }	  if(pass1.equals(pass2)){	    setErrorMessage(null);	  }	  else{	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	  }	}      });       keyPassphrase2Text.addFocusListener(new FocusListener(){	public void focusGained(FocusEvent e){	  String pass1=keyPassphrase1Text.getText();	  String pass2=keyPassphrase2Text.getText();	  if(pass2.length()<pass1.length()){	    if(pass1.startsWith(pass2)){	      setErrorMessage(null);	    }	    else{	      setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	    }	    return;	  }	  if(pass1.equals(pass2)){	    setErrorMessage(null);	  }	  else{	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	  }	}	public void focusLost(FocusEvent e){	  String pass1=keyPassphrase1Text.getText();	  String pass2=keyPassphrase2Text.getText();	  if(pass1.equals(pass2)){	    setErrorMessage(null);	  }	  else{	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	  }	}      });    saveKeyPair=new Button(group, SWT.NULL);    saveKeyPair.setText(Policy.bind("CVSSSH2PreferencePage.45")); //$NON-NLS-1$    gd=new GridData(GridData.HORIZONTAL_ALIGN_END);    gd.horizontalSpan=columnSpan;    saveKeyPair.setLayoutData(gd);    SelectionAdapter keygenadapter=new SelectionAdapter(){	public void widgetSelected(SelectionEvent e){	  JSch jsch=JSchSession.getJSch();	  boolean ok=true;	  String _type=""; //$NON-NLS-1$	  try{	    int type=0;	    if(e.widget==keyGenerateDSA){	      type=KeyPair.DSA;	      _type=DSA;	    }	    else if(e.widget==keyGenerateRSA){	      type=KeyPair.RSA;	      _type=RSA;	    }	    else{	      return;	    }	    final KeyPair[] _kpair=new KeyPair[1];	    final JSch _jsch=jsch;	    final int __type=type;	    final JSchException[] _e=new JSchException[1];	    BusyIndicator.showWhile(getShell().getDisplay(),	    		new Runnable(){	    	public void run(){	    		try{	    		  _kpair[0]=KeyPair.genKeyPair(_jsch, __type);	    		}catch(JSchException e){	    		  _e[0]=e;	    		}	    	}}	    		);	    if(_e[0]!=null){	    	throw _e[0];	    }	    kpair=_kpair[0];	    	    ByteArrayOutputStream out=new ByteArrayOutputStream();	    kpairComment=_type+"-1024"; //$NON-NLS-1$	    kpair.writePublicKey(out, kpairComment);	    out.close();	    publicKeyText.setText(out.toString());	    keyFingerPrintText.setText(kpair.getFingerPrint());	    keyCommentText.setText(kpairComment);	    keyPassphrase1Text.setText(""); //$NON-NLS-1$	    keyPassphrase2Text.setText(""); //$NON-NLS-1$	    updateControls();	  }	  catch(IOException ee){	    ok=false;	  }	  catch(JSchException ee){	    ok=false;	  }	  if(!ok){ 	    MessageDialog.openError(getShell(),				    Policy.bind("CVSSSH2PreferencePage.error"),  //$NON-NLS-1$				    Policy.bind("CVSSSH2PreferencePage.47"));  //$NON-NLS-1$	  }	}      };    keyGenerateDSA.addSelectionListener(keygenadapter);    keyGenerateRSA.addSelectionListener(keygenadapter);    keyLoad.addSelectionListener(new SelectionAdapter(){	public void widgetSelected(SelectionEvent e){	  boolean ok=true;	  String home=ssh2HomeText.getText();	  FileDialog fd=new FileDialog(getShell(), SWT.OPEN);	  fd.setFilterPath(home);	  Object o=fd.open();	  if(o==null){ // cancel	    return;	  }	  String pkey=fd.getFileName();	  String pkeyab=(new File(fd.getFilterPath(), pkey)).getAbsolutePath();	  try{	    JSch jsch=JSchSession.getJSch();	    KeyPair _kpair=KeyPair.load(jsch, pkeyab);	    PassphrasePrompt prompt=null;	    while(_kpair.isEncrypted()){	      if(prompt==null){		prompt=new PassphrasePrompt(Policy.bind("CVSSSH2PreferencePage.126", pkey));   //$NON-NLS-1$	      }	      Display.getDefault().syncExec(prompt);	      String passphrase=prompt.getPassphrase();	      if(passphrase==null) break;	      if(_kpair.decrypt(passphrase)){	      	break;	      }	      MessageDialog.openError(getShell(),				      Policy.bind("CVSSSH2PreferencePage.error"),  //$NON-NLS-1$				      Policy.bind("CVSSSH2PreferencePage.129", pkey));  //$NON-NLS-1$	    }	    if(_kpair.isEncrypted()){	      return;	    }	    kpair=_kpair;	    String _type=(kpair.getKeyType()==KeyPair.DSA)?DSA:RSA;	    ByteArrayOutputStream out=new ByteArrayOutputStream();	    kpairComment=_type+"-1024"; //$NON-NLS-1$	    kpair.writePublicKey(out, kpairComment);	    out.close();	    publicKeyText.setText(out.toString());	    keyFingerPrintText.setText(kpair.getFingerPrint());	    keyCommentText.setText(kpairComment);	    keyPassphrase1Text.setText(""); //$NON-NLS-1$	    keyPassphrase2Text.setText(""); //$NON-NLS-1$	    updateControls();	  }	  catch(IOException ee){	    ok=false;	  }	  catch(JSchException ee){	    ok=false;	  }	  if(!ok){	    MessageDialog.openError(getShell(),				    Policy.bind("CVSSSH2PreferencePage.error"),  //$NON-NLS-1$				    Policy.bind("CVSSSH2PreferencePage.130"));  //$NON-NLS-1$	  }	}      });    keyExport.addSelectionListener(new SelectionAdapter(){	public void widgetSelected(SelectionEvent e){	  if(kpair==null)return;          setErrorMessage(null);	  final String[] target=new String[1];	  final String title=Policy.bind("CVSSSH2PreferencePage.106");  //$NON-NLS-1$	  final String message=Policy.bind("CVSSSH2PreferencePage.107");  //$NON-NLS-1$	  Display.getDefault().syncExec(new Runnable(){	      public void run(){		Display display=Display.getCurrent();		Shell shell=new Shell(display);		ExportDialog dialog=new ExportDialog(shell, title, message);		dialog.open();		shell.dispose();		target[0]=dialog.getTarget();	      }});	  if(target[0]==null){	    return;	  }	  String user=""; //$NON-NLS-1$	  String host=""; //$NON-NLS-1$	  int port=22;  	  if(target[0].indexOf('@')>0){	    user=target[0].substring(0, target[0].indexOf('@'));	    host=target[0].substring(target[0].indexOf('@')+1);	  }          if(host.indexOf(':')>0){	    try{port=Integer.parseInt(host.substring(host.indexOf(':')+1));}	    catch(NumberFormatException ee) {	      port=-1;	    }	    host=host.substring(0, host.indexOf(':'));	  }	  if(user.length()==0 || 	     host.length()==0 ||	     port==-1){	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.108", target[0])); //$NON-NLS-1$	    return;	  }	  String options=""; //$NON-NLS-1$	  try{	    ByteArrayOutputStream bos=new ByteArrayOutputStream();	    if(options.length()!=0){	      try{bos.write((options+" ").getBytes());} //$NON-NLS-1$	      catch(IOException eeee){}	    }	    kpair.writePublicKey(bos, kpairComment);	    bos.close();	    export_via_sftp(user, host, port, 			    ".ssh/authorized_keys", //$NON-NLS-1$			    bos.toByteArray());	  }	  catch(IOException ee){	  }	  catch(JSchException ee){	  	setErrorMessage(Policy.bind("CVSSSH2PreferencePage.111")); //$NON-NLS-1$	  }	}});    saveKeyPair.addSelectionListener(new SelectionAdapter(){	public void widgetSelected(SelectionEvent e){	  if(kpair==null)return;	  String pass=keyPassphrase1Text.getText();	  /*	  if(!pass.equals(keyPassphrase2Text.getText())){	    setErrorMessage(Policy.bind("CVSSSH2PreferencePage.48")); //$NON-NLS-1$	    return;	  }	  */	  if(pass.length()==0){	    if(!MessageDialog.openConfirm(getShell(),					  Policy.bind("CVSSSH2PreferencePage.confirmation"), //$NON-NLS-1$					  Policy.bind("CVSSSH2PreferencePage.49") //$NON-NLS-1$					  )){	      return ;	    }	  }	  kpair.setPassphrase(pass);	  IPreferenceStore store=CVSSSH2Plugin.getDefault().getPreferenceStore();	  String home=ssh2HomeText.getText();	  File _home=new File(home);	  if(!_home.exists()){	    if(!MessageDialog.openConfirm(getShell(),					  Policy.bind("CVSSSH2PreferencePage.confirmation"), //$NON-NLS-1$					  Policy.bind("CVSSSH2PreferencePage.50",home) //$NON-NLS-1$					  )){	      return ;	    }	    if(!_home.mkdirs()){	      setErrorMessage(Policy.bind("CVSSSH2PreferencePage.100")+home); //$NON-NLS-1$	      return;	    }	  }	  FileDialog fd=new FileDialog(getShell(), SWT.SAVE);	  fd.setFilterPath(home);	  String file=(kpair.getKeyType()==KeyPair.RSA) ? "id_rsa" : "id_dsa"; //$NON-NLS-1$ //$NON-NLS-2$	  fd.setFileName(file);	  file=fd.open();	  if(file==null){ // cancel	    return;	  }	  if(new File(file).exists()){	    if(!MessageDialog.openConfirm(getShell(),					  Policy.bind("CVSSSH2PreferencePage.confirmation"), //$NON-NLS-1$ 					  Policy.bind("CVSSSH2PreferencePage.53", file) //$NON-NLS-1$					  )){	      return;	    }	  }	  boolean ok=true;	  try{	    kpair.writePrivateKey(file);	    kpair.writePublicKey(file+".pub", kpairComment); //$NON-NLS-1$	  }	  catch(Exception ee){	    ok=false;	  }	  if(ok){ 	    MessageDialog.openInformation(getShell(),					  Policy.bind("CVSSSH2PreferencePage.information"), //$NON-NLS-1$					  Policy.bind("CVSSSH2PreferencePage.55")+ //$NON-NLS-1$					  "\n"+ //$NON-NLS-1$					  Policy.bind("CVSSSH2PreferencePage.57")+file+ //$NON-NLS-1$					  "\n"+ //$NON-NLS-1$					  Policy.bind("CVSSSH2PreferencePage.59")+ //$NON-NLS-1$					  file+					  ".pub"); //$NON-NLS-1$	  }	}      });    return group;  }  private TableViewer viewer;  private Button addHostKeyButton;  private Button removeHostKeyButton;  class TableLabelProvider extends LabelProvider implements ITableLabelProvider {    public String getColumnText(Object element, int columnIndex) {      KnownHosts.HostKey entry = (KnownHosts.HostKey)element;      switch (columnIndex) {      case 0:	return entry.getHost();      case 1:	return entry.getType();      case 2:	return entry.getFingerPrint();      default:	return null;      }    }    public Image getColumnImage(Object element, int columnIndex) {      return null;    }  };  private Control createHostKeyManagementPage(Composite parent) {    int columnSpan=3;    Composite group=new Composite(parent, SWT.NULL);    GridLayout layout=new GridLayout();    layout.marginWidth = 0;    layout.marginHeight = 0;    layout.numColumns = 2;    group.setLayout(layout);    GridData gd = new GridData();    gd.horizontalAlignment = GridData.FILL;    gd.verticalAlignment = GridData.FILL;    group.setLayoutData(gd);    Label label=new Label(group, SWT.NONE);    label.setText(Policy.bind("CVSSSH2PreferencePage.139")); //$NON-NLS-1$    gd=new GridData();    gd.horizontalSpan=2;    label.setLayoutData(gd);        viewer = new TableViewer(group, SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);    Table table = viewer.getTable();    new TableEditor(table);    table.setHeaderVisible(true);    table.setLinesVisible(true);    gd = new GridData(GridData.FILL_BOTH);    gd.widthHint = convertWidthInCharsToPixels(30);    gd.heightHint = 100;    table.setLayoutData(gd);    table.addListener(SWT.Selection, new Listener() {	public void handleEvent(Event e) {	  handleSelection();	}      });    // Create the table columns    new TableColumn(table, SWT.NULL);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -