Guillaume Valadon | 5a61e5c | 2013-09-10 15:37:27 +0200 | [diff] [blame] | 1 | # DNSSEC Ressource Record unit tests |
| 2 | # |
| 3 | # Type the following command to launch start the tests: |
| 4 | # $ sudo bash test/run_tests -t test/dnssecRR.uts -F |
| 5 | |
| 6 | + bitmap2RRlist() |
| 7 | |
| 8 | = example from RFC 4034 |
| 9 | RRlist2bitmap([1, 15, 46, 47, 1234]) == '\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 | |
| 11 | = [0] |
| 12 | RRlist2bitmap([0]) == '\x00\x01\x80' |
| 13 | |
| 14 | = [0,1,2,3,4,5,6,7] |
| 15 | RRlist2bitmap([0,1,2,3,4,5,6,7]) == '\x00\x01\xff' |
| 16 | |
| 17 | = [256,512,4096,36864] |
| 18 | RRlist2bitmap([256,512,4096,36864]) == '\x01\x01\x80\x02\x01\x80\x10\x01\x80\x90\x01\x80' |
| 19 | |
| 20 | = [65535] |
| 21 | RRlist2bitmap([65535]) == '\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 | |
| 23 | + From RRlist2bitmap() to bitmap2RRlist() |
| 24 | |
| 25 | = example from RFC 4034 |
| 26 | 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 | RRlist2bitmap(bitmap2RRlist(b)) == b |
| 28 | |
| 29 | = [0] |
| 30 | b= '\x00\x01\x80' |
| 31 | RRlist2bitmap(bitmap2RRlist(b)) == b |
| 32 | |
| 33 | = [0,1,2,3,4,5,6,7] |
| 34 | b = '\x00\x01\xff' |
| 35 | RRlist2bitmap(bitmap2RRlist(b)) == b |
| 36 | |
| 37 | = [256,512,4096,36864] |
| 38 | b = '\x01\x01\x80\x02\x01\x80\x10\x01\x80\x90\x01\x80' |
| 39 | RRlist2bitmap(bitmap2RRlist(b)) == b |
| 40 | |
| 41 | = [65535] |
| 42 | 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 | RRlist2bitmap(bitmap2RRlist(b)) == b |
| 44 | |
| 45 | + Test NSEC RR |
| 46 | |
| 47 | = DNSRRNSEC(), basic instanciation |
| 48 | t = DNSRRNSEC() |
| 49 | str(t) == '\x00\x00/\x00\x01\x00\x00\x00\x00\x00\x01\x00' |
| 50 | |
| 51 | = DNSRRRNSEC(), check parameters |
| 52 | t = DNSRRNSEC(rrname="scapy.secdev.org.", rclass=42, ttl=28, nextname="www.secdev.org.", typebitmaps=RRlist2bitmap([1,2,3,4,1234])) |
| 53 | str(t) == '\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 | |
| 55 | + Test NSEC3 RR |
| 56 | |
| 57 | = DNSRRNSEC3(), basic instanciation |
| 58 | t = DNSRRNSEC3() |
| 59 | str(t) == '\x00\x002\x00\x01\x00\x00\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00' |
| 60 | |
| 61 | = DNSRRRNSEC3(), check parameters |
| 62 | t = DNSRRNSEC3(rrname="scapy.secdev.org.", rclass=42, ttl=28, hashalg=7, iterations=80, saltlength=28, salt="\x28\x07", hashlength=31, nexthashedownername="XXX.scapy.secdev.org", typebitmaps=RRlist2bitmap([1,2,3,4,1234])) |
| 63 | str(t) == '\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 | |
| 65 | + Test NSEC3PARAM RR |
| 66 | |
| 67 | = DNSRRNSEC3PARAM(), basic instanciation |
| 68 | t = DNSRRNSEC3PARAM() |
| 69 | str(t) == '\x00\x003\x00\x01\x00\x00\x00\x00\x00\x05\x00\x00\x00\x00\x00' |
| 70 | |
| 71 | = DNSRRRNSEC3PARAM(), check parameters |
| 72 | t = DNSRRNSEC3(rrname="scapy.secdev.org.", rclass=42, ttl=28, hashalg=7, flags=80, iterations=80, saltlength=28, salt="\x28\x07") |
| 73 | str(t) == '\x05scapy\x06secdev\x03org\x00\x002\x00*\x00\x00\x00\x1c\x00\x08\x07P\x00P\x1c(\x07\x00' |
| 74 | |
| 75 | + Test RRSIG RR |
| 76 | |
| 77 | = DNSRRRSIG(), basic instanciation |
| 78 | t = DNSRRRSIG() |
| 79 | str(t) == '\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 | |
| 81 | = DNSRRRSIG(), check parameters |
| 82 | t = DNSRRRSIG(rrname="test.example.com.", type=46, rclass=12, ttl=64, originalttl=2807, keytag=42, signersname="test.rsig", signature="test RSIG") |
| 83 | str(t) == '\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 | |
| 85 | = DNSRRRSIG(), dissection |
| 86 | rrsig = '\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 | t = DNSRRRSIG(rrsig) |
| 88 | t.rrname == 'isc.org.' and t.labels == 2 and t.keytag == 60726 and t.signature[-4:] == '\xd2\x99\xc2\xb4' |
| 89 | |
| 90 | + Test DNSKEY RR |
| 91 | |
| 92 | = DNSRRDNSKEY(), basic instanciation |
| 93 | t = DNSRRDNSKEY() |
| 94 | str(t) == '\x00\x000\x00\x01\x00\x00\x00\x00\x00\x04\x01\x00\x03\x05' and t.sprintf("%flags%") == 'Z' |
| 95 | |
| 96 | = DNSRRDNSKEY(), check parameters |
| 97 | t = DNSRRDNSKEY(rrname="www.secdev.org.", type=42, rclass=12, ttl=1234, rdlen=567, flags=2807, protocol=195, algorithm=66, publickey="strong public key") |
| 98 | str(t) == '\x03www\x06secdev\x03org\x00\x00*\x00\x0c\x00\x00\x04\xd2\x027\n\xf7\xc3Bstrong public key' |
| 99 | |
| 100 | = DNSRRDNSKEY(), dissection |
| 101 | t = DNSRRDNSKEY('\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 | t.rrname == "dlv.isc.org." and t.rdlen == 265 and t.sprintf("%flags%") == 'SZ' and t.publickey == '\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 | |
| 104 | + Test DS and DLV RR |
| 105 | |
| 106 | = DNSRRDS() and DNSRRDLV(), basic instancaition |
| 107 | ds = DNSRRDS() |
| 108 | dlv = DNSRRDLV(type=43) |
| 109 | str(ds) == str(dlv) |
| 110 | |
| 111 | = DNSRRDS(), check parameters |
| 112 | t = DNSRRDS('\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 | t.rrname == 'isc.org.' and t.keytag == 12892 and t.algorithm == 5 and t.digesttype == 1 and t.digest == '\x98!\x13\xd0\x8bLj\x1d\x9fj\xee\x1e"7\xae\xf6\x9f?\x97Y' |
Guillaume Valadon | c727d57 | 2014-02-24 16:29:05 +0100 | [diff] [blame] | 114 | |
| 115 | + Test TXT RR |
| 116 | |
| 117 | = DNSRR(type="TXT") instanciation |
| 118 | t = DNSRR(type="TXT", rdata="test") |
| 119 | |
| 120 | = DNSRRR(), check parameters |
| 121 | t = DNSRR('\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.') |
| 122 | t.type == 16 and t.rdlen == 312 and t.rdata[:5] == "Scapy" and t.rdata[-10:] == "discovery." |