@Test public void testReloadCorruptTrustStore() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testcorrupt.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); X509Certificate cert = tm.getAcceptedIssuers()[0]; OutputStream os = new FileOutputStream(truststoreLocation); os.write(1); os.close(); new File(truststoreLocation).setLastModified(System.currentTimeMillis() - 1000); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(1, tm.getAcceptedIssuers().length); assertEquals(cert, tm.getAcceptedIssuers()[0]); } finally { tm.destroy(); } }
@Test public void testReloadCorruptTrustStore() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testcorrupt.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); X509Certificate cert = tm.getAcceptedIssuers()[0]; OutputStream os = new FileOutputStream(truststoreLocation); os.write(1); os.close(); new File(truststoreLocation).setLastModified(System.currentTimeMillis() - 1000); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(1, tm.getAcceptedIssuers().length); assertEquals(cert, tm.getAcceptedIssuers()[0]); } finally { tm.destroy(); } }
@Test public void testReloadMissingTrustStore() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testmissing.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); X509Certificate cert = tm.getAcceptedIssuers()[0]; new File(truststoreLocation).delete(); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(1, tm.getAcceptedIssuers().length); assertEquals(cert, tm.getAcceptedIssuers()[0]); } finally { tm.destroy(); } }
@Test public void testReloadMissingTrustStore() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testmissing.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); X509Certificate cert = tm.getAcceptedIssuers()[0]; new File(truststoreLocation).delete(); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(1, tm.getAcceptedIssuers().length); assertEquals(cert, tm.getAcceptedIssuers()[0]); } finally { tm.destroy(); } }
@Test public void testReload() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testreload.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 1000)); // Add another cert Map<String, X509Certificate> certs = new HashMap<String, X509Certificate>(); certs.put("cert1", cert1); certs.put("cert2", cert2); createTrustStore(truststoreLocation, "password", certs); // and wait to be sure reload has taken place assertEquals(10, tm.getReloadInterval()); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(2, tm.getAcceptedIssuers().length); } finally { tm.destroy(); } }
@Test public void testReload() throws Exception { KeyPair kp = generateKeyPair("RSA"); cert1 = generateCertificate("CN=Cert1", kp, 30, "SHA1withRSA"); cert2 = generateCertificate("CN=Cert2", kp, 30, "SHA1withRSA"); String truststoreLocation = BASEDIR + "/testreload.jks"; createTrustStore(truststoreLocation, "password", "cert1", cert1); ReloadingX509TrustManager tm = new ReloadingX509TrustManager("jks", truststoreLocation, "password", 10); try { tm.init(); assertEquals(1, tm.getAcceptedIssuers().length); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 1000)); // Add another cert Map<String, X509Certificate> certs = new HashMap<String, X509Certificate>(); certs.put("cert1", cert1); certs.put("cert2", cert2); createTrustStore(truststoreLocation, "password", certs); // and wait to be sure reload has taken place assertEquals(10, tm.getReloadInterval()); // Wait so that the file modification time is different Thread.sleep((tm.getReloadInterval() + 200)); assertEquals(2, tm.getAcceptedIssuers().length); } finally { tm.destroy(); } }