Skip to content

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

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

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

Conversation

@yohimik

@yohimik yohimik commented Aug 30, 2026

Copy link
Copy Markdown

Superseded by #5700. The problem is tracked in #5696.

Closed on 17 September 2026 with a request for an issue first. The replacement uses the same patch, rebased on 18 September onto dev at 93940cb6. Its description contains the scope, dependencies, and test status.

@yohimik

yohimik commented Sep 2, 2026

Copy link
Copy Markdown
Author

Rebased on dev after the 0.42.0 release. The change applies on top of v0.42.0
as released without a conflict. An observation about the released toolchain:
testdata/hostcryptotls.go from this branch, built with the official v0.42.0
tarballs, prints "negotiated an unexpected version: 0" on linux/arm64 and on
darwin/arm64. The stub gives back a plaintext connection from tls.Dial that
verifies nothing. This change puts the real package in its place.

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.
@deadprogram

Copy link
Copy Markdown
Member

See my other feedback on recent PRs @yohimik and resubmit after creating a specific issue first. Make sure to follow AGENTS.md

Thank you!

@yohimik yohimik changed the title loader: use the real crypto/tls on hosted linux and darwin loader: use software TLS on hosted Linux and Darwin Sep 17, 2026
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.

2 participants