X-Git-Url: https://git.svenne.dk/?p=public%2Fdnssec-swede-utility.git;a=blobdiff_plain;f=swede;h=8e329127dbce1e3a25356f1d7cd492ebd56d1ec1;hp=2ebaf9bbe4d721e25b0a4d3260edb22f2ad156f2;hb=c72c29895d1bfdaeb16fc726c5d76d7944143a7f;hpb=8a12ccd534f0aa1d7f00e1e1962ebd8f5a62523f diff --git a/swede b/swede index 2ebaf9b..8e32912 100755 --- a/swede +++ b/swede @@ -59,7 +59,14 @@ def genTLSA(hostname, protocol, port, certificate, output='draft', usage=1, sele def getA(hostname, secure=True): """Gets a list of A records for hostname, returns a list of ARecords""" - records = getRecords(hostname, rrtype='A', secure=secure) + try: + records = getRecords(hostname, rrtype='A', secure=secure) + except InsecureLookupException, e: + print str(e) + sys.exit(1) + except DNSLookupError, e: + print 'Unable to resolve %s: %s' % (hostname, str(e)) + sys.exit(1) ret = [] for record in records: ret.append(ARecord(hostname, str(IPv4Address(int(b2a_hex(record),16))))) @@ -67,7 +74,14 @@ def getA(hostname, secure=True): def getAAAA(hostname, secure=True): """Gets a list of A records for hostname, returns a list of AAAARecords""" - records = getRecords(hostname, rrtype='AAAA', secure=secure) + try: + records = getRecords(hostname, rrtype='AAAA', secure=secure) + except InsecureLookupException, e: + print str(e) + sys.exit(1) + except DNSLookupError, e: + print 'Unable to resolve %s: %s' % (hostname, str(e)) + sys.exit(1) ret = [] for record in records: ret.append(AAAARecord(hostname, str(IPv6Address(int(b2a_hex(record),16))))) @@ -281,7 +295,7 @@ class TLSARecord: def isNameValid(self): """Check if the name if in the correct format""" - if not re.match('^(_\d{1,5}|\*)\._(tcp|udp|sctp)\.([a-z0-9]*\.){2,}$', self.name): + if not re.match('^(_\d{1,5}|\*)\._(tcp|udp|sctp)\.([-a-z0-9]*\.){2,}$', self.name): return False return True @@ -409,8 +423,8 @@ if __name__ == '__main__': try: record.isValid(raiseException=True) except RecordValidityException, e: - print sys.stderr, 'Error: %s' % str(e) - sys.exit(1) + print >> sys.stderr, 'Error: %s' % str(e) + continue else: if not args.quiet: print 'This record is valid (well-formed).' @@ -574,14 +588,14 @@ if __name__ == '__main__': break if cert: # Print the requested records based on the retrieved certificates - if args.output == 'b': + if args.output == 'both': print genTLSA(args.host, args.protocol, args.port, cert, 'draft', args.usage, args.selector, args.mtype) print genTLSA(args.host, args.protocol, args.port, cert, 'rfc', args.usage, args.selector, args.mtype) else: print genTLSA(args.host, args.protocol, args.port, cert, args.output, args.usage, args.selector, args.mtype) else: # Pass the path to the certificate to the genTLSA function - if args.output == 'b': + if args.output == 'both': print genTLSA(args.host, args.protocol, args.port, args.certificate, 'draft', args.usage, args.selector, args.mtype) print genTLSA(args.host, args.protocol, args.port, args.certificate, 'rfc', args.usage, args.selector, args.mtype) else: