Skip to content

Commit ceffe18

Browse files
authored
Add testing for golang 1.16 (letsencrypt#5313)
- Add 1.16.1 to the GitHub CI test matrix - Fix tlsalpn tests for go 1.16.1 but maintain compatibility with 1.15.x - Fix integration tests. Fix: letsencrypt#5301 Fix: letsencrypt#5316
1 parent 1f776ba commit ceffe18

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

.github/workflows/boulder-ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ jobs:
3030
matrix:
3131
# Add additional docker image tags here and all tests will be run with the additional image.
3232
BOULDER_TOOLS_TAG:
33-
- go1.15.7_2021-02-25
33+
- go1.15.7_2021-03-11
34+
- go1.16.1_2021-03-11
3435
# Tests command definitions. Use the entire docker-compose command you want to run.
3536
tests:
3637
# Run ./test.sh --help for a description of each of the flags

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22
services:
33
boulder:
44
# To minimize fetching this should be the same version used below
5-
image: letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.15.7_2021-02-25}
5+
image: letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.15.7_2021-03-11}
66
environment:
77
- FAKE_DNS=10.77.77.77
88
- BOULDER_CONFIG_DIR=test/config
@@ -76,7 +76,7 @@ services:
7676
logging:
7777
driver: none
7878
netaccess:
79-
image: letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.15.7_2021-02-25}
79+
image: letsencrypt/boulder-tools:${BOULDER_TOOLS_TAG:-go1.15.7_2021-03-11}
8080
environment:
8181
GO111MODULE: "on"
8282
GOFLAGS: "-mod=vendor"

test/boulder-tools/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ GO111MODULE=on go get \
4848

4949
# Pebble's latest version is v2+, but it's not properly go mod compatible, so we
5050
# fetch it in GOPATH mode.
51-
go get github.com/letsencrypt/pebble/cmd/pebble-challtestsrv
51+
GO111MODULE=off go get github.com/letsencrypt/pebble/cmd/pebble-challtestsrv
5252

5353
go clean -cache
5454
go clean -modcache

test/boulder-tools/tag_and_upload.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ cd $(dirname $0)
55
DATESTAMP=$(date +%Y-%m-%d)
66
DOCKER_REPO="letsencrypt/boulder-tools"
77

8-
GO_VERSIONS=( "1.15.7" )
8+
GO_VERSIONS=( "1.15.7" "1.16.1" )
99

1010
# Build a tagged image for each GO_VERSION
1111
for GO_VERSION in "${GO_VERSIONS[@]}"

va/tlsalpn.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ func certNames(cert *x509.Certificate) []string {
4848
}
4949
names = append(names, cert.DNSNames...)
5050
names = core.UniqueLowerNames(names)
51+
// TODO(#5321): This for loop can be deleted after new builds of boulder use
52+
// golang 1.16. In 1.16, code was added to crypto/x509 to not allow
53+
// invalid unicode into a DNSName in a SAN. An error will be caught in
54+
// the standard library before it gets to this point.
5155
for i, n := range names {
5256
names[i] = replaceInvalidUTF8([]byte(n))
5357
}

va/tlsalpn_test.go

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,34 +114,45 @@ func tlsalpn01Srv(
114114
chall core.Challenge,
115115
oid asn1.ObjectIdentifier,
116116
minTLSVersion uint16,
117-
names ...string) *httptest.Server {
117+
names ...string) (*httptest.Server, error) {
118118
template := tlsCertTemplate(names)
119-
certBytes, _ := x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
119+
certBytes, err := x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
120+
if err != nil {
121+
return nil, err
122+
}
120123
cert := &tls.Certificate{
121124
Certificate: [][]byte{certBytes},
122125
PrivateKey: &TheKey,
123126
}
124127

125128
shasum := sha256.Sum256([]byte(chall.ProvidedKeyAuthorization))
126-
encHash, _ := asn1.Marshal(shasum[:])
129+
encHash, err := asn1.Marshal(shasum[:])
130+
if err != nil {
131+
return nil, err
132+
}
127133
acmeExtension := pkix.Extension{
128134
Id: oid,
129135
Critical: true,
130136
Value: encHash,
131137
}
132138
template.ExtraExtensions = []pkix.Extension{acmeExtension}
133-
certBytes, _ = x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
139+
certBytes, err = x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
140+
if err != nil {
141+
return nil, err
142+
}
134143
acmeCert := &tls.Certificate{
135144
Certificate: [][]byte{certBytes},
136145
PrivateKey: &TheKey,
137146
}
138147

139-
return tlsalpn01SrvWithCert(t, chall, oid, names, cert, acmeCert, minTLSVersion)
148+
return tlsalpn01SrvWithCert(t, chall, oid, names, cert, acmeCert, minTLSVersion), nil
140149
}
141150

142151
func TestTLSALPN01FailIP(t *testing.T) {
143152
chall := tlsalpnChallenge()
144-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
153+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
154+
test.AssertNotError(t, err, "Error creating test server")
155+
145156
va, _ := setup(hs, 0, "", nil)
146157

147158
port := getPort(hs)
@@ -254,7 +265,9 @@ func TestTLSALPN01DialTimeout(t *testing.T) {
254265

255266
func TestTLSALPN01Refused(t *testing.T) {
256267
chall := tlsalpnChallenge()
257-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
268+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
269+
test.AssertNotError(t, err, "Error creating test server")
270+
258271
va, _ := setup(hs, 0, "", nil)
259272
// Take down validation server and check that validation fails.
260273
hs.Close()
@@ -271,7 +284,9 @@ func TestTLSALPN01Refused(t *testing.T) {
271284

272285
func TestTLSALPN01TalkingToHTTP(t *testing.T) {
273286
chall := tlsalpnChallenge()
274-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
287+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
288+
test.AssertNotError(t, err, "Error creating test server")
289+
275290
va, _ := setup(hs, 0, "", nil)
276291
httpOnly := httpSrv(t, "")
277292
va.tlsPort = getPort(httpOnly)
@@ -334,13 +349,11 @@ func TestCertNames(t *testing.T) {
334349
"hello.world", "goodbye.world",
335350
"bonjour.le.monde", "au.revoir.le.monde",
336351
"bonjour.le.monde", "au.revoir.le.monde",
337-
"f\xffoo", "f\xffoo",
338352
}
339-
// We expect only unique names, in sorted order and with any invalid utf-8
340-
// replaced.
353+
// We expect only unique names, in sorted order.
341354
expected := []string{
342355
"au.revoir.le.monde", "bonjour.le.monde",
343-
"f\ufffdoo", "goodbye.world", "hello.world",
356+
"goodbye.world", "hello.world",
344357
}
345358
template := &x509.Certificate{
346359
SerialNumber: big.NewInt(1337),
@@ -358,15 +371,20 @@ func TestCertNames(t *testing.T) {
358371
}
359372

360373
// Create the certificate, check that certNames provides the expected result
361-
certBytes, _ := x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
362-
cert, _ := x509.ParseCertificate(certBytes)
374+
certBytes, err := x509.CreateCertificate(rand.Reader, template, template, &TheKey.PublicKey, &TheKey)
375+
test.AssertNotError(t, err, "Error creating certificate")
376+
377+
cert, err := x509.ParseCertificate(certBytes)
378+
test.AssertNotError(t, err, "Error parsing certificate")
379+
363380
actual := certNames(cert)
364381
test.AssertDeepEquals(t, actual, expected)
365382
}
366383

367384
func TestTLSALPN01Success(t *testing.T) {
368385
chall := tlsalpnChallenge()
369-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
386+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost")
387+
test.AssertNotError(t, err, "Error creating test server")
370388

371389
va, _ := setup(hs, 0, "", nil)
372390

@@ -378,7 +396,8 @@ func TestTLSALPN01Success(t *testing.T) {
378396

379397
hs.Close()
380398
chall = tlsalpnChallenge()
381-
hs = tlsalpn01Srv(t, chall, IdPeAcmeIdentifierV1Obsolete, 0, "localhost")
399+
hs, err = tlsalpn01Srv(t, chall, IdPeAcmeIdentifierV1Obsolete, 0, "localhost")
400+
test.AssertNotError(t, err, "Error creating test server")
382401

383402
va, _ = setup(hs, 0, "", nil)
384403

@@ -394,7 +413,9 @@ func TestValidateTLSALPN01BadChallenge(t *testing.T) {
394413
chall2 := chall
395414
setChallengeToken(&chall2, "bad token")
396415

397-
hs := tlsalpn01Srv(t, chall2, IdPeAcmeIdentifier, 0, "localhost")
416+
hs, err := tlsalpn01Srv(t, chall2, IdPeAcmeIdentifier, 0, "localhost")
417+
test.AssertNotError(t, err, "Error creating test server")
418+
398419
va, _ := setup(hs, 0, "", nil)
399420

400421
_, prob := va.validateTLSALPN01(ctx, dnsi("localhost"), chall)
@@ -446,7 +467,18 @@ func TestValidateTLSALPN01UnawareSrv(t *testing.T) {
446467
// will result in a problem with the invalid UTF-8 replaced.
447468
func TestValidateTLSALPN01BadUTFSrv(t *testing.T) {
448469
chall := tlsalpnChallenge()
449-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost", "\xf0\x28\x8c\xbc")
470+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, 0, "localhost", "\xf0\x28\x8c\xbc")
471+
// TODO(#5321): Remove this comment and the err check below. In go1.16 and
472+
// greater tlsalpn01Srv is expected to fail because of invalid unicode
473+
// attempted in the certificate creation. If that error occurs, then
474+
// the standard library has done it's job and this test is satisfied.
475+
// If the error is for any other reason, the unit test will fail. In
476+
// 1.15.x this error is not expected and the other test cases will
477+
// continue.
478+
if err != nil {
479+
test.AssertContains(t, err.Error(), "cannot be encoded as an IA5String")
480+
return
481+
}
450482
port := getPort(hs)
451483
va, _ := setup(hs, 0, "", nil)
452484

@@ -523,7 +555,8 @@ func TestValidateTLSALPN01MalformedExtnValue(t *testing.T) {
523555
func TestTLSALPN01TLS13(t *testing.T) {
524556
chall := tlsalpnChallenge()
525557
// Create a server that uses tls.VersionTLS13 as the minimum supported version
526-
hs := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, tls.VersionTLS13, "localhost")
558+
hs, err := tlsalpn01Srv(t, chall, IdPeAcmeIdentifier, tls.VersionTLS13, "localhost")
559+
test.AssertNotError(t, err, "Error creating test server")
527560
defer hs.Close()
528561

529562
va, _ := setup(hs, 0, "", nil)

0 commit comments

Comments
 (0)