forked from letsencrypt/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaa_test.go
1558 lines (1489 loc) · 51.9 KB
/
caa_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package va
import (
"context"
"errors"
"fmt"
"net"
"strings"
"testing"
"github.com/miekg/dns"
"github.com/letsencrypt/boulder/bdns"
"github.com/letsencrypt/boulder/core"
berrors "github.com/letsencrypt/boulder/errors"
"github.com/letsencrypt/boulder/features"
"github.com/letsencrypt/boulder/identifier"
"github.com/letsencrypt/boulder/probs"
"github.com/letsencrypt/boulder/test"
blog "github.com/letsencrypt/boulder/log"
vapb "github.com/letsencrypt/boulder/va/proto"
)
// caaMockDNS implements the `dns.DNSClient` interface with a set of useful test
// answers for CAA queries.
type caaMockDNS struct{}
func (mock caaMockDNS) LookupTXT(_ context.Context, hostname string) ([]string, bdns.ResolverAddrs, error) {
return nil, bdns.ResolverAddrs{"caaMockDNS"}, nil
}
func (mock caaMockDNS) LookupHost(_ context.Context, hostname string) ([]net.IP, bdns.ResolverAddrs, error) {
ip := net.ParseIP("127.0.0.1")
return []net.IP{ip}, bdns.ResolverAddrs{"caaMockDNS"}, nil
}
func (mock caaMockDNS) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, string, bdns.ResolverAddrs, error) {
var results []*dns.CAA
var record dns.CAA
switch strings.TrimRight(domain, ".") {
case "caa-timeout.com":
return nil, "", bdns.ResolverAddrs{"caaMockDNS"}, fmt.Errorf("error")
case "reserved.com":
record.Tag = "issue"
record.Value = "ca.com"
results = append(results, &record)
case "mixedcase.com":
record.Tag = "iSsUe"
record.Value = "ca.com"
results = append(results, &record)
case "critical.com":
record.Flag = 1
record.Tag = "issue"
record.Value = "ca.com"
results = append(results, &record)
case "present.com", "present.servfail.com":
record.Tag = "issue"
record.Value = "letsencrypt.org"
results = append(results, &record)
case "com":
// com has no CAA records.
return nil, "", bdns.ResolverAddrs{"caaMockDNS"}, nil
case "gonetld":
return nil, "", bdns.ResolverAddrs{"caaMockDNS"}, fmt.Errorf("NXDOMAIN")
case "servfail.com", "servfail.present.com":
return results, "", bdns.ResolverAddrs{"caaMockDNS"}, fmt.Errorf("SERVFAIL")
case "multi-crit-present.com":
record.Flag = 1
record.Tag = "issue"
record.Value = "ca.com"
results = append(results, &record)
secondRecord := record
secondRecord.Value = "letsencrypt.org"
results = append(results, &secondRecord)
case "unknown-critical.com":
record.Flag = 128
record.Tag = "foo"
record.Value = "bar"
results = append(results, &record)
case "unknown-critical2.com":
record.Flag = 1
record.Tag = "foo"
record.Value = "bar"
results = append(results, &record)
case "unknown-noncritical.com":
record.Flag = 0x7E // all bits we don't treat as meaning "critical"
record.Tag = "foo"
record.Value = "bar"
results = append(results, &record)
case "present-with-parameter.com":
record.Tag = "issue"
record.Value = " letsencrypt.org ;foo=bar;baz=bar"
results = append(results, &record)
case "present-with-invalid-tag.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; a_b=123"
results = append(results, &record)
case "present-with-invalid-value.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; ab=1 2 3"
results = append(results, &record)
case "present-dns-only.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; validationmethods=dns-01"
results = append(results, &record)
case "present-http-only.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; validationmethods=http-01"
results = append(results, &record)
case "present-http-or-dns.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; validationmethods=http-01,dns-01"
results = append(results, &record)
case "present-dns-only-correct-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/123; validationmethods=dns-01"
results = append(results, &record)
case "present-http-only-correct-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/123; validationmethods=http-01"
results = append(results, &record)
case "present-http-only-incorrect-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/321; validationmethods=http-01"
results = append(results, &record)
case "present-correct-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/123"
results = append(results, &record)
case "present-incorrect-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/321"
results = append(results, &record)
case "present-multiple-accounturi.com":
record.Tag = "issue"
record.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/321"
results = append(results, &record)
secondRecord := record
secondRecord.Tag = "issue"
secondRecord.Value = "letsencrypt.org; accounturi=https://letsencrypt.org/acct/reg/123"
results = append(results, &secondRecord)
case "unsatisfiable.com":
record.Tag = "issue"
record.Value = ";"
results = append(results, &record)
case "unsatisfiable-wildcard.com":
// Forbidden issuance - issuewild doesn't contain LE
record.Tag = "issuewild"
record.Value = ";"
results = append(results, &record)
case "unsatisfiable-wildcard-override.com":
// Forbidden issuance - issue allows LE, issuewild overrides and does not
record.Tag = "issue"
record.Value = "letsencrypt.org"
results = append(results, &record)
secondRecord := record
secondRecord.Tag = "issuewild"
secondRecord.Value = "ca.com"
results = append(results, &secondRecord)
case "satisfiable-wildcard-override.com":
// Ok issuance - issue doesn't allow LE, issuewild overrides and does
record.Tag = "issue"
record.Value = "ca.com"
results = append(results, &record)
secondRecord := record
secondRecord.Tag = "issuewild"
secondRecord.Value = "letsencrypt.org"
results = append(results, &secondRecord)
case "satisfiable-multi-wildcard.com":
// Ok issuance - first issuewild doesn't permit LE but second does
record.Tag = "issuewild"
record.Value = "ca.com"
results = append(results, &record)
secondRecord := record
secondRecord.Tag = "issuewild"
secondRecord.Value = "letsencrypt.org"
results = append(results, &secondRecord)
case "satisfiable-wildcard.com":
// Ok issuance - issuewild allows LE
record.Tag = "issuewild"
record.Value = "letsencrypt.org"
results = append(results, &record)
}
var response string
if len(results) > 0 {
response = "foo"
}
return results, response, bdns.ResolverAddrs{"caaMockDNS"}, nil
}
func TestCAATimeout(t *testing.T) {
va, _ := setup(nil, 0, "", nil, caaMockDNS{})
params := &caaParams{
accountURIID: 12345,
validationMethod: core.ChallengeTypeHTTP01,
}
err := va.checkCAA(ctx, identifier.DNSIdentifier("caa-timeout.com"), params)
test.AssertErrorIs(t, err, berrors.DNS)
test.AssertContains(t, err.Error(), "error")
}
func TestCAAChecking(t *testing.T) {
testCases := []struct {
Name string
Domain string
FoundAt string
Valid bool
}{
{
Name: "Bad (Reserved)",
Domain: "reserved.com",
FoundAt: "reserved.com",
Valid: false,
},
{
Name: "Bad (Reserved, Mixed case Issue)",
Domain: "mixedcase.com",
FoundAt: "mixedcase.com",
Valid: false,
},
{
Name: "Bad (Critical)",
Domain: "critical.com",
FoundAt: "critical.com",
Valid: false,
},
{
Name: "Bad (NX Critical)",
Domain: "nx.critical.com",
FoundAt: "critical.com",
Valid: false,
},
{
Name: "Good (absent)",
Domain: "absent.com",
FoundAt: "",
Valid: true,
},
{
Name: "Good (example.co.uk, absent)",
Domain: "example.co.uk",
FoundAt: "",
Valid: true,
},
{
Name: "Good (present and valid)",
Domain: "present.com",
FoundAt: "present.com",
Valid: true,
},
{
Name: "Good (present on parent)",
Domain: "child.present.com",
FoundAt: "present.com",
Valid: true,
},
{
Name: "Good (present w/ servfail exception?)",
Domain: "present.servfail.com",
FoundAt: "present.servfail.com",
Valid: true,
},
{
Name: "Good (multiple critical, one matching)",
Domain: "multi-crit-present.com",
FoundAt: "multi-crit-present.com",
Valid: true,
},
{
Name: "Bad (unknown critical)",
Domain: "unknown-critical.com",
FoundAt: "unknown-critical.com",
Valid: false,
},
{
Name: "Bad (unknown critical 2)",
Domain: "unknown-critical2.com",
FoundAt: "unknown-critical2.com",
Valid: false,
},
{
Name: "Good (unknown non-critical, no issue/issuewild)",
Domain: "unknown-noncritical.com",
FoundAt: "unknown-noncritical.com",
Valid: true,
},
{
Name: "Good (issue rec with unknown params)",
Domain: "present-with-parameter.com",
FoundAt: "present-with-parameter.com",
Valid: true,
},
{
Name: "Bad (issue rec with invalid tag)",
Domain: "present-with-invalid-tag.com",
FoundAt: "present-with-invalid-tag.com",
Valid: false,
},
{
Name: "Bad (issue rec with invalid value)",
Domain: "present-with-invalid-value.com",
FoundAt: "present-with-invalid-value.com",
Valid: false,
},
{
Name: "Bad (restricts to dns-01, but tested with http-01)",
Domain: "present-dns-only.com",
FoundAt: "present-dns-only.com",
Valid: false,
},
{
Name: "Good (restricts to http-01, tested with http-01)",
Domain: "present-http-only.com",
FoundAt: "present-http-only.com",
Valid: true,
},
{
Name: "Good (restricts to http-01 or dns-01, tested with http-01)",
Domain: "present-http-or-dns.com",
FoundAt: "present-http-or-dns.com",
Valid: true,
},
{
Name: "Good (restricts to accounturi, tested with correct account)",
Domain: "present-correct-accounturi.com",
FoundAt: "present-correct-accounturi.com",
Valid: true,
},
{
Name: "Good (restricts to http-01 and accounturi, tested with correct account)",
Domain: "present-http-only-correct-accounturi.com",
FoundAt: "present-http-only-correct-accounturi.com",
Valid: true,
},
{
Name: "Bad (restricts to dns-01 and accounturi, tested with http-01)",
Domain: "present-dns-only-correct-accounturi.com",
FoundAt: "present-dns-only-correct-accounturi.com",
Valid: false,
},
{
Name: "Bad (restricts to http-01 and accounturi, tested with incorrect account)",
Domain: "present-http-only-incorrect-accounturi.com",
FoundAt: "present-http-only-incorrect-accounturi.com",
Valid: false,
},
{
Name: "Bad (restricts to accounturi, tested with incorrect account)",
Domain: "present-incorrect-accounturi.com",
FoundAt: "present-incorrect-accounturi.com",
Valid: false,
},
{
Name: "Good (restricts to multiple accounturi, tested with a correct account)",
Domain: "present-multiple-accounturi.com",
FoundAt: "present-multiple-accounturi.com",
Valid: true,
},
{
Name: "Bad (unsatisfiable issue record)",
Domain: "unsatisfiable.com",
FoundAt: "unsatisfiable.com",
Valid: false,
},
{
Name: "Bad (unsatisfiable issue, wildcard)",
Domain: "*.unsatisfiable.com",
FoundAt: "unsatisfiable.com",
Valid: false,
},
{
Name: "Bad (unsatisfiable wildcard)",
Domain: "*.unsatisfiable-wildcard.com",
FoundAt: "unsatisfiable-wildcard.com",
Valid: false,
},
{
Name: "Bad (unsatisfiable wildcard override)",
Domain: "*.unsatisfiable-wildcard-override.com",
FoundAt: "unsatisfiable-wildcard-override.com",
Valid: false,
},
{
Name: "Good (satisfiable wildcard)",
Domain: "*.satisfiable-wildcard.com",
FoundAt: "satisfiable-wildcard.com",
Valid: true,
},
{
Name: "Good (multiple issuewild, one satisfiable)",
Domain: "*.satisfiable-multi-wildcard.com",
FoundAt: "satisfiable-multi-wildcard.com",
Valid: true,
},
{
Name: "Good (satisfiable wildcard override)",
Domain: "*.satisfiable-wildcard-override.com",
FoundAt: "satisfiable-wildcard-override.com",
Valid: true,
},
}
accountURIID := int64(123)
method := core.ChallengeTypeHTTP01
params := &caaParams{accountURIID: accountURIID, validationMethod: method}
va, _ := setup(nil, 0, "", nil, caaMockDNS{})
va.accountURIPrefixes = []string{"https://letsencrypt.org/acct/reg/"}
for _, caaTest := range testCases {
mockLog := va.log.(*blog.Mock)
defer mockLog.Clear()
t.Run(caaTest.Name, func(t *testing.T) {
ident := identifier.DNSIdentifier(caaTest.Domain)
foundAt, valid, _, err := va.checkCAARecords(ctx, ident, params)
if err != nil {
t.Errorf("checkCAARecords error for %s: %s", caaTest.Domain, err)
}
if foundAt != caaTest.FoundAt {
t.Errorf("checkCAARecords presence mismatch for %s: got %q expected %q", caaTest.Domain, foundAt, caaTest.FoundAt)
}
if valid != caaTest.Valid {
t.Errorf("checkCAARecords validity mismatch for %s: got %t expected %t", caaTest.Domain, valid, caaTest.Valid)
}
})
}
}
func TestCAALogging(t *testing.T) {
va, _ := setup(nil, 0, "", nil, caaMockDNS{})
testCases := []struct {
Name string
Domain string
AccountURIID int64
ChallengeType core.AcmeChallenge
ExpectedLogline string
}{
{
Domain: "reserved.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for reserved.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: false, Found at: \"reserved.com\"] Response=\"foo\"",
},
{
Domain: "reserved.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeDNS01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for reserved.com, [Present: true, Account ID: 12345, Challenge: dns-01, Valid for issuance: false, Found at: \"reserved.com\"] Response=\"foo\"",
},
{
Domain: "mixedcase.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for mixedcase.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: false, Found at: \"mixedcase.com\"] Response=\"foo\"",
},
{
Domain: "critical.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for critical.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: false, Found at: \"critical.com\"] Response=\"foo\"",
},
{
Domain: "present.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for present.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: true, Found at: \"present.com\"] Response=\"foo\"",
},
{
Domain: "not.here.but.still.present.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for not.here.but.still.present.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: true, Found at: \"present.com\"] Response=\"foo\"",
},
{
Domain: "multi-crit-present.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for multi-crit-present.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: true, Found at: \"multi-crit-present.com\"] Response=\"foo\"",
},
{
Domain: "present-with-parameter.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for present-with-parameter.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: true, Found at: \"present-with-parameter.com\"] Response=\"foo\"",
},
{
Domain: "satisfiable-wildcard-override.com",
AccountURIID: 12345,
ChallengeType: core.ChallengeTypeHTTP01,
ExpectedLogline: "INFO: [AUDIT] Checked CAA records for satisfiable-wildcard-override.com, [Present: true, Account ID: 12345, Challenge: http-01, Valid for issuance: false, Found at: \"satisfiable-wildcard-override.com\"] Response=\"foo\"",
},
}
for _, tc := range testCases {
t.Run(tc.Domain, func(t *testing.T) {
mockLog := va.log.(*blog.Mock)
defer mockLog.Clear()
params := &caaParams{
accountURIID: tc.AccountURIID,
validationMethod: tc.ChallengeType,
}
_ = va.checkCAA(ctx, identifier.ACMEIdentifier{Type: identifier.DNS, Value: tc.Domain}, params)
caaLogLines := mockLog.GetAllMatching(`Checked CAA records for`)
if len(caaLogLines) != 1 {
t.Errorf("checkCAARecords didn't audit log CAA record info. Instead got:\n%s\n",
strings.Join(mockLog.GetAllMatching(`.*`), "\n"))
} else {
test.AssertEquals(t, caaLogLines[0], tc.ExpectedLogline)
}
})
}
}
// TestIsCAAValidErrMessage tests that an error result from `va.IsCAAValid`
// includes the domain name that was being checked in the failure detail.
func TestIsCAAValidErrMessage(t *testing.T) {
va, _ := setup(nil, 0, "", nil, caaMockDNS{})
// Call IsCAAValid with a domain we know fails with a generic error from the
// caaMockDNS.
domain := "caa-timeout.com"
resp, err := va.IsCAAValid(ctx, &vapb.IsCAAValidRequest{
Domain: domain,
ValidationMethod: string(core.ChallengeTypeHTTP01),
AccountURIID: 12345,
})
// The lookup itself should not return an error
test.AssertNotError(t, err, "Unexpected error calling IsCAAValidRequest")
// The result should not be nil
test.AssertNotNil(t, resp, "Response to IsCAAValidRequest was nil")
// The result's Problem should not be nil
test.AssertNotNil(t, resp.Problem, "Response Problem was nil")
// The result's Problem should be an error message that includes the domain.
test.AssertEquals(t, resp.Problem.Detail, fmt.Sprintf("While processing CAA for %s: error", domain))
}
// TestIsCAAValidParams tests that the IsCAAValid method rejects any requests
// which do not have the necessary parameters to do CAA Account and Method
// Binding checks.
func TestIsCAAValidParams(t *testing.T) {
va, _ := setup(nil, 0, "", nil, caaMockDNS{})
// Calling IsCAAValid without a ValidationMethod should fail.
_, err := va.IsCAAValid(ctx, &vapb.IsCAAValidRequest{
Domain: "present.com",
AccountURIID: 12345,
})
test.AssertError(t, err, "calling IsCAAValid without a ValidationMethod")
// Calling IsCAAValid with an invalid ValidationMethod should fail.
_, err = va.IsCAAValid(ctx, &vapb.IsCAAValidRequest{
Domain: "present.com",
ValidationMethod: "tls-sni-01",
AccountURIID: 12345,
})
test.AssertError(t, err, "calling IsCAAValid with a bad ValidationMethod")
// Calling IsCAAValid without an AccountURIID should fail.
_, err = va.IsCAAValid(ctx, &vapb.IsCAAValidRequest{
Domain: "present.com",
ValidationMethod: string(core.ChallengeTypeHTTP01),
})
test.AssertError(t, err, "calling IsCAAValid without an AccountURIID")
}
var errCAABrokenDNSClient = errors.New("dnsClient is broken")
// caaBrokenDNS implements the `dns.DNSClient` interface, but always returns
// errors.
type caaBrokenDNS struct{}
func (b caaBrokenDNS) LookupTXT(_ context.Context, hostname string) ([]string, bdns.ResolverAddrs, error) {
return nil, bdns.ResolverAddrs{"caaBrokenDNS"}, errCAABrokenDNSClient
}
func (b caaBrokenDNS) LookupHost(_ context.Context, hostname string) ([]net.IP, bdns.ResolverAddrs, error) {
return nil, bdns.ResolverAddrs{"caaBrokenDNS"}, errCAABrokenDNSClient
}
func (b caaBrokenDNS) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, string, bdns.ResolverAddrs, error) {
return nil, "", bdns.ResolverAddrs{"caaBrokenDNS"}, errCAABrokenDNSClient
}
func TestDisabledMultiCAARechecking(t *testing.T) {
brokenRVA := setupRemote(nil, "broken", caaBrokenDNS{})
remoteVAs := []RemoteVA{{brokenRVA, "broken"}}
va, _ := setup(nil, 0, "local", remoteVAs, nil)
features.Set(features.Config{
EnforceMultiCAA: false,
MultiCAAFullResults: false,
})
defer features.Reset()
isValidRes, err := va.IsCAAValid(context.TODO(), &vapb.IsCAAValidRequest{
Domain: "present.com",
ValidationMethod: string(core.ChallengeTypeDNS01),
AccountURIID: 1,
})
test.AssertNotError(t, err, "Error during IsCAAValid")
// The primary VA can successfully recheck the CAA record and is allowed to
// issue for this domain. If `EnforceMultiCAA`` was enabled, the configured
// remote VA with broken dns.Client would fail the check and return a
// Problem, but that code path could never trigger.
test.AssertBoxedNil(t, isValidRes.Problem, "IsCAAValid returned a problem, but should not have")
}
// caaHijackedDNS implements the `dns.DNSClient` interface with a set of useful
// test answers for CAA queries. It returns alternate CAA records than what
// caaMockDNS returns simulating either a BGP hijack or DNS records that have
// changed while queries were inflight.
type caaHijackedDNS struct{}
func (h caaHijackedDNS) LookupTXT(_ context.Context, hostname string) ([]string, bdns.ResolverAddrs, error) {
return nil, bdns.ResolverAddrs{"caaHijackedDNS"}, nil
}
func (h caaHijackedDNS) LookupHost(_ context.Context, hostname string) ([]net.IP, bdns.ResolverAddrs, error) {
ip := net.ParseIP("127.0.0.1")
return []net.IP{ip}, bdns.ResolverAddrs{"caaHijackedDNS"}, nil
}
func (h caaHijackedDNS) LookupCAA(_ context.Context, domain string) ([]*dns.CAA, string, bdns.ResolverAddrs, error) {
// These records are altered from their caaMockDNS counterparts. Use this to
// tickle remoteValidationFailures.
var results []*dns.CAA
var record dns.CAA
switch strings.TrimRight(domain, ".") {
case "present.com", "present.servfail.com":
record.Tag = "issue"
record.Value = "other-ca.com"
results = append(results, &record)
case "present-dns-only.com":
return results, "", bdns.ResolverAddrs{"caaHijackedDNS"}, fmt.Errorf("SERVFAIL")
case "satisfiable-wildcard.com":
record.Tag = "issuewild"
record.Value = ";"
results = append(results, &record)
secondRecord := record
secondRecord.Tag = "issue"
secondRecord.Value = ";"
results = append(results, &secondRecord)
}
var response string
if len(results) > 0 {
response = "foo"
}
return results, response, bdns.ResolverAddrs{"caaHijackedDNS"}, nil
}
func TestMultiCAARechecking(t *testing.T) {
// The remote differential log order is non-deterministic, so let's use
// the same UA for all applicable RVAs.
const (
localUA = "local"
remoteUA = "remote"
brokenUA = "broken"
hijackedUA = "hijacked"
)
remoteVA := setupRemote(nil, remoteUA, nil)
brokenVA := setupRemote(nil, brokenUA, caaBrokenDNS{})
// Returns incorrect results
hijackedVA := setupRemote(nil, hijackedUA, caaHijackedDNS{})
testCases := []struct {
name string
maxLookupFailures int
domains string
remoteVAs []RemoteVA
expectedProbSubstring string
expectedProbType probs.ProblemType
expectedDiffLogSubstring string
localDNSClient bdns.Client
}{
{
name: "all VAs functional, no CAA records",
domains: "present-dns-only.com",
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{remoteVA, remoteUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "broken localVA, RVAs functional, no CAA records",
domains: "present-dns-only.com",
localDNSClient: caaBrokenDNS{},
expectedProbSubstring: "While processing CAA for present-dns-only.com: dnsClient is broken",
expectedProbType: probs.DNSProblem,
remoteVAs: []RemoteVA{
{remoteVA, remoteUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "functional localVA, 1 broken RVA, no CAA records",
domains: "present-dns-only.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.DNSProblem,
expectedDiffLogSubstring: `RemoteSuccesses":2,"RemoteFailures":[{"VAHostname":"broken","Problem":{"type":"dns","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{brokenVA, brokenUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "functional localVA, all broken RVAs, no CAA records",
domains: "present-dns-only.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.DNSProblem,
expectedDiffLogSubstring: `RemoteSuccesses":0,"RemoteFailures":[{"VAHostname":"broken","Problem":{"type":"dns","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{brokenVA, brokenUA},
{brokenVA, brokenUA},
{brokenVA, brokenUA},
},
},
{
name: "all VAs functional, CAA issue type present",
domains: "present.com",
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{remoteVA, remoteUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "functional localVA, 1 broken RVA, CAA issue type present",
domains: "present.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.DNSProblem,
expectedDiffLogSubstring: `RemoteSuccesses":2,"RemoteFailures":[{"VAHostname":"broken","Problem":{"type":"dns","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{brokenVA, brokenUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "functional localVA, all broken RVAs, CAA issue type present",
domains: "present.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.DNSProblem,
expectedDiffLogSubstring: `RemoteSuccesses":0,"RemoteFailures":[{"VAHostname":"broken","Problem":{"type":"dns","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{brokenVA, brokenUA},
{brokenVA, brokenUA},
{brokenVA, brokenUA},
},
},
{
// The localVA kicks off the background goroutines before doing its
// own check. But if its own check fails, it doesn't wait for their
// results.
name: "all VAs functional, CAA issue type forbids issuance",
domains: "unsatisfiable.com",
expectedProbSubstring: "CAA record for unsatisfiable.com prevents issuance",
expectedProbType: probs.CAAProblem,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{remoteVA, remoteUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "1 hijacked RVA, CAA issue type present",
domains: "present.com",
expectedProbSubstring: "CAA record for present.com prevents issuance",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":2,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "2 hijacked RVAs, CAA issue type present",
domains: "present.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":1,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
},
},
{
name: "3 hijacked RVAs, CAA issue type present",
domains: "present.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":0,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
},
},
{
name: "1 hijacked RVA, CAA issuewild type present",
domains: "satisfiable-wildcard.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":2,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "2 hijacked RVAs, CAA issuewild type present",
domains: "satisfiable-wildcard.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":1,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
},
},
{
name: "3 hijacked RVAs, CAA issuewild type present",
domains: "satisfiable-wildcard.com",
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":0,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
},
},
{
name: "1 hijacked RVA, CAA issuewild type present, 1 failure allowed",
domains: "satisfiable-wildcard.com",
maxLookupFailures: 1,
expectedDiffLogSubstring: `RemoteSuccesses":2,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
{remoteVA, remoteUA},
},
},
{
name: "2 hijacked RVAs, CAA issuewild type present, 1 failure allowed",
domains: "satisfiable-wildcard.com",
maxLookupFailures: 1,
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":1,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{remoteVA, remoteUA},
},
},
{
name: "3 hijacked RVAs, CAA issuewild type present, 1 failure allowed",
domains: "satisfiable-wildcard.com",
maxLookupFailures: 1,
expectedProbSubstring: "During secondary CAA checking: While processing CAA",
expectedProbType: probs.CAAProblem,
expectedDiffLogSubstring: `RemoteSuccesses":0,"RemoteFailures":[{"VAHostname":"hijacked","Problem":{"type":"caa","detail":"While processing CAA for`,
localDNSClient: caaMockDNS{},
remoteVAs: []RemoteVA{
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
{hijackedVA, hijackedUA},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
va, mockLog := setup(nil, tc.maxLookupFailures, localUA, tc.remoteVAs, tc.localDNSClient)
defer mockLog.Clear()
// MultiCAAFullResults: false is inherently flaky because of the
// non-deterministic nature of concurrent goroutine returns. We,
// boulder dev, made a decision to skip testing that path and
// eventually make MultiCAAFullResults: true the default.
features.Set(features.Config{
EnforceMultiCAA: true,
MultiCAAFullResults: true,
})
defer features.Reset()
isValidRes, err := va.IsCAAValid(context.TODO(), &vapb.IsCAAValidRequest{
Domain: tc.domains,
ValidationMethod: string(core.ChallengeTypeDNS01),
AccountURIID: 1,
})
test.AssertNotError(t, err, "Should not have errored, but did")
if tc.expectedProbSubstring != "" {
test.AssertContains(t, isValidRes.Problem.Detail, tc.expectedProbSubstring)
} else if isValidRes.Problem != nil {
test.AssertBoxedNil(t, isValidRes.Problem, "IsCAAValidRequest returned a problem, but should not have")
}
if tc.expectedProbType != "" {
test.AssertEquals(t, string(tc.expectedProbType), isValidRes.Problem.ProblemType)
}
var invalidRVACount int
for _, x := range va.remoteVAs {
if x.Address == "broken" || x.Address == "hijacked" {
invalidRVACount++
}
}
gotRequestProbs := mockLog.GetAllMatching(".IsCAAValid returned problem: ")
test.AssertEquals(t, len(gotRequestProbs), invalidRVACount)
gotDifferential := mockLog.GetAllMatching("remoteVADifferentials JSON=.*")
if features.Get().MultiCAAFullResults && tc.expectedDiffLogSubstring != "" {
test.AssertEquals(t, len(gotDifferential), 1)
test.AssertContains(t, gotDifferential[0], tc.expectedDiffLogSubstring)
} else {
test.AssertEquals(t, len(gotDifferential), 0)
}
gotAnyRemoteFailures := mockLog.GetAllMatching("CAA check failed due to remote failures:")
if len(gotAnyRemoteFailures) >= 1 {
// The primary VA only emits this line once.
test.AssertEquals(t, len(gotAnyRemoteFailures), 1)
} else {
test.AssertEquals(t, len(gotAnyRemoteFailures), 0)
}
})
}
}
func TestCAAFailure(t *testing.T) {
hs := httpSrv(t, expectedToken)
defer hs.Close()
va, _ := setup(hs, 0, "", nil, caaMockDNS{})
err := va.checkCAA(ctx, dnsi("reserved.com"), &caaParams{1, core.ChallengeTypeHTTP01})
if err == nil {
t.Fatalf("Expected CAA rejection for reserved.com, got success")
}
test.AssertErrorIs(t, err, berrors.CAA)
err = va.checkCAA(ctx, dnsi("example.gonetld"), &caaParams{1, core.ChallengeTypeHTTP01})
if err == nil {
t.Fatalf("Expected CAA rejection for gonetld, got success")
}
prob := detailedError(err)
test.AssertEquals(t, prob.Type, probs.DNSProblem)
test.AssertContains(t, prob.Error(), "NXDOMAIN")
}
func TestFilterCAA(t *testing.T) {
testCases := []struct {
name string
input []*dns.CAA
expectedIssueVals []string
expectedWildVals []string
expectedCU bool
}{
{
name: "recognized non-critical",
input: []*dns.CAA{
{Tag: "issue", Value: "a"},
{Tag: "issuewild", Value: "b"},
{Tag: "iodef", Value: "c"},
{Tag: "issuemail", Value: "c"},
},
expectedIssueVals: []string{"a"},
expectedWildVals: []string{"b"},
},