Skip to content

Commit

Permalink
Update installer to set truststore.
Browse files Browse the repository at this point in the history
  • Loading branch information
josejulio committed Mar 7, 2017
1 parent 8fe34a4 commit 57ee3b0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -259,18 +259,16 @@ public static void main(String[] args) throws Exception {
// info is supplied, the user must know he isn't going to be using https so allow that to happen).
String keystorePath = installerConfig.getKeystorePath();
String keystorePass = installerConfig.getKeystorePassword();
String keyPass = installerConfig.getKeyPassword();
String keyAlias = installerConfig.getKeyAlias();

// If protocol is explicitly defined as https, this if-stmt merely performs some helpful things
// like abort to remind the user to provide required keystore info.
// If we cannot tell if https is to be used, we keep going but these helpful things
// are not performed and the user must ensure they provide this information if they expect to use https.
if (hawkularServerProtocol.equals("https")) {
if (keystorePath == null || keyAlias == null) {
if (keystorePath == null) {
throw new Exception(String.format("When using https protocol, the following keystore "
+ "command line options are required: %s, %s",
InstallerConfiguration.OPTION_KEYSTORE_PATH, InstallerConfiguration.OPTION_KEY_ALIAS));
+ "command line option is required: %s",
InstallerConfiguration.OPTION_KEYSTORE_PATH));
}
}

Expand All @@ -285,14 +283,6 @@ public static void main(String[] args) throws Exception {
+ " was not provided; using empty password");
}
}
if (keyPass == null) {
keyPass = readPasswordFromStdin("Key password:");
if (keyPass == null || keyPass.isEmpty()) {
keyPass = "";
log.warn(InstallerConfiguration.OPTION_KEY_PASSWORD
+ " was not provided; using empty password");
}
}

File keystoreSrcFile = new File(keystorePath);
if (!(keystoreSrcFile.isFile() && keystoreSrcFile.canRead())) {
Expand All @@ -314,7 +304,7 @@ public static void main(String[] args) throws Exception {
Files.copy(Paths.get(keystoreSrcFile.getAbsolutePath()), keystoreDst);
}

String securityRealm = createSecurityRealm(keystoreSrcFile.getName(), keystorePass, keyPass, keyAlias);
String securityRealm = createSecurityRealm(keystoreSrcFile.getName(), keystorePass);
configurationBldr.addXmlEdit(new XmlEdit(targetConfigInfo.getSecurityRealmsXPath(), securityRealm));
}

Expand Down Expand Up @@ -381,20 +371,15 @@ private static String readPasswordFromStdin(String message) {
*
* @param keystoreFile location of the keystore file
* @param keystorePass the password to access the keystore file
* @param keyPass the password to access the data for the given alias
* @param keyAlias the alias specifying the identifying security information
* @return XML snippet
*/
private static String createSecurityRealm(String keystoreFile, String keystorePass,
String keyPass, String keyAlias) {
private static String createSecurityRealm(String keystoreFile, String keystorePass) {
return new StringBuilder("<security-realm name=\"" + SECURITY_REALM_NAME + "\">")
.append("<server-identities><ssl>")
.append("<keystore path=\"" + keystoreFile + "\"")
.append("<authentication>")
.append("<truststore path=\"" + keystoreFile + "\"")
.append(" relative-to=\"jboss.server.config.dir\"")
.append(" keystore-password=\"" + keystorePass + "\"")
.append(" key-password=\"" + keyPass + "\"")
.append(" alias=\"" + keyAlias + "\"")
.append(" /></ssl></server-identities></security-realm>").toString();
.append(" /></authentication></security-realm>").toString();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ public class InstallerConfiguration {
static final String OPTION_DOWNLOAD_SERVER_URL = "download-server-url";
static final String OPTION_KEYSTORE_PATH = "keystore-path";
static final String OPTION_KEYSTORE_PASSWORD = "keystore-password";
static final String OPTION_KEY_PASSWORD = "key-password";
static final String OPTION_KEY_ALIAS = "key-alias";
static final String OPTION_USERNAME = "username";
static final String OPTION_PASSWORD = "password";
static final String OPTION_MANAGED_SERVER_NAME = "managed-server-name";
Expand Down Expand Up @@ -208,20 +206,6 @@ static ProcessedCommand<?> buildCommandLineOptions() throws Exception {
.description("Keystore password. When " + InstallerConfiguration.OPTION_SERVER_URL
+ " protocol is https and this option is not passed, installer will ask for password")
.create());
cmd.addOption(new ProcessedOptionBuilder()
.name(InstallerConfiguration.OPTION_KEY_PASSWORD)
.optionType(OptionType.NORMAL)
.type(String.class)
.description("Key password. When " + InstallerConfiguration.OPTION_SERVER_URL
+ " protocol is https and this option is not passed, installer will ask for password")
.create());
cmd.addOption(new ProcessedOptionBuilder()
.name(InstallerConfiguration.OPTION_KEY_ALIAS)
.optionType(OptionType.NORMAL)
.type(String.class)
.description("Key alias. Required when " + InstallerConfiguration.OPTION_SERVER_URL
+ " protocol is https")
.create());
cmd.addOption(new ProcessedOptionBuilder()
.name(InstallerConfiguration.OPTION_USERNAME)
.optionType(OptionType.NORMAL)
Expand Down Expand Up @@ -292,8 +276,6 @@ public InstallerConfiguration(CommandLine<?> commandLine) throws Exception {
setProperty(properties, commandLine, OPTION_DOWNLOAD_SERVER_URL);
setProperty(properties, commandLine, OPTION_KEYSTORE_PATH);
setProperty(properties, commandLine, OPTION_KEYSTORE_PASSWORD);
setProperty(properties, commandLine, OPTION_KEY_PASSWORD);
setProperty(properties, commandLine, OPTION_KEY_ALIAS);
setProperty(properties, commandLine, OPTION_USERNAME);
setProperty(properties, commandLine, OPTION_PASSWORD);
setProperty(properties, commandLine, OPTION_MANAGED_RESOURCE_TYPE_SETS);
Expand All @@ -308,7 +290,6 @@ private void setProperty(Properties props, CommandLine<?> commandLine, String op

public void decodeProperties(String encryptionKey, byte[] salt) throws Exception {
decodeProperty(properties, OPTION_KEYSTORE_PASSWORD, encryptionKey, salt);
decodeProperty(properties, OPTION_KEY_PASSWORD, encryptionKey, salt);
decodeProperty(properties, OPTION_PASSWORD, encryptionKey, salt);
}

Expand Down Expand Up @@ -365,14 +346,6 @@ public String getKeystorePassword() {
return properties.getProperty(OPTION_KEYSTORE_PASSWORD);
}

public String getKeyPassword() {
return properties.getProperty(OPTION_KEY_PASSWORD);
}

public String getKeyAlias() {
return properties.getProperty(OPTION_KEY_ALIAS);
}

public String getUsername() {
return properties.getProperty(OPTION_USERNAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ public void testOverridePropertiesFromArgs() throws Exception {
"--managed-server-name", "MyLocalNameOVERRIDE",
"--keystore-path", "/tmp/OVERRIDE/path",
"--keystore-password", "OVERRIDE-keystore-password",
"--key-password", "OVERRIDE-key-password",
"--key-alias", "OVERRIDE-alias",
"--username", "OVERRIDE-username",
"--password", "OVERRIDE-password",
"--module-dist", "/OVERRIDE/dist.zip",
Expand All @@ -129,8 +127,6 @@ public void testOverridePropertiesFromArgs() throws Exception {
Assert.assertEquals("MyLocalNameOVERRIDE", installerConfig.getManagedServerName());
Assert.assertEquals("/tmp/OVERRIDE/path", installerConfig.getKeystorePath());
Assert.assertEquals("OVERRIDE-keystore-password", installerConfig.getKeystorePassword());
Assert.assertEquals("OVERRIDE-key-password", installerConfig.getKeyPassword());
Assert.assertEquals("OVERRIDE-alias", installerConfig.getKeyAlias());
Assert.assertEquals("OVERRIDE-username", installerConfig.getUsername());
Assert.assertEquals("OVERRIDE-password", installerConfig.getPassword());
Assert.assertEquals("/OVERRIDE/dist.zip", installerConfig.getModuleDistribution());
Expand Down Expand Up @@ -223,8 +219,6 @@ private void assertTestProperties(InstallerConfiguration installerConfig) {
Assert.assertEquals("MyLocalName", installerConfig.getManagedServerName());
Assert.assertEquals("/tmp/test/path", installerConfig.getKeystorePath());
Assert.assertEquals("test-keystore-password", installerConfig.getKeystorePassword());
Assert.assertEquals("test-key-password", installerConfig.getKeyPassword());
Assert.assertEquals("test-alias", installerConfig.getKeyAlias());
Assert.assertEquals("test-username", installerConfig.getUsername());
Assert.assertEquals("test-password", installerConfig.getPassword());
Assert.assertEquals("/test/dist.zip", installerConfig.getModuleDistribution());
Expand Down

0 comments on commit 57ee3b0

Please sign in to comment.