Skip to content

loader: use software TLS on hosted Linux and Darwin - #5700

Draft
yohimik wants to merge 2 commits into
tinygo-org:devfrom
yohimik:upstream-pr/hosted-crypto-tls
Draft

yohimik wants to merge 2 commits into
tinygo-org:devfrom
yohimik:upstream-pr/hosted-crypto-tls

Conversation

@yohimik

@yohimik yohimik commented Sep 17, 2026

Copy link
Copy Markdown

Addresses #5696. The selected TLS stub reports success without a TLS handshake. Select Go's crypto/tls on hosted Linux and Darwin. Other targets keep the stub.

Depends on #5693 (PR #5698). Tests cover package selection, a real handshake, data exchange, and refusal of an untrusted certificate. Darwin callers must supply trust roots until #3592 is resolved.

#5645 closed on 5 September in favor of this work. #5204 tracks API gaps. #4273 covers a broader network package replacement.

Replaces #5635, closed on 17 September 2026 with a request for an issue first. Based on dev at 93940cb6. Patches are unchanged after rebase. Formatting and whitespace checks pass. New runtime tests and CI are pending.

TinyGo replaces crypto/tls with a stub whose handshake does nothing, so a
program that dials https gets a plaintext connection behind the TLS API. That
stub is correct for a target with no OS below it, which has neither the code
size for a full TLS implementation nor usually a socket to speak it over.
Hosted linux and macOS have both, and there the crypto/tls of the Go standard
library compiles and runs.

Make the override conditional. Without an entry in the map, crypto/tls falls
under the "crypto/" merge, which links the package of the standard library into
the synthetic GOROOT. GOOS alone cannot decide this, because a baremetal target
reports GOOS=linux, so the build tags decide as well.

The goroot cache key is a hash of the merge links, so the two variants get
separate cache entries.

testdata/hostcryptotls.go does a TLS handshake over an in-memory pipe with a
certificate that it makes at run time. On the current dev branch it prints
"negotiated an unexpected version: 0", because the stub does no handshake. With
this change the handshake completes, the data goes through, and a client that
does not trust the certificate refuses it. loader/goroot_test.go covers the
targets that keep the stub, the baremetal one that reports GOOS=linux included.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant