]> git.saurik.com Git - apple/network_cmds.git/blob - unbound/libunbound/python/examples/dnssec_test.py
0d62b9ff2154438daf49a5b6e3e0c31141b40a1a
[apple/network_cmds.git] / unbound / libunbound / python / examples / dnssec_test.py
1 #!/usr/bin/env python
2 from unbound import ub_ctx, RR_TYPE_A, RR_TYPE_RRSIG, RR_TYPE_NSEC, RR_TYPE_NSEC3
3 import ldns
4
5 def dnssecParse(domain, rrType=RR_TYPE_A):
6 print("Resolving domain", domain)
7 s, r = resolver.resolve(domain)
8 print("status: %s, secure: %s, rcode: %s, havedata: %s, answer_len; %s" % (s, r.secure, r.rcode_str, r.havedata, r.answer_len))
9
10 s, pkt = ldns.ldns_wire2pkt(r.packet)
11 if s != 0:
12 raise RuntimeError("Error parsing DNS packet")
13
14 rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_ANSWER)
15 print("RRSIGs from answer:", rrsigs)
16
17 rrsigs = pkt.rr_list_by_type(RR_TYPE_RRSIG, ldns.LDNS_SECTION_AUTHORITY)
18 print("RRSIGs from authority:", rrsigs)
19
20 nsecs = pkt.rr_list_by_type(RR_TYPE_NSEC, ldns.LDNS_SECTION_AUTHORITY)
21 print("NSECs:", nsecs)
22
23 nsec3s = pkt.rr_list_by_type(RR_TYPE_NSEC3, ldns.LDNS_SECTION_AUTHORITY)
24 print("NSEC3s:", nsec3s)
25
26 print("---")
27
28
29 resolver = ub_ctx()
30 resolver.add_ta(". IN DS 19036 8 2 49AAC11D7B6F6446702E54A1607371607A1A41855200FD2CE1CDDE32F24E8FB5")
31
32 dnssecParse("nic.cz")
33 dnssecParse("nonexistent-domain-blablabla.cz")
34 dnssecParse("nonexistent-domain-blablabla.root.cz")
35