Skip to content

Commit 14633b7

Browse files
committed
Using constants for default keystore type, file names, password
- in few tests changed to different to avoid confusion Signed-off-by: David Matějček <[email protected]>
1 parent 9e633c5 commit 14633b7

File tree

31 files changed

+206
-198
lines changed

31 files changed

+206
-198
lines changed

appserver/itest-tools/src/main/java/org/glassfish/main/itest/tools/GlassFishTestEnvironment.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@
5757
import org.glassfish.main.itest.tools.asadmin.StartServ;
5858
import org.glassfish.main.jdke.security.KeyTool;
5959

60+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
6061
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
62+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
6163
import static java.net.http.HttpResponse.BodyHandlers.ofString;
6264
import static org.glassfish.embeddable.GlassFishVariable.JAVA_HOME;
6365
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
@@ -172,7 +174,7 @@ public static Path getDomain1Directory() {
172174

173175

174176
public static KeyStore getDomain1KeyStore() {
175-
Path keystore = getDomain1Directory().resolve(Paths.get("config", "keystore.jks"));
177+
Path keystore = getDomain1Directory().resolve(Paths.get("config", KEYSTORE_FILENAME_DEFAULT));
176178
try {
177179
return new KeyTool(keystore.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
178180
} catch (IOException e) {
@@ -182,7 +184,7 @@ public static KeyStore getDomain1KeyStore() {
182184

183185

184186
public static KeyStore getDomain1TrustStore() {
185-
Path cacerts = getDomain1Directory().resolve(Paths.get("config", "cacerts.jks"));
187+
Path cacerts = getDomain1Directory().resolve(Paths.get("config", TRUSTSTORE_FILENAME_DEFAULT));
186188
try {
187189
return new KeyTool(cacerts.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
188190
} catch (IOException e) {

appserver/tests/application/src/test/java/org/glassfish/main/test/app/security/jmac/https/JmacHttpsTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import org.junit.jupiter.api.io.TempDir;
5050

5151
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
52+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
5253
import static java.lang.System.Logger.Level.DEBUG;
5354
import static java.lang.System.Logger.Level.INFO;
5455
import static java.lang.System.Logger.Level.TRACE;
@@ -83,11 +84,11 @@ public class JmacHttpsTest {
8384

8485
@BeforeAll
8586
public static void prepareDeployment() throws Exception {
86-
myKeyStore = new File(tempDir, "httpstest.jks");
87+
myKeyStore = new File(tempDir, "httpstest.p12");
8788
myKeyStoreTool = new KeyTool(myKeyStore, MYKS_PASSWORD);
8889
myKeyStoreTool.generateKeyPair("httpstest", "CN=HTTPSTEST,OU=Eclipse GlassFish Tests", "RSA", 7);
8990

90-
File cacertsFile = getDomain1Directory().resolve(Paths.get("config", "cacerts.jks")).toFile();
91+
File cacertsFile = getDomain1Directory().resolve(Paths.get("config", TRUSTSTORE_FILENAME_DEFAULT)).toFile();
9192
myKeyStoreTool.copyCertificate("httpstest", cacertsFile, KEYSTORE_PASSWORD_DEFAULT.toCharArray());
9293

9394
// Default is false, required to set the client certificate to the context.

appserver/tests/embedded/maven-plugin/secureWebApp/src/test/java/org/glassfish/tests/embedded/securewebapp/SecureWebAppTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
6565

6666
@BeforeAll
6767
public static void createKeyStore() throws Exception {
68-
File keystore = JUnitSystem.detectBasedir().resolve(Path.of("target", "keystore.jks")).toFile();
68+
// The file is set also in system.properties file
69+
File keystore = JUnitSystem.detectBasedir().resolve(Path.of("target", "testkeystore.p12")).toFile();
6970
KeyTool keyTool = new KeyTool(keystore, KEYSTORE_PASSWORD_DEFAULT.toCharArray());
7071
keyTool.generateKeyPair("s1as", "CN=localhost", "RSA", 1);
7172
}

appserver/tests/embedded/maven-plugin/secureWebApp/src/test/resources/system.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
#
1717

1818
org.glassfish.embedded.greeting=Hi from BHAVANI
19-
javax.net.ssl.keyStore=${project.build.directory}/keystore.jks
20-
javax.net.ssl.trustStore=${project.build.directory}/truststore.jks
19+
javax.net.ssl.keyStore=${project.build.directory}/testkeystore.p12
20+
javax.net.ssl.trustStore=${project.build.directory}/testtruststore.p12

appserver/tests/embedded/web/web-api/src/test/java/org/glassfish/tests/embedded/web/EmbeddedAddHttpsListenerTest.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.io.BufferedReader;
2121
import java.io.File;
2222
import java.io.InputStreamReader;
23+
import java.net.URI;
2324
import java.net.URL;
2425
import java.security.SecureRandom;
2526
import java.security.cert.X509Certificate;
@@ -34,7 +35,6 @@
3435
import org.glassfish.embeddable.GlassFish;
3536
import org.glassfish.embeddable.GlassFishException;
3637
import org.glassfish.embeddable.GlassFishRuntime;
37-
import org.glassfish.embeddable.GlassFishVariable;
3838
import org.glassfish.embeddable.web.HttpsListener;
3939
import org.glassfish.embeddable.web.WebContainer;
4040
import org.glassfish.embeddable.web.config.SslConfig;
@@ -46,6 +46,7 @@
4646
import org.junit.jupiter.api.Test;
4747
import org.junit.jupiter.api.io.TempDir;
4848

49+
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_FILE;
4950
import static org.glassfish.main.jdke.props.SystemProperties.setProperty;
5051

5152
/**
@@ -56,17 +57,17 @@
5657
public class EmbeddedAddHttpsListenerTest {
5758

5859
@TempDir
59-
static File tempDir;
60-
static GlassFish glassfish;
61-
static WebContainer embedded;
62-
static File root;
63-
static String contextRoot = "test";
60+
private static File tempDir;
61+
private static GlassFish glassfish;
62+
private static WebContainer embedded;
63+
private static File root;
64+
private static File keystore;
6465

6566
@BeforeAll
6667
public static void setupServer() throws Exception {
6768

68-
File keystore = new File(tempDir, "keystore.jks");
69-
setProperty(GlassFishVariable.KEYSTORE_FILE.getSystemPropertyName(), keystore.getAbsolutePath(), true);
69+
keystore = new File(tempDir, "test_keystore.p12");
70+
setProperty(KEYSTORE_FILE.getSystemPropertyName(), keystore.getAbsolutePath(), true);
7071
KeyTool keyTool = new KeyTool(keystore, "changeit".toCharArray());
7172
keyTool.generateKeyPair("s1as", "CN=localhost", "RSA", 1);
7273

@@ -87,7 +88,6 @@ public static void setupServer() throws Exception {
8788

8889
private void createHttpsListener(int port,
8990
String name,
90-
String keystore,
9191
String password,
9292
String certname) throws Exception {
9393

@@ -96,11 +96,8 @@ private void createHttpsListener(int port,
9696
listener.setId(name);
9797

9898
String keyStorePath = root.getAbsolutePath() + keystore;
99-
String trustStorePath = root.getAbsolutePath() + "/cacerts.jks";
100-
SslConfig sslConfig = new SslConfig(keyStorePath, trustStorePath);
99+
SslConfig sslConfig = new SslConfig(keyStorePath, null);
101100
sslConfig.setKeyPassword(password.toCharArray());
102-
String trustPassword = "changeit";
103-
sslConfig.setTrustPassword(trustPassword.toCharArray());
104101
if (certname != null) {
105102
sslConfig.setCertNickname(certname);
106103
}
@@ -110,26 +107,23 @@ private void createHttpsListener(int port,
110107
}
111108

112109
private void verify(int port) throws Exception {
113-
114-
URL servlet = new URL("https://localhost:"+port+"/classes/hello");
110+
URL servlet = new URI("https://localhost:" + port + "/classes/hello").toURL();
115111
HttpsURLConnection uc = (HttpsURLConnection) servlet.openConnection();
116-
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()));
117112
StringBuilder sb = new StringBuilder();
118-
String inputLine;
119-
while ((inputLine = in.readLine()) != null){
120-
sb.append(inputLine);
113+
try (BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream()))) {
114+
String inputLine;
115+
while ((inputLine = in.readLine()) != null) {
116+
sb.append(inputLine);
117+
}
121118
}
122-
in.close();
123119
System.out.println(sb);
124120
Assertions.assertEquals("Hello World!", sb.toString());
125121
}
126122

127123
@Test
128124
public void test() throws Exception {
129125

130-
createHttpsListener(9191, "default-ssl-listener", "/keystore.jks", "changeit", "s1as");
131-
//createHttpsListener(9292, "ssl-listener0", "/keystore0", "password0", "keystore0");
132-
//createHttpsListener(9393, "ssl-listener1", "/keystore1", "password1", null);
126+
createHttpsListener(9191, "default-ssl-listener", "changeit", "s1as");
133127

134128
Deployer deployer = glassfish.getDeployer();
135129

appserver/web/web-core/src/main/java/org/apache/catalina/connector/CoyoteServerSocketFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.net.ServerSocket;
2424

2525
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
26+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_TYPE_DEFAULT;
2627

2728

2829
/**
@@ -43,7 +44,7 @@
4344
* <li><strong>keystorePass</strong> - Password for the Key Store file to be
4445
* loaded. ["changeit"]</li>
4546
* <li><strong>keystoreType</strong> - Type of the Key Store file to be
46-
* loaded. ["JKS"]</li>
47+
* loaded.</li>
4748
* <li><strong>protocol</strong> - SSL protocol to use. [TLS]</li>
4849
* </ul>
4950
*
@@ -61,7 +62,7 @@ public class CoyoteServerSocketFactory
6162
private String randomFile;
6263
private String rootFile;
6364
private String keystorePass = KEYSTORE_PASSWORD_DEFAULT;
64-
private String keystoreType = "JKS";
65+
private String keystoreType = KEYSTORE_TYPE_DEFAULT;
6566
private String protocol = "TLS";
6667
private String protocols;
6768
private String sslImplementation;

appserver/web/web-glue/src/main/java/com/sun/enterprise/web/connector/coyote/PECoyoteConnector.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@
6060
import org.glassfish.web.admin.monitor.RequestProbeProvider;
6161
import org.glassfish.web.util.IntrospectionUtils;
6262

63+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_TYPE_DEFAULT;
6364
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_FILE;
6465
import static org.glassfish.embeddable.GlassFishVariable.KEYSTORE_TYPE;
6566
import static org.glassfish.embeddable.GlassFishVariable.TRUSTSTORE_FILE;
6667
import static org.glassfish.embeddable.GlassFishVariable.TRUSTSTORE_TYPE;
6768

6869
public class PECoyoteConnector extends Connector {
6970

70-
private static final String DEFAULT_KEYSTORE_TYPE = "JKS";
71-
private static final String DEFAULT_TRUSTSTORE_TYPE = "JKS";
72-
7371
private static final String DUMMY_CONNECTOR_LAUNCHER = DummyConnectorLauncher.class.getName();
7472

7573
protected static final Logger _logger = LogFacade.getLogger();
@@ -1334,14 +1332,14 @@ private void configureSSL(NetworkListener listener) {
13341332
*/
13351333
private void configureKeysAndCerts() {
13361334
String prop = System.getProperty(KEYSTORE_FILE.getSystemPropertyName());
1337-
String keyStoreType = System.getProperty(KEYSTORE_TYPE.getSystemPropertyName(), DEFAULT_KEYSTORE_TYPE);
1335+
String keyStoreType = System.getProperty(KEYSTORE_TYPE.getSystemPropertyName(), KEYSTORE_TYPE_DEFAULT);
13381336
if (prop != null) {
13391337
setKeystoreFile(prop);
13401338
setKeystoreType(keyStoreType);
13411339
}
13421340

13431341
prop = System.getProperty(TRUSTSTORE_FILE.getSystemPropertyName());
1344-
keyStoreType = System.getProperty(TRUSTSTORE_TYPE.getSystemPropertyName(), DEFAULT_TRUSTSTORE_TYPE);
1342+
keyStoreType = System.getProperty(TRUSTSTORE_TYPE.getSystemPropertyName(), KEYSTORE_TYPE_DEFAULT);
13451343
if (prop != null) {
13461344
setTruststore(prop);
13471345
setTruststoreType(keyStoreType);

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/KeystoreManager.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232

3333
import org.glassfish.main.jdke.security.KeyTool;
3434

35-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.KEYSTORE_FILE;
36-
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.TRUSTSTORE_FILE;
35+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
36+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
3737

3838
/**
3939
* @author kebbs
@@ -102,8 +102,8 @@ protected void createKeyStore(File keyStore, RepositoryConfig config, String mas
102102

103103
protected void copyCertificatesToTrustStore(File configRoot, DomainConfig config, String masterPassword)
104104
throws DomainException {
105-
final File keyStore = new File(configRoot, KEYSTORE_FILE);
106-
final File trustStore = new File(configRoot, TRUSTSTORE_FILE);
105+
final File keyStore = new File(configRoot, KEYSTORE_FILENAME_DEFAULT);
106+
final File trustStore = new File(configRoot, TRUSTSTORE_FILENAME_DEFAULT);
107107
final KeyTool keyTool = new KeyTool(keyStore, masterPassword.toCharArray());
108108
try {
109109
keyTool.copyCertificate(CERTIFICATE_ALIAS, trustStore);

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/cli/LocalServerCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import static com.sun.enterprise.admin.cli.CLIConstants.DEFAULT_HOSTNAME;
4747
import static com.sun.enterprise.admin.cli.ProgramOptions.PasswordLocation.LOCAL_PASSWORD;
4848
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
49+
import static com.sun.enterprise.util.SystemPropertyConstants.TRUSTSTORE_FILENAME_DEFAULT;
4950
import static java.util.logging.Level.CONFIG;
5051
import static java.util.logging.Level.FINER;
5152

@@ -407,7 +408,7 @@ private File getJKS() {
407408
return null;
408409
}
409410

410-
File mp = new File(new File(serverDirs.getServerDir(), "config"), "cacerts.jks");
411+
File mp = new File(new File(serverDirs.getServerDir(), "config"), TRUSTSTORE_FILENAME_DEFAULT);
411412
if (!mp.canRead()) {
412413
return null;
413414
}

nucleus/admin/server-mgmt/src/main/java/com/sun/enterprise/admin/servermgmt/domain/DomainBuilder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
import java.util.logging.Logger;
5050

5151
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.DOMAIN_XML_FILE;
52+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_FILENAME_DEFAULT;
5253
import static java.text.MessageFormat.format;
5354
import static org.glassfish.embeddable.GlassFishVariable.INSTALL_ROOT;
5455

@@ -137,7 +138,7 @@ private void initialize() throws DomainException {
137138
_domainTempalte = new DomainTemplate(templateInfoHolder, stringSubstitutor, templateJarPath);
138139

139140
// Loads default self signed certificate.
140-
je = _templateJar.getJarEntry("config/" + DomainConstants.KEYSTORE_FILE);
141+
je = _templateJar.getJarEntry("config/" + KEYSTORE_FILENAME_DEFAULT);
141142
if (je != null) {
142143
_keystoreBytes = new byte[(int) je.getSize()];
143144
InputStream in = null;

0 commit comments

Comments
 (0)