-
Notifications
You must be signed in to change notification settings - Fork 61
#1552: add certificates to truststore #1789
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
hohwille
merged 32 commits into
devonfw:main
from
MarvMa:feature/#1552-add-certificates-to-truststore
Apr 7, 2026
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
5b8f1d5
#1750: added Updater for golang support
MarvMa a13c169
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MarvMa 4f72ebe
#1751: create Go commandlet
MarvMa 16b6a0e
#1751: remove wrongly committed files
MarvMa e2da970
#1751: added Go tag, fixed naming and added go to the commandletManger
MarvMa 2e39d2f
#1751: added tool installation for go
MarvMa 4945197
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MarvMa 0fe2b3d
#1751: implemented go installation
MarvMa 4a4f561
#1751: updated implementation of go installation, added tests and doc…
MarvMa e20a599
#1751: added go-lang support for cli to changelog
MarvMa 10f9880
#1687: added argument to suppress native warning
MarvMa 92b1726
merge
MarvMa dd0067a
Merge branch 'main' into feature/#1687-fix-JLine-warning
hohwille 0905a1f
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MarvMa 189ed57
#1687: updated changelog
MarvMa 5779788
#1552: integrated a truststore commandlet to create a custom truststore
MarvMa a4d5fdc
#1552: integrated a truststore commandlet to create a custom truststore
MarvMa 3736c9c
#1552: added tests, description for the commandlet and remove changab…
MarvMa e63fc70
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MarvMa 61b29a8
#1552: added tests for truststore cmdlet
MarvMa 22b773a
#1552: update changelog
MarvMa a937aac
#1552: log information if certificate related exception occurs
MarvMa 72a5eb1
#1552: applied requested PR changes
MarvMa ea6dc23
#1552: updated test
MarvMa 2dbe39d
#1552: update test
MarvMa ecdb045
Merge branch 'main' into feature/#1552-add-certificates-to-truststore
hohwille acece02
Merge branch 'main' of https://github.com/devonfw/IDEasy into feature…
MarvMa fe95ff8
Merge branch 'feature/#1552-add-certificates-to-truststore' of https:…
MarvMa f8e194e
#1552: requested changes from pr
MarvMa 4e0f71e
Merge branch 'main' into feature/#1552-add-certificates-to-truststore
hohwille bc30f54
Update cli/src/main/java/com/devonfw/tools/ide/network/NetworkStatusI…
MarvMa d94dcce
fixed CHANGELOG
hohwille File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
cli/src/main/java/com/devonfw/tools/ide/commandlet/TruststoreCommandlet.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,203 @@ | ||
| package com.devonfw.tools.ide.commandlet; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.Arrays; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.devonfw.tools.ide.cli.CliException; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.environment.EnvironmentVariables; | ||
| import com.devonfw.tools.ide.environment.EnvironmentVariablesType; | ||
| import com.devonfw.tools.ide.log.IdeLogLevel; | ||
| import com.devonfw.tools.ide.property.StringProperty; | ||
| import com.devonfw.tools.ide.util.TruststoreUtil; | ||
|
|
||
| /** | ||
| * {@link Commandlet} to fix the TLS problem for VPN users. | ||
| */ | ||
| public class TruststoreCommandlet extends Commandlet { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TruststoreCommandlet.class); | ||
|
|
||
| private static final String IDE_OPTIONS = "IDE_OPTIONS"; | ||
|
|
||
| private static final String TRUSTSTORE_OPTION_PREFIX = "-Djavax.net.ssl.trustStore="; | ||
|
|
||
| private static final String TRUSTSTORE_PASSWORD_OPTION_PREFIX = "-Djavax.net.ssl.trustStorePassword="; | ||
|
|
||
| private final StringProperty url; | ||
|
|
||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the {@link IdeContext}. | ||
| */ | ||
| public TruststoreCommandlet(IdeContext context) { | ||
| super(context); | ||
| addKeyword(getName()); | ||
| this.url = add(new StringProperty("", false, "url")); | ||
| } | ||
|
|
||
| @Override | ||
| public String getName() { | ||
| return "fix-vpn-tls-problem"; | ||
| } | ||
|
|
||
hohwille marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @Override | ||
| public boolean isIdeHomeRequired() { | ||
| return false; | ||
| } | ||
|
|
||
| /** | ||
| * This commandlet tries to fix TLS problems for VPN users by capturing the untrusted certificate from the target endpoint and adding it to a custom | ||
| * truststore. It also configures IDE_OPTIONS to use the custom truststore by default. The commandlet is idempotent and will not make changes if the endpoint | ||
| * is already reachable or if the certificate is already trusted. | ||
| * <p> | ||
| * The flow is as follows: | ||
| * <ul> | ||
| * <li>Parse the input URL/host and port.</li> | ||
| * <li>Check if a custom truststore already exists and can establish a TLS connection to the endpoint. If yes, exit successfully.</li> | ||
| * <li>Check if the endpoint is reachable without any certificate changes. If yes, exit successfully.</li> | ||
| * <li>Try to capture the server certificate from the endpoint. If it fails, log an error and exit.</li> | ||
| * <li>Show the captured certificate details to the user and ask if they want to add it to the custom truststore.</li> | ||
| * <li>If the user agrees, ask for a password for the custom truststore and create/update it with the captured certificate.</li> | ||
| * <li>Configure IDE_OPTIONS to use the custom truststore by default.</li> | ||
| * <li>Check if the endpoint is now reachable with the custom truststore and log the result.</li> | ||
| * </ul> | ||
| */ | ||
| @Override | ||
| protected void doRun() { | ||
|
|
||
| String endpointInput = this.url.getValueAsString(); | ||
| boolean defaultUrlUsed = false; | ||
|
|
||
| if (endpointInput == null || endpointInput.isBlank()) { | ||
| endpointInput = "https://www.github.com"; | ||
| defaultUrlUsed = true; | ||
| } | ||
|
|
||
| TruststoreUtil.TlsEndpoint endpoint; | ||
| try { | ||
| endpoint = TruststoreUtil.parseTlsEndpoint(endpointInput); | ||
| } catch (IllegalArgumentException e) { | ||
| throw new CliException("Invalid target URL/host '" + endpointInput + "': " + e.getMessage(), e); | ||
| } | ||
|
|
||
| String host = endpoint.host(); | ||
| int port = endpoint.port(); | ||
| Path customTruststorePath = this.context.getUserHomeIde().resolve("truststore").resolve("truststore.p12"); | ||
|
|
||
| if (TruststoreUtil.isTruststorePresent(customTruststorePath) && TruststoreUtil.isReachable(host, port, customTruststorePath)) { | ||
| IdeLogLevel.SUCCESS.log(LOG, "TLS handshake succeeded with existing custom truststore at {}.", customTruststorePath); | ||
| configureIdeOptions(customTruststorePath); | ||
| return; | ||
| } | ||
|
|
||
| if (TruststoreUtil.isReachable(host, port)) { | ||
| IdeLogLevel.SUCCESS.log(LOG, "Successfully connected to {}:{} without certificate changes.", host, port); | ||
| LOG.info("No truststore update is required for the given address."); | ||
| if (defaultUrlUsed) { | ||
| LOG.info( | ||
| "If the issue still occurs try to call the command again and add the url that is causing the problem to the command: \n ide fix-vpn-tls-problem <url>"); | ||
| } | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| LOG.info("The given address {}:{} is not reachable/valid without certificate changes. Continuing with certificate capture.", host, port); | ||
|
|
||
| X509Certificate certificate; | ||
| try { | ||
| certificate = TruststoreUtil.fetchServerCertificate(host, port); | ||
| } catch (Exception e) { | ||
| LOG.error("Failed to capture certificate from {}:{}.", host, port, e); | ||
| IdeLogLevel.INTERACTION.log(LOG, | ||
| "Please check proxy/VPN and retry. You can also follow: https://github.com/devonfw/IDEasy/blob/main/documentation/proxy-support.adoc#tls-certificate-issues"); | ||
| return; | ||
| } | ||
|
|
||
| LOG.info("Captured untrusted certificate:"); | ||
| LOG.info(TruststoreUtil.describeCertificate(certificate)); | ||
|
|
||
| boolean addToTruststore = this.context.question("Do you want to add this certificate to the custom truststore at {}?", customTruststorePath); | ||
|
|
||
| if (!addToTruststore) { | ||
| LOG.info("Skipped truststore update by user choice."); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| TruststoreUtil.createOrUpdateTruststore(customTruststorePath, certificate, "custom"); | ||
| IdeLogLevel.SUCCESS.log(LOG, "Custom truststore updated at {}", customTruststorePath); | ||
| } catch (Exception e) { | ||
| LOG.error("Failed to create or update custom truststore at {}", customTruststorePath, e); | ||
| return; | ||
| } | ||
|
|
||
| configureIdeOptions(customTruststorePath); | ||
|
|
||
| if (TruststoreUtil.isReachable(host, port, customTruststorePath)) { | ||
| IdeLogLevel.SUCCESS.log(LOG, "TLS handshake succeeded with custom truststore."); | ||
| } else { | ||
| LOG.warn("TLS handshake still fails even with custom truststore."); | ||
| } | ||
| } | ||
|
|
||
| private void configureIdeOptions(Path customTruststorePath) { | ||
| String truststorePath = customTruststorePath.toAbsolutePath().toString(); | ||
| String truststoreOption = TRUSTSTORE_OPTION_PREFIX + truststorePath; | ||
| String truststorePasswordOption = TRUSTSTORE_PASSWORD_OPTION_PREFIX + Arrays.toString(TruststoreUtil.CUSTOM_TRUSTSTORE_PASSWORD); | ||
|
|
||
| EnvironmentVariables confVariables = this.context.getVariables().getByType(EnvironmentVariablesType.USER); | ||
|
|
||
| if (confVariables == null) { | ||
| IdeLogLevel.INTERACTION.log(LOG, "Please configure IDE_OPTIONS manually: {} {}", truststoreOption, truststorePasswordOption); | ||
| return; | ||
| } | ||
|
|
||
| String options = confVariables.getFlat(IDE_OPTIONS); | ||
| options = removeOptionWithPrefix(options, TRUSTSTORE_OPTION_PREFIX); | ||
| options = removeOptionWithPrefix(options, TRUSTSTORE_PASSWORD_OPTION_PREFIX); | ||
| options = appendOption(options, truststoreOption); | ||
| options = appendOption(options, truststorePasswordOption); | ||
|
|
||
| try { | ||
| confVariables.set(IDE_OPTIONS, options, true); | ||
| confVariables.save(); | ||
| // Apply directly for the current process as well. | ||
| System.setProperty("javax.net.ssl.trustStore", truststorePath); | ||
| System.setProperty("javax.net.ssl.trustStorePassword", Arrays.toString(TruststoreUtil.CUSTOM_TRUSTSTORE_PASSWORD)); | ||
| IdeLogLevel.SUCCESS.log(LOG, "IDE_OPTIONS configured to use custom truststore by default."); | ||
| } catch (UnsupportedOperationException e) { | ||
| IdeLogLevel.INTERACTION.log(LOG, "Please configure IDE_OPTIONS manually: {} {}", truststoreOption, truststorePasswordOption); | ||
| } | ||
| } | ||
|
|
||
| private static String removeOptionWithPrefix(String options, String prefix) { | ||
| if ((options == null) || options.isBlank()) { | ||
| return ""; | ||
| } | ||
| StringBuilder result = new StringBuilder(); | ||
| String[] tokens = options.trim().split("\\s+"); | ||
| for (String token : tokens) { | ||
| if (!token.startsWith(prefix)) { | ||
| if (!result.isEmpty()) { | ||
| result.append(' '); | ||
| } | ||
| result.append(token); | ||
| } | ||
| } | ||
| return result.toString(); | ||
| } | ||
|
|
||
| private static String appendOption(String options, String option) { | ||
| if ((options == null) || options.isBlank()) { | ||
| return option; | ||
| } | ||
| return options + " " + option; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.