From 1b303e449ae125c7936406bfe08a5338125b4aed Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 1 Nov 2024 18:50:19 -0400 Subject: [PATCH] Support rpki-client JSON format --- aspa/data.py | 21 +- aspa/example.json | 105 ++++- aspa/rpki-client.json | 915 ++++++++++++++++++++++++++++++++++++++++++ aspa/test.py | 15 +- 4 files changed, 1043 insertions(+), 13 deletions(-) create mode 100644 aspa/rpki-client.json diff --git a/aspa/data.py b/aspa/data.py index 371bd3d..1c5cb95 100644 --- a/aspa/data.py +++ b/aspa/data.py @@ -1,13 +1,16 @@ import json import re from dataclasses import dataclass -from typing import Optional +from typing import Optional, Union reasn = re.compile(r"^AS(\d+)$") -def parse_asn(text: str) -> Optional[int]: - match = reasn.match(text) +def parse_asn(value: Union[str, int]) -> Optional[int]: + if isinstance(value, int): + return value + + match = reasn.match(value) if match: return int(match.group(1)) @@ -16,14 +19,20 @@ def parse_asn(text: str) -> Optional[int]: class ASPA: customer: int providers: list[int] - ta: str + ta: Optional[str] @classmethod def from_dict(cls, d): try: - customer = parse_asn(d['customer']) + if 'customer' in d: + customer = parse_asn(d['customer']) + elif 'customer_asid' in d: + customer = parse_asn(d['customer_asid']) + else: + return None + providers = list(map(parse_asn, d['providers'])) - return cls(customer, providers, d['ta']) + return cls(customer, providers, d.get('ta')) except (KeyError, TypeError): return None diff --git a/aspa/example.json b/aspa/example.json index 26d4e64..f47ed0f 100644 --- a/aspa/example.json +++ b/aspa/example.json @@ -1,9 +1,16 @@ { "metadata": { - "generated": 1730172244, - "generatedTime": "2024-10-29T03:24:04Z" + "generated": 1730500980, + "generatedTime": "2024-11-01T22:43:00Z" }, "aspas": [ + { + "customer": "AS970", + "providers": [ + "AS54874" + ], + "ta": "arin" + }, { "customer": "AS11358", "providers": [ @@ -43,6 +50,13 @@ ], "ta": "arin" }, + { + "customer": "AS21957", + "providers": [ + "AS970" + ], + "ta": "arin" + }, { "customer": "AS28584", "providers": [ @@ -213,6 +227,13 @@ ], "ta": "ripe" }, + { + "customer": "AS50555", + "providers": [ + "AS970" + ], + "ta": "ripe" + }, { "customer": "AS51019", "providers": [ @@ -438,6 +459,31 @@ ], "ta": "ripe" }, + { + "customer": "AS200160", + "providers": [ + "AS945", + "AS6939", + "AS15353", + "AS21738", + "AS29632", + "AS34465", + "AS34549", + "AS34927", + "AS36369", + "AS48605", + "AS140731", + "AS150249", + "AS199762", + "AS203686", + "AS203913", + "AS210152", + "AS210475", + "AS400304", + "AS400818" + ], + "ta": "ripe" + }, { "customer": "AS200242", "providers": [ @@ -615,6 +661,32 @@ ], "ta": "ripe" }, + { + "customer": "AS209025", + "providers": [ + "AS945", + "AS6939", + "AS15353", + "AS21738", + "AS29632", + "AS34465", + "AS34549", + "AS34927", + "AS36369", + "AS48605", + "AS140731", + "AS150249", + "AS199762", + "AS200160", + "AS203686", + "AS203913", + "AS210152", + "AS210475", + "AS400304", + "AS400818" + ], + "ta": "ripe" + }, { "customer": "AS210561", "providers": [ @@ -656,6 +728,33 @@ ], "ta": "ripe" }, + { + "customer": "AS213086", + "providers": [ + "AS945", + "AS6939", + "AS15353", + "AS21738", + "AS29632", + "AS34465", + "AS34549", + "AS34927", + "AS36369", + "AS48605", + "AS140731", + "AS150249", + "AS199762", + "AS200160", + "AS203686", + "AS203913", + "AS207656", + "AS210152", + "AS210475", + "AS400304", + "AS400818" + ], + "ta": "ripe" + }, { "customer": "AS215028", "providers": [ @@ -707,7 +806,6 @@ { "customer": "AS215778", "providers": [ - "AS34465", "AS39249", "AS41051", "AS207656", @@ -813,7 +911,6 @@ "customer": "AS401111", "providers": [ "AS945", - "AS6939", "AS17676" ], "ta": "arin" diff --git a/aspa/rpki-client.json b/aspa/rpki-client.json new file mode 100644 index 0000000..8988b07 --- /dev/null +++ b/aspa/rpki-client.json @@ -0,0 +1,915 @@ +{ + "aspas": [ + { + "customer_asid": 970, + "expires": 1730538312, + "providers": [ + 54874 + ] + }, + { + "customer_asid": 11358, + "expires": 1730531608, + "providers": [ + 835, + 924, + 6939, + 20473, + 34927 + ] + }, + { + "customer_asid": 13852, + "expires": 1730549327, + "providers": [ + 6939, + 20473, + 34927, + 41051, + 52025 + ] + }, + { + "customer_asid": 15562, + "expires": 1730520011, + "providers": [ + 2914, + 8283, + 51088, + 206238 + ] + }, + { + "customer_asid": 19330, + "expires": 1730571436, + "providers": [ + 393577 + ] + }, + { + "customer_asid": 21957, + "expires": 1730538312, + "providers": [ + 970 + ] + }, + { + "customer_asid": 28584, + "expires": 1730578637, + "providers": [ + 28605 + ] + }, + { + "customer_asid": 33733, + "expires": 1730582237, + "providers": [ + 174, + 6939, + 12186, + 47787, + 200454 + ] + }, + { + "customer_asid": 40544, + "expires": 1730556387, + "providers": [ + 924, + 6939, + 12186, + 52025 + ] + }, + { + "customer_asid": 41720, + "expires": 1730563201, + "providers": [ + 174, + 1299, + 9002, + 50877, + 60068, + 203446, + 212508 + ] + }, + { + "customer_asid": 44324, + "expires": 1730540598, + "providers": [ + 945, + 955, + 1299, + 3204, + 6939, + 7720, + 8772, + 8849, + 15353, + 18041, + 20473, + 29632, + 32595, + 34465, + 34927, + 41051, + 43426, + 47272, + 51087, + 53667, + 53808, + 59538, + 61112, + 134823, + 138997, + 139317, + 151364, + 199545, + 199765, + 200105, + 206499, + 207656, + 207841, + 209554, + 209735, + 212483 + ] + }, + { + "customer_asid": 47272, + "expires": 1730561019, + "providers": [ + 835, + 924, + 1299, + 6830, + 6939, + 20473, + 21738, + 25759, + 34927, + 35133, + 41051, + 48605, + 50391, + 50917, + 52025, + 52210, + 58057, + 210667, + 212514, + 212895 + ] + }, + { + "customer_asid": 47689, + "expires": 1730563201, + "providers": [ + 924, + 1299, + 6939, + 21738, + 34465, + 34549, + 34927, + 395823 + ] + }, + { + "customer_asid": 48070, + "expires": 1730563201, + "providers": [ + 174, + 1299 + ] + }, + { + "customer_asid": 48606, + "expires": 1730531513, + "providers": [ + 30893, + 54681, + 57974, + 59678, + 210691, + 212276 + ] + }, + { + "customer_asid": 50224, + "expires": 1730546559, + "providers": [ + 6939, + 15353, + 26930, + 34465, + 37988, + 50104, + 52025, + 52210, + 59920, + 60841, + 210475, + 400304 + ] + }, + { + "customer_asid": 50391, + "expires": 1730537906, + "providers": [ + 6939, + 20473, + 48070 + ] + }, + { + "customer_asid": 50555, + "expires": 1730532071, + "providers": [ + 970 + ] + }, + { + "customer_asid": 51019, + "expires": 1730560829, + "providers": [ + 6939, + 34549, + 34927, + 52025, + 207841 + ] + }, + { + "customer_asid": 51396, + "expires": 1730563201, + "providers": [ + 6939, + 30823, + 44066, + 49581, + 60223, + 203446, + 214995, + 215436 + ] + }, + { + "customer_asid": 52025, + "expires": 1730547627, + "providers": [ + 174, + 835, + 906, + 917, + 924, + 1299, + 3257, + 6204, + 6939, + 7720, + 8860, + 12186, + 18041, + 20473, + 21700, + 21738, + 25369, + 29802, + 32097, + 34549, + 34927, + 35133, + 35661, + 36369, + 37988, + 39409, + 47787, + 48070, + 48605, + 50917, + 51519, + 52210, + 56655, + 57695, + 61138, + 197216, + 199545, + 209022, + 209533, + 394177, + 396998, + 397423, + 400304, + 400587 + ] + }, + { + "customer_asid": 52210, + "expires": 1730562314, + "providers": [ + 174, + 835, + 6939, + 52025, + 62513, + 210667 + ] + }, + { + "customer_asid": 54148, + "expires": 1730563237, + "providers": [ + 835, + 924, + 6939, + 20473, + 21738, + 34927, + 37988, + 47272, + 50917, + 53667 + ] + }, + { + "customer_asid": 54218, + "expires": 1730572673, + "providers": [ + 917, + 16509, + 37988, + 53667, + 59678 + ] + }, + { + "customer_asid": 56762, + "expires": 1730563201, + "providers": [ + 47689 + ] + }, + { + "customer_asid": 57194, + "expires": 1730562314, + "providers": [ + 924, + 52210 + ] + }, + { + "customer_asid": 57984, + "expires": 1730563201, + "providers": [ + 8283, + 48112, + 206763 + ] + }, + { + "customer_asid": 59678, + "expires": 1730531513, + "providers": [ + 6939, + 34927, + 54218, + 55081 + ] + }, + { + "customer_asid": 60223, + "expires": 1730563201, + "providers": [ + 945, + 49581 + ] + }, + { + "customer_asid": 60431, + "expires": 1730563201, + "providers": [ + 34927, + 41495, + 50917 + ] + }, + { + "customer_asid": 60841, + "expires": 1730563201, + "providers": [ + 30456, + 400304 + ] + }, + { + "customer_asid": 149301, + "expires": 1730539765, + "providers": [ + 20473, + 61138 + ] + }, + { + "customer_asid": 151642, + "expires": 1730596405, + "providers": [ + 20473, + 61138 + ] + }, + { + "customer_asid": 198136, + "expires": 1730563201, + "providers": [ + 0 + ] + }, + { + "customer_asid": 199376, + "expires": 1730563201, + "providers": [ + 47311, + 61112, + 150249, + 151544, + 199762, + 209533, + 215379 + ] + }, + { + "customer_asid": 199762, + "expires": 1730563201, + "providers": [ + 945, + 6939, + 8849, + 15353, + 34927, + 44817, + 47311, + 48605, + 140731, + 150249 + ] + }, + { + "customer_asid": 200160, + "expires": 1730534753, + "providers": [ + 945, + 6939, + 15353, + 21738, + 29632, + 34465, + 34549, + 34927, + 36369, + 48605, + 140731, + 150249, + 199762, + 203686, + 203913, + 210152, + 210475, + 400304, + 400818 + ] + }, + { + "customer_asid": 200242, + "expires": 1730531523, + "providers": [ + 835, + 6939, + 21738, + 34465, + 34927, + 52025, + 59678, + 60841, + 210475 + ] + }, + { + "customer_asid": 200351, + "expires": 1730563237, + "providers": [ + 34927, + 47272, + 209022, + 210475 + ] + }, + { + "customer_asid": 200454, + "expires": 1730563201, + "providers": [ + 174, + 6424, + 6939, + 9186, + 12186 + ] + }, + { + "customer_asid": 202076, + "expires": 1730563201, + "providers": [ + 207960 + ] + }, + { + "customer_asid": 202359, + "expires": 1730530237, + "providers": [ + 30740, + 33920, + 41495 + ] + }, + { + "customer_asid": 202881, + "expires": 1730563201, + "providers": [ + 205329 + ] + }, + { + "customer_asid": 203619, + "expires": 1730563201, + "providers": [ + 200454 + ] + }, + { + "customer_asid": 203843, + "expires": 1730546014, + "providers": [ + 6939, + 20473, + 53667 + ] + }, + { + "customer_asid": 204857, + "expires": 1730563201, + "providers": [ + 50224, + 59920, + 60841, + 400304 + ] + }, + { + "customer_asid": 204931, + "expires": 1730563201, + "providers": [ + 34927, + 44103, + 207656 + ] + }, + { + "customer_asid": 205329, + "expires": 1730563201, + "providers": [ + 945, + 983, + 6939, + 7720, + 8894, + 9409, + 20473, + 34927, + 41051, + 131657, + 134823, + 151364 + ] + }, + { + "customer_asid": 205603, + "expires": 1730563201, + "providers": [ + 38074, + 59105 + ] + }, + { + "customer_asid": 205663, + "expires": 1730590405, + "providers": [ + 20473, + 61138 + ] + }, + { + "customer_asid": 205789, + "expires": 1730563201, + "providers": [ + 200242, + 207960 + ] + }, + { + "customer_asid": 205848, + "expires": 1730563201, + "providers": [ + 1299, + 6939, + 34549, + 34927, + 52025, + 209022 + ] + }, + { + "customer_asid": 207487, + "expires": 1730563201, + "providers": [ + 20473 + ] + }, + { + "customer_asid": 207841, + "expires": 1730563201, + "providers": [ + 174, + 6939, + 137409 + ] + }, + { + "customer_asid": 207960, + "expires": 1730530237, + "providers": [ + 6939, + 20473, + 34854, + 34927, + 136620, + 202359, + 207968 + ] + }, + { + "customer_asid": 209025, + "expires": 1730563201, + "providers": [ + 945, + 6939, + 15353, + 21738, + 29632, + 34465, + 34549, + 34927, + 36369, + 48605, + 140731, + 150249, + 199762, + 200160, + 203686, + 203913, + 210152, + 210475, + 400304, + 400818 + ] + }, + { + "customer_asid": 210561, + "expires": 1730540499, + "providers": [ + 207960 + ] + }, + { + "customer_asid": 212068, + "expires": 1730563201, + "providers": [ + 6939, + 13237, + 62240, + 207960 + ] + }, + { + "customer_asid": 212245, + "expires": 1730553868, + "providers": [ + 917, + 57695, + 212068 + ] + }, + { + "customer_asid": 212934, + "expires": 1730562314, + "providers": [ + 835, + 6939, + 34927, + 52210, + 53667, + 61138, + 62513, + 209533, + 210667 + ] + }, + { + "customer_asid": 213086, + "expires": 1730552333, + "providers": [ + 945, + 6939, + 15353, + 21738, + 29632, + 34465, + 34549, + 34927, + 36369, + 48605, + 140731, + 150249, + 199762, + 200160, + 203686, + 203913, + 207656, + 210152, + 210475, + 400304, + 400818 + ] + }, + { + "customer_asid": 215028, + "expires": 1730561919, + "providers": [ + 216107 + ] + }, + { + "customer_asid": 215131, + "expires": 1730563201, + "providers": [ + 8283, + 34927 + ] + }, + { + "customer_asid": 215147, + "expires": 1730532329, + "providers": [ + 47263, + 207252, + 215828 + ] + }, + { + "customer_asid": 215436, + "expires": 1730563201, + "providers": [ + 6762, + 6939, + 51396, + 60223 + ] + }, + { + "customer_asid": 215664, + "expires": 1730537714, + "providers": [ + 1299, + 3204, + 6939, + 34549, + 41720, + 56382, + 203446, + 212508 + ] + }, + { + "customer_asid": 215778, + "expires": 1730563201, + "providers": [ + 39249, + 41051, + 207656, + 209533, + 393577 + ] + }, + { + "customer_asid": 215828, + "expires": 1730546789, + "providers": [ + 6204, + 6939, + 8772, + 29390, + 29632, + 34465, + 34927, + 39249, + 41051, + 44592, + 48752, + 50917, + 51019, + 58057, + 62403, + 152726, + 197071, + 199524, + 203686, + 207656, + 209533, + 210464, + 216324, + 216360, + 393577 + ] + }, + { + "customer_asid": 215849, + "expires": 1730552922, + "providers": [ + 215828 + ] + }, + { + "customer_asid": 216107, + "expires": 1730561919, + "providers": [ + 924, + 6939, + 16509, + 20473, + 21738, + 34927, + 63473, + 209022, + 211588 + ] + }, + { + "customer_asid": 216311, + "expires": 1730546448, + "providers": [ + 6939, + 13852, + 20473, + 34927, + 52025 + ] + }, + { + "customer_asid": 267386, + "expires": 1730538516, + "providers": [ + 6939, + 25933, + 28220, + 28649, + 267613 + ] + }, + { + "customer_asid": 270470, + "expires": 1730571406, + "providers": [ + 53062 + ] + }, + { + "customer_asid": 393577, + "expires": 1730531956, + "providers": [ + 1299, + 6939, + 32097, + 40676, + 137409 + ] + }, + { + "customer_asid": 401111, + "expires": 1730531576, + "providers": [ + 945, + 17676 + ] + } + ] +} diff --git a/aspa/test.py b/aspa/test.py index aef0cdb..5509bb8 100644 --- a/aspa/test.py +++ b/aspa/test.py @@ -6,16 +6,25 @@ class ParserTest(unittest.TestCase): + file = Path(__file__).parent / 'example.json' + test_ta = True + def test_parse(self): - with open(Path(__file__).parent / 'example.json') as f: + with open(self.file) as f: result = parse_json(f.read()) - self.assertEqual(len(result), 69) + self.assertEqual(len(result), 75) for aspa in result: if aspa.customer == 54148: self.assertEqual(aspa.providers, [835, 924, 6939, 20473, 21738, 34927, 37988, 47272, 50917, 53667]) - self.assertEqual(aspa.ta, 'arin') + if self.test_ta: + self.assertEqual(aspa.ta, 'arin') + + +class RPKIClientTest(ParserTest): + file = Path(__file__).parent / 'rpki-client.json' + test_ta = False class CustomerTest(unittest.TestCase):