@@ -10,6 +10,7 @@ import (
10
10
"crypto/tls"
11
11
"crypto/x509"
12
12
"crypto/x509/pkix"
13
+ "encoding/asn1"
13
14
"encoding/base64"
14
15
"fmt"
15
16
"math/big"
@@ -308,7 +309,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
308
309
t .Logf ("using keyAuthorizationTestCase [tc=%d] as alpnTestCase [tc=%d]..." , index , len (alpnTestCases ))
309
310
// Properly encode the authorization.
310
311
checksum := sha256 .Sum256 ([]byte (tc .keyAuthz ))
311
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
312
+ authz , err := asn1 .Marshal (checksum [:])
313
+ require .NoError (t , err , "failed asn.1 marshalling authz" )
312
314
313
315
// Build a self-signed certificate.
314
316
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -329,11 +331,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
329
331
{
330
332
Id : OIDACMEIdentifier ,
331
333
Critical : true ,
332
- Value : [] byte ( authz ) ,
334
+ Value : authz ,
333
335
},
334
336
},
335
337
BasicConstraintsValid : true ,
336
- IsCA : true ,
338
+ IsCA : false ,
337
339
}
338
340
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , tmpl , key .Public (), key )
339
341
require .NoError (t , err , "failed to create certificate" )
@@ -378,7 +380,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
378
380
379
381
// Compute our authorization.
380
382
checksum := sha256 .Sum256 ([]byte ("valid.valid" ))
381
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
383
+ authz , err := asn1 .Marshal (checksum [:])
384
+ require .NoError (t , err , "failed to marshal authz with asn.1 " )
382
385
383
386
// Build a leaf certificate which _could_ pass validation
384
387
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -399,11 +402,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
399
402
{
400
403
Id : OIDACMEIdentifier ,
401
404
Critical : true ,
402
- Value : [] byte ( authz ) ,
405
+ Value : authz ,
403
406
},
404
407
},
405
408
BasicConstraintsValid : true ,
406
- IsCA : true ,
409
+ IsCA : false ,
407
410
}
408
411
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , rootCert , key .Public (), rootKey )
409
412
require .NoError (t , err , "failed to create leaf certificate" )
@@ -426,7 +429,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
426
429
// Test case: cert without DNSSan
427
430
// Compute our authorization.
428
431
checksum := sha256 .Sum256 ([]byte ("valid.valid" ))
429
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
432
+ authz , err := asn1 .Marshal (checksum [:])
433
+ require .NoError (t , err , "failed to marshal authz with asn.1 " )
430
434
431
435
// Build a leaf certificate without a DNSSan
432
436
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -447,11 +451,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
447
451
{
448
452
Id : OIDACMEIdentifier ,
449
453
Critical : true ,
450
- Value : [] byte ( authz ) ,
454
+ Value : authz ,
451
455
},
452
456
},
453
457
BasicConstraintsValid : true ,
454
- IsCA : true ,
458
+ IsCA : false ,
455
459
}
456
460
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , tmpl , key .Public (), key )
457
461
require .NoError (t , err , "failed to create leaf certificate" )
@@ -474,7 +478,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
474
478
// Test case: cert without matching DNSSan
475
479
// Compute our authorization.
476
480
checksum := sha256 .Sum256 ([]byte ("valid.valid" ))
477
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
481
+ authz , err := asn1 .Marshal (checksum [:])
482
+ require .NoError (t , err , "failed to marshal authz with asn.1 " )
478
483
479
484
// Build a leaf certificate which fails validation due to bad DNSName
480
485
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -495,11 +500,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
495
500
{
496
501
Id : OIDACMEIdentifier ,
497
502
Critical : true ,
498
- Value : [] byte ( authz ) ,
503
+ Value : authz ,
499
504
},
500
505
},
501
506
BasicConstraintsValid : true ,
502
- IsCA : true ,
507
+ IsCA : false ,
503
508
}
504
509
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , tmpl , key .Public (), key )
505
510
require .NoError (t , err , "failed to create leaf certificate" )
@@ -522,7 +527,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
522
527
// Test case: cert with additional SAN
523
528
// Compute our authorization.
524
529
checksum := sha256 .Sum256 ([]byte ("valid.valid" ))
525
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
530
+ authz , err := asn1 .Marshal (checksum [:])
531
+ require .NoError (t , err , "failed to marshal authz with asn.1 " )
526
532
527
533
// Build a leaf certificate which has an invalid additional SAN
528
534
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -544,11 +550,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
544
550
{
545
551
Id : OIDACMEIdentifier ,
546
552
Critical : true ,
547
- Value : [] byte ( authz ) ,
553
+ Value : authz ,
548
554
},
549
555
},
550
556
BasicConstraintsValid : true ,
551
- IsCA : true ,
557
+ IsCA : false ,
552
558
}
553
559
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , tmpl , key .Public (), key )
554
560
require .NoError (t , err , "failed to create leaf certificate" )
@@ -571,7 +577,8 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
571
577
// Test case: cert without CN
572
578
// Compute our authorization.
573
579
checksum := sha256 .Sum256 ([]byte ("valid.valid" ))
574
- authz := base64 .RawURLEncoding .EncodeToString (checksum [:])
580
+ authz , err := asn1 .Marshal (checksum [:])
581
+ require .NoError (t , err , "failed to marshal authz with asn.1 " )
575
582
576
583
// Build a leaf certificate which should pass validation
577
584
key , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
@@ -588,11 +595,11 @@ func TestAcmeValidateTLSALPN01Challenge(t *testing.T) {
588
595
{
589
596
Id : OIDACMEIdentifier ,
590
597
Critical : true ,
591
- Value : [] byte ( authz ) ,
598
+ Value : authz ,
592
599
},
593
600
},
594
601
BasicConstraintsValid : true ,
595
- IsCA : true ,
602
+ IsCA : false ,
596
603
}
597
604
certBytes , err := x509 .CreateCertificate (rand .Reader , tmpl , tmpl , key .Public (), key )
598
605
require .NoError (t , err , "failed to create leaf certificate" )
0 commit comments