def dnscurve_decode_txt_response(packet): # XXX: Be stricter? rest = packet[12:] query, rest = dns.dns_query_read(rest, packet) (name, type, qclass, ttl, rdata), rest = dns.dns_result_read(rest, packet) if type != 'TXT': raise 'Expected TXT record' key, nonce1, box1 = dnscurve_decode_queryname(dns.dns_domain_fromdot(name)) nonce2, box2 = dnscurve_decode_rdata(parse_txt_rdata(rdata)) return nonce1 + nonce2, box2
import sys import socket import getopt import dns import dnscurve try: import nacl except ImportError, e: import slownacl as nacl type = sys.argv[1] name = sys.argv[2] server = sys.argv[3] pubkey = len(sys.argv) >= 5 and sys.argv[4] zone = len(sys.argv) >= 6 and dns.dns_domain_fromdot(sys.argv[5]) if pubkey: try: pubkey = pubkey.decode('hex') if len(pubkey) != 32: raise 'Invalid DNSCurve public key' except TypeError, e: pubkey = dnscurve.dnscurve_getpubkey(dns.dns_domain_fromdot(pubkey)) if not pubkey: raise 'Invalid DNSCurve public key' s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s.connect((server, 53)) query0 = dns.dns_build_query(type, name)