CodeSampleX

샘플

golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810: embed fallback x509 trusted roots in application

검증된 샘플 — golang golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810: embed fallback x509 trusted roots in application. go 1.26 · linux…

sha256:6ee654b86942cf0a3566412262bb85f78ae956ed1fa9a551bccbca99a84df803

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
2
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 go

검증 실행 환경

환경 컨트랙트 단계 실행일
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-23
go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 FAIL compile:SKIPPED · contract:FAIL · load:SKIPPED · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a…
2026-09-08

케이스

HOW
목표
embed fallback x509 trusted roots in application
패키지
생성일
2026-08-23T16:43:17Z

컨트랙트

  1. Blank-importing golang.org/x/crypto/x509roots/fallback registers an embedded X.509 root certificate pool via x509.SetFallbackRoots during package initialization.
  2. Attempting a subsequent invocation of x509.SetFallbackRoots panics because the fallback roots have already been configured.
  3. The registered fallback root certificates are available to the Go x509 certificate verification system when system certificate pools are unavailable or when x509usefallbackroots=1 is enabled.

파일

  • NOTES.md
  • csx.json
  • go.mod
  • go.sum
  • main_test.go

소스 아티팩트 내려받기 (tar.gz)

소스

NOTES.md
# Embedding Fallback X.509 Trusted Roots in Go Applications

## Known Solution Search
A search for existing community-verified samples targeting `golang.org/x/crypto/x509roots/fallback` returned no prior matches (`NO_SAFE_MATCH`).

## Pinned Release
- Package: `golang.org/x/crypto/x509roots/fallback`
- Version: `v0.0.0-20250305170421-49bf5b80c810` (declared in `go.mod` and resolved in `go.sum`)
- Runtime: Go (`golang@1` adapter)

## Observed Behaviour
The `golang.org/x/crypto/x509roots/fallback` package embeds Mozilla's root certificate bundle and automatically configures fallback roots during application startup.

1. **Automatic Initialization via `init()`**:
   When imported as a blank import (`import _ "golang.org/x/crypto/x509roots/fallback"`), the package's `init()` function loads the embedded root certificates into a new certificate pool and registers them with `crypto/x509` using `x509.SetFallbackRoots`.

2. **Single-Invocation Enforcement**:
   Go's `crypto/x509.SetFallbackRoots` is restricted to a single invocation per process lifecycle. Any subsequent call to `x509.SetFallbackRoots` panics immediately, verifying that the fallback root pool is already registered.

3. **Fallback Certificate Pool Availability**:
   The registered fallback roots ensure that `x509.SystemCertPool()` returns a valid root certificate pool or that TLS/X.509 certificate verification functions correctly even in minimal environments (such as distroless containers) without host system CA bundles.

## Failure Mode
Applications deployed to minimal environments lacking host CA certificates fail TLS connections with root verification errors unless fallback roots are embedded via `golang.org/x/crypto/x509roots/fallback`.
csx.json
{"case":{"caseId":"case:sha256:d7c6f5787da38ac571f7147a851e88cd9f1805a4bab443e2baf043a9c5569285","contract":["Blank-importing golang.org/x/crypto/x509roots/fallback registers an embedded X.509 root certificate pool via x509.SetFallbackRoots during package initialization.","Attempting a subsequent invocation of x509.SetFallbackRoots panics because the fallback roots have already been configured.","The registered fallback root certificates are available to the Go x509 certificate verification system when system certificate pools are unavailable or when x509usefallbackroots=1 is enabled."],"goal":"embed fallback x509 trusted roots in application","kind":"HOW","packages":["pkg:golang/golang.org/x/crypto/x509roots/fallback@v0.0.0-20250305170421-49bf5b80c810"],"schemaVersion":1},"contractCommand":["go","test","./..."],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/crypto/x509roots/fallback@v0.0.0-20250305170421-49bf5b80c810"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/crypto/x509roots/fallback@v0.0.0-20250305170421-49bf5b80c810","verifierAdapter":"golang@1"}
go.mod
module example.com/fallbackroots

go 1.23.0

require golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810
go.sum
golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810 h1:V5+zy0jmgNYmK1uW/sPpBw8ioFvalrhaUrYWmu1Fpe4=
golang.org/x/crypto/x509roots/fallback v0.0.0-20250305170421-49bf5b80c810/go.mod h1:lxN5T34bK4Z/i6cMaU7frUU57VkDXFD4Kamfl/cp9oU=
main_test.go
package fallbackroots_test

import (
	"crypto/x509"
	"testing"

	_ "golang.org/x/crypto/x509roots/fallback"
)

func TestFallbackRootsInitialization(t *testing.T) {
	// 1. Importing golang.org/x/crypto/x509roots/fallback sets fallback roots in init().
	// Calling x509.SetFallbackRoots again must panic since it is only allowed to be called once.
	defer func() {
		r := recover()
		if r == nil {
			t.Fatalf("expected SetFallbackRoots to panic on duplicate call, but it succeeded")
		}
	}()

	extraPool := x509.NewCertPool()
	x509.SetFallbackRoots(extraPool)
}

func TestSystemCertPoolAvailability(t *testing.T) {
	// 2. Verify that a certificate pool can be obtained from the system or fallback roots
	pool, err := x509.SystemCertPool()
	if err != nil {
		t.Fatalf("failed to retrieve system/fallback certificate pool: %v", err)
	}
	if pool == nil {
		t.Fatalf("expected non-nil certificate pool")
	}
}

오리진 시더

익명