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
|
#!/usr/bin/env python
#
# $Id$
#
# Copyright (C) 2014 Dragon Research Labs ("DRL")
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND DRL DISCLAIMS ALL WARRANTIES WITH
# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
# AND FITNESS. IN NO EVENT SHALL DRL BE LIABLE FOR ANY SPECIAL, DIRECT,
# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
"""
Pretty-print the content of a ROA. Does NOT attempt to verify the
signature.
"""
import argparse
import rpki.POW
class ROA(rpki.POW.ROA): # pylint: disable=W0232
v4_prefixes = None
v6_prefixes = None
@staticmethod
def _format_prefix(p):
if p[2] in (None, p[1]):
return "%s/%d" % (p[0], p[1])
else:
return "%s/%d-%d" % (p[0], p[1], p[2])
def parse(self):
self.extractWithoutVerifying() # pylint: disable=E1101
v4, v6 = self.getPrefixes() # pylint: disable=E1101
self.v4_prefixes = [self._format_prefix(p) for p in (v4 or ())]
self.v6_prefixes = [self._format_prefix(p) for p in (v6 or ())]
parser = argparse.ArgumentParser(description = __doc__)
parser.add_argument("-b", "--brief", action = "store_true", help = "show only ASN and prefix(es)")
parser.add_argument("-c", "--cms", action = "store_true", help = "print text representation of entire CMS blob")
parser.add_argument("-s", "--signing-time", action = "store_true", help = "show SigningTime in brief mode")
parser.add_argument("roas", nargs = "+", type = ROA.derReadFile, help = "ROA(s) to print") # pylint: disable=E1101
args = parser.parse_args()
for roa in args.roas:
roa.parse()
if args.brief:
if args.signing_time:
print roa.signingTime(),
print roa.getASID(), " ".join(roa.v4_prefixes + roa.v6_prefixes)
else:
print "ROA Version: ", roa.getVersion()
print "SigningTime: ", roa.signingTime()
print "asID: ", roa.getASID()
if roa.v4_prefixes:
print " addressFamily:", 1
for prefix in roa.v4_prefixes:
print " IPAddress:", prefix
if roa.v6_prefixes:
print " addressFamily:", 2
for prefix in roa.v6_prefixes:
print " IPAddress:", prefix
if args.cms:
print roa.pprint()
for cer in roa.certs():
print cer.pprint()
for crl in roa.crls():
print crl.pprint()
print
|