Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix(core): read client certificate files without Bun globals
Co-authored-by: Adam <2363879+adamdotdevin@users.noreply.github.com>
  • Loading branch information
rekram1-node and adamdotdevin committed Oct 29, 2026
commit 17a120a86801c9013d103820d1e90b98cc8f4ddf
18 changes: 10 additions & 8 deletions packages/core/src/client-certificate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export const httpClientLayer = Layer.effect(
HttpClient.HttpClient,
Effect.gen(function* () {
const certificates = yield* Service
const fs = yield* FSUtil.Service
const client = yield* HttpClient.HttpClient
return HttpClient.transform(client, (effect, request) =>
Effect.gen(function* () {
Expand All @@ -128,21 +129,22 @@ export const httpClientLayer = Layer.effect(
return yield* fail(
`A client certificate is configured for ${host}, which would also be sent to the HTTPS proxy. Add ${host} to NO_PROXY or use an http:// proxy`,
)
const tls = yield* Effect.all({
cert: fs.readFileString(rule.cert),
key: fs.readFileString(rule.key),
passphrase: rule.passphraseFile
? fs.readFileString(rule.passphraseFile).pipe(Effect.map((text) => text.replace(/[\r\n]+$/, "")))
: Effect.succeed(undefined),
}).pipe(Effect.mapError((error) => fail(`Could not read the client certificate for ${host}: ${error.message}`)))
const fetch = yield* FetchHttpClient.Fetch
return yield* effect.pipe(
Effect.provideService(
FetchHttpClient.Fetch,
Object.assign(
async (input: Parameters<typeof globalThis.fetch>[0], init?: BunFetchRequestInit) =>
(input: Parameters<typeof globalThis.fetch>[0], init?: BunFetchRequestInit) =>
fetch(input, {
...init,
tls: {
...init?.tls,
cert: Bun.file(rule.cert),
key: Bun.file(rule.key),
passphrase:
rule.passphraseFile && (await Bun.file(rule.passphraseFile).text()).replace(/[\r\n]+$/, ""),
},
tls: { ...init?.tls, ...tls },
// Fetch would follow a redirect with the same TLS options, presenting the certificate to whatever
// host the server names. Only callers that handle redirects themselves see the 3xx.
redirect: init?.redirect === "manual" ? "manual" : "error",
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/effect/app-node-platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { FetchHttpClient, HttpClient } from "effect/http"
import { Socket } from "effect/socket"
import { makeGlobalNode } from "@opencode/util/effect/app-node"
import { httpClient } from "@opencode/util/effect/app-node-platform"
import { FSUtil } from "@opencode/util/fs-util"
import { ClientCertificate } from "../client-certificate.js"
import { WebSocketConstructor } from "./websocket-constructor.js"

Expand All @@ -22,7 +23,7 @@ const withoutBunTimeout = Layer.effect(
export const requestExecutor = makeGlobalNode({
service: RequestExecutor.Service,
layer: RequestExecutor.layer.pipe(Layer.provide(withoutBunTimeout), Layer.provide(ClientCertificate.httpClientLayer)),
deps: [httpClient, ClientCertificate.node],
deps: [httpClient, ClientCertificate.node, FSUtil.node],
})

export const llmClient = makeGlobalNode({ service: LLMClient.Service, layer: LLMClient.layer, deps: [requestExecutor] })
Expand Down
Loading