Skip to content

feat(lsp): respect IDE user proxy settings / forward trust store #5553

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
merged 19 commits into from
May 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.intellij.openapi.util.SystemInfo
import com.intellij.util.animation.consumer
import com.intellij.util.io.await
import com.intellij.util.net.HttpConfigurable

Check failure on line 24 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal
import com.intellij.util.net.JdkProxyProvider
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.async
Expand All @@ -29,6 +31,7 @@
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import kotlinx.coroutines.withTimeout
import org.apache.http.client.utils.URIBuilder
import org.eclipse.lsp4j.ClientCapabilities
import org.eclipse.lsp4j.ClientInfo
import org.eclipse.lsp4j.DidChangeConfigurationParams
Expand All @@ -48,6 +51,7 @@
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.info
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.core.utils.writeText
import software.aws.toolkits.jetbrains.isDeveloperMode
import software.aws.toolkits.jetbrains.services.amazonq.lsp.artifacts.ArtifactManager
import software.aws.toolkits.jetbrains.services.amazonq.lsp.auth.DefaultAuthCredentialsService
Expand All @@ -60,6 +64,7 @@
import software.aws.toolkits.jetbrains.services.amazonq.lsp.textdocument.TextDocumentServiceHandler
import software.aws.toolkits.jetbrains.services.amazonq.lsp.util.WorkspaceFolderUtil.createWorkspaceFolders
import software.aws.toolkits.jetbrains.services.amazonq.lsp.workspace.WorkspaceServiceHandler
import software.aws.toolkits.jetbrains.services.amazonq.profile.QDefaultServiceConfig
import software.aws.toolkits.jetbrains.services.telemetry.ClientMetadata
import software.aws.toolkits.jetbrains.settings.LspSettings
import java.io.IOException
Expand All @@ -68,7 +73,10 @@
import java.io.PipedOutputStream
import java.io.PrintWriter
import java.io.StringWriter
import java.net.Proxy
import java.net.URI
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.util.Collections
import java.util.concurrent.Future
import kotlin.time.Duration.Companion.seconds
Expand Down Expand Up @@ -263,13 +271,49 @@
init {
// will cause slow service init, but maybe fine for now. will not block UI since fetch/extract will be under background progress
val artifact = runBlocking { service<ArtifactManager>().fetchArtifact(project) }.toAbsolutePath()

// more network calls
// make assumption that all requests will resolve to the same CA
// also terrible assumption that default endpoint is reachable
val qUri = URI(QDefaultServiceConfig.ENDPOINT)
val rtsTrustChain = TrustChainUtil.getTrustChain(qUri)
val extraCaCerts = Files.createTempFile("q-extra-ca", ".pem").apply {
writeText(
TrustChainUtil.certsToPem(rtsTrustChain)

Check warning on line 282 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L278-L282

Added lines #L278 - L282 were not covered by tests
)
}

Check warning on line 284 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L284

Added line #L284 was not covered by tests

val node = if (SystemInfo.isWindows) "node.exe" else "node"
val cmd = GeneralCommandLine(
artifact.resolve(node).toString(),
LspSettings.getInstance().getArtifactPath() ?: artifact.resolve("aws-lsp-codewhisperer.js").toString(),
"--stdio",
"--set-credentials-encryption-key",
).withEnvironment(
buildMap {
put("NODE_EXTRA_CA_CERTS", extraCaCerts.toAbsolutePath().toString())

Check warning on line 294 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L292-L294

Added lines #L292 - L294 were not covered by tests

val proxy = JdkProxyProvider.getInstance().proxySelector.select(qUri)

Check warning on line 296 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L296

Added line #L296 was not covered by tests
// log if only socks proxy available
.firstOrNull { it.type() == Proxy.Type.HTTP }

if (proxy != null) {
val address = proxy.address()

Check warning on line 301 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L301

Added line #L301 was not covered by tests
if (address is java.net.InetSocketAddress) {
put(
"HTTPS_PROXY",
URIBuilder("http://${address.hostName}:${address.port}").apply {
val login = HttpConfigurable.getInstance().proxyLogin

Check failure on line 306 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'getProxyLogin()' is deprecated and marked for removal

Check failure on line 306 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure on line 306 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check warning on line 306 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L303-L306

Added lines #L303 - L306 were not covered by tests

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'getProxyLogin()' is deprecated and marked for removal
if (login != null) {
setUserInfo(login, HttpConfigurable.getInstance().plainProxyPassword)

Check failure on line 308 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure on line 308 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'getPlainProxyPassword()' is deprecated and marked for removal

Check failure on line 308 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Usage of API marked for removal

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check warning on line 308 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L308

Added line #L308 was not covered by tests

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'com.intellij.util.net.HttpConfigurable' is deprecated and marked for removal

Check failure

Code scanning / QDJVMC

Usage of API marked for removal Error

'getPlainProxyPassword()' is deprecated and marked for removal
}
}.build().toASCIIString()

Check warning on line 310 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L310

Added line #L310 was not covered by tests
)
}
}
}

Check warning on line 314 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L314

Added line #L314 was not covered by tests
)
.withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE)

Check warning on line 316 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/AmazonQLspService.kt#L316

Added line #L316 was not covered by tests

launcherHandler = KillableColoredProcessHandler.Silent(cmd)
val inputWrapper = LSPProcessListener()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
// Copyright 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package software.aws.toolkits.jetbrains.services.amazonq.lsp

import com.intellij.util.io.DigestUtil
import com.intellij.util.net.JdkProxyProvider
import com.intellij.util.net.ssl.CertificateManager
import org.apache.http.client.methods.RequestBuilder
import org.apache.http.conn.ssl.DefaultHostnameVerifier
import org.apache.http.impl.client.HttpClientBuilder
import org.apache.http.impl.client.SystemDefaultCredentialsProvider
import org.apache.http.impl.conn.SystemDefaultRoutePlanner
import org.jetbrains.annotations.TestOnly
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
import java.net.URI
import java.security.KeyStore
import java.security.cert.CertPathBuilder
import java.security.cert.CertStore
import java.security.cert.Certificate
import java.security.cert.CollectionCertStoreParameters
import java.security.cert.PKIXBuilderParameters
import java.security.cert.PKIXCertPathBuilderResult
import java.security.cert.X509CertSelector
import java.security.cert.X509Certificate
import java.util.Base64
import kotlin.collections.ifEmpty

object TrustChainUtil {
private val LOG = getLogger<TrustChainUtil>()

Check warning on line 31 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L31

Added line #L31 was not covered by tests

@TestOnly
fun resolveTrustChain(certs: Collection<X509Certificate>, trustAnchors: Collection<X509Certificate>) = resolveTrustChain(
certs,
keystoreFromCertificates(trustAnchors)
)

Check warning on line 37 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L34-L37

Added lines #L34 - L37 were not covered by tests

/**
* Build and validate the complete certificate chain
* @param certs The end-entity certificate
* @param trustAnchors The truststore containing trusted CA certificates
* @return The complete certificate chain
*/
fun resolveTrustChain(certs: Collection<X509Certificate>, trustAnchors: KeyStore): List<X509Certificate> {
try {

Check warning on line 46 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L46

Added line #L46 was not covered by tests
// Create the selector for the certificate
val selector = X509CertSelector()
selector.certificate = certs.first()

Check warning on line 49 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L48-L49

Added lines #L48 - L49 were not covered by tests

// Create the parameters for path validation
val pkixParams = PKIXBuilderParameters(trustAnchors, selector)

Check warning on line 52 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L52

Added line #L52 was not covered by tests

// Disable CRL checking since we just want to build the path
pkixParams.isRevocationEnabled = false

Check warning on line 55 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L55

Added line #L55 was not covered by tests

// Create a CertStore containing the certificate we want to validate
val ccsp = CollectionCertStoreParameters(certs)
val certStore = CertStore.getInstance("Collection", ccsp)
pkixParams.addCertStore(certStore)

Check warning on line 60 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L58-L60

Added lines #L58 - L60 were not covered by tests

// Get the certification path
val builder = CertPathBuilder.getInstance("PKIX")
val result = builder.build(pkixParams) as PKIXCertPathBuilderResult
val certPath = result.certPath
val chain = (certPath.certificates as List<X509Certificate>).toMutableList()

Check warning on line 66 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L63-L66

Added lines #L63 - L66 were not covered by tests

// Add the trust anchor (root CA) to complete the chain
val trustAnchorCert = result.trustAnchor.trustedCert

Check warning on line 69 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L69

Added line #L69 was not covered by tests
if (trustAnchorCert != null) {
chain.add(trustAnchorCert)

Check warning on line 71 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L71

Added line #L71 was not covered by tests
}

return chain
} catch (e: Exception) {

Check warning on line 75 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L74-L75

Added lines #L74 - L75 were not covered by tests
// Java PKIX is happy with leaf cert in certification path, but Node.JS will not respect in NODE_CA_CERTS
LOG.warn(e) { "Could not build trust anchor via CertPathBuilder? maybe user accepted leaf cert but not intermediate" }

Check warning on line 77 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L77

Added line #L77 was not covered by tests

return emptyList()

Check warning on line 79 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L79

Added line #L79 was not covered by tests
}
}

fun getTrustChain(uri: URI): List<X509Certificate> {
val proxyProvider = JdkProxyProvider.getInstance()
var peerCerts: Array<Certificate> = emptyArray()
val verifierDelegate = DefaultHostnameVerifier()
val client = HttpClientBuilder.create()
.setRoutePlanner(SystemDefaultRoutePlanner(proxyProvider.proxySelector))
.setDefaultCredentialsProvider(SystemDefaultCredentialsProvider())
.setSSLHostnameVerifier { hostname, sslSession ->
peerCerts = sslSession.peerCertificates

Check warning on line 91 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L84-L91

Added lines #L84 - L91 were not covered by tests

verifierDelegate.verify(hostname, sslSession)

Check warning on line 93 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L93

Added line #L93 was not covered by tests
}
// prompt user via modal to accept certificate if needed; otherwise need to prompt separately prior to launching flare
.setSSLContext(CertificateManager.getInstance().sslContext)

Check warning on line 96 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L96

Added line #L96 was not covered by tests

// client request will fail if user did not accept cert
client.build().use { it.execute(RequestBuilder.options(uri).build()) }

Check warning on line 99 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L99

Added line #L99 was not covered by tests

val certificates = peerCerts as Array<X509Certificate>

Check warning on line 101 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L101

Added line #L101 was not covered by tests

// java default + custom system
// excluding leaf cert for case where user has both leaf and issuing CA as trusted roots
val allAccepted = CertificateManager.getInstance().trustManager.acceptedIssuers.toSet() - certificates.first()
val ks = keystoreFromCertificates(allAccepted)

Check warning on line 106 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L105-L106

Added lines #L105 - L106 were not covered by tests

// if this throws then there is a bug because it passed PKIX validation in apache client
val trustChain = try {
resolveTrustChain(certificates.toList(), ks)
} catch (e: Exception) {

Check warning on line 111 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L109-L111

Added lines #L109 - L111 were not covered by tests
// Java PKIX is happy with leaf cert in certification path, but Node.JS will not respect in NODE_CA_CERTS
LOG.warn(e) { "Passed Apache PKIX verification but could not build trust anchor via CertPathBuilder? maybe user accepted leaf cert but not root" }
emptyList()

Check warning on line 114 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L113-L114

Added lines #L113 - L114 were not covered by tests
}

// if trust chain is empty, then somehow user only trusts the leaf cert???
return trustChain.ifEmpty {
// so return the served certificate chain from the server and hope that works
certificates.toList()

Check warning on line 120 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L120

Added line #L120 was not covered by tests
}
}

fun certsToPem(certs: List<X509Certificate>): String =
buildList {
certs.forEach {
add("-----BEGIN CERTIFICATE-----")
add(Base64.getMimeEncoder(64, System.lineSeparator().toByteArray()).encodeToString(it.encoded))
add("-----END CERTIFICATE-----")
}
}.joinToString(separator = System.lineSeparator())

Check warning on line 131 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L125-L131

Added lines #L125 - L131 were not covered by tests

private fun keystoreFromCertificates(certificates: Collection<X509Certificate>): KeyStore {
val ks = KeyStore.getInstance(KeyStore.getDefaultType())
ks.load(null, null)
certificates.forEachIndexed { index, cert ->
ks.setCertificateEntry(
cert.subjectX500Principal.toString() + "-" + DigestUtil.sha256Hex(cert.encoded),
cert

Check warning on line 139 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L134-L139

Added lines #L134 - L139 were not covered by tests
)
}
return ks

Check warning on line 142 in plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt

View check run for this annotation

Codecov / codecov/patch

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/lsp/TrustChainUtil.kt#L141-L142

Added lines #L141 - L142 were not covered by tests
}
}
Loading
Loading