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

Filter out duplicate and bad ROAs #136

Merged
merged 1 commit into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions cmd/octorpki/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main

import "github.com/cloudflare/gortr/prefixfile"

func FilterInvalidPrefixLen(roalist []prefixfile.ROAJson) []prefixfile.ROAJson {
validROAs := make([]prefixfile.ROAJson, 0)
for _, roa := range roalist {
prefix := roa.GetPrefix()
ones, _ := prefix.Mask.Size()
if prefix.IP.To4() != nil && ones <= 24 {
validROAs = append(validROAs, roa)
continue
}

if prefix.IP.To16() != nil && ones <= 48 {
validROAs = append(validROAs, roa)
}
}

return validROAs
}

func FilterDuplicates(roalist []prefixfile.ROAJson) []prefixfile.ROAJson {
roalistNodup := make([]prefixfile.ROAJson, 0)
existingsROAs := make(map[string]struct{})
for _, roa := range roalist {
k := roa.String()
_, present := existingsROAs[k]
if !present {
roalistNodup = append(roalistNodup, roa)
existingsROAs[k] = struct{}{}
}
}

return roalistNodup
}
7 changes: 7 additions & 0 deletions cmd/octorpki/octorpki.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ var (
LogLevel = flag.String("loglevel", "info", "Log level")
Refresh = flag.Duration("refresh", time.Minute*20, "Revalidation interval")
MaxIterations = flag.Int("max.iterations", 32, "Specify the max number of iterations octorpki will make before failing to generate output.json")
Filter = flag.Bool("filter", true, "Filter out non accessible prefixes and duplicates")

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

DoCT bool
CTPath string
Filter bool
}

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

if s.Filter {
roalist.Data = FilterInvalidPrefixLen(FilterDuplicates(roalist.Data))
}

roalist.Data = filterDuplicates(roalist.Data)
if *Sign {
s.signROAList(roalist, span)
Expand Down Expand Up @@ -1480,6 +1486,7 @@ func NewOctoRPKI(tals []*pki.PKIFile, talNames []string) *OctoRPKI {
tracer: opentracing.GlobalTracer(),
DoCT: *CertTransparency,
CTPath: *CertTransparencyAddr,
Filter: *Filter,
}
}

Expand Down