Ignore:
Timestamp:
2019-10-22T23:32:51+02:00 (5 years ago)
Author:
Don-vip
Message:

fix #10033, fix #15748, fix #17097 - drop remote control https support

Rationale: all modern browsers (including next version of Safari) allow mixed-content to localhost.

Cross-platform / cross-browser HTTPS support is a pain to maintain, was never completed, and is no longer needed.

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/RemoteControlTest.java

    r14217 r15469  
    1111import java.net.URL;
    1212import java.nio.charset.StandardCharsets;
    13 import java.nio.file.Files;
    14 import java.nio.file.Paths;
    1513import java.security.GeneralSecurityException;
    1614import java.security.KeyStore.TrustedCertificateEntry;
    17 import java.security.SecureRandom;
    18 import java.security.cert.X509Certificate;
    19 
    20 import javax.net.ssl.HostnameVerifier;
    21 import javax.net.ssl.HttpsURLConnection;
    22 import javax.net.ssl.SSLContext;
    23 import javax.net.ssl.TrustManager;
    24 import javax.net.ssl.X509TrustManager;
    2515
    2616import org.junit.After;
     
    3121import org.openstreetmap.josm.spi.preferences.Config;
    3222import org.openstreetmap.josm.testutils.JOSMTestRules;
    33 import org.openstreetmap.josm.tools.Logging;
    3423import org.openstreetmap.josm.tools.PlatformHookWindows;
    3524import org.openstreetmap.josm.tools.PlatformManager;
     
    4534
    4635    private String httpBase;
    47     private String httpsBase;
    4836
    4937    private static class PlatformHookWindowsMock extends MockUp<PlatformHookWindows> {
     
    6755    @Before
    6856    public void setUp() throws GeneralSecurityException {
    69         RemoteControl.PROP_REMOTECONTROL_HTTPS_ENABLED.put(true);
    70         deleteKeystore();
    71 
    7257        if (PlatformManager.isPlatformWindows() && "True".equals(System.getenv("APPVEYOR"))) {
    7358            // appveyor doesn't like us tinkering with the root keystore, so mock this out
     
    7762
    7863        RemoteControl.start();
    79         disableCertificateValidation();
    8064        httpBase = "http://127.0.0.1:"+Config.getPref().getInt("remote.control.port", 8111);
    81         httpsBase = "https://127.0.0.1:"+Config.getPref().getInt("remote.control.https.port", 8112);
    82     }
    83 
    84     /**
    85      * Deletes JOSM keystore, if it exists.
    86      */
    87     public static void deleteKeystore() {
    88         try {
    89             Files.deleteIfExists(Paths.get(
    90                     RemoteControl.getRemoteControlDir()).resolve(RemoteControlHttpsServer.KEYSTORE_FILENAME));
    91         } catch (IOException e) {
    92             Logging.error(e);
    93         }
    94     }
    95 
    96     /**
    97      * Disable all HTTPS validation mechanisms as described
    98      * <a href="http://stackoverflow.com/a/2893932/2257172">here</a> and
    99      * <a href="http://stackoverflow.com/a/19542614/2257172">here</a>
    100      * @throws GeneralSecurityException if a security error occurs
    101      */
    102     public void disableCertificateValidation() throws GeneralSecurityException {
    103         // Create a trust manager that does not validate certificate chains
    104         TrustManager[] trustAllCerts = new TrustManager[] {
    105             new X509TrustManager() {
    106                 @Override
    107                 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    108                 public X509Certificate[] getAcceptedIssuers() {
    109                     return new X509Certificate[0];
    110                 }
    111 
    112                 @Override
    113                 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    114                 public void checkClientTrusted(X509Certificate[] certs, String authType) {
    115                 }
    116 
    117                 @Override
    118                 @SuppressFBWarnings(value = "WEAK_TRUST_MANAGER")
    119                 public void checkServerTrusted(X509Certificate[] certs, String authType) {
    120                 }
    121             }
    122         };
    123 
    124         // Install the all-trusting trust manager
    125         SSLContext sc = SSLContext.getInstance("TLS");
    126         sc.init(null, trustAllCerts, new SecureRandom());
    127         HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    128 
    129         // Create all-trusting host name verifier
    130         HostnameVerifier allHostsValid = (hostname, session) -> true;
    131 
    132         // Install the all-trusting host verifier
    133         HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
    13465    }
    13566
     
    14980    public void testHttpListOfCommands() throws Exception {
    15081        testListOfCommands(httpBase);
    151     }
    152 
    153     /**
    154      * Tests that sending an HTTPS request without command results in HTTP 400, with all available commands in error message.
    155      * @throws Exception if an error occurs
    156      */
    157     @Test
    158     public void testHttpsListOfCommands() throws Exception {
    159         testListOfCommands(httpsBase);
    16082    }
    16183
  • trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookOsxTest.java

    r14190 r15469  
    3838    public void testStartupHook() {
    3939        hook.startupHook((a, b, c, d) -> System.out.println("callback"));
    40     }
    41 
    42     /**
    43      * Test method for {@code PlatformHookOsx#setupHttpsCertificate}
    44      * @throws Exception if an error occurs
    45      */
    46     @Test
    47     public void testSetupHttpsCertificate() throws Exception {
    48         assertFalse(hook.setupHttpsCertificate(null, null));
    4940    }
    5041
  • trunk/test/unit/org/openstreetmap/josm/tools/PlatformHookWindowsTest.java

    r14412 r15469  
    77import static org.junit.Assert.assertNull;
    88import static org.junit.Assert.assertTrue;
    9 import static org.junit.Assume.assumeFalse;
    109import static org.junit.Assert.fail;
    1110
     
    1312import java.io.File;
    1413import java.io.IOException;
    15 import java.security.KeyStore;
    16 import java.security.KeyStore.TrustedCertificateEntry;
    1714import java.security.KeyStoreException;
    1815import java.util.Collection;
     
    2219import org.openstreetmap.josm.JOSMFixture;
    2320import org.openstreetmap.josm.TestUtils;
    24 import org.openstreetmap.josm.io.remotecontrol.RemoteControlHttpsServer;
    25 import org.openstreetmap.josm.io.remotecontrol.RemoteControlTest;
    2621import org.openstreetmap.josm.spi.preferences.Config;
    2722
     
    6459            try {
    6560                PlatformHookWindows.getRootKeystore();
    66                 fail("Expected KeyStoreException");
    67             } catch (KeyStoreException e) {
    68                 Logging.info(e.getMessage());
    69             }
    70         }
    71     }
    72 
    73     /**
    74      * Test method for {@code PlatformHookWindows#removeInsecureCertificates}
    75      * @throws Exception if an error occurs
    76      */
    77     @Test
    78     public void testRemoveInsecureCertificates() throws Exception {
    79         if (PlatformManager.isPlatformWindows()) {
    80             PlatformHookWindows.removeInsecureCertificates();
    81         } else {
    82             try {
    83                 PlatformHookWindows.removeInsecureCertificates();
    84                 fail("Expected KeyStoreException");
    85             } catch (KeyStoreException e) {
    86                 Logging.info(e.getMessage());
    87             }
    88         }
    89     }
    90 
    91     /**
    92      * Test method for {@code PlatformHookWindows#setupHttpsCertificate}
    93      * @throws Exception if an error occurs
    94      */
    95     @Test
    96     public void testSetupHttpsCertificate() throws Exception {
    97         // appveyor doesn't like us tinkering with the root keystore
    98         assumeFalse(PlatformManager.isPlatformWindows() && "True".equals(System.getenv("APPVEYOR")));
    99 
    100         RemoteControlTest.deleteKeystore();
    101         KeyStore ks = RemoteControlHttpsServer.loadJosmKeystore();
    102         TrustedCertificateEntry trustedCert = new KeyStore.TrustedCertificateEntry(ks.getCertificate(ks.aliases().nextElement()));
    103         if (PlatformManager.isPlatformWindows()) {
    104             hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
    105         } else {
    106             try {
    107                 hook.setupHttpsCertificate(RemoteControlHttpsServer.ENTRY_ALIAS, trustedCert);
    10861                fail("Expected KeyStoreException");
    10962            } catch (KeyStoreException e) {
Note: See TracChangeset for help on using the changeset viewer.