mirror of
https://github.com/Tautulli/Tautulli.git
synced 2025-08-14 10:36:57 -07:00
Add ipwhois library + dependencies
This commit is contained in:
parent
43bd49ce5b
commit
469d22a833
104 changed files with 21349 additions and 2417 deletions
53
lib/dns/rdtypes/ANY/AFSDB.py
Normal file
53
lib/dns/rdtypes/ANY/AFSDB.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.mxbase
|
||||
|
||||
|
||||
class AFSDB(dns.rdtypes.mxbase.UncompressedDowncasingMX):
|
||||
|
||||
"""AFSDB record
|
||||
|
||||
@ivar subtype: the subtype value
|
||||
@type subtype: int
|
||||
@ivar hostname: the hostname name
|
||||
@type hostname: dns.name.Name object"""
|
||||
|
||||
# Use the property mechanism to make "subtype" an alias for the
|
||||
# "preference" attribute, and "hostname" an alias for the "exchange"
|
||||
# attribute.
|
||||
#
|
||||
# This lets us inherit the UncompressedMX implementation but lets
|
||||
# the caller use appropriate attribute names for the rdata type.
|
||||
#
|
||||
# We probably lose some performance vs. a cut-and-paste
|
||||
# implementation, but this way we don't copy code, and that's
|
||||
# good.
|
||||
|
||||
def get_subtype(self):
|
||||
return self.preference
|
||||
|
||||
def set_subtype(self, subtype):
|
||||
self.preference = subtype
|
||||
|
||||
subtype = property(get_subtype, set_subtype)
|
||||
|
||||
def get_hostname(self):
|
||||
return self.exchange
|
||||
|
||||
def set_hostname(self, hostname):
|
||||
self.exchange = hostname
|
||||
|
||||
hostname = property(get_hostname, set_hostname)
|
74
lib/dns/rdtypes/ANY/CAA.py
Normal file
74
lib/dns/rdtypes/ANY/CAA.py
Normal file
|
@ -0,0 +1,74 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
|
||||
|
||||
class CAA(dns.rdata.Rdata):
|
||||
|
||||
"""CAA (Certification Authority Authorization) record
|
||||
|
||||
@ivar flags: the flags
|
||||
@type flags: int
|
||||
@ivar tag: the tag
|
||||
@type tag: string
|
||||
@ivar value: the value
|
||||
@type value: string
|
||||
@see: RFC 6844"""
|
||||
|
||||
__slots__ = ['flags', 'tag', 'value']
|
||||
|
||||
def __init__(self, rdclass, rdtype, flags, tag, value):
|
||||
super(CAA, self).__init__(rdclass, rdtype)
|
||||
self.flags = flags
|
||||
self.tag = tag
|
||||
self.value = value
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%u %s "%s"' % (self.flags,
|
||||
dns.rdata._escapify(self.tag),
|
||||
dns.rdata._escapify(self.value))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
flags = tok.get_uint8()
|
||||
tag = tok.get_string().encode()
|
||||
if len(tag) > 255:
|
||||
raise dns.exception.SyntaxError("tag too long")
|
||||
if not tag.isalnum():
|
||||
raise dns.exception.SyntaxError("tag is not alphanumeric")
|
||||
value = tok.get_string().encode()
|
||||
return cls(rdclass, rdtype, flags, tag, value)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(struct.pack('!B', self.flags))
|
||||
l = len(self.tag)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.tag)
|
||||
file.write(self.value)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(flags, l) = struct.unpack('!BB', wire[current: current + 2])
|
||||
current += 2
|
||||
tag = wire[current: current + l]
|
||||
value = wire[current + l:current + rdlen - 2]
|
||||
return cls(rdclass, rdtype, flags, tag, value)
|
||||
|
25
lib/dns/rdtypes/ANY/CDNSKEY.py
Normal file
25
lib/dns/rdtypes/ANY/CDNSKEY.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.dnskeybase
|
||||
from dns.rdtypes.dnskeybase import flags_to_text_set, flags_from_text_set
|
||||
|
||||
|
||||
__all__ = ['flags_to_text_set', 'flags_from_text_set']
|
||||
|
||||
|
||||
class CDNSKEY(dns.rdtypes.dnskeybase.DNSKEYBase):
|
||||
|
||||
"""CDNSKEY record"""
|
21
lib/dns/rdtypes/ANY/CDS.py
Normal file
21
lib/dns/rdtypes/ANY/CDS.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.dsbase
|
||||
|
||||
|
||||
class CDS(dns.rdtypes.dsbase.DSBase):
|
||||
|
||||
"""CDS record"""
|
122
lib/dns/rdtypes/ANY/CERT.py
Normal file
122
lib/dns/rdtypes/ANY/CERT.py
Normal file
|
@ -0,0 +1,122 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import base64
|
||||
|
||||
import dns.exception
|
||||
import dns.dnssec
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
|
||||
_ctype_by_value = {
|
||||
1: 'PKIX',
|
||||
2: 'SPKI',
|
||||
3: 'PGP',
|
||||
253: 'URI',
|
||||
254: 'OID',
|
||||
}
|
||||
|
||||
_ctype_by_name = {
|
||||
'PKIX': 1,
|
||||
'SPKI': 2,
|
||||
'PGP': 3,
|
||||
'URI': 253,
|
||||
'OID': 254,
|
||||
}
|
||||
|
||||
|
||||
def _ctype_from_text(what):
|
||||
v = _ctype_by_name.get(what)
|
||||
if v is not None:
|
||||
return v
|
||||
return int(what)
|
||||
|
||||
|
||||
def _ctype_to_text(what):
|
||||
v = _ctype_by_value.get(what)
|
||||
if v is not None:
|
||||
return v
|
||||
return str(what)
|
||||
|
||||
|
||||
class CERT(dns.rdata.Rdata):
|
||||
|
||||
"""CERT record
|
||||
|
||||
@ivar certificate_type: certificate type
|
||||
@type certificate_type: int
|
||||
@ivar key_tag: key tag
|
||||
@type key_tag: int
|
||||
@ivar algorithm: algorithm
|
||||
@type algorithm: int
|
||||
@ivar certificate: the certificate or CRL
|
||||
@type certificate: string
|
||||
@see: RFC 2538"""
|
||||
|
||||
__slots__ = ['certificate_type', 'key_tag', 'algorithm', 'certificate']
|
||||
|
||||
def __init__(self, rdclass, rdtype, certificate_type, key_tag, algorithm,
|
||||
certificate):
|
||||
super(CERT, self).__init__(rdclass, rdtype)
|
||||
self.certificate_type = certificate_type
|
||||
self.key_tag = key_tag
|
||||
self.algorithm = algorithm
|
||||
self.certificate = certificate
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
certificate_type = _ctype_to_text(self.certificate_type)
|
||||
return "%s %d %s %s" % (certificate_type, self.key_tag,
|
||||
dns.dnssec.algorithm_to_text(self.algorithm),
|
||||
dns.rdata._base64ify(self.certificate))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
certificate_type = _ctype_from_text(tok.get_string())
|
||||
key_tag = tok.get_uint16()
|
||||
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
|
||||
if algorithm < 0 or algorithm > 255:
|
||||
raise dns.exception.SyntaxError("bad algorithm type")
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
b64 = b''.join(chunks)
|
||||
certificate = base64.b64decode(b64)
|
||||
return cls(rdclass, rdtype, certificate_type, key_tag,
|
||||
algorithm, certificate)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
prefix = struct.pack("!HHB", self.certificate_type, self.key_tag,
|
||||
self.algorithm)
|
||||
file.write(prefix)
|
||||
file.write(self.certificate)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
prefix = wire[current: current + 5].unwrap()
|
||||
current += 5
|
||||
rdlen -= 5
|
||||
if rdlen < 0:
|
||||
raise dns.exception.FormError
|
||||
(certificate_type, key_tag, algorithm) = struct.unpack("!HHB", prefix)
|
||||
certificate = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, certificate_type, key_tag, algorithm,
|
||||
certificate)
|
||||
|
25
lib/dns/rdtypes/ANY/CNAME.py
Normal file
25
lib/dns/rdtypes/ANY/CNAME.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.nsbase
|
||||
|
||||
|
||||
class CNAME(dns.rdtypes.nsbase.NSBase):
|
||||
|
||||
"""CNAME record
|
||||
|
||||
Note: although CNAME is officially a singleton type, dnspython allows
|
||||
non-singleton CNAME rdatasets because such sets have been commonly
|
||||
used by BIND and other nameservers for load balancing."""
|
124
lib/dns/rdtypes/ANY/CSYNC.py
Normal file
124
lib/dns/rdtypes/ANY/CSYNC.py
Normal file
|
@ -0,0 +1,124 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011, 2016 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
import dns.name
|
||||
from dns._compat import xrange
|
||||
|
||||
class CSYNC(dns.rdata.Rdata):
|
||||
|
||||
"""CSYNC record
|
||||
|
||||
@ivar serial: the SOA serial number
|
||||
@type serial: int
|
||||
@ivar flags: the CSYNC flags
|
||||
@type flags: int
|
||||
@ivar windows: the windowed bitmap list
|
||||
@type windows: list of (window number, string) tuples"""
|
||||
|
||||
__slots__ = ['serial', 'flags', 'windows']
|
||||
|
||||
def __init__(self, rdclass, rdtype, serial, flags, windows):
|
||||
super(CSYNC, self).__init__(rdclass, rdtype)
|
||||
self.serial = serial
|
||||
self.flags = flags
|
||||
self.windows = windows
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
text = ''
|
||||
for (window, bitmap) in self.windows:
|
||||
bits = []
|
||||
for i in xrange(0, len(bitmap)):
|
||||
byte = bitmap[i]
|
||||
for j in xrange(0, 8):
|
||||
if byte & (0x80 >> j):
|
||||
bits.append(dns.rdatatype.to_text(window * 256 +
|
||||
i * 8 + j))
|
||||
text += (' ' + ' '.join(bits))
|
||||
return '%d %d%s' % (self.serial, self.flags, text)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
serial = tok.get_uint32()
|
||||
flags = tok.get_uint16()
|
||||
rdtypes = []
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
nrdtype = dns.rdatatype.from_text(token.value)
|
||||
if nrdtype == 0:
|
||||
raise dns.exception.SyntaxError("CSYNC with bit 0")
|
||||
if nrdtype > 65535:
|
||||
raise dns.exception.SyntaxError("CSYNC with bit > 65535")
|
||||
rdtypes.append(nrdtype)
|
||||
rdtypes.sort()
|
||||
window = 0
|
||||
octets = 0
|
||||
prior_rdtype = 0
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
windows = []
|
||||
for nrdtype in rdtypes:
|
||||
if nrdtype == prior_rdtype:
|
||||
continue
|
||||
prior_rdtype = nrdtype
|
||||
new_window = nrdtype // 256
|
||||
if new_window != window:
|
||||
windows.append((window, bitmap[0:octets]))
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
window = new_window
|
||||
offset = nrdtype % 256
|
||||
byte = offset // 8
|
||||
bit = offset % 8
|
||||
octets = byte + 1
|
||||
bitmap[byte] = bitmap[byte] | (0x80 >> bit)
|
||||
|
||||
windows.append((window, bitmap[0:octets]))
|
||||
return cls(rdclass, rdtype, serial, flags, windows)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(struct.pack('!IH', self.serial, self.flags))
|
||||
for (window, bitmap) in self.windows:
|
||||
file.write(struct.pack('!BB', window, len(bitmap)))
|
||||
file.write(bitmap)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
if rdlen < 6:
|
||||
raise dns.exception.FormError("CSYNC too short")
|
||||
(serial, flags) = struct.unpack("!IH", wire[current: current + 6])
|
||||
current += 6
|
||||
rdlen -= 6
|
||||
windows = []
|
||||
while rdlen > 0:
|
||||
if rdlen < 3:
|
||||
raise dns.exception.FormError("CSYNC too short")
|
||||
window = wire[current]
|
||||
octets = wire[current + 1]
|
||||
if octets == 0 or octets > 32:
|
||||
raise dns.exception.FormError("bad CSYNC octets")
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
if rdlen < octets:
|
||||
raise dns.exception.FormError("bad CSYNC bitmap length")
|
||||
bitmap = bytearray(wire[current: current + octets].unwrap())
|
||||
current += octets
|
||||
rdlen -= octets
|
||||
windows.append((window, bitmap))
|
||||
return cls(rdclass, rdtype, serial, flags, windows)
|
21
lib/dns/rdtypes/ANY/DLV.py
Normal file
21
lib/dns/rdtypes/ANY/DLV.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.dsbase
|
||||
|
||||
|
||||
class DLV(dns.rdtypes.dsbase.DSBase):
|
||||
|
||||
"""DLV record"""
|
24
lib/dns/rdtypes/ANY/DNAME.py
Normal file
24
lib/dns/rdtypes/ANY/DNAME.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.nsbase
|
||||
|
||||
|
||||
class DNAME(dns.rdtypes.nsbase.UncompressedNS):
|
||||
|
||||
"""DNAME record"""
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
return self.target.to_digestable(origin)
|
25
lib/dns/rdtypes/ANY/DNSKEY.py
Normal file
25
lib/dns/rdtypes/ANY/DNSKEY.py
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.dnskeybase
|
||||
from dns.rdtypes.dnskeybase import flags_to_text_set, flags_from_text_set
|
||||
|
||||
|
||||
__all__ = ['flags_to_text_set', 'flags_from_text_set']
|
||||
|
||||
|
||||
class DNSKEY(dns.rdtypes.dnskeybase.DNSKEYBase):
|
||||
|
||||
"""DNSKEY record"""
|
21
lib/dns/rdtypes/ANY/DS.py
Normal file
21
lib/dns/rdtypes/ANY/DS.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.dsbase
|
||||
|
||||
|
||||
class DS(dns.rdtypes.dsbase.DSBase):
|
||||
|
||||
"""DS record"""
|
29
lib/dns/rdtypes/ANY/EUI48.py
Normal file
29
lib/dns/rdtypes/ANY/EUI48.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Copyright (C) 2015 Red Hat, Inc.
|
||||
# Author: Petr Spacek <pspacek@redhat.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.euibase
|
||||
|
||||
|
||||
class EUI48(dns.rdtypes.euibase.EUIBase):
|
||||
|
||||
"""EUI48 record
|
||||
|
||||
@ivar fingerprint: 48-bit Extended Unique Identifier (EUI-48)
|
||||
@type fingerprint: string
|
||||
@see: rfc7043.txt"""
|
||||
|
||||
byte_len = 6 # 0123456789ab (in hex)
|
||||
text_len = byte_len * 3 - 1 # 01-23-45-67-89-ab
|
29
lib/dns/rdtypes/ANY/EUI64.py
Normal file
29
lib/dns/rdtypes/ANY/EUI64.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
# Copyright (C) 2015 Red Hat, Inc.
|
||||
# Author: Petr Spacek <pspacek@redhat.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.euibase
|
||||
|
||||
|
||||
class EUI64(dns.rdtypes.euibase.EUIBase):
|
||||
|
||||
"""EUI64 record
|
||||
|
||||
@ivar fingerprint: 64-bit Extended Unique Identifier (EUI-64)
|
||||
@type fingerprint: string
|
||||
@see: rfc7043.txt"""
|
||||
|
||||
byte_len = 8 # 0123456789abcdef (in hex)
|
||||
text_len = byte_len * 3 - 1 # 01-23-45-67-89-ab-cd-ef
|
160
lib/dns/rdtypes/ANY/GPOS.py
Normal file
160
lib/dns/rdtypes/ANY/GPOS.py
Normal file
|
@ -0,0 +1,160 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import long, text_type
|
||||
|
||||
|
||||
def _validate_float_string(what):
|
||||
if what[0] == b'-'[0] or what[0] == b'+'[0]:
|
||||
what = what[1:]
|
||||
if what.isdigit():
|
||||
return
|
||||
(left, right) = what.split(b'.')
|
||||
if left == b'' and right == b'':
|
||||
raise dns.exception.FormError
|
||||
if not left == b'' and not left.decode().isdigit():
|
||||
raise dns.exception.FormError
|
||||
if not right == b'' and not right.decode().isdigit():
|
||||
raise dns.exception.FormError
|
||||
|
||||
|
||||
def _sanitize(value):
|
||||
if isinstance(value, text_type):
|
||||
return value.encode()
|
||||
return value
|
||||
|
||||
|
||||
class GPOS(dns.rdata.Rdata):
|
||||
|
||||
"""GPOS record
|
||||
|
||||
@ivar latitude: latitude
|
||||
@type latitude: string
|
||||
@ivar longitude: longitude
|
||||
@type longitude: string
|
||||
@ivar altitude: altitude
|
||||
@type altitude: string
|
||||
@see: RFC 1712"""
|
||||
|
||||
__slots__ = ['latitude', 'longitude', 'altitude']
|
||||
|
||||
def __init__(self, rdclass, rdtype, latitude, longitude, altitude):
|
||||
super(GPOS, self).__init__(rdclass, rdtype)
|
||||
if isinstance(latitude, float) or \
|
||||
isinstance(latitude, int) or \
|
||||
isinstance(latitude, long):
|
||||
latitude = str(latitude)
|
||||
if isinstance(longitude, float) or \
|
||||
isinstance(longitude, int) or \
|
||||
isinstance(longitude, long):
|
||||
longitude = str(longitude)
|
||||
if isinstance(altitude, float) or \
|
||||
isinstance(altitude, int) or \
|
||||
isinstance(altitude, long):
|
||||
altitude = str(altitude)
|
||||
latitude = _sanitize(latitude)
|
||||
longitude = _sanitize(longitude)
|
||||
altitude = _sanitize(altitude)
|
||||
_validate_float_string(latitude)
|
||||
_validate_float_string(longitude)
|
||||
_validate_float_string(altitude)
|
||||
self.latitude = latitude
|
||||
self.longitude = longitude
|
||||
self.altitude = altitude
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%s %s %s' % (self.latitude.decode(),
|
||||
self.longitude.decode(),
|
||||
self.altitude.decode())
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
latitude = tok.get_string()
|
||||
longitude = tok.get_string()
|
||||
altitude = tok.get_string()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, latitude, longitude, altitude)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.latitude)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.latitude)
|
||||
l = len(self.longitude)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.longitude)
|
||||
l = len(self.altitude)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.altitude)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen:
|
||||
raise dns.exception.FormError
|
||||
latitude = wire[current: current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen:
|
||||
raise dns.exception.FormError
|
||||
longitude = wire[current: current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l != rdlen:
|
||||
raise dns.exception.FormError
|
||||
altitude = wire[current: current + l].unwrap()
|
||||
return cls(rdclass, rdtype, latitude, longitude, altitude)
|
||||
|
||||
def _get_float_latitude(self):
|
||||
return float(self.latitude)
|
||||
|
||||
def _set_float_latitude(self, value):
|
||||
self.latitude = str(value)
|
||||
|
||||
float_latitude = property(_get_float_latitude, _set_float_latitude,
|
||||
doc="latitude as a floating point value")
|
||||
|
||||
def _get_float_longitude(self):
|
||||
return float(self.longitude)
|
||||
|
||||
def _set_float_longitude(self, value):
|
||||
self.longitude = str(value)
|
||||
|
||||
float_longitude = property(_get_float_longitude, _set_float_longitude,
|
||||
doc="longitude as a floating point value")
|
||||
|
||||
def _get_float_altitude(self):
|
||||
return float(self.altitude)
|
||||
|
||||
def _set_float_altitude(self, value):
|
||||
self.altitude = str(value)
|
||||
|
||||
float_altitude = property(_get_float_altitude, _set_float_altitude,
|
||||
doc="altitude as a floating point value")
|
85
lib/dns/rdtypes/ANY/HINFO.py
Normal file
85
lib/dns/rdtypes/ANY/HINFO.py
Normal file
|
@ -0,0 +1,85 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import text_type
|
||||
|
||||
|
||||
class HINFO(dns.rdata.Rdata):
|
||||
|
||||
"""HINFO record
|
||||
|
||||
@ivar cpu: the CPU type
|
||||
@type cpu: string
|
||||
@ivar os: the OS type
|
||||
@type os: string
|
||||
@see: RFC 1035"""
|
||||
|
||||
__slots__ = ['cpu', 'os']
|
||||
|
||||
def __init__(self, rdclass, rdtype, cpu, os):
|
||||
super(HINFO, self).__init__(rdclass, rdtype)
|
||||
if isinstance(cpu, text_type):
|
||||
self.cpu = cpu.encode()
|
||||
else:
|
||||
self.cpu = cpu
|
||||
if isinstance(os, text_type):
|
||||
self.os = os.encode()
|
||||
else:
|
||||
self.os = os
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '"%s" "%s"' % (dns.rdata._escapify(self.cpu),
|
||||
dns.rdata._escapify(self.os))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
cpu = tok.get_string()
|
||||
os = tok.get_string()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, cpu, os)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.cpu)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.cpu)
|
||||
l = len(self.os)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.os)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen:
|
||||
raise dns.exception.FormError
|
||||
cpu = wire[current:current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l != rdlen:
|
||||
raise dns.exception.FormError
|
||||
os = wire[current: current + l].unwrap()
|
||||
return cls(rdclass, rdtype, cpu, os)
|
||||
|
113
lib/dns/rdtypes/ANY/HIP.py
Normal file
113
lib/dns/rdtypes/ANY/HIP.py
Normal file
|
@ -0,0 +1,113 @@
|
|||
# Copyright (C) 2010, 2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import base64
|
||||
import binascii
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
class HIP(dns.rdata.Rdata):
|
||||
|
||||
"""HIP record
|
||||
|
||||
@ivar hit: the host identity tag
|
||||
@type hit: string
|
||||
@ivar algorithm: the public key cryptographic algorithm
|
||||
@type algorithm: int
|
||||
@ivar key: the public key
|
||||
@type key: string
|
||||
@ivar servers: the rendezvous servers
|
||||
@type servers: list of dns.name.Name objects
|
||||
@see: RFC 5205"""
|
||||
|
||||
__slots__ = ['hit', 'algorithm', 'key', 'servers']
|
||||
|
||||
def __init__(self, rdclass, rdtype, hit, algorithm, key, servers):
|
||||
super(HIP, self).__init__(rdclass, rdtype)
|
||||
self.hit = hit
|
||||
self.algorithm = algorithm
|
||||
self.key = key
|
||||
self.servers = servers
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
hit = binascii.hexlify(self.hit).decode()
|
||||
key = base64.b64encode(self.key).replace(b'\n', b'').decode()
|
||||
text = u''
|
||||
servers = []
|
||||
for server in self.servers:
|
||||
servers.append(server.choose_relativity(origin, relativize))
|
||||
if len(servers) > 0:
|
||||
text += (u' ' + u' '.join(map(lambda x: x.to_unicode(), servers)))
|
||||
return u'%u %s %s%s' % (self.algorithm, hit, key, text)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
algorithm = tok.get_uint8()
|
||||
hit = binascii.unhexlify(tok.get_string().encode())
|
||||
if len(hit) > 255:
|
||||
raise dns.exception.SyntaxError("HIT too long")
|
||||
key = base64.b64decode(tok.get_string().encode())
|
||||
servers = []
|
||||
while 1:
|
||||
token = tok.get()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
server = dns.name.from_text(token.value, origin)
|
||||
server.choose_relativity(origin, relativize)
|
||||
servers.append(server)
|
||||
return cls(rdclass, rdtype, hit, algorithm, key, servers)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
lh = len(self.hit)
|
||||
lk = len(self.key)
|
||||
file.write(struct.pack("!BBH", lh, self.algorithm, lk))
|
||||
file.write(self.hit)
|
||||
file.write(self.key)
|
||||
for server in self.servers:
|
||||
server.to_wire(file, None, origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(lh, algorithm, lk) = struct.unpack('!BBH',
|
||||
wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
hit = wire[current: current + lh].unwrap()
|
||||
current += lh
|
||||
rdlen -= lh
|
||||
key = wire[current: current + lk].unwrap()
|
||||
current += lk
|
||||
rdlen -= lk
|
||||
servers = []
|
||||
while rdlen > 0:
|
||||
(server, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
if origin is not None:
|
||||
server = server.relativize(origin)
|
||||
servers.append(server)
|
||||
return cls(rdclass, rdtype, hit, algorithm, key, servers)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
servers = []
|
||||
for server in self.servers:
|
||||
server = server.choose_relativity(origin, relativize)
|
||||
servers.append(server)
|
||||
self.servers = servers
|
98
lib/dns/rdtypes/ANY/ISDN.py
Normal file
98
lib/dns/rdtypes/ANY/ISDN.py
Normal file
|
@ -0,0 +1,98 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import text_type
|
||||
|
||||
|
||||
class ISDN(dns.rdata.Rdata):
|
||||
|
||||
"""ISDN record
|
||||
|
||||
@ivar address: the ISDN address
|
||||
@type address: string
|
||||
@ivar subaddress: the ISDN subaddress (or '' if not present)
|
||||
@type subaddress: string
|
||||
@see: RFC 1183"""
|
||||
|
||||
__slots__ = ['address', 'subaddress']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address, subaddress):
|
||||
super(ISDN, self).__init__(rdclass, rdtype)
|
||||
if isinstance(address, text_type):
|
||||
self.address = address.encode()
|
||||
else:
|
||||
self.address = address
|
||||
if isinstance(address, text_type):
|
||||
self.subaddress = subaddress.encode()
|
||||
else:
|
||||
self.subaddress = subaddress
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
if self.subaddress:
|
||||
return '"%s" "%s"' % (dns.rdata._escapify(self.address),
|
||||
dns.rdata._escapify(self.subaddress))
|
||||
else:
|
||||
return '"%s"' % dns.rdata._escapify(self.address)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_string()
|
||||
t = tok.get()
|
||||
if not t.is_eol_or_eof():
|
||||
tok.unget(t)
|
||||
subaddress = tok.get_string()
|
||||
else:
|
||||
tok.unget(t)
|
||||
subaddress = ''
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, address, subaddress)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.address)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.address)
|
||||
l = len(self.subaddress)
|
||||
if l > 0:
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.subaddress)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen:
|
||||
raise dns.exception.FormError
|
||||
address = wire[current: current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
if rdlen > 0:
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l != rdlen:
|
||||
raise dns.exception.FormError
|
||||
subaddress = wire[current: current + l].unwrap()
|
||||
else:
|
||||
subaddress = ''
|
||||
return cls(rdclass, rdtype, address, subaddress)
|
||||
|
327
lib/dns/rdtypes/ANY/LOC.py
Normal file
327
lib/dns/rdtypes/ANY/LOC.py
Normal file
|
@ -0,0 +1,327 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
from dns._compat import long, xrange
|
||||
|
||||
|
||||
_pows = tuple(long(10**i) for i in range(0, 11))
|
||||
|
||||
# default values are in centimeters
|
||||
_default_size = 100.0
|
||||
_default_hprec = 1000000.0
|
||||
_default_vprec = 1000.0
|
||||
|
||||
|
||||
def _exponent_of(what, desc):
|
||||
if what == 0:
|
||||
return 0
|
||||
exp = None
|
||||
for i in xrange(len(_pows)):
|
||||
if what // _pows[i] == long(0):
|
||||
exp = i - 1
|
||||
break
|
||||
if exp is None or exp < 0:
|
||||
raise dns.exception.SyntaxError("%s value out of bounds" % desc)
|
||||
return exp
|
||||
|
||||
|
||||
def _float_to_tuple(what):
|
||||
if what < 0:
|
||||
sign = -1
|
||||
what *= -1
|
||||
else:
|
||||
sign = 1
|
||||
what = long(round(what * 3600000))
|
||||
degrees = int(what // 3600000)
|
||||
what -= degrees * 3600000
|
||||
minutes = int(what // 60000)
|
||||
what -= minutes * 60000
|
||||
seconds = int(what // 1000)
|
||||
what -= int(seconds * 1000)
|
||||
what = int(what)
|
||||
return (degrees, minutes, seconds, what, sign)
|
||||
|
||||
|
||||
def _tuple_to_float(what):
|
||||
value = float(what[0])
|
||||
value += float(what[1]) / 60.0
|
||||
value += float(what[2]) / 3600.0
|
||||
value += float(what[3]) / 3600000.0
|
||||
return float(what[4]) * value
|
||||
|
||||
|
||||
def _encode_size(what, desc):
|
||||
what = long(what)
|
||||
exponent = _exponent_of(what, desc) & 0xF
|
||||
base = what // pow(10, exponent) & 0xF
|
||||
return base * 16 + exponent
|
||||
|
||||
|
||||
def _decode_size(what, desc):
|
||||
exponent = what & 0x0F
|
||||
if exponent > 9:
|
||||
raise dns.exception.SyntaxError("bad %s exponent" % desc)
|
||||
base = (what & 0xF0) >> 4
|
||||
if base > 9:
|
||||
raise dns.exception.SyntaxError("bad %s base" % desc)
|
||||
return long(base) * pow(10, exponent)
|
||||
|
||||
|
||||
class LOC(dns.rdata.Rdata):
|
||||
|
||||
"""LOC record
|
||||
|
||||
@ivar latitude: latitude
|
||||
@type latitude: (int, int, int, int, sign) tuple specifying the degrees, minutes,
|
||||
seconds, milliseconds, and sign of the coordinate.
|
||||
@ivar longitude: longitude
|
||||
@type longitude: (int, int, int, int, sign) tuple specifying the degrees,
|
||||
minutes, seconds, milliseconds, and sign of the coordinate.
|
||||
@ivar altitude: altitude
|
||||
@type altitude: float
|
||||
@ivar size: size of the sphere
|
||||
@type size: float
|
||||
@ivar horizontal_precision: horizontal precision
|
||||
@type horizontal_precision: float
|
||||
@ivar vertical_precision: vertical precision
|
||||
@type vertical_precision: float
|
||||
@see: RFC 1876"""
|
||||
|
||||
__slots__ = ['latitude', 'longitude', 'altitude', 'size',
|
||||
'horizontal_precision', 'vertical_precision']
|
||||
|
||||
def __init__(self, rdclass, rdtype, latitude, longitude, altitude,
|
||||
size=_default_size, hprec=_default_hprec,
|
||||
vprec=_default_vprec):
|
||||
"""Initialize a LOC record instance.
|
||||
|
||||
The parameters I{latitude} and I{longitude} may be either a 4-tuple
|
||||
of integers specifying (degrees, minutes, seconds, milliseconds),
|
||||
or they may be floating point values specifying the number of
|
||||
degrees. The other parameters are floats. Size, horizontal precision,
|
||||
and vertical precision are specified in centimeters."""
|
||||
|
||||
super(LOC, self).__init__(rdclass, rdtype)
|
||||
if isinstance(latitude, int) or isinstance(latitude, long):
|
||||
latitude = float(latitude)
|
||||
if isinstance(latitude, float):
|
||||
latitude = _float_to_tuple(latitude)
|
||||
self.latitude = latitude
|
||||
if isinstance(longitude, int) or isinstance(longitude, long):
|
||||
longitude = float(longitude)
|
||||
if isinstance(longitude, float):
|
||||
longitude = _float_to_tuple(longitude)
|
||||
self.longitude = longitude
|
||||
self.altitude = float(altitude)
|
||||
self.size = float(size)
|
||||
self.horizontal_precision = float(hprec)
|
||||
self.vertical_precision = float(vprec)
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
if self.latitude[4] > 0:
|
||||
lat_hemisphere = 'N'
|
||||
lat_degrees = self.latitude[0]
|
||||
else:
|
||||
lat_hemisphere = 'S'
|
||||
lat_degrees = -1 * self.latitude[0]
|
||||
if self.longitude[4] > 0:
|
||||
long_hemisphere = 'E'
|
||||
long_degrees = self.longitude[0]
|
||||
else:
|
||||
long_hemisphere = 'W'
|
||||
long_degrees = -1 * self.longitude[0]
|
||||
text = "%d %d %d.%03d %s %d %d %d.%03d %s %0.2fm" % (
|
||||
self.latitude[0], self.latitude[1],
|
||||
self.latitude[2], self.latitude[3], lat_hemisphere,
|
||||
self.longitude[0], self.longitude[1], self.longitude[2],
|
||||
self.longitude[3], long_hemisphere,
|
||||
self.altitude / 100.0
|
||||
)
|
||||
|
||||
# do not print default values
|
||||
if self.size != _default_size or \
|
||||
self.horizontal_precision != _default_hprec or \
|
||||
self.vertical_precision != _default_vprec:
|
||||
text += " %0.2fm %0.2fm %0.2fm" % (
|
||||
self.size / 100.0, self.horizontal_precision / 100.0,
|
||||
self.vertical_precision / 100.0
|
||||
)
|
||||
return text
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
latitude = [0, 0, 0, 0, 1]
|
||||
longitude = [0, 0, 0, 0, 1]
|
||||
size = _default_size
|
||||
hprec = _default_hprec
|
||||
vprec = _default_vprec
|
||||
|
||||
latitude[0] = tok.get_int()
|
||||
t = tok.get_string()
|
||||
if t.isdigit():
|
||||
latitude[1] = int(t)
|
||||
t = tok.get_string()
|
||||
if '.' in t:
|
||||
(seconds, milliseconds) = t.split('.')
|
||||
if not seconds.isdigit():
|
||||
raise dns.exception.SyntaxError(
|
||||
'bad latitude seconds value')
|
||||
latitude[2] = int(seconds)
|
||||
if latitude[2] >= 60:
|
||||
raise dns.exception.SyntaxError('latitude seconds >= 60')
|
||||
l = len(milliseconds)
|
||||
if l == 0 or l > 3 or not milliseconds.isdigit():
|
||||
raise dns.exception.SyntaxError(
|
||||
'bad latitude milliseconds value')
|
||||
if l == 1:
|
||||
m = 100
|
||||
elif l == 2:
|
||||
m = 10
|
||||
else:
|
||||
m = 1
|
||||
latitude[3] = m * int(milliseconds)
|
||||
t = tok.get_string()
|
||||
elif t.isdigit():
|
||||
latitude[2] = int(t)
|
||||
t = tok.get_string()
|
||||
if t == 'S':
|
||||
latitude[4] = -1
|
||||
elif t != 'N':
|
||||
raise dns.exception.SyntaxError('bad latitude hemisphere value')
|
||||
|
||||
longitude[0] = tok.get_int()
|
||||
t = tok.get_string()
|
||||
if t.isdigit():
|
||||
longitude[1] = int(t)
|
||||
t = tok.get_string()
|
||||
if '.' in t:
|
||||
(seconds, milliseconds) = t.split('.')
|
||||
if not seconds.isdigit():
|
||||
raise dns.exception.SyntaxError(
|
||||
'bad longitude seconds value')
|
||||
longitude[2] = int(seconds)
|
||||
if longitude[2] >= 60:
|
||||
raise dns.exception.SyntaxError('longitude seconds >= 60')
|
||||
l = len(milliseconds)
|
||||
if l == 0 or l > 3 or not milliseconds.isdigit():
|
||||
raise dns.exception.SyntaxError(
|
||||
'bad longitude milliseconds value')
|
||||
if l == 1:
|
||||
m = 100
|
||||
elif l == 2:
|
||||
m = 10
|
||||
else:
|
||||
m = 1
|
||||
longitude[3] = m * int(milliseconds)
|
||||
t = tok.get_string()
|
||||
elif t.isdigit():
|
||||
longitude[2] = int(t)
|
||||
t = tok.get_string()
|
||||
if t == 'W':
|
||||
longitude[4] = -1
|
||||
elif t != 'E':
|
||||
raise dns.exception.SyntaxError('bad longitude hemisphere value')
|
||||
|
||||
t = tok.get_string()
|
||||
if t[-1] == 'm':
|
||||
t = t[0: -1]
|
||||
altitude = float(t) * 100.0 # m -> cm
|
||||
|
||||
token = tok.get().unescape()
|
||||
if not token.is_eol_or_eof():
|
||||
value = token.value
|
||||
if value[-1] == 'm':
|
||||
value = value[0: -1]
|
||||
size = float(value) * 100.0 # m -> cm
|
||||
token = tok.get().unescape()
|
||||
if not token.is_eol_or_eof():
|
||||
value = token.value
|
||||
if value[-1] == 'm':
|
||||
value = value[0: -1]
|
||||
hprec = float(value) * 100.0 # m -> cm
|
||||
token = tok.get().unescape()
|
||||
if not token.is_eol_or_eof():
|
||||
value = token.value
|
||||
if value[-1] == 'm':
|
||||
value = value[0: -1]
|
||||
vprec = float(value) * 100.0 # m -> cm
|
||||
tok.get_eol()
|
||||
|
||||
return cls(rdclass, rdtype, latitude, longitude, altitude,
|
||||
size, hprec, vprec)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
milliseconds = (self.latitude[0] * 3600000 +
|
||||
self.latitude[1] * 60000 +
|
||||
self.latitude[2] * 1000 +
|
||||
self.latitude[3]) * self.latitude[4]
|
||||
latitude = long(0x80000000) + milliseconds
|
||||
milliseconds = (self.longitude[0] * 3600000 +
|
||||
self.longitude[1] * 60000 +
|
||||
self.longitude[2] * 1000 +
|
||||
self.longitude[3]) * self.longitude[4]
|
||||
longitude = long(0x80000000) + milliseconds
|
||||
altitude = long(self.altitude) + long(10000000)
|
||||
size = _encode_size(self.size, "size")
|
||||
hprec = _encode_size(self.horizontal_precision, "horizontal precision")
|
||||
vprec = _encode_size(self.vertical_precision, "vertical precision")
|
||||
wire = struct.pack("!BBBBIII", 0, size, hprec, vprec, latitude,
|
||||
longitude, altitude)
|
||||
file.write(wire)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(version, size, hprec, vprec, latitude, longitude, altitude) = \
|
||||
struct.unpack("!BBBBIII", wire[current: current + rdlen])
|
||||
if latitude > long(0x80000000):
|
||||
latitude = float(latitude - long(0x80000000)) / 3600000
|
||||
else:
|
||||
latitude = -1 * float(long(0x80000000) - latitude) / 3600000
|
||||
if latitude < -90.0 or latitude > 90.0:
|
||||
raise dns.exception.FormError("bad latitude")
|
||||
if longitude > long(0x80000000):
|
||||
longitude = float(longitude - long(0x80000000)) / 3600000
|
||||
else:
|
||||
longitude = -1 * float(long(0x80000000) - longitude) / 3600000
|
||||
if longitude < -180.0 or longitude > 180.0:
|
||||
raise dns.exception.FormError("bad longitude")
|
||||
altitude = float(altitude) - 10000000.0
|
||||
size = _decode_size(size, "size")
|
||||
hprec = _decode_size(hprec, "horizontal precision")
|
||||
vprec = _decode_size(vprec, "vertical precision")
|
||||
return cls(rdclass, rdtype, latitude, longitude, altitude,
|
||||
size, hprec, vprec)
|
||||
|
||||
def _get_float_latitude(self):
|
||||
return _tuple_to_float(self.latitude)
|
||||
|
||||
def _set_float_latitude(self, value):
|
||||
self.latitude = _float_to_tuple(value)
|
||||
|
||||
float_latitude = property(_get_float_latitude, _set_float_latitude,
|
||||
doc="latitude as a floating point value")
|
||||
|
||||
def _get_float_longitude(self):
|
||||
return _tuple_to_float(self.longitude)
|
||||
|
||||
def _set_float_longitude(self, value):
|
||||
self.longitude = _float_to_tuple(value)
|
||||
|
||||
float_longitude = property(_get_float_longitude, _set_float_longitude,
|
||||
doc="longitude as a floating point value")
|
21
lib/dns/rdtypes/ANY/MX.py
Normal file
21
lib/dns/rdtypes/ANY/MX.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.mxbase
|
||||
|
||||
|
||||
class MX(dns.rdtypes.mxbase.MXBase):
|
||||
|
||||
"""MX record"""
|
21
lib/dns/rdtypes/ANY/NS.py
Normal file
21
lib/dns/rdtypes/ANY/NS.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.nsbase
|
||||
|
||||
|
||||
class NS(dns.rdtypes.nsbase.NSBase):
|
||||
|
||||
"""NS record"""
|
126
lib/dns/rdtypes/ANY/NSEC.py
Normal file
126
lib/dns/rdtypes/ANY/NSEC.py
Normal file
|
@ -0,0 +1,126 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
import dns.name
|
||||
from dns._compat import xrange
|
||||
|
||||
|
||||
class NSEC(dns.rdata.Rdata):
|
||||
|
||||
"""NSEC record
|
||||
|
||||
@ivar next: the next name
|
||||
@type next: dns.name.Name object
|
||||
@ivar windows: the windowed bitmap list
|
||||
@type windows: list of (window number, string) tuples"""
|
||||
|
||||
__slots__ = ['next', 'windows']
|
||||
|
||||
def __init__(self, rdclass, rdtype, next, windows):
|
||||
super(NSEC, self).__init__(rdclass, rdtype)
|
||||
self.next = next
|
||||
self.windows = windows
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
next = self.next.choose_relativity(origin, relativize)
|
||||
text = ''
|
||||
for (window, bitmap) in self.windows:
|
||||
bits = []
|
||||
for i in xrange(0, len(bitmap)):
|
||||
byte = bitmap[i]
|
||||
for j in xrange(0, 8):
|
||||
if byte & (0x80 >> j):
|
||||
bits.append(dns.rdatatype.to_text(window * 256 +
|
||||
i * 8 + j))
|
||||
text += (' ' + ' '.join(bits))
|
||||
return '%s%s' % (next, text)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
next = tok.get_name()
|
||||
next = next.choose_relativity(origin, relativize)
|
||||
rdtypes = []
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
nrdtype = dns.rdatatype.from_text(token.value)
|
||||
if nrdtype == 0:
|
||||
raise dns.exception.SyntaxError("NSEC with bit 0")
|
||||
if nrdtype > 65535:
|
||||
raise dns.exception.SyntaxError("NSEC with bit > 65535")
|
||||
rdtypes.append(nrdtype)
|
||||
rdtypes.sort()
|
||||
window = 0
|
||||
octets = 0
|
||||
prior_rdtype = 0
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
windows = []
|
||||
for nrdtype in rdtypes:
|
||||
if nrdtype == prior_rdtype:
|
||||
continue
|
||||
prior_rdtype = nrdtype
|
||||
new_window = nrdtype // 256
|
||||
if new_window != window:
|
||||
windows.append((window, bitmap[0:octets]))
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
window = new_window
|
||||
offset = nrdtype % 256
|
||||
byte = offset // 8
|
||||
bit = offset % 8
|
||||
octets = byte + 1
|
||||
bitmap[byte] = bitmap[byte] | (0x80 >> bit)
|
||||
|
||||
windows.append((window, bitmap[0:octets]))
|
||||
return cls(rdclass, rdtype, next, windows)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
self.next.to_wire(file, None, origin)
|
||||
for (window, bitmap) in self.windows:
|
||||
file.write(struct.pack('!BB', window, len(bitmap)))
|
||||
file.write(bitmap)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(next, cused) = dns.name.from_wire(wire[: current + rdlen], current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
windows = []
|
||||
while rdlen > 0:
|
||||
if rdlen < 3:
|
||||
raise dns.exception.FormError("NSEC too short")
|
||||
window = wire[current]
|
||||
octets = wire[current + 1]
|
||||
if octets == 0 or octets > 32:
|
||||
raise dns.exception.FormError("bad NSEC octets")
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
if rdlen < octets:
|
||||
raise dns.exception.FormError("bad NSEC bitmap length")
|
||||
bitmap = bytearray(wire[current: current + octets].unwrap())
|
||||
current += octets
|
||||
rdlen -= octets
|
||||
windows.append((window, bitmap))
|
||||
if origin is not None:
|
||||
next = next.relativize(origin)
|
||||
return cls(rdclass, rdtype, next, windows)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.next = self.next.choose_relativity(origin, relativize)
|
192
lib/dns/rdtypes/ANY/NSEC3.py
Normal file
192
lib/dns/rdtypes/ANY/NSEC3.py
Normal file
|
@ -0,0 +1,192 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import base64
|
||||
import binascii
|
||||
import string
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
from dns._compat import xrange, text_type
|
||||
|
||||
try:
|
||||
b32_hex_to_normal = string.maketrans('0123456789ABCDEFGHIJKLMNOPQRSTUV',
|
||||
'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
|
||||
b32_normal_to_hex = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
|
||||
'0123456789ABCDEFGHIJKLMNOPQRSTUV')
|
||||
except AttributeError:
|
||||
b32_hex_to_normal = bytes.maketrans(b'0123456789ABCDEFGHIJKLMNOPQRSTUV',
|
||||
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
|
||||
b32_normal_to_hex = bytes.maketrans(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
|
||||
b'0123456789ABCDEFGHIJKLMNOPQRSTUV')
|
||||
|
||||
# hash algorithm constants
|
||||
SHA1 = 1
|
||||
|
||||
# flag constants
|
||||
OPTOUT = 1
|
||||
|
||||
|
||||
class NSEC3(dns.rdata.Rdata):
|
||||
|
||||
"""NSEC3 record
|
||||
|
||||
@ivar algorithm: the hash algorithm number
|
||||
@type algorithm: int
|
||||
@ivar flags: the flags
|
||||
@type flags: int
|
||||
@ivar iterations: the number of iterations
|
||||
@type iterations: int
|
||||
@ivar salt: the salt
|
||||
@type salt: string
|
||||
@ivar next: the next name hash
|
||||
@type next: string
|
||||
@ivar windows: the windowed bitmap list
|
||||
@type windows: list of (window number, string) tuples"""
|
||||
|
||||
__slots__ = ['algorithm', 'flags', 'iterations', 'salt', 'next', 'windows']
|
||||
|
||||
def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt,
|
||||
next, windows):
|
||||
super(NSEC3, self).__init__(rdclass, rdtype)
|
||||
self.algorithm = algorithm
|
||||
self.flags = flags
|
||||
self.iterations = iterations
|
||||
if isinstance(salt, text_type):
|
||||
self.salt = salt.encode()
|
||||
else:
|
||||
self.salt = salt
|
||||
self.next = next
|
||||
self.windows = windows
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
next = base64.b32encode(self.next).translate(
|
||||
b32_normal_to_hex).lower().decode()
|
||||
if self.salt == b'':
|
||||
salt = '-'
|
||||
else:
|
||||
salt = binascii.hexlify(self.salt).decode()
|
||||
text = u''
|
||||
for (window, bitmap) in self.windows:
|
||||
bits = []
|
||||
for i in xrange(0, len(bitmap)):
|
||||
byte = bitmap[i]
|
||||
for j in xrange(0, 8):
|
||||
if byte & (0x80 >> j):
|
||||
bits.append(dns.rdatatype.to_text(window * 256 +
|
||||
i * 8 + j))
|
||||
text += (u' ' + u' '.join(bits))
|
||||
return u'%u %u %u %s %s%s' % (self.algorithm, self.flags,
|
||||
self.iterations, salt, next, text)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
algorithm = tok.get_uint8()
|
||||
flags = tok.get_uint8()
|
||||
iterations = tok.get_uint16()
|
||||
salt = tok.get_string()
|
||||
if salt == u'-':
|
||||
salt = b''
|
||||
else:
|
||||
salt = binascii.unhexlify(salt.encode('ascii'))
|
||||
next = tok.get_string().encode(
|
||||
'ascii').upper().translate(b32_hex_to_normal)
|
||||
next = base64.b32decode(next)
|
||||
rdtypes = []
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
nrdtype = dns.rdatatype.from_text(token.value)
|
||||
if nrdtype == 0:
|
||||
raise dns.exception.SyntaxError("NSEC3 with bit 0")
|
||||
if nrdtype > 65535:
|
||||
raise dns.exception.SyntaxError("NSEC3 with bit > 65535")
|
||||
rdtypes.append(nrdtype)
|
||||
rdtypes.sort()
|
||||
window = 0
|
||||
octets = 0
|
||||
prior_rdtype = 0
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
windows = []
|
||||
for nrdtype in rdtypes:
|
||||
if nrdtype == prior_rdtype:
|
||||
continue
|
||||
prior_rdtype = nrdtype
|
||||
new_window = nrdtype // 256
|
||||
if new_window != window:
|
||||
if octets != 0:
|
||||
windows.append((window, ''.join(bitmap[0:octets])))
|
||||
bitmap = bytearray(b'\0' * 32)
|
||||
window = new_window
|
||||
offset = nrdtype % 256
|
||||
byte = offset // 8
|
||||
bit = offset % 8
|
||||
octets = byte + 1
|
||||
bitmap[byte] = bitmap[byte] | (0x80 >> bit)
|
||||
if octets != 0:
|
||||
windows.append((window, bitmap[0:octets]))
|
||||
return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next,
|
||||
windows)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.salt)
|
||||
file.write(struct.pack("!BBHB", self.algorithm, self.flags,
|
||||
self.iterations, l))
|
||||
file.write(self.salt)
|
||||
l = len(self.next)
|
||||
file.write(struct.pack("!B", l))
|
||||
file.write(self.next)
|
||||
for (window, bitmap) in self.windows:
|
||||
file.write(struct.pack("!BB", window, len(bitmap)))
|
||||
file.write(bitmap)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(algorithm, flags, iterations, slen) = \
|
||||
struct.unpack('!BBHB', wire[current: current + 5])
|
||||
|
||||
current += 5
|
||||
rdlen -= 5
|
||||
salt = wire[current: current + slen].unwrap()
|
||||
current += slen
|
||||
rdlen -= slen
|
||||
nlen = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
next = wire[current: current + nlen].unwrap()
|
||||
current += nlen
|
||||
rdlen -= nlen
|
||||
windows = []
|
||||
while rdlen > 0:
|
||||
if rdlen < 3:
|
||||
raise dns.exception.FormError("NSEC3 too short")
|
||||
window = wire[current]
|
||||
octets = wire[current + 1]
|
||||
if octets == 0 or octets > 32:
|
||||
raise dns.exception.FormError("bad NSEC3 octets")
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
if rdlen < octets:
|
||||
raise dns.exception.FormError("bad NSEC3 bitmap length")
|
||||
bitmap = bytearray(wire[current: current + octets].unwrap())
|
||||
current += octets
|
||||
rdlen -= octets
|
||||
windows.append((window, bitmap))
|
||||
return cls(rdclass, rdtype, algorithm, flags, iterations, salt, next,
|
||||
windows)
|
||||
|
89
lib/dns/rdtypes/ANY/NSEC3PARAM.py
Normal file
89
lib/dns/rdtypes/ANY/NSEC3PARAM.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
from dns._compat import text_type
|
||||
|
||||
|
||||
class NSEC3PARAM(dns.rdata.Rdata):
|
||||
|
||||
"""NSEC3PARAM record
|
||||
|
||||
@ivar algorithm: the hash algorithm number
|
||||
@type algorithm: int
|
||||
@ivar flags: the flags
|
||||
@type flags: int
|
||||
@ivar iterations: the number of iterations
|
||||
@type iterations: int
|
||||
@ivar salt: the salt
|
||||
@type salt: string"""
|
||||
|
||||
__slots__ = ['algorithm', 'flags', 'iterations', 'salt']
|
||||
|
||||
def __init__(self, rdclass, rdtype, algorithm, flags, iterations, salt):
|
||||
super(NSEC3PARAM, self).__init__(rdclass, rdtype)
|
||||
self.algorithm = algorithm
|
||||
self.flags = flags
|
||||
self.iterations = iterations
|
||||
if isinstance(salt, text_type):
|
||||
self.salt = salt.encode()
|
||||
else:
|
||||
self.salt = salt
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
if self.salt == b'':
|
||||
salt = '-'
|
||||
else:
|
||||
salt = binascii.hexlify(self.salt).decode()
|
||||
return '%u %u %u %s' % (self.algorithm, self.flags, self.iterations,
|
||||
salt)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
algorithm = tok.get_uint8()
|
||||
flags = tok.get_uint8()
|
||||
iterations = tok.get_uint16()
|
||||
salt = tok.get_string()
|
||||
if salt == '-':
|
||||
salt = ''
|
||||
else:
|
||||
salt = binascii.unhexlify(salt.encode())
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, algorithm, flags, iterations, salt)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.salt)
|
||||
file.write(struct.pack("!BBHB", self.algorithm, self.flags,
|
||||
self.iterations, l))
|
||||
file.write(self.salt)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(algorithm, flags, iterations, slen) = \
|
||||
struct.unpack('!BBHB',
|
||||
wire[current: current + 5])
|
||||
current += 5
|
||||
rdlen -= 5
|
||||
salt = wire[current: current + slen].unwrap()
|
||||
current += slen
|
||||
rdlen -= slen
|
||||
if rdlen != 0:
|
||||
raise dns.exception.FormError
|
||||
return cls(rdclass, rdtype, algorithm, flags, iterations, salt)
|
||||
|
21
lib/dns/rdtypes/ANY/PTR.py
Normal file
21
lib/dns/rdtypes/ANY/PTR.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.nsbase
|
||||
|
||||
|
||||
class PTR(dns.rdtypes.nsbase.NSBase):
|
||||
|
||||
"""PTR record"""
|
80
lib/dns/rdtypes/ANY/RP.py
Normal file
80
lib/dns/rdtypes/ANY/RP.py
Normal file
|
@ -0,0 +1,80 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class RP(dns.rdata.Rdata):
|
||||
|
||||
"""RP record
|
||||
|
||||
@ivar mbox: The responsible person's mailbox
|
||||
@type mbox: dns.name.Name object
|
||||
@ivar txt: The owner name of a node with TXT records, or the root name
|
||||
if no TXT records are associated with this RP.
|
||||
@type txt: dns.name.Name object
|
||||
@see: RFC 1183"""
|
||||
|
||||
__slots__ = ['mbox', 'txt']
|
||||
|
||||
def __init__(self, rdclass, rdtype, mbox, txt):
|
||||
super(RP, self).__init__(rdclass, rdtype)
|
||||
self.mbox = mbox
|
||||
self.txt = txt
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
mbox = self.mbox.choose_relativity(origin, relativize)
|
||||
txt = self.txt.choose_relativity(origin, relativize)
|
||||
return "%s %s" % (str(mbox), str(txt))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
mbox = tok.get_name()
|
||||
txt = tok.get_name()
|
||||
mbox = mbox.choose_relativity(origin, relativize)
|
||||
txt = txt.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, mbox, txt)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
self.mbox.to_wire(file, None, origin)
|
||||
self.txt.to_wire(file, None, origin)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
return self.mbox.to_digestable(origin) + \
|
||||
self.txt.to_digestable(origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(mbox, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
if rdlen <= 0:
|
||||
raise dns.exception.FormError
|
||||
(txt, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
mbox = mbox.relativize(origin)
|
||||
txt = txt.relativize(origin)
|
||||
return cls(rdclass, rdtype, mbox, txt)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.mbox = self.mbox.choose_relativity(origin, relativize)
|
||||
self.txt = self.txt.choose_relativity(origin, relativize)
|
156
lib/dns/rdtypes/ANY/RRSIG.py
Normal file
156
lib/dns/rdtypes/ANY/RRSIG.py
Normal file
|
@ -0,0 +1,156 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import base64
|
||||
import calendar
|
||||
import struct
|
||||
import time
|
||||
|
||||
import dns.dnssec
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
class BadSigTime(dns.exception.DNSException):
|
||||
|
||||
"""Time in DNS SIG or RRSIG resource record cannot be parsed."""
|
||||
|
||||
|
||||
def sigtime_to_posixtime(what):
|
||||
if len(what) != 14:
|
||||
raise BadSigTime
|
||||
year = int(what[0:4])
|
||||
month = int(what[4:6])
|
||||
day = int(what[6:8])
|
||||
hour = int(what[8:10])
|
||||
minute = int(what[10:12])
|
||||
second = int(what[12:14])
|
||||
return calendar.timegm((year, month, day, hour, minute, second,
|
||||
0, 0, 0))
|
||||
|
||||
|
||||
def posixtime_to_sigtime(what):
|
||||
return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
|
||||
|
||||
|
||||
class RRSIG(dns.rdata.Rdata):
|
||||
|
||||
"""RRSIG record
|
||||
|
||||
@ivar type_covered: the rdata type this signature covers
|
||||
@type type_covered: int
|
||||
@ivar algorithm: the algorithm used for the sig
|
||||
@type algorithm: int
|
||||
@ivar labels: number of labels
|
||||
@type labels: int
|
||||
@ivar original_ttl: the original TTL
|
||||
@type original_ttl: long
|
||||
@ivar expiration: signature expiration time
|
||||
@type expiration: long
|
||||
@ivar inception: signature inception time
|
||||
@type inception: long
|
||||
@ivar key_tag: the key tag
|
||||
@type key_tag: int
|
||||
@ivar signer: the signer
|
||||
@type signer: dns.name.Name object
|
||||
@ivar signature: the signature
|
||||
@type signature: string"""
|
||||
|
||||
__slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl',
|
||||
'expiration', 'inception', 'key_tag', 'signer',
|
||||
'signature']
|
||||
|
||||
def __init__(self, rdclass, rdtype, type_covered, algorithm, labels,
|
||||
original_ttl, expiration, inception, key_tag, signer,
|
||||
signature):
|
||||
super(RRSIG, self).__init__(rdclass, rdtype)
|
||||
self.type_covered = type_covered
|
||||
self.algorithm = algorithm
|
||||
self.labels = labels
|
||||
self.original_ttl = original_ttl
|
||||
self.expiration = expiration
|
||||
self.inception = inception
|
||||
self.key_tag = key_tag
|
||||
self.signer = signer
|
||||
self.signature = signature
|
||||
|
||||
def covers(self):
|
||||
return self.type_covered
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%s %d %d %d %s %s %d %s %s' % (
|
||||
dns.rdatatype.to_text(self.type_covered),
|
||||
self.algorithm,
|
||||
self.labels,
|
||||
self.original_ttl,
|
||||
posixtime_to_sigtime(self.expiration),
|
||||
posixtime_to_sigtime(self.inception),
|
||||
self.key_tag,
|
||||
self.signer.choose_relativity(origin, relativize),
|
||||
dns.rdata._base64ify(self.signature)
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
type_covered = dns.rdatatype.from_text(tok.get_string())
|
||||
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
|
||||
labels = tok.get_int()
|
||||
original_ttl = tok.get_ttl()
|
||||
expiration = sigtime_to_posixtime(tok.get_string())
|
||||
inception = sigtime_to_posixtime(tok.get_string())
|
||||
key_tag = tok.get_int()
|
||||
signer = tok.get_name()
|
||||
signer = signer.choose_relativity(origin, relativize)
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
b64 = b''.join(chunks)
|
||||
signature = base64.b64decode(b64)
|
||||
return cls(rdclass, rdtype, type_covered, algorithm, labels,
|
||||
original_ttl, expiration, inception, key_tag, signer,
|
||||
signature)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack('!HBBIIIH', self.type_covered,
|
||||
self.algorithm, self.labels,
|
||||
self.original_ttl, self.expiration,
|
||||
self.inception, self.key_tag)
|
||||
file.write(header)
|
||||
self.signer.to_wire(file, None, origin)
|
||||
file.write(self.signature)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
header = struct.unpack('!HBBIIIH', wire[current: current + 18])
|
||||
current += 18
|
||||
rdlen -= 18
|
||||
(signer, cused) = dns.name.from_wire(wire[: current + rdlen], current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
if origin is not None:
|
||||
signer = signer.relativize(origin)
|
||||
signature = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], header[1], header[2],
|
||||
header[3], header[4], header[5], header[6], signer,
|
||||
signature)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.signer = self.signer.choose_relativity(origin, relativize)
|
21
lib/dns/rdtypes/ANY/RT.py
Normal file
21
lib/dns/rdtypes/ANY/RT.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.mxbase
|
||||
|
||||
|
||||
class RT(dns.rdtypes.mxbase.UncompressedDowncasingMX):
|
||||
|
||||
"""RT record"""
|
114
lib/dns/rdtypes/ANY/SOA.py
Normal file
114
lib/dns/rdtypes/ANY/SOA.py
Normal file
|
@ -0,0 +1,114 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class SOA(dns.rdata.Rdata):
|
||||
|
||||
"""SOA record
|
||||
|
||||
@ivar mname: the SOA MNAME (master name) field
|
||||
@type mname: dns.name.Name object
|
||||
@ivar rname: the SOA RNAME (responsible name) field
|
||||
@type rname: dns.name.Name object
|
||||
@ivar serial: The zone's serial number
|
||||
@type serial: int
|
||||
@ivar refresh: The zone's refresh value (in seconds)
|
||||
@type refresh: int
|
||||
@ivar retry: The zone's retry value (in seconds)
|
||||
@type retry: int
|
||||
@ivar expire: The zone's expiration value (in seconds)
|
||||
@type expire: int
|
||||
@ivar minimum: The zone's negative caching time (in seconds, called
|
||||
"minimum" for historical reasons)
|
||||
@type minimum: int
|
||||
@see: RFC 1035"""
|
||||
|
||||
__slots__ = ['mname', 'rname', 'serial', 'refresh', 'retry', 'expire',
|
||||
'minimum']
|
||||
|
||||
def __init__(self, rdclass, rdtype, mname, rname, serial, refresh, retry,
|
||||
expire, minimum):
|
||||
super(SOA, self).__init__(rdclass, rdtype)
|
||||
self.mname = mname
|
||||
self.rname = rname
|
||||
self.serial = serial
|
||||
self.refresh = refresh
|
||||
self.retry = retry
|
||||
self.expire = expire
|
||||
self.minimum = minimum
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
mname = self.mname.choose_relativity(origin, relativize)
|
||||
rname = self.rname.choose_relativity(origin, relativize)
|
||||
return '%s %s %d %d %d %d %d' % (
|
||||
mname, rname, self.serial, self.refresh, self.retry,
|
||||
self.expire, self.minimum)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
mname = tok.get_name()
|
||||
rname = tok.get_name()
|
||||
mname = mname.choose_relativity(origin, relativize)
|
||||
rname = rname.choose_relativity(origin, relativize)
|
||||
serial = tok.get_uint32()
|
||||
refresh = tok.get_ttl()
|
||||
retry = tok.get_ttl()
|
||||
expire = tok.get_ttl()
|
||||
minimum = tok.get_ttl()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, mname, rname, serial, refresh, retry,
|
||||
expire, minimum)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
self.mname.to_wire(file, compress, origin)
|
||||
self.rname.to_wire(file, compress, origin)
|
||||
five_ints = struct.pack('!IIIII', self.serial, self.refresh,
|
||||
self.retry, self.expire, self.minimum)
|
||||
file.write(five_ints)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
return self.mname.to_digestable(origin) + \
|
||||
self.rname.to_digestable(origin) + \
|
||||
struct.pack('!IIIII', self.serial, self.refresh,
|
||||
self.retry, self.expire, self.minimum)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(mname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
(rname, cused) = dns.name.from_wire(wire[: current + rdlen], current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
if rdlen != 20:
|
||||
raise dns.exception.FormError
|
||||
five_ints = struct.unpack('!IIIII',
|
||||
wire[current: current + rdlen])
|
||||
if origin is not None:
|
||||
mname = mname.relativize(origin)
|
||||
rname = rname.relativize(origin)
|
||||
return cls(rdclass, rdtype, mname, rname,
|
||||
five_ints[0], five_ints[1], five_ints[2], five_ints[3],
|
||||
five_ints[4])
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.mname = self.mname.choose_relativity(origin, relativize)
|
||||
self.rname = self.rname.choose_relativity(origin, relativize)
|
23
lib/dns/rdtypes/ANY/SPF.py
Normal file
23
lib/dns/rdtypes/ANY/SPF.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.txtbase
|
||||
|
||||
|
||||
class SPF(dns.rdtypes.txtbase.TXTBase):
|
||||
|
||||
"""SPF record
|
||||
|
||||
@see: RFC 4408"""
|
78
lib/dns/rdtypes/ANY/SSHFP.py
Normal file
78
lib/dns/rdtypes/ANY/SSHFP.py
Normal file
|
@ -0,0 +1,78 @@
|
|||
# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
class SSHFP(dns.rdata.Rdata):
|
||||
|
||||
"""SSHFP record
|
||||
|
||||
@ivar algorithm: the algorithm
|
||||
@type algorithm: int
|
||||
@ivar fp_type: the digest type
|
||||
@type fp_type: int
|
||||
@ivar fingerprint: the fingerprint
|
||||
@type fingerprint: string
|
||||
@see: draft-ietf-secsh-dns-05.txt"""
|
||||
|
||||
__slots__ = ['algorithm', 'fp_type', 'fingerprint']
|
||||
|
||||
def __init__(self, rdclass, rdtype, algorithm, fp_type,
|
||||
fingerprint):
|
||||
super(SSHFP, self).__init__(rdclass, rdtype)
|
||||
self.algorithm = algorithm
|
||||
self.fp_type = fp_type
|
||||
self.fingerprint = fingerprint
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%d %d %s' % (self.algorithm,
|
||||
self.fp_type,
|
||||
dns.rdata._hexify(self.fingerprint,
|
||||
chunksize=128))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
algorithm = tok.get_uint8()
|
||||
fp_type = tok.get_uint8()
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
fingerprint = b''.join(chunks)
|
||||
fingerprint = binascii.unhexlify(fingerprint)
|
||||
return cls(rdclass, rdtype, algorithm, fp_type, fingerprint)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack("!BB", self.algorithm, self.fp_type)
|
||||
file.write(header)
|
||||
file.write(self.fingerprint)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
header = struct.unpack("!BB", wire[current: current + 2])
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
fingerprint = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], header[1], fingerprint)
|
||||
|
83
lib/dns/rdtypes/ANY/TLSA.py
Normal file
83
lib/dns/rdtypes/ANY/TLSA.py
Normal file
|
@ -0,0 +1,83 @@
|
|||
# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
class TLSA(dns.rdata.Rdata):
|
||||
|
||||
"""TLSA record
|
||||
|
||||
@ivar usage: The certificate usage
|
||||
@type usage: int
|
||||
@ivar selector: The selector field
|
||||
@type selector: int
|
||||
@ivar mtype: The 'matching type' field
|
||||
@type mtype: int
|
||||
@ivar cert: The 'Certificate Association Data' field
|
||||
@type cert: string
|
||||
@see: RFC 6698"""
|
||||
|
||||
__slots__ = ['usage', 'selector', 'mtype', 'cert']
|
||||
|
||||
def __init__(self, rdclass, rdtype, usage, selector,
|
||||
mtype, cert):
|
||||
super(TLSA, self).__init__(rdclass, rdtype)
|
||||
self.usage = usage
|
||||
self.selector = selector
|
||||
self.mtype = mtype
|
||||
self.cert = cert
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%d %d %d %s' % (self.usage,
|
||||
self.selector,
|
||||
self.mtype,
|
||||
dns.rdata._hexify(self.cert,
|
||||
chunksize=128))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
usage = tok.get_uint8()
|
||||
selector = tok.get_uint8()
|
||||
mtype = tok.get_uint8()
|
||||
cert_chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
cert_chunks.append(t.value.encode())
|
||||
cert = b''.join(cert_chunks)
|
||||
cert = binascii.unhexlify(cert)
|
||||
return cls(rdclass, rdtype, usage, selector, mtype, cert)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack("!BBB", self.usage, self.selector, self.mtype)
|
||||
file.write(header)
|
||||
file.write(self.cert)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
header = struct.unpack("!BBB", wire[current: current + 3])
|
||||
current += 3
|
||||
rdlen -= 3
|
||||
cert = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
|
||||
|
21
lib/dns/rdtypes/ANY/TXT.py
Normal file
21
lib/dns/rdtypes/ANY/TXT.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.txtbase
|
||||
|
||||
|
||||
class TXT(dns.rdtypes.txtbase.TXTBase):
|
||||
|
||||
"""TXT record"""
|
81
lib/dns/rdtypes/ANY/URI.py
Normal file
81
lib/dns/rdtypes/ANY/URI.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
# Copyright (C) 2015 Red Hat, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
from dns._compat import text_type
|
||||
|
||||
|
||||
class URI(dns.rdata.Rdata):
|
||||
|
||||
"""URI record
|
||||
|
||||
@ivar priority: the priority
|
||||
@type priority: int
|
||||
@ivar weight: the weight
|
||||
@type weight: int
|
||||
@ivar target: the target host
|
||||
@type target: dns.name.Name object
|
||||
@see: draft-faltstrom-uri-13"""
|
||||
|
||||
__slots__ = ['priority', 'weight', 'target']
|
||||
|
||||
def __init__(self, rdclass, rdtype, priority, weight, target):
|
||||
super(URI, self).__init__(rdclass, rdtype)
|
||||
self.priority = priority
|
||||
self.weight = weight
|
||||
if len(target) < 1:
|
||||
raise dns.exception.SyntaxError("URI target cannot be empty")
|
||||
if isinstance(target, text_type):
|
||||
self.target = target.encode()
|
||||
else:
|
||||
self.target = target
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%d %d "%s"' % (self.priority, self.weight,
|
||||
self.target.decode())
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
priority = tok.get_uint16()
|
||||
weight = tok.get_uint16()
|
||||
target = tok.get().unescape()
|
||||
if not (target.is_quoted_string() or target.is_identifier()):
|
||||
raise dns.exception.SyntaxError("URI target must be a string")
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, priority, weight, target.value)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
two_ints = struct.pack("!HH", self.priority, self.weight)
|
||||
file.write(two_ints)
|
||||
file.write(self.target)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
if rdlen < 5:
|
||||
raise dns.exception.FormError('URI RR is shorter than 5 octets')
|
||||
|
||||
(priority, weight) = struct.unpack('!HH', wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
target = wire[current: current + rdlen]
|
||||
current += rdlen
|
||||
|
||||
return cls(rdclass, rdtype, priority, weight, target)
|
||||
|
65
lib/dns/rdtypes/ANY/X25.py
Normal file
65
lib/dns/rdtypes/ANY/X25.py
Normal file
|
@ -0,0 +1,65 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import text_type
|
||||
|
||||
|
||||
class X25(dns.rdata.Rdata):
|
||||
|
||||
"""X25 record
|
||||
|
||||
@ivar address: the PSDN address
|
||||
@type address: string
|
||||
@see: RFC 1183"""
|
||||
|
||||
__slots__ = ['address']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address):
|
||||
super(X25, self).__init__(rdclass, rdtype)
|
||||
if isinstance(address, text_type):
|
||||
self.address = address.encode()
|
||||
else:
|
||||
self.address = address
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '"%s"' % dns.rdata._escapify(self.address)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_string()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
l = len(self.address)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(self.address)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l != rdlen:
|
||||
raise dns.exception.FormError
|
||||
address = wire[current: current + l].unwrap()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
50
lib/dns/rdtypes/ANY/__init__.py
Normal file
50
lib/dns/rdtypes/ANY/__init__.py
Normal file
|
@ -0,0 +1,50 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""Class ANY (generic) rdata type classes."""
|
||||
|
||||
__all__ = [
|
||||
'AFSDB',
|
||||
'CDNSKEY',
|
||||
'CDS',
|
||||
'CERT',
|
||||
'CNAME',
|
||||
'DLV',
|
||||
'DNAME',
|
||||
'DNSKEY',
|
||||
'DS',
|
||||
'EUI48',
|
||||
'EUI64',
|
||||
'GPOS',
|
||||
'HINFO',
|
||||
'HIP',
|
||||
'ISDN',
|
||||
'LOC',
|
||||
'MX',
|
||||
'NS',
|
||||
'NSEC',
|
||||
'NSEC3',
|
||||
'NSEC3PARAM',
|
||||
'TLSA',
|
||||
'PTR',
|
||||
'RP',
|
||||
'RRSIG',
|
||||
'RT',
|
||||
'SOA',
|
||||
'SPF',
|
||||
'SSHFP',
|
||||
'TXT',
|
||||
'X25',
|
||||
]
|
53
lib/dns/rdtypes/IN/A.py
Normal file
53
lib/dns/rdtypes/IN/A.py
Normal file
|
@ -0,0 +1,53 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.exception
|
||||
import dns.ipv4
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
|
||||
|
||||
class A(dns.rdata.Rdata):
|
||||
|
||||
"""A record.
|
||||
|
||||
@ivar address: an IPv4 address
|
||||
@type address: string (in the standard "dotted quad" format)"""
|
||||
|
||||
__slots__ = ['address']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address):
|
||||
super(A, self).__init__(rdclass, rdtype)
|
||||
# check that it's OK
|
||||
dns.ipv4.inet_aton(address)
|
||||
self.address = address
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return self.address
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_identifier()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(dns.ipv4.inet_aton(self.address))
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
address = dns.ipv4.inet_ntoa(wire[current: current + rdlen]).decode()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
54
lib/dns/rdtypes/IN/AAAA.py
Normal file
54
lib/dns/rdtypes/IN/AAAA.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.exception
|
||||
import dns.inet
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
|
||||
|
||||
class AAAA(dns.rdata.Rdata):
|
||||
|
||||
"""AAAA record.
|
||||
|
||||
@ivar address: an IPv6 address
|
||||
@type address: string (in the standard IPv6 format)"""
|
||||
|
||||
__slots__ = ['address']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address):
|
||||
super(AAAA, self).__init__(rdclass, rdtype)
|
||||
# check that it's OK
|
||||
dns.inet.inet_pton(dns.inet.AF_INET6, address)
|
||||
self.address = address
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return self.address
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_identifier()
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(dns.inet.inet_pton(dns.inet.AF_INET6, self.address))
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
address = dns.inet.inet_ntop(dns.inet.AF_INET6,
|
||||
wire[current: current + rdlen])
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
162
lib/dns/rdtypes/IN/APL.py
Normal file
162
lib/dns/rdtypes/IN/APL.py
Normal file
|
@ -0,0 +1,162 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
|
||||
import dns.exception
|
||||
import dns.inet
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import xrange
|
||||
|
||||
|
||||
class APLItem(object):
|
||||
|
||||
"""An APL list item.
|
||||
|
||||
@ivar family: the address family (IANA address family registry)
|
||||
@type family: int
|
||||
@ivar negation: is this item negated?
|
||||
@type negation: bool
|
||||
@ivar address: the address
|
||||
@type address: string
|
||||
@ivar prefix: the prefix length
|
||||
@type prefix: int
|
||||
"""
|
||||
|
||||
__slots__ = ['family', 'negation', 'address', 'prefix']
|
||||
|
||||
def __init__(self, family, negation, address, prefix):
|
||||
self.family = family
|
||||
self.negation = negation
|
||||
self.address = address
|
||||
self.prefix = prefix
|
||||
|
||||
def __str__(self):
|
||||
if self.negation:
|
||||
return "!%d:%s/%s" % (self.family, self.address, self.prefix)
|
||||
else:
|
||||
return "%d:%s/%s" % (self.family, self.address, self.prefix)
|
||||
|
||||
def to_wire(self, file):
|
||||
if self.family == 1:
|
||||
address = dns.inet.inet_pton(dns.inet.AF_INET, self.address)
|
||||
elif self.family == 2:
|
||||
address = dns.inet.inet_pton(dns.inet.AF_INET6, self.address)
|
||||
else:
|
||||
address = binascii.unhexlify(self.address)
|
||||
#
|
||||
# Truncate least significant zero bytes.
|
||||
#
|
||||
last = 0
|
||||
for i in xrange(len(address) - 1, -1, -1):
|
||||
if address[i] != chr(0):
|
||||
last = i + 1
|
||||
break
|
||||
address = address[0: last]
|
||||
l = len(address)
|
||||
assert l < 128
|
||||
if self.negation:
|
||||
l |= 0x80
|
||||
header = struct.pack('!HBB', self.family, self.prefix, l)
|
||||
file.write(header)
|
||||
file.write(address)
|
||||
|
||||
|
||||
class APL(dns.rdata.Rdata):
|
||||
|
||||
"""APL record.
|
||||
|
||||
@ivar items: a list of APL items
|
||||
@type items: list of APL_Item
|
||||
@see: RFC 3123"""
|
||||
|
||||
__slots__ = ['items']
|
||||
|
||||
def __init__(self, rdclass, rdtype, items):
|
||||
super(APL, self).__init__(rdclass, rdtype)
|
||||
self.items = items
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return ' '.join(map(lambda x: str(x), self.items))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
items = []
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
item = token.value
|
||||
if item[0] == '!':
|
||||
negation = True
|
||||
item = item[1:]
|
||||
else:
|
||||
negation = False
|
||||
(family, rest) = item.split(':', 1)
|
||||
family = int(family)
|
||||
(address, prefix) = rest.split('/', 1)
|
||||
prefix = int(prefix)
|
||||
item = APLItem(family, negation, address, prefix)
|
||||
items.append(item)
|
||||
|
||||
return cls(rdclass, rdtype, items)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
for item in self.items:
|
||||
item.to_wire(file)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
items = []
|
||||
while 1:
|
||||
if rdlen == 0:
|
||||
break
|
||||
if rdlen < 4:
|
||||
raise dns.exception.FormError
|
||||
header = struct.unpack('!HBB', wire[current: current + 4])
|
||||
afdlen = header[2]
|
||||
if afdlen > 127:
|
||||
negation = True
|
||||
afdlen -= 128
|
||||
else:
|
||||
negation = False
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
if rdlen < afdlen:
|
||||
raise dns.exception.FormError
|
||||
address = wire[current: current + afdlen].unwrap()
|
||||
l = len(address)
|
||||
if header[0] == 1:
|
||||
if l < 4:
|
||||
address += '\x00' * (4 - l)
|
||||
address = dns.inet.inet_ntop(dns.inet.AF_INET, address)
|
||||
elif header[0] == 2:
|
||||
if l < 16:
|
||||
address += '\x00' * (16 - l)
|
||||
address = dns.inet.inet_ntop(dns.inet.AF_INET6, address)
|
||||
else:
|
||||
#
|
||||
# This isn't really right according to the RFC, but it
|
||||
# seems better than throwing an exception
|
||||
#
|
||||
address = address.encode('hex_codec')
|
||||
current += afdlen
|
||||
rdlen -= afdlen
|
||||
item = APLItem(header[0], negation, address, header[1])
|
||||
items.append(item)
|
||||
return cls(rdclass, rdtype, items)
|
||||
|
60
lib/dns/rdtypes/IN/DHCID.py
Normal file
60
lib/dns/rdtypes/IN/DHCID.py
Normal file
|
@ -0,0 +1,60 @@
|
|||
# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import base64
|
||||
|
||||
import dns.exception
|
||||
|
||||
|
||||
class DHCID(dns.rdata.Rdata):
|
||||
|
||||
"""DHCID record
|
||||
|
||||
@ivar data: the data (the content of the RR is opaque as far as the
|
||||
DNS is concerned)
|
||||
@type data: string
|
||||
@see: RFC 4701"""
|
||||
|
||||
__slots__ = ['data']
|
||||
|
||||
def __init__(self, rdclass, rdtype, data):
|
||||
super(DHCID, self).__init__(rdclass, rdtype)
|
||||
self.data = data
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return dns.rdata._base64ify(self.data)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
b64 = b''.join(chunks)
|
||||
data = base64.b64decode(b64)
|
||||
return cls(rdclass, rdtype, data)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(self.data)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
data = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, data)
|
||||
|
149
lib/dns/rdtypes/IN/IPSECKEY.py
Normal file
149
lib/dns/rdtypes/IN/IPSECKEY.py
Normal file
|
@ -0,0 +1,149 @@
|
|||
# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import base64
|
||||
|
||||
import dns.exception
|
||||
import dns.inet
|
||||
import dns.name
|
||||
|
||||
|
||||
class IPSECKEY(dns.rdata.Rdata):
|
||||
|
||||
"""IPSECKEY record
|
||||
|
||||
@ivar precedence: the precedence for this key data
|
||||
@type precedence: int
|
||||
@ivar gateway_type: the gateway type
|
||||
@type gateway_type: int
|
||||
@ivar algorithm: the algorithm to use
|
||||
@type algorithm: int
|
||||
@ivar gateway: the public key
|
||||
@type gateway: None, IPv4 address, IPV6 address, or domain name
|
||||
@ivar key: the public key
|
||||
@type key: string
|
||||
@see: RFC 4025"""
|
||||
|
||||
__slots__ = ['precedence', 'gateway_type', 'algorithm', 'gateway', 'key']
|
||||
|
||||
def __init__(self, rdclass, rdtype, precedence, gateway_type, algorithm,
|
||||
gateway, key):
|
||||
super(IPSECKEY, self).__init__(rdclass, rdtype)
|
||||
if gateway_type == 0:
|
||||
if gateway != '.' and gateway is not None:
|
||||
raise SyntaxError('invalid gateway for gateway type 0')
|
||||
gateway = None
|
||||
elif gateway_type == 1:
|
||||
# check that it's OK
|
||||
dns.inet.inet_pton(dns.inet.AF_INET, gateway)
|
||||
elif gateway_type == 2:
|
||||
# check that it's OK
|
||||
dns.inet.inet_pton(dns.inet.AF_INET6, gateway)
|
||||
elif gateway_type == 3:
|
||||
pass
|
||||
else:
|
||||
raise SyntaxError(
|
||||
'invalid IPSECKEY gateway type: %d' % gateway_type)
|
||||
self.precedence = precedence
|
||||
self.gateway_type = gateway_type
|
||||
self.algorithm = algorithm
|
||||
self.gateway = gateway
|
||||
self.key = key
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
if self.gateway_type == 0:
|
||||
gateway = '.'
|
||||
elif self.gateway_type == 1:
|
||||
gateway = self.gateway
|
||||
elif self.gateway_type == 2:
|
||||
gateway = self.gateway
|
||||
elif self.gateway_type == 3:
|
||||
gateway = str(self.gateway.choose_relativity(origin, relativize))
|
||||
else:
|
||||
raise ValueError('invalid gateway type')
|
||||
return '%d %d %d %s %s' % (self.precedence, self.gateway_type,
|
||||
self.algorithm, gateway,
|
||||
dns.rdata._base64ify(self.key))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
precedence = tok.get_uint8()
|
||||
gateway_type = tok.get_uint8()
|
||||
algorithm = tok.get_uint8()
|
||||
if gateway_type == 3:
|
||||
gateway = tok.get_name().choose_relativity(origin, relativize)
|
||||
else:
|
||||
gateway = tok.get_string()
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
b64 = b''.join(chunks)
|
||||
key = base64.b64decode(b64)
|
||||
return cls(rdclass, rdtype, precedence, gateway_type, algorithm,
|
||||
gateway, key)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack("!BBB", self.precedence, self.gateway_type,
|
||||
self.algorithm)
|
||||
file.write(header)
|
||||
if self.gateway_type == 0:
|
||||
pass
|
||||
elif self.gateway_type == 1:
|
||||
file.write(dns.inet.inet_pton(dns.inet.AF_INET, self.gateway))
|
||||
elif self.gateway_type == 2:
|
||||
file.write(dns.inet.inet_pton(dns.inet.AF_INET6, self.gateway))
|
||||
elif self.gateway_type == 3:
|
||||
self.gateway.to_wire(file, None, origin)
|
||||
else:
|
||||
raise ValueError('invalid gateway type')
|
||||
file.write(self.key)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
if rdlen < 3:
|
||||
raise dns.exception.FormError
|
||||
header = struct.unpack('!BBB', wire[current: current + 3])
|
||||
gateway_type = header[1]
|
||||
current += 3
|
||||
rdlen -= 3
|
||||
if gateway_type == 0:
|
||||
gateway = None
|
||||
elif gateway_type == 1:
|
||||
gateway = dns.inet.inet_ntop(dns.inet.AF_INET,
|
||||
wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
elif gateway_type == 2:
|
||||
gateway = dns.inet.inet_ntop(dns.inet.AF_INET6,
|
||||
wire[current: current + 16])
|
||||
current += 16
|
||||
rdlen -= 16
|
||||
elif gateway_type == 3:
|
||||
(gateway, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
else:
|
||||
raise dns.exception.FormError('invalid IPSECKEY gateway type')
|
||||
key = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], gateway_type, header[2],
|
||||
gateway, key)
|
||||
|
21
lib/dns/rdtypes/IN/KX.py
Normal file
21
lib/dns/rdtypes/IN/KX.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.mxbase
|
||||
|
||||
|
||||
class KX(dns.rdtypes.mxbase.UncompressedMX):
|
||||
|
||||
"""KX record"""
|
125
lib/dns/rdtypes/IN/NAPTR.py
Normal file
125
lib/dns/rdtypes/IN/NAPTR.py
Normal file
|
@ -0,0 +1,125 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.name
|
||||
import dns.rdata
|
||||
from dns._compat import xrange, text_type
|
||||
|
||||
|
||||
def _write_string(file, s):
|
||||
l = len(s)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(s)
|
||||
|
||||
|
||||
def _sanitize(value):
|
||||
if isinstance(value, text_type):
|
||||
return value.encode()
|
||||
return value
|
||||
|
||||
|
||||
class NAPTR(dns.rdata.Rdata):
|
||||
|
||||
"""NAPTR record
|
||||
|
||||
@ivar order: order
|
||||
@type order: int
|
||||
@ivar preference: preference
|
||||
@type preference: int
|
||||
@ivar flags: flags
|
||||
@type flags: string
|
||||
@ivar service: service
|
||||
@type service: string
|
||||
@ivar regexp: regular expression
|
||||
@type regexp: string
|
||||
@ivar replacement: replacement name
|
||||
@type replacement: dns.name.Name object
|
||||
@see: RFC 3403"""
|
||||
|
||||
__slots__ = ['order', 'preference', 'flags', 'service', 'regexp',
|
||||
'replacement']
|
||||
|
||||
def __init__(self, rdclass, rdtype, order, preference, flags, service,
|
||||
regexp, replacement):
|
||||
super(NAPTR, self).__init__(rdclass, rdtype)
|
||||
self.flags = _sanitize(flags)
|
||||
self.service = _sanitize(service)
|
||||
self.regexp = _sanitize(regexp)
|
||||
self.order = order
|
||||
self.preference = preference
|
||||
self.replacement = replacement
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
replacement = self.replacement.choose_relativity(origin, relativize)
|
||||
return '%d %d "%s" "%s" "%s" %s' % \
|
||||
(self.order, self.preference,
|
||||
dns.rdata._escapify(self.flags),
|
||||
dns.rdata._escapify(self.service),
|
||||
dns.rdata._escapify(self.regexp),
|
||||
replacement)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
order = tok.get_uint16()
|
||||
preference = tok.get_uint16()
|
||||
flags = tok.get_string()
|
||||
service = tok.get_string()
|
||||
regexp = tok.get_string()
|
||||
replacement = tok.get_name()
|
||||
replacement = replacement.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, order, preference, flags, service,
|
||||
regexp, replacement)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
two_ints = struct.pack("!HH", self.order, self.preference)
|
||||
file.write(two_ints)
|
||||
_write_string(file, self.flags)
|
||||
_write_string(file, self.service)
|
||||
_write_string(file, self.regexp)
|
||||
self.replacement.to_wire(file, compress, origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(order, preference) = struct.unpack('!HH', wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
strings = []
|
||||
for i in xrange(3):
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen or rdlen < 0:
|
||||
raise dns.exception.FormError
|
||||
s = wire[current: current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
strings.append(s)
|
||||
(replacement, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
replacement = replacement.relativize(origin)
|
||||
return cls(rdclass, rdtype, order, preference, strings[0], strings[1],
|
||||
strings[2], replacement)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.replacement = self.replacement.choose_relativity(origin,
|
||||
relativize)
|
59
lib/dns/rdtypes/IN/NSAP.py
Normal file
59
lib/dns/rdtypes/IN/NSAP.py
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import binascii
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
|
||||
|
||||
class NSAP(dns.rdata.Rdata):
|
||||
|
||||
"""NSAP record.
|
||||
|
||||
@ivar address: a NASP
|
||||
@type address: string
|
||||
@see: RFC 1706"""
|
||||
|
||||
__slots__ = ['address']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address):
|
||||
super(NSAP, self).__init__(rdclass, rdtype)
|
||||
self.address = address
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return "0x%s" % binascii.hexlify(self.address).decode()
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_string()
|
||||
tok.get_eol()
|
||||
if address[0:2] != '0x':
|
||||
raise dns.exception.SyntaxError('string does not start with 0x')
|
||||
address = address[2:].replace('.', '')
|
||||
if len(address) % 2 != 0:
|
||||
raise dns.exception.SyntaxError('hexstring has odd length')
|
||||
address = binascii.unhexlify(address.encode())
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(self.address)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
address = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, address)
|
||||
|
21
lib/dns/rdtypes/IN/NSAP_PTR.py
Normal file
21
lib/dns/rdtypes/IN/NSAP_PTR.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import dns.rdtypes.nsbase
|
||||
|
||||
|
||||
class NSAP_PTR(dns.rdtypes.nsbase.UncompressedNS):
|
||||
|
||||
"""NSAP-PTR record"""
|
87
lib/dns/rdtypes/IN/PX.py
Normal file
87
lib/dns/rdtypes/IN/PX.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class PX(dns.rdata.Rdata):
|
||||
|
||||
"""PX record.
|
||||
|
||||
@ivar preference: the preference value
|
||||
@type preference: int
|
||||
@ivar map822: the map822 name
|
||||
@type map822: dns.name.Name object
|
||||
@ivar mapx400: the mapx400 name
|
||||
@type mapx400: dns.name.Name object
|
||||
@see: RFC 2163"""
|
||||
|
||||
__slots__ = ['preference', 'map822', 'mapx400']
|
||||
|
||||
def __init__(self, rdclass, rdtype, preference, map822, mapx400):
|
||||
super(PX, self).__init__(rdclass, rdtype)
|
||||
self.preference = preference
|
||||
self.map822 = map822
|
||||
self.mapx400 = mapx400
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
map822 = self.map822.choose_relativity(origin, relativize)
|
||||
mapx400 = self.mapx400.choose_relativity(origin, relativize)
|
||||
return '%d %s %s' % (self.preference, map822, mapx400)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
preference = tok.get_uint16()
|
||||
map822 = tok.get_name()
|
||||
map822 = map822.choose_relativity(origin, relativize)
|
||||
mapx400 = tok.get_name(None)
|
||||
mapx400 = mapx400.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, preference, map822, mapx400)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
pref = struct.pack("!H", self.preference)
|
||||
file.write(pref)
|
||||
self.map822.to_wire(file, None, origin)
|
||||
self.mapx400.to_wire(file, None, origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(preference, ) = struct.unpack('!H', wire[current: current + 2])
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
(map822, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused > rdlen:
|
||||
raise dns.exception.FormError
|
||||
current += cused
|
||||
rdlen -= cused
|
||||
if origin is not None:
|
||||
map822 = map822.relativize(origin)
|
||||
(mapx400, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
mapx400 = mapx400.relativize(origin)
|
||||
return cls(rdclass, rdtype, preference, map822, mapx400)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.map822 = self.map822.choose_relativity(origin, relativize)
|
||||
self.mapx400 = self.mapx400.choose_relativity(origin, relativize)
|
81
lib/dns/rdtypes/IN/SRV.py
Normal file
81
lib/dns/rdtypes/IN/SRV.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class SRV(dns.rdata.Rdata):
|
||||
|
||||
"""SRV record
|
||||
|
||||
@ivar priority: the priority
|
||||
@type priority: int
|
||||
@ivar weight: the weight
|
||||
@type weight: int
|
||||
@ivar port: the port of the service
|
||||
@type port: int
|
||||
@ivar target: the target host
|
||||
@type target: dns.name.Name object
|
||||
@see: RFC 2782"""
|
||||
|
||||
__slots__ = ['priority', 'weight', 'port', 'target']
|
||||
|
||||
def __init__(self, rdclass, rdtype, priority, weight, port, target):
|
||||
super(SRV, self).__init__(rdclass, rdtype)
|
||||
self.priority = priority
|
||||
self.weight = weight
|
||||
self.port = port
|
||||
self.target = target
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
target = self.target.choose_relativity(origin, relativize)
|
||||
return '%d %d %d %s' % (self.priority, self.weight, self.port,
|
||||
target)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
priority = tok.get_uint16()
|
||||
weight = tok.get_uint16()
|
||||
port = tok.get_uint16()
|
||||
target = tok.get_name(None)
|
||||
target = target.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, priority, weight, port, target)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
three_ints = struct.pack("!HHH", self.priority, self.weight, self.port)
|
||||
file.write(three_ints)
|
||||
self.target.to_wire(file, compress, origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(priority, weight, port) = struct.unpack('!HHH',
|
||||
wire[current: current + 6])
|
||||
current += 6
|
||||
rdlen -= 6
|
||||
(target, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
target = target.relativize(origin)
|
||||
return cls(rdclass, rdtype, priority, weight, port, target)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.target = self.target.choose_relativity(origin, relativize)
|
106
lib/dns/rdtypes/IN/WKS.py
Normal file
106
lib/dns/rdtypes/IN/WKS.py
Normal file
|
@ -0,0 +1,106 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import socket
|
||||
import struct
|
||||
|
||||
import dns.ipv4
|
||||
import dns.rdata
|
||||
from dns._compat import xrange
|
||||
|
||||
_proto_tcp = socket.getprotobyname('tcp')
|
||||
_proto_udp = socket.getprotobyname('udp')
|
||||
|
||||
|
||||
class WKS(dns.rdata.Rdata):
|
||||
|
||||
"""WKS record
|
||||
|
||||
@ivar address: the address
|
||||
@type address: string
|
||||
@ivar protocol: the protocol
|
||||
@type protocol: int
|
||||
@ivar bitmap: the bitmap
|
||||
@type bitmap: string
|
||||
@see: RFC 1035"""
|
||||
|
||||
__slots__ = ['address', 'protocol', 'bitmap']
|
||||
|
||||
def __init__(self, rdclass, rdtype, address, protocol, bitmap):
|
||||
super(WKS, self).__init__(rdclass, rdtype)
|
||||
self.address = address
|
||||
self.protocol = protocol
|
||||
if not isinstance(bitmap, bytearray):
|
||||
self.bitmap = bytearray(bitmap)
|
||||
else:
|
||||
self.bitmap = bitmap
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
bits = []
|
||||
for i in xrange(0, len(self.bitmap)):
|
||||
byte = self.bitmap[i]
|
||||
for j in xrange(0, 8):
|
||||
if byte & (0x80 >> j):
|
||||
bits.append(str(i * 8 + j))
|
||||
text = ' '.join(bits)
|
||||
return '%s %d %s' % (self.address, self.protocol, text)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
address = tok.get_string()
|
||||
protocol = tok.get_string()
|
||||
if protocol.isdigit():
|
||||
protocol = int(protocol)
|
||||
else:
|
||||
protocol = socket.getprotobyname(protocol)
|
||||
bitmap = bytearray()
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
if token.value.isdigit():
|
||||
serv = int(token.value)
|
||||
else:
|
||||
if protocol != _proto_udp and protocol != _proto_tcp:
|
||||
raise NotImplementedError("protocol must be TCP or UDP")
|
||||
if protocol == _proto_udp:
|
||||
protocol_text = "udp"
|
||||
else:
|
||||
protocol_text = "tcp"
|
||||
serv = socket.getservbyname(token.value, protocol_text)
|
||||
i = serv // 8
|
||||
l = len(bitmap)
|
||||
if l < i + 1:
|
||||
for j in xrange(l, i + 1):
|
||||
bitmap.append(0)
|
||||
bitmap[i] = bitmap[i] | (0x80 >> (serv % 8))
|
||||
bitmap = dns.rdata._truncate_bitmap(bitmap)
|
||||
return cls(rdclass, rdtype, address, protocol, bitmap)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(dns.ipv4.inet_aton(self.address))
|
||||
protocol = struct.pack('!B', self.protocol)
|
||||
file.write(protocol)
|
||||
file.write(self.bitmap)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
address = dns.ipv4.inet_ntoa(wire[current: current + 4])
|
||||
protocol, = struct.unpack('!B', wire[current + 4: current + 5])
|
||||
current += 5
|
||||
rdlen -= 5
|
||||
bitmap = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, address, protocol, bitmap)
|
||||
|
30
lib/dns/rdtypes/IN/__init__.py
Normal file
30
lib/dns/rdtypes/IN/__init__.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""Class IN rdata type classes."""
|
||||
|
||||
__all__ = [
|
||||
'A',
|
||||
'AAAA',
|
||||
'APL',
|
||||
'DHCID',
|
||||
'KX',
|
||||
'NAPTR',
|
||||
'NSAP',
|
||||
'NSAP_PTR',
|
||||
'PX',
|
||||
'SRV',
|
||||
'WKS',
|
||||
]
|
24
lib/dns/rdtypes/__init__.py
Normal file
24
lib/dns/rdtypes/__init__.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""DNS rdata type classes"""
|
||||
|
||||
__all__ = [
|
||||
'ANY',
|
||||
'IN',
|
||||
'euibase',
|
||||
'mxbase',
|
||||
'nsbase',
|
||||
]
|
136
lib/dns/rdtypes/dnskeybase.py
Normal file
136
lib/dns/rdtypes/dnskeybase.py
Normal file
|
@ -0,0 +1,136 @@
|
|||
# Copyright (C) 2004-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import base64
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.dnssec
|
||||
import dns.rdata
|
||||
|
||||
# wildcard import
|
||||
__all__ = ["SEP", "REVOKE", "ZONE",
|
||||
"flags_to_text_set", "flags_from_text_set"]
|
||||
|
||||
# flag constants
|
||||
SEP = 0x0001
|
||||
REVOKE = 0x0080
|
||||
ZONE = 0x0100
|
||||
|
||||
_flag_by_text = {
|
||||
'SEP': SEP,
|
||||
'REVOKE': REVOKE,
|
||||
'ZONE': ZONE
|
||||
}
|
||||
|
||||
# We construct the inverse mapping programmatically to ensure that we
|
||||
# cannot make any mistakes (e.g. omissions, cut-and-paste errors) that
|
||||
# would cause the mapping not to be true inverse.
|
||||
_flag_by_value = dict((y, x) for x, y in _flag_by_text.items())
|
||||
|
||||
|
||||
def flags_to_text_set(flags):
|
||||
"""Convert a DNSKEY flags value to set texts
|
||||
@rtype: set([string])"""
|
||||
|
||||
flags_set = set()
|
||||
mask = 0x1
|
||||
while mask <= 0x8000:
|
||||
if flags & mask:
|
||||
text = _flag_by_value.get(mask)
|
||||
if not text:
|
||||
text = hex(mask)
|
||||
flags_set.add(text)
|
||||
mask <<= 1
|
||||
return flags_set
|
||||
|
||||
|
||||
def flags_from_text_set(texts_set):
|
||||
"""Convert set of DNSKEY flag mnemonic texts to DNSKEY flag value
|
||||
@rtype: int"""
|
||||
|
||||
flags = 0
|
||||
for text in texts_set:
|
||||
try:
|
||||
flags += _flag_by_text[text]
|
||||
except KeyError:
|
||||
raise NotImplementedError(
|
||||
"DNSKEY flag '%s' is not supported" % text)
|
||||
return flags
|
||||
|
||||
|
||||
class DNSKEYBase(dns.rdata.Rdata):
|
||||
|
||||
"""Base class for rdata that is like a DNSKEY record
|
||||
|
||||
@ivar flags: the key flags
|
||||
@type flags: int
|
||||
@ivar protocol: the protocol for which this key may be used
|
||||
@type protocol: int
|
||||
@ivar algorithm: the algorithm used for the key
|
||||
@type algorithm: int
|
||||
@ivar key: the public key
|
||||
@type key: string"""
|
||||
|
||||
__slots__ = ['flags', 'protocol', 'algorithm', 'key']
|
||||
|
||||
def __init__(self, rdclass, rdtype, flags, protocol, algorithm, key):
|
||||
super(DNSKEYBase, self).__init__(rdclass, rdtype)
|
||||
self.flags = flags
|
||||
self.protocol = protocol
|
||||
self.algorithm = algorithm
|
||||
self.key = key
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%d %d %d %s' % (self.flags, self.protocol, self.algorithm,
|
||||
dns.rdata._base64ify(self.key))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
flags = tok.get_uint16()
|
||||
protocol = tok.get_uint8()
|
||||
algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
b64 = b''.join(chunks)
|
||||
key = base64.b64decode(b64)
|
||||
return cls(rdclass, rdtype, flags, protocol, algorithm, key)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack("!HBB", self.flags, self.protocol, self.algorithm)
|
||||
file.write(header)
|
||||
file.write(self.key)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
if rdlen < 4:
|
||||
raise dns.exception.FormError
|
||||
header = struct.unpack('!HBB', wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
key = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], header[1], header[2],
|
||||
key)
|
||||
|
||||
def flags_to_text_set(self):
|
||||
"""Convert a DNSKEY flags value to set texts
|
||||
@rtype: set([string])"""
|
||||
return flags_to_text_set(self.flags)
|
84
lib/dns/rdtypes/dsbase.py
Normal file
84
lib/dns/rdtypes/dsbase.py
Normal file
|
@ -0,0 +1,84 @@
|
|||
# Copyright (C) 2010, 2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import struct
|
||||
import binascii
|
||||
|
||||
import dns.rdata
|
||||
import dns.rdatatype
|
||||
|
||||
|
||||
class DSBase(dns.rdata.Rdata):
|
||||
|
||||
"""Base class for rdata that is like a DS record
|
||||
|
||||
@ivar key_tag: the key tag
|
||||
@type key_tag: int
|
||||
@ivar algorithm: the algorithm
|
||||
@type algorithm: int
|
||||
@ivar digest_type: the digest type
|
||||
@type digest_type: int
|
||||
@ivar digest: the digest
|
||||
@type digest: int
|
||||
@see: draft-ietf-dnsext-delegation-signer-14.txt"""
|
||||
|
||||
__slots__ = ['key_tag', 'algorithm', 'digest_type', 'digest']
|
||||
|
||||
def __init__(self, rdclass, rdtype, key_tag, algorithm, digest_type,
|
||||
digest):
|
||||
super(DSBase, self).__init__(rdclass, rdtype)
|
||||
self.key_tag = key_tag
|
||||
self.algorithm = algorithm
|
||||
self.digest_type = digest_type
|
||||
self.digest = digest
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return '%d %d %d %s' % (self.key_tag, self.algorithm,
|
||||
self.digest_type,
|
||||
dns.rdata._hexify(self.digest,
|
||||
chunksize=128))
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
key_tag = tok.get_uint16()
|
||||
algorithm = tok.get_uint8()
|
||||
digest_type = tok.get_uint8()
|
||||
chunks = []
|
||||
while 1:
|
||||
t = tok.get().unescape()
|
||||
if t.is_eol_or_eof():
|
||||
break
|
||||
if not t.is_identifier():
|
||||
raise dns.exception.SyntaxError
|
||||
chunks.append(t.value.encode())
|
||||
digest = b''.join(chunks)
|
||||
digest = binascii.unhexlify(digest)
|
||||
return cls(rdclass, rdtype, key_tag, algorithm, digest_type,
|
||||
digest)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
header = struct.pack("!HBB", self.key_tag, self.algorithm,
|
||||
self.digest_type)
|
||||
file.write(header)
|
||||
file.write(self.digest)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
header = struct.unpack("!HBB", wire[current: current + 4])
|
||||
current += 4
|
||||
rdlen -= 4
|
||||
digest = wire[current: current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, header[0], header[1], header[2], digest)
|
||||
|
71
lib/dns/rdtypes/euibase.py
Normal file
71
lib/dns/rdtypes/euibase.py
Normal file
|
@ -0,0 +1,71 @@
|
|||
# Copyright (C) 2015 Red Hat, Inc.
|
||||
# Author: Petr Spacek <pspacek@redhat.com>
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED 'AS IS' AND RED HAT DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
import binascii
|
||||
|
||||
import dns.rdata
|
||||
|
||||
|
||||
class EUIBase(dns.rdata.Rdata):
|
||||
|
||||
"""EUIxx record
|
||||
|
||||
@ivar fingerprint: xx-bit Extended Unique Identifier (EUI-xx)
|
||||
@type fingerprint: string
|
||||
@see: rfc7043.txt"""
|
||||
|
||||
__slots__ = ['eui']
|
||||
# define these in subclasses
|
||||
# byte_len = 6 # 0123456789ab (in hex)
|
||||
# text_len = byte_len * 3 - 1 # 01-23-45-67-89-ab
|
||||
|
||||
def __init__(self, rdclass, rdtype, eui):
|
||||
super(EUIBase, self).__init__(rdclass, rdtype)
|
||||
if len(eui) != self.byte_len:
|
||||
raise dns.exception.FormError('EUI%s rdata has to have %s bytes'
|
||||
% (self.byte_len * 8, self.byte_len))
|
||||
self.eui = eui
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
return dns.rdata._hexify(self.eui, chunksize=2).replace(' ', '-')
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
text = tok.get_string()
|
||||
tok.get_eol()
|
||||
if len(text) != cls.text_len:
|
||||
raise dns.exception.SyntaxError(
|
||||
'Input text must have %s characters' % cls.text_len)
|
||||
expected_dash_idxs = range(2, cls.byte_len * 3 - 1, 3)
|
||||
for i in expected_dash_idxs:
|
||||
if text[i] != '-':
|
||||
raise dns.exception.SyntaxError('Dash expected at position %s'
|
||||
% i)
|
||||
text = text.replace('-', '')
|
||||
try:
|
||||
data = binascii.unhexlify(text.encode())
|
||||
except (ValueError, TypeError) as ex:
|
||||
raise dns.exception.SyntaxError('Hex decoding error: %s' % str(ex))
|
||||
return cls(rdclass, rdtype, data)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
file.write(self.eui)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
eui = wire[current:current + rdlen].unwrap()
|
||||
return cls(rdclass, rdtype, eui)
|
||||
|
101
lib/dns/rdtypes/mxbase.py
Normal file
101
lib/dns/rdtypes/mxbase.py
Normal file
|
@ -0,0 +1,101 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""MX-like base classes."""
|
||||
|
||||
from io import BytesIO
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class MXBase(dns.rdata.Rdata):
|
||||
|
||||
"""Base class for rdata that is like an MX record.
|
||||
|
||||
@ivar preference: the preference value
|
||||
@type preference: int
|
||||
@ivar exchange: the exchange name
|
||||
@type exchange: dns.name.Name object"""
|
||||
|
||||
__slots__ = ['preference', 'exchange']
|
||||
|
||||
def __init__(self, rdclass, rdtype, preference, exchange):
|
||||
super(MXBase, self).__init__(rdclass, rdtype)
|
||||
self.preference = preference
|
||||
self.exchange = exchange
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
exchange = self.exchange.choose_relativity(origin, relativize)
|
||||
return '%d %s' % (self.preference, exchange)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
preference = tok.get_uint16()
|
||||
exchange = tok.get_name()
|
||||
exchange = exchange.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, preference, exchange)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
pref = struct.pack("!H", self.preference)
|
||||
file.write(pref)
|
||||
self.exchange.to_wire(file, compress, origin)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
return struct.pack("!H", self.preference) + \
|
||||
self.exchange.to_digestable(origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(preference, ) = struct.unpack('!H', wire[current: current + 2])
|
||||
current += 2
|
||||
rdlen -= 2
|
||||
(exchange, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
exchange = exchange.relativize(origin)
|
||||
return cls(rdclass, rdtype, preference, exchange)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.exchange = self.exchange.choose_relativity(origin, relativize)
|
||||
|
||||
|
||||
class UncompressedMX(MXBase):
|
||||
|
||||
"""Base class for rdata that is like an MX record, but whose name
|
||||
is not compressed when converted to DNS wire format, and whose
|
||||
digestable form is not downcased."""
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
super(UncompressedMX, self).to_wire(file, None, origin)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
f = BytesIO()
|
||||
self.to_wire(f, None, origin)
|
||||
return f.getvalue()
|
||||
|
||||
|
||||
class UncompressedDowncasingMX(MXBase):
|
||||
|
||||
"""Base class for rdata that is like an MX record, but whose name
|
||||
is not compressed when convert to DNS wire format."""
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
super(UncompressedDowncasingMX, self).to_wire(file, None, origin)
|
81
lib/dns/rdtypes/nsbase.py
Normal file
81
lib/dns/rdtypes/nsbase.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
# Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""NS-like base classes."""
|
||||
|
||||
from io import BytesIO
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.name
|
||||
|
||||
|
||||
class NSBase(dns.rdata.Rdata):
|
||||
|
||||
"""Base class for rdata that is like an NS record.
|
||||
|
||||
@ivar target: the target name of the rdata
|
||||
@type target: dns.name.Name object"""
|
||||
|
||||
__slots__ = ['target']
|
||||
|
||||
def __init__(self, rdclass, rdtype, target):
|
||||
super(NSBase, self).__init__(rdclass, rdtype)
|
||||
self.target = target
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
target = self.target.choose_relativity(origin, relativize)
|
||||
return str(target)
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
target = tok.get_name()
|
||||
target = target.choose_relativity(origin, relativize)
|
||||
tok.get_eol()
|
||||
return cls(rdclass, rdtype, target)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
self.target.to_wire(file, compress, origin)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
return self.target.to_digestable(origin)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
(target, cused) = dns.name.from_wire(wire[: current + rdlen],
|
||||
current)
|
||||
if cused != rdlen:
|
||||
raise dns.exception.FormError
|
||||
if origin is not None:
|
||||
target = target.relativize(origin)
|
||||
return cls(rdclass, rdtype, target)
|
||||
|
||||
def choose_relativity(self, origin=None, relativize=True):
|
||||
self.target = self.target.choose_relativity(origin, relativize)
|
||||
|
||||
|
||||
class UncompressedNS(NSBase):
|
||||
|
||||
"""Base class for rdata that is like an NS record, but whose name
|
||||
is not compressed when convert to DNS wire format, and whose
|
||||
digestable form is not downcased."""
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
super(UncompressedNS, self).to_wire(file, None, origin)
|
||||
|
||||
def to_digestable(self, origin=None):
|
||||
f = BytesIO()
|
||||
self.to_wire(f, None, origin)
|
||||
return f.getvalue()
|
91
lib/dns/rdtypes/txtbase.py
Normal file
91
lib/dns/rdtypes/txtbase.py
Normal file
|
@ -0,0 +1,91 @@
|
|||
# Copyright (C) 2006, 2007, 2009-2011 Nominum, Inc.
|
||||
#
|
||||
# Permission to use, copy, modify, and distribute this software and its
|
||||
# documentation for any purpose with or without fee is hereby granted,
|
||||
# provided that the above copyright notice and this permission notice
|
||||
# appear in all copies.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
|
||||
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
|
||||
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
||||
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
"""TXT-like base class."""
|
||||
|
||||
import struct
|
||||
|
||||
import dns.exception
|
||||
import dns.rdata
|
||||
import dns.tokenizer
|
||||
from dns._compat import binary_type
|
||||
|
||||
|
||||
class TXTBase(dns.rdata.Rdata):
|
||||
|
||||
"""Base class for rdata that is like a TXT record
|
||||
|
||||
@ivar strings: the text strings
|
||||
@type strings: list of string
|
||||
@see: RFC 1035"""
|
||||
|
||||
__slots__ = ['strings']
|
||||
|
||||
def __init__(self, rdclass, rdtype, strings):
|
||||
super(TXTBase, self).__init__(rdclass, rdtype)
|
||||
if isinstance(strings, str):
|
||||
strings = [strings]
|
||||
self.strings = strings[:]
|
||||
|
||||
def to_text(self, origin=None, relativize=True, **kw):
|
||||
txt = ''
|
||||
prefix = ''
|
||||
for s in self.strings:
|
||||
txt += '%s"%s"' % (prefix, dns.rdata._escapify(s))
|
||||
prefix = ' '
|
||||
return txt
|
||||
|
||||
@classmethod
|
||||
def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
|
||||
strings = []
|
||||
while 1:
|
||||
token = tok.get().unescape()
|
||||
if token.is_eol_or_eof():
|
||||
break
|
||||
if not (token.is_quoted_string() or token.is_identifier()):
|
||||
raise dns.exception.SyntaxError("expected a string")
|
||||
if len(token.value) > 255:
|
||||
raise dns.exception.SyntaxError("string too long")
|
||||
value = token.value
|
||||
if isinstance(value, binary_type):
|
||||
strings.append(value)
|
||||
else:
|
||||
strings.append(value.encode())
|
||||
if len(strings) == 0:
|
||||
raise dns.exception.UnexpectedEnd
|
||||
return cls(rdclass, rdtype, strings)
|
||||
|
||||
def to_wire(self, file, compress=None, origin=None):
|
||||
for s in self.strings:
|
||||
l = len(s)
|
||||
assert l < 256
|
||||
file.write(struct.pack('!B', l))
|
||||
file.write(s)
|
||||
|
||||
@classmethod
|
||||
def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
|
||||
strings = []
|
||||
while rdlen > 0:
|
||||
l = wire[current]
|
||||
current += 1
|
||||
rdlen -= 1
|
||||
if l > rdlen:
|
||||
raise dns.exception.FormError
|
||||
s = wire[current: current + l].unwrap()
|
||||
current += l
|
||||
rdlen -= l
|
||||
strings.append(s)
|
||||
return cls(rdclass, rdtype, strings)
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue