Skip to content

Commit d23c187

Browse files
titoclaude
andauthored
fix: include CA cert in TLS chain and use explicit trust policies on macOS (#13)
The MITM TLS handshake was only sending the leaf certificate, causing "unable to get local issuer certificate" errors. Now sends the full chain (leaf + CA) so clients can verify the issuer. Also switches macOS cert install from `-r trustRoot` to `-p ssl -p basic` which sets explicit per-policy trust settings in the Keychain, matching the approach used by mitmproxy. This ensures LibreSSL/curl honor the Keychain trust when verifying certificates through CONNECT tunnels. Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5425da3 commit d23c187

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

cmd/greyproxy/cert.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ func handleCertInstall(force bool) {
196196

197197
fmt.Println("Installing CA certificate into system trust store (requires sudo)...")
198198
cmd := exec.Command("sudo", "security", "add-trusted-cert",
199-
"-d", "-r", "trustRoot",
199+
"-d", "-p", "ssl", "-p", "basic",
200200
"-k", "/Library/Keychains/System.keychain",
201201
certFile,
202202
)
@@ -205,7 +205,7 @@ func handleCertInstall(force bool) {
205205
cmd.Stdin = os.Stdin
206206
if err := cmd.Run(); err != nil {
207207
fmt.Fprintf(os.Stderr, "\nAutomatic install failed. Please run manually:\n\n")
208-
fmt.Fprintf(os.Stderr, " sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain \"%s\"\n\n", certFile)
208+
fmt.Fprintf(os.Stderr, " sudo security add-trusted-cert -d -p ssl -p basic -k /Library/Keychains/System.keychain \"%s\"\n\n", certFile)
209209
os.Exit(1)
210210
}
211211
fmt.Printf("CA certificate installed and trusted in %s\n", certInstallLocation())

internal/gostx/internal/util/sniffing/sniffer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ func (h *Sniffer) terminateTLS(ctx context.Context, network string, conn, cc net
928928
}
929929

930930
return &tls.Certificate{
931-
Certificate: [][]byte{cert.Raw},
931+
Certificate: [][]byte{cert.Raw, h.Certificate.Raw},
932932
PrivateKey: h.PrivateKey,
933933
}, nil
934934
},
@@ -1025,7 +1025,7 @@ func (h *Sniffer) terminateTLSDeferred(ctx context.Context, network string, conn
10251025
return nil, err
10261026
}
10271027
return &tls.Certificate{
1028-
Certificate: [][]byte{cert.Raw},
1028+
Certificate: [][]byte{cert.Raw, h.Certificate.Raw},
10291029
PrivateKey: h.PrivateKey,
10301030
}, nil
10311031
},

internal/greyproxy/api/cert.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func buildInstallCommands(certPath string) map[string]string {
7070
cmds := make(map[string]string)
7171
switch runtime.GOOS {
7272
case "darwin":
73-
cmds["macos"] = fmt.Sprintf("sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain \"%s\"", certPath)
73+
cmds["macos"] = fmt.Sprintf("sudo security add-trusted-cert -d -p ssl -p basic -k /Library/Keychains/System.keychain \"%s\"", certPath)
7474
case "linux":
7575
destPath, updateCmd := linuxCertInstallInfo()
7676
cmds["linux"] = fmt.Sprintf("sudo cp \"%s\" %s && sudo %s", certPath, destPath, updateCmd)

0 commit comments

Comments
 (0)