Skip to content

Commit 2250465

Browse files
committed
Using same constants for default keystore password and type
- note that type can be autodetected both by keytool and KeyStore Signed-off-by: David Matějček <[email protected]>
1 parent adfd5f4 commit 2250465

File tree

23 files changed

+118
-98
lines changed

23 files changed

+118
-98
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
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_PASSWORD_DEFAULT;
6061
import static java.net.http.HttpResponse.BodyHandlers.ofString;
6162
import static org.glassfish.embeddable.GlassFishVariable.JAVA_HOME;
6263
import static org.glassfish.main.itest.tools.asadmin.AsadminResultMatcher.asadminOK;
@@ -173,7 +174,7 @@ public static Path getDomain1Directory() {
173174
public static KeyStore getDomain1KeyStore() {
174175
Path keystore = getDomain1Directory().resolve(Paths.get("config", "keystore.jks"));
175176
try {
176-
return new KeyTool(keystore.toFile(), "changeit".toCharArray()).loadKeyStore();
177+
return new KeyTool(keystore.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
177178
} catch (IOException e) {
178179
throw new IllegalStateException(e);
179180
}
@@ -183,7 +184,7 @@ public static KeyStore getDomain1KeyStore() {
183184
public static KeyStore getDomain1TrustStore() {
184185
Path cacerts = getDomain1Directory().resolve(Paths.get("config", "cacerts.jks"));
185186
try {
186-
return new KeyTool(cacerts.toFile(), "changeit".toCharArray()).loadKeyStore();
187+
return new KeyTool(cacerts.toFile(), KEYSTORE_PASSWORD_DEFAULT.toCharArray()).loadKeyStore();
187188
} catch (IOException e) {
188189
throw new IllegalStateException(e);
189190
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import org.junit.jupiter.api.Test;
4949
import org.junit.jupiter.api.io.TempDir;
5050

51+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
5152
import static java.lang.System.Logger.Level.DEBUG;
5253
import static java.lang.System.Logger.Level.INFO;
5354
import static java.lang.System.Logger.Level.TRACE;
@@ -87,7 +88,7 @@ public static void prepareDeployment() throws Exception {
8788
myKeyStoreTool.generateKeyPair("httpstest", "CN=HTTPSTEST,OU=Eclipse GlassFish Tests", "RSA", 7);
8889

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

9293
// Default is false, required to set the client certificate to the context.
9394
ASADMIN.exec("set", "configs.config.server-config.network-config.protocols.protocol.http-listener-2.ssl.client-auth-enabled=true");

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
@@ -40,6 +40,7 @@
4040
import org.junit.jupiter.api.BeforeAll;
4141
import org.junit.jupiter.api.Test;
4242

43+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
4344
import static org.junit.jupiter.api.Assertions.assertEquals;
4445

4546
public class SecureWebAppTest {
@@ -65,7 +66,7 @@ public void checkServerTrusted(X509Certificate[] certs, String authType) {
6566
@BeforeAll
6667
public static void createKeyStore() throws Exception {
6768
File keystore = JUnitSystem.detectBasedir().resolve(Path.of("target", "keystore.jks")).toFile();
68-
KeyTool keyTool = new KeyTool(keystore, "changeit".toCharArray());
69+
KeyTool keyTool = new KeyTool(keystore, KEYSTORE_PASSWORD_DEFAULT.toCharArray());
6970
keyTool.generateKeyPair("s1as", "CN=localhost", "RSA", 1);
7071
}
7172

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022 Contributors to the Eclipse Foundation
2+
* Copyright (c) 2022, 2025 Contributors to the Eclipse Foundation
33
* Copyright (c) 1997-2018 Oracle and/or its affiliates. All rights reserved.
44
* Copyright 2004 The Apache Software Foundation
55
*
@@ -22,6 +22,8 @@
2222
import java.net.InetAddress;
2323
import java.net.ServerSocket;
2424

25+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
26+
2527

2628
/**
2729
* This socket factory holds secure socket factory parameters. Besides the usual
@@ -58,7 +60,7 @@ public class CoyoteServerSocketFactory
5860
private String keystoreFile;
5961
private String randomFile;
6062
private String rootFile;
61-
private String keystorePass = "changeit";
63+
private String keystorePass = KEYSTORE_PASSWORD_DEFAULT;
6264
private String keystoreType = "JKS";
6365
private String protocol = "TLS";
6466
private String protocols;

nucleus/admin/cli/src/test/java/com/sun/enterprise/admin/cli/CLIUtilTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2024 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2021, 2025 Contributors to the Eclipse Foundation.
33
* Copyright (c) 2008, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -41,12 +41,12 @@ public void getUploadFileTest() throws Exception {
4141
f.deleteOnExit();
4242
try (BufferedWriter out = new BufferedWriter(new FileWriter(f, UTF_8))) {
4343
out.write("AS_ADMIN_PASSWORD=adminadmin\n");
44-
out.write("AS_ADMIN_MASTERPASSWORD=changeit\n");
44+
out.write("AS_ADMIN_MASTERPASSWORD=changeit123\n");
4545
}
4646

4747
Map<String, String> po = CLIUtil.readPasswordFileOptions(fileName, false);
4848
assertEquals("adminadmin", po.get("password"), "admin password");
49-
assertEquals("changeit", po.get("masterpassword"), "master password");
49+
assertEquals("changeit123", po.get("masterpassword"), "master password");
5050
assertNull(po.get("foobar"), "null");
5151
}
5252
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ public class KeystoreManager {
5050
private static final String CERTIFICATE_DN_SUFFIX = ",OU=GlassFish,O=Eclipse Foundation";
5151
public static final String CERTIFICATE_ALIAS = "s1as";
5252
public static final String INSTANCE_SECURE_ADMIN_ALIAS = "glassfish-instance";
53-
public static final String DEFAULT_MASTER_PASSWORD = "changeit";
5453
private static final String INSTANCE_CN_SUFFIX = "-instance";
5554

5655
private static final StringManager _strMgr = StringManager.getManager(KeystoreManager.class);

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
import static com.sun.enterprise.config.util.PortConstants.PORTBASE_JMX_SUFFIX;
6565
import static com.sun.enterprise.config.util.PortConstants.PORTBASE_OSGI_SUFFIX;
6666
import static com.sun.enterprise.config.util.PortConstants.PORT_MAX_VAL;
67+
import static com.sun.enterprise.util.SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD;
68+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
6769
import static org.glassfish.embeddable.GlassFishVariable.DOMAINS_ROOT;
6870

6971
/**
@@ -76,7 +78,6 @@ public final class CreateDomainCommand extends CLICommand {
7678
private static final String ADMIN_PORT = "adminport";
7779
private static final String ADMIN_PASSWORD = "password";
7880
private static final String MASTER_PASSWORD = "masterpassword";
79-
private static final String DEFAULT_MASTER_PASSWORD = KeystoreManager.DEFAULT_MASTER_PASSWORD;
8081
private static final String SAVE_MASTER_PASSWORD = "savemasterpassword";
8182
private static final String INSTANCE_PORT = "instanceport";
8283
private static final String DOMAIN_PROPERTIES = "domainproperties";
@@ -257,9 +258,9 @@ protected int executeCommand() throws CommandException, CommandValidationExcepti
257258
adminUser = programOpts.getUser();
258259
if (!ok(adminUser)) {
259260
adminUser = SystemPropertyConstants.DEFAULT_ADMIN_USER;
260-
adminPassword = SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD;
261+
adminPassword = DEFAULT_ADMIN_PASSWORD;
261262
} else if (noPassword) {
262-
adminPassword = SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD;
263+
adminPassword = DEFAULT_ADMIN_PASSWORD;
263264
} else {
264265
char[] pwdArr = getAdminPassword();
265266
adminPassword = pwdArr != null ? new String(pwdArr) : null;
@@ -273,9 +274,9 @@ protected int executeCommand() throws CommandException, CommandValidationExcepti
273274
if (masterPassword == null) {
274275
if (useMasterPassword) {
275276
char[] mpArr = getMasterPassword();
276-
masterPassword = mpArr != null ? new String(mpArr) : null;
277+
masterPassword = mpArr == null ? null : new String(mpArr);
277278
} else {
278-
masterPassword = DEFAULT_MASTER_PASSWORD;
279+
masterPassword = KEYSTORE_PASSWORD_DEFAULT;
279280
}
280281
}
281282

@@ -291,14 +292,14 @@ protected int executeCommand() throws CommandException, CommandValidationExcepti
291292

292293
// saving the login information happens inside this method
293294
createTheDomain(domainDir, domainProperties);
295+
return 0;
294296
} catch (CommandException ce) {
295297
logger.info(ce.getLocalizedMessage());
296298
throw new CommandException(strings.get("CouldNotCreateDomain", domainName), ce);
297299
} catch (Exception e) {
298300
logger.fine(e.getLocalizedMessage());
299301
throw new CommandException(strings.get("CouldNotCreateDomain", domainName), e);
300302
}
301-
return 0;
302303
}
303304

304305
/**
@@ -310,7 +311,7 @@ private char[] getAdminPassword() throws CommandValidationException {
310311
po.prompt = strings.get("AdminPassword");
311312
po.promptAgain = strings.get("AdminPasswordAgain");
312313
po.param._password = true;
313-
return getPassword(po, SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD, true);
314+
return getPassword(po, DEFAULT_ADMIN_PASSWORD, true);
314315
}
315316

316317
/**
@@ -322,7 +323,7 @@ private char[] getMasterPassword() throws CommandValidationException {
322323
po.prompt = strings.get("MasterPassword");
323324
po.promptAgain = strings.get("MasterPasswordAgain");
324325
po.param._password = true;
325-
return getPassword(po, DEFAULT_MASTER_PASSWORD, true);
326+
return getPassword(po, KEYSTORE_PASSWORD_DEFAULT, true);
326327
}
327328

328329
/**
@@ -438,7 +439,7 @@ private void createTheDomain(final String domainPath, Properties domainPropertie
438439
logger.info(strings.get("DomainCreated", domainName));
439440
Integer aPort = (Integer) domainConfig.get(DomainConfig.K_ADMIN_PORT);
440441
logger.info(strings.get("DomainPort", domainName, Integer.toString(aPort)));
441-
if (adminPassword != null && adminPassword.equals(SystemPropertyConstants.DEFAULT_ADMIN_PASSWORD)) {
442+
if (adminPassword != null && adminPassword.equals(DEFAULT_ADMIN_PASSWORD)) {
442443
logger.info(strings.get("DomainAllowsUnauth", domainName, adminUser));
443444
} else {
444445
logger.info(strings.get("DomainAdminUser", domainName, adminUser));

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
@@ -45,6 +45,7 @@
4545
import static com.sun.enterprise.admin.cli.CLIConstants.DEFAULT_ADMIN_PORT;
4646
import static com.sun.enterprise.admin.cli.CLIConstants.DEFAULT_HOSTNAME;
4747
import static com.sun.enterprise.admin.cli.ProgramOptions.PasswordLocation.LOCAL_PASSWORD;
48+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
4849
import static java.util.logging.Level.CONFIG;
4950
import static java.util.logging.Level.FINER;
5051

@@ -230,7 +231,7 @@ protected final String getMasterPassword() throws CommandException {
230231
if (mpv == null) {
231232
// not specified in the password file
232233
// optimization for the default case
233-
mpv = "changeit";
234+
mpv = KEYSTORE_PASSWORD_DEFAULT;
234235
if (!verifyMasterPassword(mpv)) {
235236
mpv = readFromMasterPasswordFile();
236237
if (!verifyMasterPassword(mpv)) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.KEYSTORE_FILE;
3131
import static com.sun.enterprise.admin.servermgmt.domain.DomainConstants.TRUSTSTORE_FILE;
32+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
3233

3334
public class DomainSecurity extends MasterPasswordFileManager {
3435

@@ -75,7 +76,7 @@ void createPasswordAliasKeystore(File pwFile, String password) throws Repository
7576
*/
7677
void createSSLCertificateDatabase(File configDir, DomainConfig config, String masterPassword) throws RepositoryException {
7778
createKeyStore(new File(configDir, KEYSTORE_FILE), config, masterPassword);
78-
changeKeystorePassword(DEFAULT_MASTER_PASSWORD, masterPassword, new File(configDir, TRUSTSTORE_FILE));
79+
changeKeystorePassword(KEYSTORE_PASSWORD_DEFAULT, masterPassword, new File(configDir, TRUSTSTORE_FILE));
7980
copyCertificatesToTrustStore(configDir, config, masterPassword);
8081
}
8182

nucleus/cluster/cli/src/main/java/com/sun/enterprise/admin/cli/cluster/CreateLocalInstanceCommand.java

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
23
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
34
*
45
* This program and the accompanying materials are made available under the
@@ -18,7 +19,6 @@
1819

1920
import com.sun.enterprise.admin.cli.CLIConstants;
2021
import com.sun.enterprise.admin.cli.remote.RemoteCLICommand;
21-
import com.sun.enterprise.admin.servermgmt.KeystoreManager;
2222
import com.sun.enterprise.admin.util.CommandModelData.ParamModelData;
2323
import com.sun.enterprise.security.store.PasswordAdapter;
2424
import com.sun.enterprise.universal.glassfish.TokenResolver;
@@ -42,6 +42,8 @@
4242
import org.glassfish.hk2.api.PerLookup;
4343
import org.jvnet.hk2.annotations.Service;
4444

45+
import static com.sun.enterprise.util.SystemPropertyConstants.KEYSTORE_PASSWORD_DEFAULT;
46+
4547

4648
/**
4749
* This is a local command that calls the primitive remote _register-instance to add the
@@ -87,7 +89,6 @@ public final class CreateLocalInstanceCommand extends CreateLocalInstanceFilesys
8789
private String RENDEZVOUS_DOTTED_NAME;
8890
private boolean _rendezvousOccurred;
8991
private String _node;
90-
private static final String DEFAULT_MASTER_PASSWORD = KeystoreManager.DEFAULT_MASTER_PASSWORD;
9192
private ParamModelData masterPasswordOption;
9293
private static final String MASTER_PASSWORD_ALIAS="master-password";
9394

@@ -154,10 +155,11 @@ protected int executeCommand()
154155
int exitCode = -1;
155156

156157
if (node == null) {
157-
if(nodeDirChild == null)
158+
if(nodeDirChild == null) {
158159
throw new CommandException(Strings.get("internal.error",
159160
"nodeDirChild was null. The Base Class is supposed to "
160161
+ "guarantee that this won't happen"));
162+
}
161163
_node = nodeDirChild.getName();
162164
String nodeHost = getInstanceHostName(true);
163165
createNodeImplicit(_node, getProductRootPath(), nodeHost);
@@ -205,8 +207,9 @@ private void validateInstanceDirUnique() throws CommandException {
205207
RemoteCLICommand rc = new RemoteCLICommand("list-instances", this.programOpts, this.env);
206208
String returnOutput =
207209
rc.executeAndReturnOutput("list-instances", "--nostatus", _node);
208-
if (returnOutput == null)
210+
if (returnOutput == null) {
209211
return;
212+
}
210213
String[] registeredInstanceNamesOnThisNode = returnOutput.split("\r?\n");
211214
for (String registeredInstanceName : registeredInstanceNamesOnThisNode) {
212215
File instanceListDir = new File(nodeDirChild, registeredInstanceName);
@@ -245,25 +248,25 @@ private int bootstrapSecureAdminFiles() throws CommandException {
245248
* @throws CommandException
246249
*/
247250
private void saveMasterPassword() throws CommandException {
248-
masterPasswordOption = new ParamModelData(CLIConstants.MASTER_PASSWORD,
249-
String.class, false, null);
251+
masterPasswordOption = new ParamModelData(CLIConstants.MASTER_PASSWORD, String.class, false, null);
250252
masterPasswordOption.prompt = Strings.get("MasterPassword");
251253
masterPasswordOption.promptAgain = Strings.get("MasterPasswordAgain");
252254
masterPasswordOption.param._password = true;
253-
if (saveMasterPassword)
255+
if (saveMasterPassword) {
254256
useMasterPassword = true;
255-
if (useMasterPassword)
256-
masterPassword = getPassword(masterPasswordOption,
257-
DEFAULT_MASTER_PASSWORD, true) != null ? new String(getPassword(masterPasswordOption,
258-
DEFAULT_MASTER_PASSWORD, true)) : null;
259-
if (masterPassword == null)
260-
masterPassword = DEFAULT_MASTER_PASSWORD;
257+
}
258+
if (useMasterPassword) {
259+
char[] password = getPassword(masterPasswordOption, KEYSTORE_PASSWORD_DEFAULT, true);
260+
masterPassword = password == null ? null : new String(password);
261+
}
262+
if (masterPassword == null) {
263+
masterPassword = KEYSTORE_PASSWORD_DEFAULT;
264+
}
261265

262266
if (saveMasterPassword) {
263267
File mp = new File(new File(getServerDirs().getServerDir(), "config"), "keystore.jks");
264268
if (mp.canRead()) {
265269
if (verifyMasterPassword(masterPassword)) {
266-
267270
createMasterPasswordFile(masterPassword);
268271
} else {
269272
logger.info(Strings.get("masterPasswordIncorrect"));
@@ -297,14 +300,17 @@ protected void createMasterPasswordFile(String masterPassword) throws CommandExc
297300

298301
protected void chmod(String args, File file) throws IOException {
299302
if (OS.isUNIX()) {
300-
if (!file.exists()) throw new IOException(Strings.get("fileNotFound", file.getAbsolutePath()));
303+
if (!file.exists()) {
304+
throw new IOException(Strings.get("fileNotFound", file.getAbsolutePath()));
305+
}
301306

302307
// " +" regular expression for 1 or more spaces
303308
final String[] argsString = args.split(" +");
304309
List<String> cmdList = new ArrayList<String>();
305310
cmdList.add("/bin/chmod");
306-
for (String arg : argsString)
311+
for (String arg : argsString) {
307312
cmdList.add(arg);
313+
}
308314
cmdList.add(file.getAbsolutePath());
309315
new ProcessBuilder(cmdList).start();
310316
}

0 commit comments

Comments
 (0)