@@ -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
142151func 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
255266func 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
272285func 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\xff oo" , "f\xff oo" ,
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 \ufffd oo" , " 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
367384func 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.
447468func 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) {
523555func 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