Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Aug 21, 2024
1 parent 945c66c commit 071027a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
14 changes: 12 additions & 2 deletions src/main/java/io/cryostat/agent/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.UUID;
import java.util.function.Predicate;
Expand Down Expand Up @@ -289,6 +290,8 @@ public static Optional<String> provideCryostatAgentWebclientTlsTruststorePassFro
String pass = IOUtils.toString(passFile, Charset.forName(passCharset));
pass = pass.substring(0, pass.length() - 1);
password = Optional.ofNullable(pass);
} catch (NoSuchElementException e) {
return password;
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -325,8 +328,16 @@ public static String provideCryostatAgentWebclientTlsTruststoreType(Config confi
@Singleton
@Named(CRYOSTAT_AGENT_WEBCLIENT_TLS_TRUSTSTORE_CERTS)
public static List<TruststoreConfig> provideCryostatAgentWecblientTlsTruststoreCerts(
Config config) {
Config config,
@Named(CRYOSTAT_AGENT_WEBCLIENT_TLS_TRUSTSTORE_PASS) Optional<String> truststorePass,
@Named(CRYOSTAT_AGENT_WEBCLIENT_TLS_TRUSTSTORE_PATH) Optional<String> truststorePath) {
Map<Integer, TruststoreConfig.Builder> truststoreBuilders = new HashMap<>();
List<TruststoreConfig> truststoreConfigs = new ArrayList<>();

if (!truststorePass.isEmpty() || !truststorePath.isEmpty()) {
return truststoreConfigs;
}

StreamSupport.stream(config.getPropertyNames().spliterator(), false)
.filter(e -> e.startsWith(CRYOSTAT_AGENT_WEBCLIENT_TLS_TRUSTSTORE_CERTS))
.forEach(
Expand Down Expand Up @@ -369,7 +380,6 @@ public static List<TruststoreConfig> provideCryostatAgentWecblientTlsTruststoreC
}
});

List<TruststoreConfig> truststoreConfigs = new ArrayList<>();
for (TruststoreConfig.Builder builder : truststoreBuilders.values()) {
try {
truststoreConfigs.add(builder.build());
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/cryostat/agent/MainModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,13 @@ public X509Certificate[] getAcceptedIssuers() {
ts.load(null, null);

// initialize truststore with user provided path and pass
if (truststorePath.isEmpty() && truststorePass.isEmpty()) {
if (!truststorePath.isEmpty() && !truststorePass.isEmpty()) {
try (InputStream truststore = new FileInputStream(truststorePath.get())) {
ts.load(truststore, truststorePass.get().toCharArray());
} catch (IOException e) {
throw new RuntimeException(e);
}
} else if (truststorePath.isEmpty() || truststorePass.isEmpty()) {
} else if (!truststorePath.isEmpty() || !truststorePass.isEmpty()) {
throw new IllegalArgumentException(
String.format(
"To import a truststore, provide both the path to the truststore"
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/cryostat/agent/TruststoreConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ private TruststoreConfig(Builder builder) {
this.alias =
Objects.requireNonNull(
builder.alias,
"Truststore config properties must include a certificate alias");
"Imported certs for the agent's truststore must include a certificate"
+ " alias");
this.path =
Objects.requireNonNull(
builder.path,
"Truststore config properties must include a certificate path");
"Imported certs for the agent's truststore must include a certificate"
+ " path");
this.type =
Objects.requireNonNull(
builder.type,
"Truststore config properties must include a certificate type");
"Imported certs for the agent's truststore must include a certificate"
+ " type");
}

public String getAlias() {
Expand Down

0 comments on commit 071027a

Please sign in to comment.