-
Notifications
You must be signed in to change notification settings - Fork 10
Pass IDE trusted system certs to Language server by default #482
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| import java.io.IOException; | ||
| import java.io.InputStreamReader; | ||
| import java.io.OutputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Paths; | ||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
|
|
@@ -58,13 +59,14 @@ public QLspConnectionProvider() throws IOException { | |
| @Override | ||
| protected final void addEnvironmentVariables(final Map<String, String> env) { | ||
| String httpsProxyUrl = ProxyUtil.getHttpsProxyUrl(); | ||
| String caCertPreference = Activator.getDefault().getPreferenceStore().getString(AmazonQPreferencePage.CA_CERT); | ||
| String caCertPath = getCaCert(); | ||
|
|
||
| if (!StringUtils.isEmpty(httpsProxyUrl)) { | ||
| env.put("HTTPS_PROXY", httpsProxyUrl); | ||
| } | ||
| if (!StringUtils.isEmpty(caCertPreference)) { | ||
| env.put("NODE_EXTRA_CA_CERTS", caCertPreference); | ||
| env.put("AWS_CA_BUNDLE", caCertPreference); | ||
| if (!StringUtils.isEmpty(caCertPath)) { | ||
| env.put("NODE_EXTRA_CA_CERTS", caCertPath); | ||
| env.put("AWS_CA_BUNDLE", caCertPath); | ||
| } | ||
| if (ArchitectureUtils.isWindowsArm()) { | ||
| env.put("DISABLE_INDEXING_LIBRARY", "true"); | ||
|
|
@@ -78,6 +80,28 @@ protected final void addEnvironmentVariables(final Map<String, String> env) { | |
| } | ||
| } | ||
|
|
||
| private String getCaCert() { | ||
| String caCertPreference = Activator.getDefault().getPreferenceStore().getString(AmazonQPreferencePage.CA_CERT); | ||
| if (!StringUtils.isEmpty(caCertPreference)) { | ||
| Activator.getLogger().info("Using user-defined CA cert: " + caCertPreference); | ||
| return caCertPreference; | ||
| } | ||
|
|
||
| try { | ||
| String pemContent = ProxyUtil.getCertificatesAsPem(); | ||
| if (StringUtils.isEmpty(pemContent)) { | ||
| return null; | ||
| } | ||
| Activator.getLogger().info("Injecting IDE trusted certificates into NODE_EXTRA_CA_CERTS"); | ||
|
||
| var tempPath = Files.createTempFile("eclipse-q-extra-ca", ".pem"); | ||
| Files.write(tempPath, pemContent.getBytes()); | ||
| return tempPath.toString(); | ||
| } catch (Exception e) { | ||
| Activator.getLogger().warn("Could not create temp CA cert file", e); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| private boolean needsPatchEnvVariables() { | ||
| return PluginUtils.getPlatform().equals(PluginPlatform.MAC); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,8 @@ | |
| import java.security.KeyStore; | ||
| import java.security.cert.CertificateFactory; | ||
| import java.security.cert.X509Certificate; | ||
| import java.util.ArrayList; | ||
| import java.util.Base64; | ||
|
|
||
| import javax.net.ssl.SSLContext; | ||
| import javax.net.ssl.TrustManager; | ||
|
|
@@ -190,6 +192,47 @@ private static SSLContext createSslContextWithCustomCert(final String certPath) | |
| return sslContext; | ||
| } | ||
|
|
||
| public static String getCertificatesAsPem() { | ||
| var certs = getSystemCertificates(); | ||
| if (certs.isEmpty()) { | ||
| return null; | ||
| } | ||
|
|
||
| var pemEntries = new ArrayList<String>(); | ||
| var encoder = Base64.getMimeEncoder(64, System.lineSeparator().getBytes()); | ||
|
|
||
| for (var cert : certs) { | ||
| try { | ||
| String encodedCert = encoder.encodeToString(cert.getEncoded()); | ||
| pemEntries.add("-----BEGIN CERTIFICATE-----"); | ||
| pemEntries.add(encodedCert); | ||
| pemEntries.add("-----END CERTIFICATE-----"); | ||
| } catch (Exception e) { | ||
| Activator.getLogger().error("Failed to encode certificate", e); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe skip the cert instead of giving up There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This already does that since the try-catch is within the for loop |
||
| } | ||
| } | ||
| return String.join(System.lineSeparator(), pemEntries); | ||
| } | ||
|
|
||
| public static ArrayList<X509Certificate> getSystemCertificates() { | ||
| try { | ||
| var tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); | ||
| tmf.init((KeyStore) null); | ||
| var certs = new ArrayList<X509Certificate>(); | ||
| for (var tm : tmf.getTrustManagers()) { | ||
| if (tm instanceof X509TrustManager xtm) { | ||
| for (var cert : xtm.getAcceptedIssuers()) { | ||
| certs.add(cert); | ||
| } | ||
| } | ||
| } | ||
| return certs; | ||
| } catch (Exception e) { | ||
| Activator.getLogger().error("Failed to get system certificates", e); | ||
| return new ArrayList<>(); | ||
| } | ||
| } | ||
|
|
||
| static synchronized ProxySelector getProxySelector() { | ||
| if (proxySelector == null) { | ||
| ProxySearch proxySearch = new ProxySearch(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably fine, but since eclipse does not really have dynamic certificate mutation it is probably safe to make one copy for the IDE session