1
0
Fork 0
mirror of https://github.com/NeoCloud/NeoNetwork synced 2024-12-26 11:39:23 +08:00

export ds records

This commit is contained in:
JerryXiao 2021-04-20 09:23:02 +08:00
parent 9b5511b6f4
commit fbf239c1c6
Signed by: Jerry
GPG key ID: 22618F758B5BE2E5
2 changed files with 15 additions and 2 deletions

View file

@ -1,3 +1,4 @@
netaddr==0.8.0 netaddr==0.8.0
tabulate==0.8.7 tabulate==0.8.7
toml==0.10.1 toml==0.10.1
dnspython==2.1.0

View file

@ -13,6 +13,11 @@ from pathlib import Path
import netaddr import netaddr
import toml import toml
from tabulate import tabulate from tabulate import tabulate
# dnssec
from base64 import b64decode
from dns.dnssec import make_ds
from dns.rdtypes.ANY.DNSKEY import DNSKEY
NEO_NETWORK_POOL = [ip_network("10.127.0.0/16"), ip_network("fd10:127::/32")] NEO_NETWORK_POOL = [ip_network("10.127.0.0/16"), ip_network("fd10:127::/32")]
@ -166,11 +171,14 @@ def prehandle_roa(asn_table: dict, args):
return roa4, roa6 return roa4, roa6
def export_dnssec_dnskey(): def export_dnssec_dnskey():
def ds_from_dnskey(zone, flags, protocol, algorithm, *key):
dnspy_dnskey = DNSKEY("IN", "DNSKEY", int(flags), int(protocol), int(algorithm), b64decode(" ".join(key)))
return make_ds(zone, dnspy_dnskey, "SHA256").to_text()
dnskey_path = Path("dns") / "dnssec" dnskey_path = Path("dns") / "dnssec"
dnskeys = list() dnskeys = list()
for f in dnskey_path.iterdir(): for f in dnskey_path.iterdir():
if f.name.endswith(".keys"): if f.name.endswith(".keys"):
zonekey = {"zone": "", "dnskeys": list()} zonekey = {"zone": "", "records": list()}
records = f.read_text().split("\n") records = f.read_text().split("\n")
records = [r.split() for r in records if r] records = [r.split() for r in records if r]
for zone, _ttl, _in, _dnskey, *dnskey in records: for zone, _ttl, _in, _dnskey, *dnskey in records:
@ -180,7 +188,11 @@ def export_dnssec_dnskey():
zonekey["zone"] = zone zonekey["zone"] = zone
else: else:
assert zonekey["zone"] == zone assert zonekey["zone"] == zone
zonekey["dnskeys"].append(" ".join(dnskey)) str_dnskey = " ".join(dnskey)
zonekey["records"].append({
"dnskey": str_dnskey,
"ds": ds_from_dnskey(zone, *dnskey),
})
if zonekey["zone"]: if zonekey["zone"]:
dnskeys.append(zonekey) dnskeys.append(zonekey)
return dnskeys return dnskeys