| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.tools;
|
|---|
| 3 |
|
|---|
| 4 | import static java.awt.event.InputEvent.ALT_DOWN_MASK;
|
|---|
| 5 | import static java.awt.event.InputEvent.CTRL_DOWN_MASK;
|
|---|
| 6 | import static java.awt.event.InputEvent.SHIFT_DOWN_MASK;
|
|---|
| 7 | import static java.awt.event.KeyEvent.VK_A;
|
|---|
| 8 | import static java.awt.event.KeyEvent.VK_C;
|
|---|
| 9 | import static java.awt.event.KeyEvent.VK_D;
|
|---|
| 10 | import static java.awt.event.KeyEvent.VK_DELETE;
|
|---|
| 11 | import static java.awt.event.KeyEvent.VK_DOWN;
|
|---|
| 12 | import static java.awt.event.KeyEvent.VK_ENTER;
|
|---|
| 13 | import static java.awt.event.KeyEvent.VK_ESCAPE;
|
|---|
| 14 | import static java.awt.event.KeyEvent.VK_F10;
|
|---|
| 15 | import static java.awt.event.KeyEvent.VK_F4;
|
|---|
| 16 | import static java.awt.event.KeyEvent.VK_LEFT;
|
|---|
| 17 | import static java.awt.event.KeyEvent.VK_NUM_LOCK;
|
|---|
| 18 | import static java.awt.event.KeyEvent.VK_PRINTSCREEN;
|
|---|
| 19 | import static java.awt.event.KeyEvent.VK_RIGHT;
|
|---|
| 20 | import static java.awt.event.KeyEvent.VK_SHIFT;
|
|---|
| 21 | import static java.awt.event.KeyEvent.VK_SPACE;
|
|---|
| 22 | import static java.awt.event.KeyEvent.VK_TAB;
|
|---|
| 23 | import static java.awt.event.KeyEvent.VK_UP;
|
|---|
| 24 | import static java.awt.event.KeyEvent.VK_V;
|
|---|
| 25 | import static java.awt.event.KeyEvent.VK_X;
|
|---|
| 26 | import static java.awt.event.KeyEvent.VK_Y;
|
|---|
| 27 | import static java.awt.event.KeyEvent.VK_Z;
|
|---|
| 28 | import static org.openstreetmap.josm.tools.I18n.tr;
|
|---|
| 29 |
|
|---|
| 30 | import java.awt.GraphicsEnvironment;
|
|---|
| 31 | import java.io.BufferedWriter;
|
|---|
| 32 | import java.io.File;
|
|---|
| 33 | import java.io.FileInputStream;
|
|---|
| 34 | import java.io.IOException;
|
|---|
| 35 | import java.io.OutputStream;
|
|---|
| 36 | import java.io.OutputStreamWriter;
|
|---|
| 37 | import java.io.Writer;
|
|---|
| 38 | import java.nio.file.FileSystems;
|
|---|
| 39 | import java.nio.file.Files;
|
|---|
| 40 | import java.nio.file.Path;
|
|---|
| 41 | import java.security.InvalidKeyException;
|
|---|
| 42 | import java.security.KeyFactory;
|
|---|
| 43 | import java.security.KeyStore;
|
|---|
| 44 | import java.security.KeyStoreException;
|
|---|
| 45 | import java.security.NoSuchAlgorithmException;
|
|---|
| 46 | import java.security.NoSuchProviderException;
|
|---|
| 47 | import java.security.PublicKey;
|
|---|
| 48 | import java.security.SignatureException;
|
|---|
| 49 | import java.security.cert.CertificateException;
|
|---|
| 50 | import java.security.spec.InvalidKeySpecException;
|
|---|
| 51 | import java.security.spec.X509EncodedKeySpec;
|
|---|
| 52 | import java.util.ArrayList;
|
|---|
| 53 | import java.util.Arrays;
|
|---|
| 54 | import java.util.Collection;
|
|---|
| 55 | import java.util.Enumeration;
|
|---|
| 56 | import java.util.List;
|
|---|
| 57 | import java.util.Properties;
|
|---|
| 58 |
|
|---|
| 59 | import javax.swing.JOptionPane;
|
|---|
| 60 | import org.openstreetmap.josm.Main;
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * {@code PlatformHook} implementation for Microsoft Windows systems.
|
|---|
| 64 | * @since 1023
|
|---|
| 65 | */
|
|---|
| 66 | public class PlatformHookWindows extends PlatformHookUnixoid implements PlatformHook {
|
|---|
| 67 |
|
|---|
| 68 | private static final byte[] INSECURE_PUBLIC_KEY = new byte[] {
|
|---|
| 69 | 0x30, (byte) 0x82, 0x1, 0x22, 0x30, 0xd, 0x6, 0x9, 0x2a, (byte) 0x86, 0x48,
|
|---|
| 70 | (byte) 0x86, (byte) 0xf7, 0xd, 0x1, 0x1, 0x1, 0x5, 0x0, 0x3, (byte) 0x82, 0x1, 0xf, 0x0,
|
|---|
| 71 | 0x30, (byte) 0x82, 0x01, 0x0a, 0x02, (byte) 0x82, 0x01, 0x01, 0x00, (byte) 0x95, (byte) 0x95, (byte) 0x88,
|
|---|
| 72 | (byte) 0x84, (byte) 0xc8, (byte) 0xd9, 0x6b, (byte) 0xc5, (byte) 0xda, 0x0b, 0x69, (byte) 0xbf, (byte) 0xfc,
|
|---|
| 73 | 0x7e, (byte) 0xb9, (byte) 0x96, 0x2c, (byte) 0xeb, (byte) 0x8f, (byte) 0xbc, 0x6e, 0x40, (byte) 0xe6, (byte) 0xe2,
|
|---|
| 74 | (byte) 0xfc, (byte) 0xf1, 0x7f, 0x73, (byte) 0xa7, (byte) 0x9d, (byte) 0xde, (byte) 0xc7, (byte) 0x88, 0x57, 0x51,
|
|---|
| 75 | (byte) 0x84, (byte) 0xed, (byte) 0x96, (byte) 0xfb, (byte) 0xe1, 0x38, (byte) 0xef, 0x08, 0x2b, (byte) 0xf3,
|
|---|
| 76 | (byte) 0xc7, (byte) 0xc3, 0x5d, (byte) 0xfe, (byte) 0xf9, 0x51, (byte) 0xe6, 0x29, (byte) 0xfc, (byte) 0xe5, 0x0d,
|
|---|
| 77 | (byte) 0xa1, 0x0d, (byte) 0xa8, (byte) 0xb4, (byte) 0xae, 0x26, 0x18, 0x19, 0x4d, 0x6c, 0x0c, 0x3b, 0x12, (byte) 0xba,
|
|---|
| 78 | (byte) 0xbc, 0x5f, 0x32, (byte) 0xb3, (byte) 0xbe, (byte) 0x9d, 0x17, 0x0d, 0x4d, 0x2f, 0x1a, 0x48, (byte) 0xb7,
|
|---|
| 79 | (byte) 0xac, (byte) 0xf7, 0x1a, 0x43, 0x01, (byte) 0x97, (byte) 0xf4, (byte) 0xf8, 0x4c, (byte) 0xbb, 0x6a, (byte) 0xbc,
|
|---|
| 80 | 0x33, (byte) 0xe1, 0x73, 0x1e, (byte) 0x86, (byte) 0xfb, 0x2e, (byte) 0xb1, 0x63, 0x75, (byte) 0x85, (byte) 0xdc,
|
|---|
| 81 | (byte) 0x82, 0x6c, 0x28, (byte) 0xf1, (byte) 0xe3, (byte) 0x90, 0x63, (byte) 0x9d, 0x3d, 0x48, (byte) 0x8a, (byte) 0x8c,
|
|---|
| 82 | 0x47, (byte) 0xe2, 0x10, 0x0b, (byte) 0xef, (byte) 0x91, (byte) 0x94, (byte) 0xb0, 0x6c, 0x4c, (byte) 0x80, 0x76, 0x03,
|
|---|
| 83 | (byte) 0xe1, (byte) 0xb6, (byte) 0x90, (byte) 0x87, (byte) 0xd9, (byte) 0xae, (byte) 0xf4, (byte) 0x8e, (byte) 0xe0,
|
|---|
| 84 | (byte) 0x9f, (byte) 0xe7, 0x3a, 0x2c, 0x2f, 0x21, (byte) 0xd4, 0x46, (byte) 0xba, (byte) 0x95, 0x70, (byte) 0xa9, 0x5b,
|
|---|
| 85 | 0x20, 0x2a, (byte) 0xfa, 0x52, 0x3e, (byte) 0x9d, (byte) 0xd9, (byte) 0xef, 0x28, (byte) 0xc5, (byte) 0xd1, 0x60,
|
|---|
| 86 | (byte) 0x89, 0x68, 0x6e, 0x7f, (byte) 0xd7, (byte) 0x9e, (byte) 0x89, 0x4c, (byte) 0xeb, 0x4d, (byte) 0xd2, (byte) 0xc6,
|
|---|
| 87 | (byte) 0xf4, 0x2d, 0x02, 0x5d, (byte) 0xda, (byte) 0xde, 0x33, (byte) 0xfe, (byte) 0xc1, 0x7e, (byte) 0xde, 0x4f, 0x1f,
|
|---|
| 88 | (byte) 0x9b, 0x6e, 0x6f, 0x0f, 0x66, 0x71, 0x19, (byte) 0xe9, 0x43, 0x3c, (byte) 0x83, 0x0a, 0x0f, 0x28, 0x21, (byte) 0xc8,
|
|---|
| 89 | 0x38, (byte) 0xd3, 0x4e, 0x48, (byte) 0xdf, (byte) 0xd4, (byte) 0x99, (byte) 0xb5, (byte) 0xc6, (byte) 0x8d, (byte) 0xd4,
|
|---|
| 90 | (byte) 0xc1, 0x69, 0x58, 0x79, (byte) 0x82, 0x32, (byte) 0x82, (byte) 0xd4, (byte) 0x86, (byte) 0xe2, 0x04, 0x08, 0x63,
|
|---|
| 91 | (byte) 0x87, (byte) 0xf0, 0x2a, (byte) 0xf6, (byte) 0xec, 0x3e, 0x51, 0x0f, (byte) 0xda, (byte) 0xb4, 0x67, 0x19, 0x5e,
|
|---|
| 92 | 0x16, 0x02, (byte) 0x9f, (byte) 0xf1, 0x19, 0x0c, 0x3e, (byte) 0xb8, 0x04, 0x49, 0x07, 0x53, 0x02, 0x03, 0x01, 0x00, 0x01
|
|---|
| 93 | };
|
|---|
| 94 |
|
|---|
| 95 | private static final String WINDOWS_ROOT = "Windows-ROOT";
|
|---|
| 96 |
|
|---|
| 97 | @Override
|
|---|
| 98 | public void preStartupHook() {
|
|---|
| 99 | extendFontconfig();
|
|---|
| 100 | }
|
|---|
| 101 |
|
|---|
| 102 | /**
|
|---|
| 103 | * Add more fallback fonts to the Java runtime, in order to get wider
|
|---|
| 104 | * unicode support.
|
|---|
| 105 | *
|
|---|
| 106 | * The font configuration in Java doesn't include some Indic scripts,
|
|---|
| 107 | * even though MS Windows ships with fonts that cover these unicode
|
|---|
| 108 | * ranges.
|
|---|
| 109 | *
|
|---|
| 110 | * To fix this, the fontconfig.properties template is copied to the JOSM
|
|---|
| 111 | * cache folder. Then, the additional entries are added to the font
|
|---|
| 112 | * configuration. Finally the system property "sun.awt.fontconfig" is set
|
|---|
| 113 | * to the customized fontconfig.properties file.
|
|---|
| 114 | *
|
|---|
| 115 | * This is a crude hack, but better than no font display at all for these
|
|---|
| 116 | * languages.
|
|---|
| 117 | * There is no guarantee, that the template file
|
|---|
| 118 | * ($JAVA_HOME/lib/fontconfig.properties.src) matches the default
|
|---|
| 119 | * configuration (which is in a binary format).
|
|---|
| 120 | * Furthermore, the system property "sun.awt.fontconfig" is undocumented and
|
|---|
| 121 | * may no longer work in future versions of Java.
|
|---|
| 122 | */
|
|---|
| 123 | protected void extendFontconfig() {
|
|---|
| 124 | String customFontconfigFile = Main.pref.get("fontconfig.properties", null);
|
|---|
| 125 | if (customFontconfigFile != null) {
|
|---|
| 126 | Utils.updateSystemProperty("sun.awt.fontconfig", customFontconfigFile);
|
|---|
| 127 | return;
|
|---|
| 128 | }
|
|---|
| 129 | if (!Main.pref.getBoolean("font.extended-unicode", true))
|
|---|
| 130 | return;
|
|---|
| 131 | String javaLibPath = System.getProperty("java.home") + File.separator + "lib";
|
|---|
| 132 | Path templateFile = FileSystems.getDefault().getPath(javaLibPath, "fontconfig.properties.src");
|
|---|
| 133 | if (!Files.isReadable(templateFile)) {
|
|---|
| 134 | Main.warn("extended unicode - unable to find font config template file "+templateFile.toString());
|
|---|
| 135 | return;
|
|---|
| 136 | }
|
|---|
| 137 | try {
|
|---|
| 138 | Properties props = new Properties();
|
|---|
| 139 | props.load(new FileInputStream(templateFile.toFile()));
|
|---|
| 140 | byte[] content = Files.readAllBytes(templateFile);
|
|---|
| 141 | File cachePath = Main.pref.getCacheDirectory();
|
|---|
| 142 | Path fontconfigFile = cachePath.toPath().resolve("fontconfig.properties");
|
|---|
| 143 | OutputStream os = Files.newOutputStream(fontconfigFile);
|
|---|
| 144 | os.write(content);
|
|---|
| 145 | try (Writer w = new BufferedWriter(new OutputStreamWriter(os))) {
|
|---|
| 146 | Collection<Collection<String>> def = new ArrayList<>();
|
|---|
| 147 | def.add(Arrays.asList("devanagari", "", "")); // just include in fallback list
|
|---|
| 148 | // no font definition needed
|
|---|
| 149 | // all of the following fonts are available in Win XP and later
|
|---|
| 150 | def.add(Arrays.asList("gujarati", "Shruti", "SHRUTI.TTF"));
|
|---|
| 151 | def.add(Arrays.asList("kannada", "Tunga", "TUNGA.TTF"));
|
|---|
| 152 | def.add(Arrays.asList("gurmuhi", "Raavi", "RAAVI.TTF"));
|
|---|
| 153 | def.add(Arrays.asList("tamil", "Latha", "LATHA.TTF"));
|
|---|
| 154 | def.add(Arrays.asList("telugu", "Gautami", "GAUTAMI.TTF"));
|
|---|
| 155 | def.add(Arrays.asList("bengali", "Vrinda", "VRINDA.TTF"));
|
|---|
| 156 | def.add(Arrays.asList("syriac", "Estrangelo Edessa", "ESTRE.TTF")); // ISO 639: arc
|
|---|
| 157 | def.add(Arrays.asList("thaana", "MV Boli", "MVBOLI.TTF")); // ISO 639: dv
|
|---|
| 158 | def.add(Arrays.asList("malayalam", "Kartika", "KARTIKA.TTF")); // ISO 639: ml; since XP SP2
|
|---|
| 159 | Collection<Collection<String>> additions =
|
|---|
| 160 | Main.pref.getArray("font.extended-unicode.added-items", def);
|
|---|
| 161 | w.append("\n\n# Added by JOSM to extend unicode coverage of Java font support:\n\n");
|
|---|
| 162 | List<String> allCharSubsets = new ArrayList<>();
|
|---|
| 163 | for (Collection<String> entry: additions) {
|
|---|
| 164 | List<String> lentry = new ArrayList<>(entry);
|
|---|
| 165 | String charSubset = lentry.get(0);
|
|---|
| 166 | allCharSubsets.add(charSubset);
|
|---|
| 167 | String platformFontName = lentry.get(1);
|
|---|
| 168 | if ("".equals(platformFontName)) {
|
|---|
| 169 | continue;
|
|---|
| 170 | }
|
|---|
| 171 | String key = "allfonts." + charSubset;
|
|---|
| 172 | String value = platformFontName;
|
|---|
| 173 | String prevValue = props.getProperty(key);
|
|---|
| 174 | if (prevValue != null && !prevValue.equals(value)) {
|
|---|
| 175 | Main.warn("extended unicode - overriding " + key + "=" + prevValue + " with " + value);
|
|---|
| 176 | }
|
|---|
| 177 | w.append(key + "=" + value + "\n");
|
|---|
| 178 | }
|
|---|
| 179 | w.append("\n");
|
|---|
| 180 | for (Collection<String> entry: additions) {
|
|---|
| 181 | List<String> lentry = new ArrayList<>(entry);
|
|---|
| 182 | String platformFontName = lentry.get(1);
|
|---|
| 183 | String fontFile = lentry.get(2);
|
|---|
| 184 | if ("".equals(platformFontName) || "".equals(fontFile)) {
|
|---|
| 185 | continue;
|
|---|
| 186 | }
|
|---|
| 187 | String key = "filename." + platformFontName;
|
|---|
| 188 | String value = fontFile;
|
|---|
| 189 | String prevValue = props.getProperty(key);
|
|---|
| 190 | if (prevValue != null && !prevValue.equals(value)) {
|
|---|
| 191 | Main.warn("extended unicode - overriding " + key + "=" + prevValue + " with " + value);
|
|---|
| 192 | }
|
|---|
| 193 | w.append(key + "=" + value + "\n");
|
|---|
| 194 | }
|
|---|
| 195 | w.append("\n");
|
|---|
| 196 | String fallback = props.getProperty("sequence.fallback");
|
|---|
| 197 | if (fallback != null) {
|
|---|
| 198 | w.append("sequence.fallback=" + fallback + "," + Utils.join(",", allCharSubsets) + "\n");
|
|---|
| 199 | } else {
|
|---|
| 200 | w.append("sequence.fallback=" + Utils.join(",", allCharSubsets) + "\n");
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | Utils.updateSystemProperty("sun.awt.fontconfig", fontconfigFile.toString());
|
|---|
| 204 | } catch (IOException ex) {
|
|---|
| 205 | Main.error(ex);
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 |
|
|---|
| 209 | @Override
|
|---|
| 210 | public void openUrl(String url) throws IOException {
|
|---|
| 211 | Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
|
|---|
| 212 | }
|
|---|
| 213 |
|
|---|
| 214 | @Override
|
|---|
| 215 | public void initSystemShortcuts() {
|
|---|
| 216 | //Shortcut.registerSystemCut("system:menuexit", tr("reserved"), VK_Q, CTRL_DOWN_MASK);
|
|---|
| 217 | Shortcut.registerSystemShortcut("system:duplicate", tr("reserved"), VK_D, CTRL_DOWN_MASK); // not really system, but to avoid odd results
|
|---|
| 218 |
|
|---|
| 219 | // Windows 7 shortcuts: http://windows.microsoft.com/en-US/windows7/Keyboard-shortcuts
|
|---|
| 220 |
|
|---|
| 221 | // Shortcuts with setAutomatic(): items with automatic shortcuts will not be added to the menu bar at all
|
|---|
| 222 |
|
|---|
| 223 | // Don't know why Ctrl-Alt-Del isn't even listed on official Microsoft support page
|
|---|
| 224 | Shortcut.registerSystemShortcut("system:reset", tr("reserved"), VK_DELETE, CTRL_DOWN_MASK | ALT_DOWN_MASK).setAutomatic();
|
|---|
| 225 |
|
|---|
| 226 | // Ease of Access keyboard shortcuts
|
|---|
| 227 | Shortcut.registerSystemShortcut("microsoft-reserved-01", tr("reserved"), VK_PRINTSCREEN, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn High Contrast on or off
|
|---|
| 228 | Shortcut.registerSystemShortcut("microsoft-reserved-02", tr("reserved"), VK_NUM_LOCK, ALT_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Turn Mouse Keys on or off
|
|---|
| 229 | //Shortcut.registerSystemCut("microsoft-reserved-03", tr("reserved"), VK_U, );// Open the Ease of Access Center (TODO: Windows-U, how to handle it in Java ?)
|
|---|
| 230 |
|
|---|
| 231 | // General keyboard shortcuts
|
|---|
| 232 | //Shortcut.registerSystemShortcut("system:help", tr("reserved"), VK_F1, 0); // Display Help
|
|---|
| 233 | Shortcut.registerSystemShortcut("system:copy", tr("reserved"), VK_C, CTRL_DOWN_MASK); // Copy the selected item
|
|---|
| 234 | Shortcut.registerSystemShortcut("system:cut", tr("reserved"), VK_X, CTRL_DOWN_MASK); // Cut the selected item
|
|---|
| 235 | Shortcut.registerSystemShortcut("system:paste", tr("reserved"), VK_V, CTRL_DOWN_MASK); // Paste the selected item
|
|---|
| 236 | Shortcut.registerSystemShortcut("system:undo", tr("reserved"), VK_Z, CTRL_DOWN_MASK); // Undo an action
|
|---|
| 237 | Shortcut.registerSystemShortcut("system:redo", tr("reserved"), VK_Y, CTRL_DOWN_MASK); // Redo an action
|
|---|
| 238 | //Shortcut.registerSystemCut("microsoft-reserved-10", tr("reserved"), VK_DELETE, 0); // Delete the selected item and move it to the Recycle Bin
|
|---|
| 239 | //Shortcut.registerSystemCut("microsoft-reserved-11", tr("reserved"), VK_DELETE, SHIFT_DOWN_MASK); // Delete the selected item without moving it to the Recycle Bin first
|
|---|
| 240 | //Shortcut.registerSystemCut("system:rename", tr("reserved"), VK_F2, 0); // Rename the selected item
|
|---|
| 241 | Shortcut.registerSystemShortcut("system:movefocusright", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next word
|
|---|
| 242 | Shortcut.registerSystemShortcut("system:movefocusleft", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous word
|
|---|
| 243 | Shortcut.registerSystemShortcut("system:movefocusdown", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK); // Move the cursor to the beginning of the next paragraph
|
|---|
| 244 | Shortcut.registerSystemShortcut("system:movefocusup", tr("reserved"), VK_UP, CTRL_DOWN_MASK); // Move the cursor to the beginning of the previous paragraph
|
|---|
| 245 | //Shortcut.registerSystemCut("microsoft-reserved-17", tr("reserved"), VK_RIGHT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 246 | //Shortcut.registerSystemCut("microsoft-reserved-18", tr("reserved"), VK_LEFT, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 247 | //Shortcut.registerSystemCut("microsoft-reserved-19", tr("reserved"), VK_DOWN, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 248 | //Shortcut.registerSystemCut("microsoft-reserved-20", tr("reserved"), VK_UP, CTRL_DOWN_MASK | SHIFT_DOWN_MASK); // Select a block of text
|
|---|
| 249 | //Shortcut.registerSystemCut("microsoft-reserved-21", tr("reserved"), VK_RIGHT, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
|
|---|
| 250 | //Shortcut.registerSystemCut("microsoft-reserved-22", tr("reserved"), VK_LEFT, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
|
|---|
| 251 | //Shortcut.registerSystemCut("microsoft-reserved-23", tr("reserved"), VK_DOWN, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
|
|---|
| 252 | //Shortcut.registerSystemCut("microsoft-reserved-24", tr("reserved"), VK_UP, SHIFT_DOWN_MASK); // Select more than one item in a window or on the desktop, or select text within a document
|
|---|
| 253 | //Shortcut.registerSystemCut("microsoft-reserved-25", tr("reserved"), VK_RIGHT+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
|
|---|
| 254 | //Shortcut.registerSystemCut("microsoft-reserved-26", tr("reserved"), VK_LEFT+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
|
|---|
| 255 | //Shortcut.registerSystemCut("microsoft-reserved-27", tr("reserved"), VK_DOWN+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
|
|---|
| 256 | //Shortcut.registerSystemCut("microsoft-reserved-28", tr("reserved"), VK_UP+, CTRL_DOWN_MASK); // Select multiple individual items in a window or on the desktop (TODO: ctrl+arrow+spacebar, how to handle it in Java ?)
|
|---|
| 257 | Shortcut.registerSystemShortcut("system:selectall", tr("reserved"), VK_A, CTRL_DOWN_MASK); // Select all items in a document or window
|
|---|
| 258 | //Shortcut.registerSystemCut("system:search", tr("reserved"), VK_F3, 0); // Search for a file or folder
|
|---|
| 259 | Shortcut.registerSystemShortcut("microsoft-reserved-31", tr("reserved"), VK_ENTER, ALT_DOWN_MASK).setAutomatic(); // Display properties for the selected item
|
|---|
| 260 | Shortcut.registerSystemShortcut("system:exit", tr("reserved"), VK_F4, ALT_DOWN_MASK).setAutomatic(); // Close the active item, or exit the active program
|
|---|
| 261 | Shortcut.registerSystemShortcut("microsoft-reserved-33", tr("reserved"), VK_SPACE, ALT_DOWN_MASK).setAutomatic(); // Open the shortcut menu for the active window
|
|---|
| 262 | //Shortcut.registerSystemCut("microsoft-reserved-34", tr("reserved"), VK_F4, CTRL_DOWN_MASK); // Close the active document (in programs that allow you to have multiple documents open simultaneously)
|
|---|
| 263 | Shortcut.registerSystemShortcut("microsoft-reserved-35", tr("reserved"), VK_TAB, ALT_DOWN_MASK).setAutomatic(); // Switch between open items
|
|---|
| 264 | Shortcut.registerSystemShortcut("microsoft-reserved-36", tr("reserved"), VK_TAB, CTRL_DOWN_MASK | ALT_DOWN_MASK).setAutomatic(); // Use the arrow keys to switch between open items
|
|---|
| 265 | //Shortcut.registerSystemCut("microsoft-reserved-37", tr("reserved"), VK_TAB, ); // Cycle through programs on the taskbar by using Aero Flip 3-D (TODO: Windows-Tab, how to handle it in Java ?)
|
|---|
| 266 | //Shortcut.registerSystemCut("microsoft-reserved-38", tr("reserved"), VK_TAB, CTRL_DOWN_MASK | ); // Use the arrow keys to cycle through programs on the taskbar by using Aero Flip 3-D (TODO: Ctrl-Windows-Tab, how to handle it in Java ?)
|
|---|
| 267 | Shortcut.registerSystemShortcut("microsoft-reserved-39", tr("reserved"), VK_ESCAPE, ALT_DOWN_MASK).setAutomatic(); // Cycle through items in the order in which they were opened
|
|---|
| 268 | //Shortcut.registerSystemCut("microsoft-reserved-40", tr("reserved"), VK_F6, 0); // Cycle through screen elements in a window or on the desktop
|
|---|
| 269 | //Shortcut.registerSystemCut("microsoft-reserved-41", tr("reserved"), VK_F4, 0); // Display the address bar list in Windows Explorer
|
|---|
| 270 | Shortcut.registerSystemShortcut("microsoft-reserved-42", tr("reserved"), VK_F10, SHIFT_DOWN_MASK); // Display the shortcut menu for the selected item
|
|---|
| 271 | Shortcut.registerSystemShortcut("microsoft-reserved-43", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK).setAutomatic(); // Open the Start menu
|
|---|
| 272 | //Shortcut.registerSystemShortcut("microsoft-reserved-44", tr("reserved"), VK_F10, 0); // Activate the menu bar in the active program
|
|---|
| 273 | //Shortcut.registerSystemCut("microsoft-reserved-45", tr("reserved"), VK_RIGHT, 0); // Open the next menu to the right, or open a submenu
|
|---|
| 274 | //Shortcut.registerSystemCut("microsoft-reserved-46", tr("reserved"), VK_LEFT, 0); // Open the next menu to the left, or close a submenu
|
|---|
| 275 | //Shortcut.registerSystemCut("microsoft-reserved-47", tr("reserved"), VK_F5, 0); // Refresh the active window
|
|---|
| 276 | //Shortcut.registerSystemCut("microsoft-reserved-48", tr("reserved"), VK_UP, ALT_DOWN_MASK); // View the folder one level up in Windows Explorer
|
|---|
| 277 | //Shortcut.registerSystemCut("microsoft-reserved-49", tr("reserved"), VK_ESCAPE, 0); // Cancel the current task
|
|---|
| 278 | Shortcut.registerSystemShortcut("microsoft-reserved-50", tr("reserved"), VK_ESCAPE, CTRL_DOWN_MASK | SHIFT_DOWN_MASK).setAutomatic(); // Open Task Manager
|
|---|
| 279 | Shortcut.registerSystemShortcut("microsoft-reserved-51", tr("reserved"), VK_SHIFT, ALT_DOWN_MASK).setAutomatic(); // Switch the input language when multiple input languages are enabled
|
|---|
| 280 | Shortcut.registerSystemShortcut("microsoft-reserved-52", tr("reserved"), VK_SHIFT, CTRL_DOWN_MASK).setAutomatic(); // Switch the keyboard layout when multiple keyboard layouts are enabled
|
|---|
| 281 | //Shortcut.registerSystemCut("microsoft-reserved-53", tr("reserved"), ); // Change the reading direction of text in right-to-left reading languages (TODO: unclear)
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | @Override
|
|---|
| 285 | public String getDefaultStyle() {
|
|---|
| 286 | return "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
|
|---|
| 287 | }
|
|---|
| 288 |
|
|---|
| 289 | @Override
|
|---|
| 290 | public boolean rename(File from, File to) {
|
|---|
| 291 | if (to.exists())
|
|---|
| 292 | to.delete();
|
|---|
| 293 | return from.renameTo(to);
|
|---|
| 294 | }
|
|---|
| 295 |
|
|---|
| 296 | @Override
|
|---|
| 297 | public String getOSDescription() {
|
|---|
| 298 | return Utils.strip(System.getProperty("os.name")) + " " +
|
|---|
| 299 | ((System.getenv("ProgramFiles(x86)") == null) ? "32" : "64") + "-Bit";
|
|---|
| 300 | }
|
|---|
| 301 |
|
|---|
| 302 | /**
|
|---|
| 303 | * Loads Windows-ROOT keystore.
|
|---|
| 304 | * @return Windows-ROOT keystore
|
|---|
| 305 | * @throws NoSuchAlgorithmException if the algorithm used to check the integrity of the keystore cannot be found
|
|---|
| 306 | * @throws CertificateException if any of the certificates in the keystore could not be loaded
|
|---|
| 307 | * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
|
|---|
| 308 | * @throws KeyStoreException if no Provider supports a KeyStore implementation for the type "Windows-ROOT"
|
|---|
| 309 | * @since 7343
|
|---|
| 310 | */
|
|---|
| 311 | public static KeyStore getRootKeystore() throws NoSuchAlgorithmException, CertificateException, IOException, KeyStoreException {
|
|---|
| 312 | KeyStore ks = KeyStore.getInstance(WINDOWS_ROOT);
|
|---|
| 313 | ks.load(null, null);
|
|---|
| 314 | return ks;
|
|---|
| 315 | }
|
|---|
| 316 |
|
|---|
| 317 | /**
|
|---|
| 318 | * Removes potential insecure certificates installed with previous versions of JOSM on Windows.
|
|---|
| 319 | * @throws NoSuchAlgorithmException on unsupported signature algorithms
|
|---|
| 320 | * @throws CertificateException if any of the certificates in the Windows keystore could not be loaded
|
|---|
| 321 | * @throws KeyStoreException if no Provider supports a KeyStoreSpi implementation for the type "Windows-ROOT"
|
|---|
| 322 | * @throws IOException if there is an I/O or format problem with the keystore data, if a password is required but not given
|
|---|
| 323 | * @since 7335
|
|---|
| 324 | */
|
|---|
| 325 | public static void removeInsecureCertificates() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException {
|
|---|
| 326 | // We offered before a public private key we need now to remove from Windows PCs as it might be a huge security risk (see #10230)
|
|---|
| 327 | PublicKey insecurePubKey = null;
|
|---|
| 328 | try {
|
|---|
| 329 | insecurePubKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(INSECURE_PUBLIC_KEY));
|
|---|
| 330 | } catch (InvalidKeySpecException | NoSuchAlgorithmException e) {
|
|---|
| 331 | Main.error(e);
|
|---|
| 332 | return;
|
|---|
| 333 | }
|
|---|
| 334 | KeyStore ks = getRootKeystore();
|
|---|
| 335 | Enumeration<String> en = ks.aliases();
|
|---|
| 336 | Collection<String> insecureCertificates = new ArrayList<>();
|
|---|
| 337 | while (en.hasMoreElements()) {
|
|---|
| 338 | String alias = en.nextElement();
|
|---|
| 339 | // Look for certificates associated with a private key
|
|---|
| 340 | if (ks.isKeyEntry(alias)) {
|
|---|
| 341 | try {
|
|---|
| 342 | ks.getCertificate(alias).verify(insecurePubKey);
|
|---|
| 343 | // If no exception, this is a certificate signed with the insecure key -> remove it
|
|---|
| 344 | insecureCertificates.add(alias);
|
|---|
| 345 | } catch (InvalidKeyException | NoSuchProviderException | SignatureException e) {
|
|---|
| 346 | // If exception this is not a certificate related to JOSM, just trace it
|
|---|
| 347 | Main.trace(alias + " --> " + e.getClass().getName());
|
|---|
| 348 | }
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 | // Remove insecure certificates
|
|---|
| 352 | if (!insecureCertificates.isEmpty()) {
|
|---|
| 353 | StringBuilder message = new StringBuilder("<html>");
|
|---|
| 354 | message.append(tr("A previous version of JOSM has installed a custom certificate "+
|
|---|
| 355 | "in order to provide HTTPS support for Remote Control:"));
|
|---|
| 356 | message.append("<br><ul>");
|
|---|
| 357 | for (String alias : insecureCertificates) {
|
|---|
| 358 | message.append("<li>");
|
|---|
| 359 | message.append(alias);
|
|---|
| 360 | message.append("</li>");
|
|---|
| 361 | }
|
|---|
| 362 | message.append("</ul>");
|
|---|
| 363 | message.append(tr("It appears it could be an important <b>security risk</b>.<br><br>"+
|
|---|
| 364 | "You are now going to be prompted by Windows to remove this insecure certificate.<br>"+
|
|---|
| 365 | "For your own safety, <b>please click Yes</b> in next dialog."));
|
|---|
| 366 | message.append("</html>");
|
|---|
| 367 | JOptionPane.showMessageDialog(Main.parent, message.toString(), tr("Warning"), JOptionPane.WARNING_MESSAGE);
|
|---|
| 368 | for (String alias : insecureCertificates) {
|
|---|
| 369 | Main.warn(tr("Removing insecure certificate from {0} keystore: {1}", WINDOWS_ROOT, alias));
|
|---|
| 370 | try {
|
|---|
| 371 | ks.deleteEntry(alias);
|
|---|
| 372 | } catch (KeyStoreException e) {
|
|---|
| 373 | Main.error(tr("Unable to remove insecure certificate from keystore: {0}", e.getMessage()));
|
|---|
| 374 | }
|
|---|
| 375 | }
|
|---|
| 376 | }
|
|---|
| 377 | }
|
|---|
| 378 |
|
|---|
| 379 | @Override
|
|---|
| 380 | public boolean setupHttpsCertificate(String entryAlias, KeyStore.TrustedCertificateEntry trustedCert)
|
|---|
| 381 | throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
|
|---|
| 382 | KeyStore ks = getRootKeystore();
|
|---|
| 383 | // Look for certificate to install
|
|---|
| 384 | String alias = ks.getCertificateAlias(trustedCert.getTrustedCertificate());
|
|---|
| 385 | if (alias != null) {
|
|---|
| 386 | // JOSM certificate found, return
|
|---|
| 387 | Main.debug(tr("JOSM localhost certificate found in {0} keystore: {1}", WINDOWS_ROOT, alias));
|
|---|
| 388 | return false;
|
|---|
| 389 | }
|
|---|
| 390 | if (!GraphicsEnvironment.isHeadless()) {
|
|---|
| 391 | // JOSM certificate not found, warn user
|
|---|
| 392 | StringBuilder message = new StringBuilder("<html>");
|
|---|
| 393 | message.append(tr("Remote Control is configured to provide HTTPS support.<br>"+
|
|---|
| 394 | "This requires to add a custom certificate generated by JOSM to the Windows Root CA store.<br><br>"+
|
|---|
| 395 | "You are now going to be prompted by Windows to confirm this operation.<br>"+
|
|---|
| 396 | "To enable proper HTTPS support, <b>please click Yes</b> in next dialog.<br><br>"+
|
|---|
| 397 | "If unsure, you can also click No then disable HTTPS support in Remote Control preferences."));
|
|---|
| 398 | message.append("</html>");
|
|---|
| 399 | JOptionPane.showMessageDialog(Main.parent, message.toString(),
|
|---|
| 400 | tr("HTTPS support in Remote Control"), JOptionPane.INFORMATION_MESSAGE);
|
|---|
| 401 | }
|
|---|
| 402 | // install it to Windows-ROOT keystore, used by IE, Chrome and Safari, but not by Firefox
|
|---|
| 403 | Main.info(tr("Adding JOSM localhost certificate to {0} keystore", WINDOWS_ROOT));
|
|---|
| 404 | ks.setEntry(entryAlias, trustedCert, null);
|
|---|
| 405 | return true;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | @Override
|
|---|
| 409 | public File getDefaultCacheDirectory() {
|
|---|
| 410 | String p = System.getenv("LOCALAPPDATA");
|
|---|
| 411 | if (p == null || p.isEmpty()) {
|
|---|
| 412 | // Fallback for Windows OS earlier than Windows Vista, where the variable is not defined
|
|---|
| 413 | p = System.getenv("APPDATA");
|
|---|
| 414 | }
|
|---|
| 415 | return new File(new File(p, "JOSM"), "cache");
|
|---|
| 416 | }
|
|---|
| 417 |
|
|---|
| 418 | @Override
|
|---|
| 419 | public File getDefaultPrefDirectory() {
|
|---|
| 420 | return new File(System.getenv("APPDATA"), "JOSM");
|
|---|
| 421 | }
|
|---|
| 422 | }
|
|---|