xref: /aosp_15_r20/external/scapy/test/dnssecRR.uts (revision 7dc08ffc4802948ccbc861daaf1e81c405c2c4bd)
1*7dc08ffcSJunyu Lai# DNSSEC Resource Record unit tests
2*7dc08ffcSJunyu Lai#
3*7dc08ffcSJunyu Lai# Type the following command to launch start the tests:
4*7dc08ffcSJunyu Lai# $ sudo bash test/run_tests -t test/dnssecRR.uts -F
5*7dc08ffcSJunyu Lai
6*7dc08ffcSJunyu Lai+ bitmap2RRlist()
7*7dc08ffcSJunyu Lai
8*7dc08ffcSJunyu Lai= example from RFC 4034
9*7dc08ffcSJunyu LaiRRlist2bitmap([1, 15, 46, 47, 1234]) == b'\x00\x06@\x01\x00\x00\x00\x03\x04\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'
10*7dc08ffcSJunyu Lai
11*7dc08ffcSJunyu Lai= [0]
12*7dc08ffcSJunyu LaiRRlist2bitmap([0]) == b'\x00\x01\x80'
13*7dc08ffcSJunyu Lai
14*7dc08ffcSJunyu Lai= [0,1,2,3,4,5,6,7]
15*7dc08ffcSJunyu LaiRRlist2bitmap([0,1,2,3,4,5,6,7]) == b'\x00\x01\xff'
16*7dc08ffcSJunyu Lai
17*7dc08ffcSJunyu Lai= [256,512,4096,36864]
18*7dc08ffcSJunyu LaiRRlist2bitmap([256,512,4096,36864]) == b'\x01\x01\x80\x02\x01\x80\x10\x01\x80\x90\x01\x80'
19*7dc08ffcSJunyu Lai
20*7dc08ffcSJunyu Lai= [65535]
21*7dc08ffcSJunyu LaiRRlist2bitmap([65535]) == b'\xff\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
22*7dc08ffcSJunyu Lai
23*7dc08ffcSJunyu Lai+ From RRlist2bitmap() to bitmap2RRlist()
24*7dc08ffcSJunyu Lai
25*7dc08ffcSJunyu Lai= example from RFC 4034
26*7dc08ffcSJunyu Laib = b'\x00\x06@\x01\x00\x00\x00\x03\x04\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20'
27*7dc08ffcSJunyu LaiRRlist2bitmap(bitmap2RRlist(b)) == b
28*7dc08ffcSJunyu Lai
29*7dc08ffcSJunyu Lai= [0]
30*7dc08ffcSJunyu Laib= b'\x00\x01\x80'
31*7dc08ffcSJunyu LaiRRlist2bitmap(bitmap2RRlist(b)) == b
32*7dc08ffcSJunyu Lai
33*7dc08ffcSJunyu Lai= [0,1,2,3,4,5,6,7]
34*7dc08ffcSJunyu Laib = b'\x00\x01\xff'
35*7dc08ffcSJunyu LaiRRlist2bitmap(bitmap2RRlist(b)) == b
36*7dc08ffcSJunyu Lai
37*7dc08ffcSJunyu Lai= [256,512,4096,36864]
38*7dc08ffcSJunyu Laib = b'\x01\x01\x80\x02\x01\x80\x10\x01\x80\x90\x01\x80'
39*7dc08ffcSJunyu LaiRRlist2bitmap(bitmap2RRlist(b)) == b
40*7dc08ffcSJunyu Lai
41*7dc08ffcSJunyu Lai= [65535]
42*7dc08ffcSJunyu Laib = b'\xff\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01'
43*7dc08ffcSJunyu LaiRRlist2bitmap(bitmap2RRlist(b)) == b
44*7dc08ffcSJunyu Lai
45*7dc08ffcSJunyu Lai+ Test NSEC RR
46*7dc08ffcSJunyu Lai
47*7dc08ffcSJunyu Lai= DNSRRNSEC(), basic instanciation
48*7dc08ffcSJunyu Lait = DNSRRNSEC()
49*7dc08ffcSJunyu Lairaw(t) == b'\x00\x00/\x00\x01\x00\x00\x00\x00\x00\x01\x00'
50*7dc08ffcSJunyu Lai
51*7dc08ffcSJunyu Lai= DNSRRRNSEC(), check parameters
52*7dc08ffcSJunyu Lait = DNSRRNSEC(rrname="scapy.secdev.org.", rclass=42, ttl=28, nextname="www.secdev.org.", typebitmaps=RRlist2bitmap([1,2,3,4,1234]))
53*7dc08ffcSJunyu Lairaw(t) == b'\x05scapy\x06secdev\x03org\x00\x00/\x00*\x00\x00\x00\x1c\x000\x03www\x06secdev\x03org\x00\x00\x01x\x04\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 '
54*7dc08ffcSJunyu Lai
55*7dc08ffcSJunyu Lai+ Test NSEC3 RR
56*7dc08ffcSJunyu Lai
57*7dc08ffcSJunyu Lai= DNSRRNSEC3(), basic instanciation
58*7dc08ffcSJunyu Lait = DNSRRNSEC3()
59*7dc08ffcSJunyu Lairaw(t) == b'\x00\x002\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00'
60*7dc08ffcSJunyu Lai
61*7dc08ffcSJunyu Lai= DNSRRRNSEC3(), check parameters
62*7dc08ffcSJunyu Lait = DNSRRNSEC3(rrname="scapy.secdev.org.", rclass=42, ttl=28, hashalg=7, iterations=80, saltlength=28, salt=b"\x28\x07", hashlength=31, nexthashedownername="XXX.scapy.secdev.org", typebitmaps=RRlist2bitmap([1,2,3,4,1234]))
63*7dc08ffcSJunyu Lairaw(t) == b'\x05scapy\x06secdev\x03org\x00\x002\x00*\x00\x00\x00\x1c\x00<\x07\x00\x00P\x1c(\x07\x1fXXX.scapy.secdev.org\x00\x01x\x04\x1b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 '
64*7dc08ffcSJunyu Lai
65*7dc08ffcSJunyu Lai+ Test NSEC3PARAM RR
66*7dc08ffcSJunyu Lai
67*7dc08ffcSJunyu Lai= DNSRRNSEC3PARAM(), basic instanciation
68*7dc08ffcSJunyu Lait = DNSRRNSEC3PARAM()
69*7dc08ffcSJunyu Lairaw(t) == b'\x00\x003\x00\x01\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00'
70*7dc08ffcSJunyu Lai
71*7dc08ffcSJunyu Lai= DNSRRRNSEC3PARAM(), check parameters
72*7dc08ffcSJunyu Lait = DNSRRNSEC3(rrname="scapy.secdev.org.", rclass=42, ttl=28, hashalg=7, flags=80, iterations=80, saltlength=28, salt=b"\x28\x07")
73*7dc08ffcSJunyu Lairaw(t) == b'\x05scapy\x06secdev\x03org\x00\x002\x00*\x00\x00\x00\x1c\x00\x08\x07P\x00P\x1c(\x07\x00'
74*7dc08ffcSJunyu Lai
75*7dc08ffcSJunyu Lai+ Test RRSIG RR
76*7dc08ffcSJunyu Lai
77*7dc08ffcSJunyu Lai= DNSRRRSIG(), basic instanciation
78*7dc08ffcSJunyu Lait = DNSRRRSIG()
79*7dc08ffcSJunyu Lairaw(t) == b'\x00\x00.\x00\x01\x00\x00\x00\x00\x00\x13\x00\x01\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
80*7dc08ffcSJunyu Lai
81*7dc08ffcSJunyu Lai= DNSRRRSIG(), check parameters
82*7dc08ffcSJunyu Lait = DNSRRRSIG(rrname="test.example.com.", type=46, rclass=12, ttl=64, originalttl=2807, keytag=42, signersname="test.rsig", signature="test RSIG")
83*7dc08ffcSJunyu Lairaw(t) == b'\x04test\x07example\x03com\x00\x00.\x00\x0c\x00\x00\x00@\x00&\x00\x01\x05\x00\x00\x00\n\xf7\x00\x00\x00\x00\x00\x00\x00\x00\x00*\x04test\x04rsig\x00test RSIG'
84*7dc08ffcSJunyu Lai
85*7dc08ffcSJunyu Lai= DNSRRRSIG(), dissection
86*7dc08ffcSJunyu Lairrsig = b'\x03isc\x03org\x00\x00.\x00\x01\x00\x00\x96O\x00\x9b\x00\x02\x05\x02\x00\x00\xa8\xc0K-3\xd9K\x05\xa6\xd9\xed6\x03isc\x03org\x00\xac\xb2_I\x9e\xdcU\xca/3\x1c\xdf{\xba\xd5\x80\xb0 \xa4~\x98\x95\xab~\x84\xb2\x1f9\x17#\x7f\xfeP\xb9\xfb\x8d\x13\x19\xd7\x7f\x9e/\x1c\xd7rv<\xc6\xd3\xf1\xae8\rh\xba\x1e\xaa\xe6\xf1\x1e\x1d\xdaS\xd4\\\xfd\xa3`P\xa1\xe0\xa2\x860\xd4?\xb4}j\x81O\x03\xdc&v\x13\xd4(k\xa07\x8f-\x08e\x06\xff\xb8h\x8f\x16j\xe4\xd92\xd2\x99\xc2\xb4'
87*7dc08ffcSJunyu Lait = DNSRRRSIG(rrsig)
88*7dc08ffcSJunyu Lait.rrname == b'isc.org.' and t.labels == 2 and t.keytag == 60726 and t.signature[-4:] == b'\xd2\x99\xc2\xb4'
89*7dc08ffcSJunyu Lai
90*7dc08ffcSJunyu Lai+ Test DNSKEY RR
91*7dc08ffcSJunyu Lai
92*7dc08ffcSJunyu Lai= DNSRRDNSKEY(), basic instanciation
93*7dc08ffcSJunyu Lait = DNSRRDNSKEY()
94*7dc08ffcSJunyu Lairaw(t) == b'\x00\x000\x00\x01\x00\x00\x00\x00\x00\x04\x01\x00\x03\x05' and t.sprintf("%flags%") == 'Z'
95*7dc08ffcSJunyu Lai
96*7dc08ffcSJunyu Lai= DNSRRDNSKEY(), check parameters
97*7dc08ffcSJunyu Lait = DNSRRDNSKEY(rrname="www.secdev.org.", type=42, rclass=12, ttl=1234, rdlen=567, flags=2807, protocol=195, algorithm=66, publickey="strong public key")
98*7dc08ffcSJunyu Lairaw(t) == b'\x03www\x06secdev\x03org\x00\x00*\x00\x0c\x00\x00\x04\xd2\x027\n\xf7\xc3Bstrong public key'
99*7dc08ffcSJunyu Lai
100*7dc08ffcSJunyu Lai= DNSRRDNSKEY(), dissection
101*7dc08ffcSJunyu Lait = DNSRRDNSKEY(b'\x03dlv\x03isc\x03org\x00\x000\x00\x01\x00\x00\x1bq\x01\t\x01\x01\x03\x05\x04@\x00\x00\x03\xc72\xef\xf9\xa2|\xeb\x10N\xf3\xd5\xe8&\x86\x0f\xd6<\xed>\x8e\xea\x19\xadm\xde\xb9a\'\xe0\xccC\x08M~\x94\xbc\xb6n\xb8P\xbf\x9a\xcd\xdfdJ\xb4\xcc\xd7\xe8\xc8\xfb\xd27sx\xd0\xf8^I\xd6\xe7\xc7g$\xd3\xc2\xc6\x7f>\x8c\x01\xa5\xd8VK+\xcb~\xd6\xea\xb8[\xe9\xe7\x03z\x8e\xdb\xe0\xcb\xfaN\x81\x0f\x89\x9e\xc0\xc2\xdb!\x81p{C\xc6\xeft\xde\xf5\xf6v\x90\x96\xf9\xe9\xd8`1\xd7\xb9\xcae\xf8\x04\x8f\xe8C\xe7\x00+\x9d?\xc6\xf2o\xd3Ak\x7f\xc90\xea\xe7\x0cO\x01e\x80\xf7\xbe\x8eq\xb1<\xf1&\x1c\x0b^\xfdDdc\xad\x99~B\xe8\x04\x00\x03,t="\xb4\xb6\xb6\xbc\x80{\xb9\x9b\x05\x95\\;\x02\x1eS\xf4p\xfedq\xfe\xfc00$\xe05\xba\x0c@\xabTv\xf3W\x0e\xb6\t\r!\xd9\xc2\xcd\xf1\x89\x15\xc5\xd5\x17\xfej_T\x99\x97\xd2j\xff\xf85b\xca\x8c|\xe9O\x9fd\xfdT\xadL3taK\x96\xac\x13a')
102*7dc08ffcSJunyu Lait.rrname == b"dlv.isc.org." and t.rdlen == 265 and t.sprintf("%flags%") == 'SZ' and t.publickey == b'\x04@\x00\x00\x03\xc72\xef\xf9\xa2|\xeb\x10N\xf3\xd5\xe8&\x86\x0f\xd6<\xed>\x8e\xea\x19\xadm\xde\xb9a\'\xe0\xccC\x08M~\x94\xbc\xb6n\xb8P\xbf\x9a\xcd\xdfdJ\xb4\xcc\xd7\xe8\xc8\xfb\xd27sx\xd0\xf8^I\xd6\xe7\xc7g$\xd3\xc2\xc6\x7f>\x8c\x01\xa5\xd8VK+\xcb~\xd6\xea\xb8[\xe9\xe7\x03z\x8e\xdb\xe0\xcb\xfaN\x81\x0f\x89\x9e\xc0\xc2\xdb!\x81p{C\xc6\xeft\xde\xf5\xf6v\x90\x96\xf9\xe9\xd8`1\xd7\xb9\xcae\xf8\x04\x8f\xe8C\xe7\x00+\x9d?\xc6\xf2o\xd3Ak\x7f\xc90\xea\xe7\x0cO\x01e\x80\xf7\xbe\x8eq\xb1<\xf1&\x1c\x0b^\xfdDdc\xad\x99~B\xe8\x04\x00\x03,t="\xb4\xb6\xb6\xbc\x80{\xb9\x9b\x05\x95\\;\x02\x1eS\xf4p\xfedq\xfe\xfc00$\xe05\xba\x0c@\xabTv\xf3W\x0e\xb6\t\r!\xd9\xc2\xcd\xf1\x89\x15\xc5\xd5\x17\xfej_T\x99\x97\xd2j\xff\xf85b\xca\x8c|\xe9O\x9fd\xfdT\xadL3taK\x96\xac\x13a'
103*7dc08ffcSJunyu Lai
104*7dc08ffcSJunyu Lai+ Test DS and DLV RR
105*7dc08ffcSJunyu Lai
106*7dc08ffcSJunyu Lai= DNSRRDS() and DNSRRDLV(), basic instancaition
107*7dc08ffcSJunyu Laids = DNSRRDS()
108*7dc08ffcSJunyu Laidlv = DNSRRDLV(type=43)
109*7dc08ffcSJunyu Lairaw(ds) == raw(dlv)
110*7dc08ffcSJunyu Lai
111*7dc08ffcSJunyu Lai= DNSRRDS(), check parameters
112*7dc08ffcSJunyu Lait = DNSRRDS(b'\x03isc\x03org\x00\x00+\x00\x01\x00\x01Q(\x00\x182\\\x05\x01\x98!\x13\xd0\x8bLj\x1d\x9fj\xee\x1e"7\xae\xf6\x9f?\x97Y')
113*7dc08ffcSJunyu Lait.rrname == b'isc.org.' and t.keytag == 12892 and t.algorithm == 5 and t.digesttype == 1 and t.digest == b'\x98!\x13\xd0\x8bLj\x1d\x9fj\xee\x1e"7\xae\xf6\x9f?\x97Y'
114*7dc08ffcSJunyu Lai
115*7dc08ffcSJunyu Lai+ Test TXT RR
116*7dc08ffcSJunyu Lai
117*7dc08ffcSJunyu Lai= DNSRR(type="TXT") instanciation
118*7dc08ffcSJunyu Lait = DNSRR(type="TXT", rdata="test")
119*7dc08ffcSJunyu Lai
120*7dc08ffcSJunyu Lai= Build DNSRR
121*7dc08ffcSJunyu Laian = DNSRR(type='AAAA', rdata='2001::1')
122*7dc08ffcSJunyu Laian = DNSRR(raw(an))
123*7dc08ffcSJunyu Laiassert an.rdata == '2001::1'
124*7dc08ffcSJunyu Lai
125*7dc08ffcSJunyu Lai= DNSRRR(), check parameters
126*7dc08ffcSJunyu Lait = DNSRR(b'\x04test\x00\x00\x10\x00\x01\x00\x00\x00\x00\x018\xffScapy is an interactive packet manipulation program that enables you to sniff, mangle, send network packets ; test equipments ; probe and discover networks ; quickly develop new protocols. It can easily handle most classical tasks like scanning, tracerout7ing, probing, unit tests, attacks or network discovery.')
127*7dc08ffcSJunyu Lait.type == 16 and t.rdlen == 312 and t.rdata[:5] == b"Scapy" and t.rdata[-10:] == b"discovery."
128*7dc08ffcSJunyu Lai
129*7dc08ffcSJunyu Lai+ Test DNSRRTSIG RR
130*7dc08ffcSJunyu Lai
131*7dc08ffcSJunyu Lai= DNSRRTSIG basic instanciation
132*7dc08ffcSJunyu Lait = DNSRRTSIG()
133*7dc08ffcSJunyu Lairaw(t) == b"\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00"
134*7dc08ffcSJunyu Lai
135*7dc08ffcSJunyu Lai= DNSRRTSIG(), check parameters
136*7dc08ffcSJunyu Lait = DNSRRTSIG(rrname="SAMPLE-ALG.EXAMPLE.", time_signed=853804800, fudge=300)
137*7dc08ffcSJunyu Lairaw(t) == b"\nSAMPLE-ALG\x07EXAMPLE\x00\x00\xfa\x00\x01\x00\x00\x00\x00\x00\x1b\thmac-sha1\x00\x00\x002\xe4\x07\x00\x01,\x00\x14\x00\x00\x00\x00\x00\x00"
138*7dc08ffcSJunyu Lai
139*7dc08ffcSJunyu Lai= TimeField methods
140*7dc08ffcSJunyu Lai
141*7dc08ffcSJunyu Laipacked_data = b"\x00\x002\xe4\x07\x00"
142*7dc08ffcSJunyu Laiassert(TimeSignedField("", 0).h2i("", 853804800) == packed_data)
143*7dc08ffcSJunyu Laiassert(TimeSignedField("", 0).i2h("", packed_data) == 853804800)
144*7dc08ffcSJunyu Laiassert(TimeSignedField("", 0).i2repr("", packed_data) == "Tue Jan 21 00:00:00 1997")
145