Skip to content
This repository was archived by the owner on Jun 9, 2024. It is now read-only.

Commit 50bd406

Browse files
taktOliver Geiselhardt-Herms
andauthored
Filter out duplicate and bad ROAs (#136)
Co-authored-by: Oliver Geiselhardt-Herms <[email protected]>
1 parent db71b12 commit 50bd406

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

cmd/octorpki/filter.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import "github.com/cloudflare/gortr/prefixfile"
4+
5+
func FilterInvalidPrefixLen(roalist []prefixfile.ROAJson) []prefixfile.ROAJson {
6+
validROAs := make([]prefixfile.ROAJson, 0)
7+
for _, roa := range roalist {
8+
prefix := roa.GetPrefix()
9+
ones, _ := prefix.Mask.Size()
10+
if prefix.IP.To4() != nil && ones <= 24 {
11+
validROAs = append(validROAs, roa)
12+
continue
13+
}
14+
15+
if prefix.IP.To16() != nil && ones <= 48 {
16+
validROAs = append(validROAs, roa)
17+
}
18+
}
19+
20+
return validROAs
21+
}
22+
23+
func FilterDuplicates(roalist []prefixfile.ROAJson) []prefixfile.ROAJson {
24+
roalistNodup := make([]prefixfile.ROAJson, 0)
25+
existingsROAs := make(map[string]struct{})
26+
for _, roa := range roalist {
27+
k := roa.String()
28+
_, present := existingsROAs[k]
29+
if !present {
30+
roalistNodup = append(roalistNodup, roa)
31+
existingsROAs[k] = struct{}{}
32+
}
33+
}
34+
35+
return roalistNodup
36+
}

cmd/octorpki/octorpki.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
LogLevel = flag.String("loglevel", "info", "Log level")
5353
Refresh = flag.Duration("refresh", time.Minute*20, "Revalidation interval")
5454
MaxIterations = flag.Int("max.iterations", 32, "Specify the max number of iterations octorpki will make before failing to generate output.json")
55+
Filter = flag.Bool("filter", true, "Filter out non accessible prefixes and duplicates")
5556

5657
StrictManifests = flag.Bool("strict.manifests", true, "Manifests must be complete or invalidate CA")
5758
StrictHash = flag.Bool("strict.hash", true, "Check the hash of files")
@@ -239,6 +240,7 @@ type OctoRPKI struct {
239240

240241
DoCT bool
241242
CTPath string
243+
Filter bool
242244
}
243245

244246
func (s *OctoRPKI) getRRDPFetch() map[string]string {
@@ -1003,6 +1005,10 @@ func (s *OctoRPKI) generateROAList(pkiManagers []*pki.SimpleManager, span opentr
10031005
Valid: int(validTime.Unix()),
10041006
}
10051007

1008+
if s.Filter {
1009+
roalist.Data = FilterInvalidPrefixLen(FilterDuplicates(roalist.Data))
1010+
}
1011+
10061012
roalist.Data = filterDuplicates(roalist.Data)
10071013
if *Sign {
10081014
s.signROAList(roalist, span)
@@ -1480,6 +1486,7 @@ func NewOctoRPKI(tals []*pki.PKIFile, talNames []string) *OctoRPKI {
14801486
tracer: opentracing.GlobalTracer(),
14811487
DoCT: *CertTransparency,
14821488
CTPath: *CertTransparencyAddr,
1489+
Filter: *Filter,
14831490
}
14841491
}
14851492

0 commit comments

Comments
 (0)