Ignore:
Timestamp:
2014-07-28T16:40:19+02:00 (10 years ago)
Author:
Don-vip
Message:

see #10230, see #10033 - add "Install/uninstall certificate" buttons in remote control preferences (Windows only)

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r7335 r7343  
    445445                // Check for insecure certificates to remove.
    446446                // This is Windows-dependant code but it can't go to preStartupHook (need i18n) neither startupHook (need to be called before remote control)
    447                 ((PlatformHookWindows)Main.platform).removeInsecureCertificates();
     447                PlatformHookWindows.removeInsecureCertificates();
    448448            } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException e) {
    449449                error(e);
  • trunk/src/org/openstreetmap/josm/gui/preferences/remotecontrol/RemoteControlPreference.java

    r7335 r7343  
    99import java.awt.event.ActionEvent;
    1010import java.awt.event.ActionListener;
     11import java.io.IOException;
     12import java.security.GeneralSecurityException;
     13import java.security.KeyStore;
     14import java.security.KeyStoreException;
     15import java.security.NoSuchAlgorithmException;
     16import java.security.cert.CertificateException;
    1117import java.util.LinkedHashMap;
    1218import java.util.Map;
     
    1521import javax.swing.BorderFactory;
    1622import javax.swing.Box;
     23import javax.swing.JButton;
    1724import javax.swing.JCheckBox;
    1825import javax.swing.JLabel;
     26import javax.swing.JOptionPane;
    1927import javax.swing.JPanel;
    2028import javax.swing.JSeparator;
     
    3139import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler;
    3240import org.openstreetmap.josm.tools.GBC;
     41import org.openstreetmap.josm.tools.PlatformHookWindows;
    3342
    3443/**
     
    6170    private JCheckBox enableRemoteControl;
    6271    private JCheckBox enableHttpsSupport;
    63     private JCheckBox loadInNewLayer = new JCheckBox(tr("Download objects to new layer"));
    64     private JCheckBox alwaysAskUserConfirm = new JCheckBox(tr("Confirm all Remote Control actions manually"));
     72
     73    private JButton installCertificate;
     74    private JButton uninstallCertificate;
     75
     76    private final JCheckBox loadInNewLayer = new JCheckBox(tr("Download objects to new layer"));
     77    private final JCheckBox alwaysAskUserConfirm = new JCheckBox(tr("Confirm all Remote Control actions manually"));
    6578
    6679    @Override
     
    91104        remote.add(wrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 5));
    92105
    93         enableHttpsSupport = new JCheckBox(tr("Enable HTTPS support"), RemoteControl.PROP_REMOTECONTROL_HTTPS_ENABLED.get());
     106        boolean https = RemoteControl.PROP_REMOTECONTROL_HTTPS_ENABLED.get();
     107
     108        enableHttpsSupport = new JCheckBox(tr("Enable HTTPS support"), https);
    94109        wrapper.add(enableHttpsSupport, GBC.eol().fill(GBC.HORIZONTAL));
     110
     111        // Certificate installation only available on Windows for now, see #10033
     112        if (Main.isPlatformWindows()) {
     113            installCertificate = new JButton(tr("Install..."));
     114            uninstallCertificate = new JButton(tr("Uninstall..."));
     115            installCertificate.setToolTipText(tr("Install JOSM localhost certificate to system/browser root keystores"));
     116            uninstallCertificate.setToolTipText(tr("Uninstall JOSM localhost certificate from system/browser root keystores"));
     117            wrapper.add(new JLabel(tr("Certificate:")), GBC.std().insets(15, 5, 0, 0));
     118            wrapper.add(installCertificate, GBC.std().insets(5, 5, 0, 0));
     119            wrapper.add(uninstallCertificate, GBC.eol().insets(5, 5, 0, 0));
     120            enableHttpsSupport.addActionListener(new ActionListener() {
     121                @Override
     122                public void actionPerformed(ActionEvent e) {
     123                    installCertificate.setEnabled(enableHttpsSupport.isSelected());
     124                }
     125            });
     126            installCertificate.addActionListener(new ActionListener() {
     127                @Override
     128                public void actionPerformed(ActionEvent e) {
     129                    try {
     130                        boolean changed = RemoteControlHttpsServer.setupPlatform(
     131                                RemoteControlHttpsServer.loadJosmKeystore());
     132                        String msg = changed ?
     133                                tr("Certificate has been successfully installed.") :
     134                                tr("Certificate is already installed. Nothing to do.");
     135                        Main.info(msg);
     136                        JOptionPane.showMessageDialog(wrapper, msg);
     137                    } catch (IOException | GeneralSecurityException ex) {
     138                        Main.error(ex);
     139                    }
     140                }
     141            });
     142            uninstallCertificate.addActionListener(new ActionListener() {
     143                @Override
     144                public void actionPerformed(ActionEvent e) {
     145                    try {
     146                        String msg;
     147                        KeyStore ks = PlatformHookWindows.getRootKeystore();
     148                        if (ks.containsAlias(RemoteControlHttpsServer.ENTRY_ALIAS)) {
     149                            Main.info(tr("Removing certificate {0} from root keystore.", RemoteControlHttpsServer.ENTRY_ALIAS));
     150                            ks.deleteEntry(RemoteControlHttpsServer.ENTRY_ALIAS);
     151                            msg = tr("Certificate has been successfully uninstalled.");
     152                        } else {
     153                            msg = tr("Certificate is not installed. Nothing to do.");
     154                        }
     155                        Main.info(msg);
     156                        JOptionPane.showMessageDialog(wrapper, msg);
     157                    } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException | IOException ex) {
     158                        Main.error(ex);
     159                    }
     160                }
     161            });
     162            installCertificate.setEnabled(https);
     163        }
     164
    95165        wrapper.add(new JSeparator(), GBC.eop().fill(GBC.HORIZONTAL).insets(15, 5, 15, 5));
    96166
     
    116186                // 'setEnabled(false)' does not work for JLabel with html text, so do it manually
    117187                // FIXME: use QuadStateCheckBox to make checkboxes unset when disabled
     188                if (installCertificate != null && uninstallCertificate != null) {
     189                    // Install certificate button is enabled if HTTPS is also enabled
     190                    installCertificate.setEnabled(enableRemoteControl.isSelected() && enableHttpsSupport.isSelected());
     191                    // Uninstall certificate button is always enabled
     192                    uninstallCertificate.setEnabled(true);
     193                }
    118194            }
    119195        };
Note: See TracChangeset for help on using the changeset viewer.