ProxyCA { public String generateKeyStorePassword() { return RandomStringUtils.random(16, 0, 0, true, true, null, srand); } ProxyCA(); void init(); void init(X509Certificate caCert, PrivateKey caPrivateKey); byte[] createChildKeyStore(ApplicationId appId, String ksPassword); byte[] getChildTrustStore(String password); String generateKeyStorePassword(); SSLContext createSSLContext(ApplicationId appId); HostnameVerifier getHostnameVerifier(); @VisibleForTesting X509Certificate getCaCert(); @VisibleForTesting KeyPair getCaKeyPair();  }
@Test public void testGenerateKeyStorePassword() throws Exception { ProxyCA proxyCA = new ProxyCA(); proxyCA.init(); Set<String> passwords = new HashSet<>(); for (int i = 0; i < 5; i++) { String password = proxyCA.generateKeyStorePassword(); Assert.assertEquals(16, password.length()); for (char c : password.toCharArray()) { Assert.assertFalse("Found character '" + c + "' in password '" + password + "' which is outside of the expected range", c < ' '); Assert.assertFalse("Found character '" + c + "' in password '" + password + "' which is outside of the expected range", c > 'z'); } Assert.assertFalse("Password " + password + " was generated twice, which is _extremely_ unlikely" + " and shouldn't practically happen: " + passwords, passwords.contains(password)); passwords.add(password); } }