-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8b1ca98
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
gen | ||
aspa-*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"deno.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
import { parseArgs } from "https://deno.land/std@0.207.0/cli/parse_args.ts"; | ||
|
||
type ASN = `AS${string}`; | ||
|
||
interface ASA { | ||
customer: ASN; | ||
providers: ASN[]; | ||
ta: string; | ||
} | ||
|
||
const printf = console.log; | ||
|
||
const flags = parseArgs(Deno.args, { | ||
string: ["input", "output"], | ||
boolean: ["strict", "verbose", "help"], | ||
alias: { | ||
i: "input", | ||
o: "output", | ||
s: "strict", | ||
v: "verbose", | ||
h: "help" | ||
} | ||
}); | ||
|
||
if (flags.help) { | ||
printf(`Usage: ${Deno.execPath()} [OPTIONS] | ||
Options: | ||
--help, -h Show this menu. | ||
--verbose, -v Show warnings. | ||
--input, -i The input file generated by \`routinator\`. (required) | ||
--output, -i The file to output the BIRD2 function to. | ||
--strict, -s Consider paths without ASPA invalid (NOT RECOMMENDED).`); | ||
|
||
Deno.exit(0); | ||
} | ||
|
||
let failed = false; | ||
if (!flags.input) { | ||
failed = true; | ||
printf("(error) `--input` flag not specified."); | ||
} | ||
|
||
if (!flags.output && flags.verbose) { | ||
printf("(warn) `--output` flag not specified."); | ||
} | ||
|
||
if (failed) { | ||
Deno.exit(1); | ||
} | ||
|
||
const data = await Deno.readTextFile(flags.input as string); // we know flags.input will not be undefined by this point. | ||
|
||
const json = parseData(data); | ||
if (!json) { | ||
printf(`(error) could not parse json from \`${flags.input}\``); | ||
Deno.exit(2); | ||
} | ||
|
||
const aspas: ASA[] = json.aspas; | ||
if (!aspas) { | ||
printf(`(error) property \`aspas\` does not exist on the parsed JSON from \`${flags.input}\``); | ||
Deno.exit(3); | ||
} | ||
|
||
let txt = "function is_aspa_valid () {\n"; | ||
|
||
const LEADING_AS = /^AS/g; | ||
for (const {customer, providers} of aspas) { | ||
const asn = customer.replace(LEADING_AS, ''); | ||
|
||
txt += ` # does the AS path include ${customer}?\n` | ||
txt += ` if (bgp_path ~ [= * ${asn} * =]) then {\n`; | ||
txt += ` # does the AS path include [carrier's asn, ${customer}]?\n` | ||
for (const provider of providers) { | ||
const carrier = provider.replace(LEADING_AS, ''); | ||
|
||
txt += ` if (bgp_path ~ [= * ${carrier} ${asn} * =]) then return true;\n`; | ||
} | ||
txt += ' return false;\n'; | ||
txt += ' }\n\n' | ||
} | ||
|
||
if (flags.strict) { | ||
txt += ' # (strict mode) if no previous condition matches there exists no ASPA for the path; it is invalid.\n'; | ||
txt += ' return false;\n'; | ||
} else { | ||
txt += ' # to avoid breaking stuff, assume the path is valid if no ASA exists.\n'; | ||
txt += ' return true;\n'; | ||
} | ||
txt += '}\n'; | ||
|
||
if (!flags.output) { | ||
console.log(txt); | ||
|
||
Deno.exit(0); | ||
} | ||
|
||
try { | ||
await Deno.writeTextFile(flags.output, txt); | ||
} catch (e) { | ||
printf(`(error) writing to disk raised: ${e}`); | ||
} | ||
|
||
function parseData(data: string) { | ||
try { | ||
return JSON.parse(data); | ||
} catch { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
## "Compilation" to a stand-alone binary | ||
|
||
This is as easy as running the following command: | ||
|
||
``` | ||
deno compile --allow-read --allow-write ./gen.ts | ||
``` | ||
|
||
# my sticky notes: | ||
|
||
## 1: | ||
|
||
the as_path filters used: | ||
|
||
is the asn in the path? | ||
`bgp_path ~ [= * <ASN> * =]` | ||
|
||
is the carrier + the asn in the path? | ||
`bgp_path ~ [= * <CARRIER> <ASN> * =]` | ||
|
||
## 2: | ||
|
||
get just the aspa dump from routinator: | ||
|
||
``` | ||
routinator --enable-aspa vrps -f json -o /root/dump.json --no-route-origins --no-router-keys | ||
``` | ||
|
||
this is probably missing a flag to skip tls verification for idiots (the ASAs are signed anyway?): | ||
|
||
`[WARN] RRDP https://rpki.cnnic.cn/rrdp/notify.xml: error sending request for url (https://rpki.cnnic.cn/rrdp/notify.xml): error trying to connect: invalid peer certificate: UnknownIssuer` |