summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@nominum.com>2009-06-19 10:16:19 +0100
committerBob Halley <halley@nominum.com>2009-06-19 10:16:19 +0100
commitd85f1ef1c7a4d66925e4c07092dbb83e5d5c4575 (patch)
treecc24ce56dfae53f65bdc9dbcf903fbebe08cbd0d
parent8e0352386e44aaa03667ef8ce8478164c010b8a7 (diff)
downloaddnspython-d85f1ef1c7a4d66925e4c07092dbb83e5d5c4575.tar.gz
Add HIP RR type
-rw-r--r--ChangeLog4
-rw-r--r--dns/rdtypes/ANY/HIP.py140
-rw-r--r--dns/rdtypes/ANY/__init__.py1
-rw-r--r--tests/example1
-rw-r--r--tests/example1.good1
-rw-r--r--tests/example2.good1
6 files changed, 148 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index b963ce2..0b26bb7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-06-19 Bob Halley <halley@dnspython.org>
+
+ * Added support for the HIP RR type.
+
2009-06-18 Bob Halley <halley@dnspython.org>
* Added support for the DLV RR type.
diff --git a/dns/rdtypes/ANY/HIP.py b/dns/rdtypes/ANY/HIP.py
new file mode 100644
index 0000000..f51f3a8
--- /dev/null
+++ b/dns/rdtypes/ANY/HIP.py
@@ -0,0 +1,140 @@
+# Copyright (C) 2009 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 cStringIO
+import string
+import struct
+
+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 = self.hit.encode('hex-codec')
+ key = self.key.encode('base64-codec').replace('\n', '')
+ text = ''
+ servers = []
+ for server in self.servers:
+ servers.append(str(server.choose_relativity(origin, relativize)))
+ if len(servers) > 0:
+ text += (' ' + ' '.join(servers))
+ return '%u %s %s%s' % (self.algorithm, hit, key, text)
+
+ def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
+ algorithm = tok.get_uint8()
+ hit = tok.get_string().decode('hex-codec')
+ if len(hit) > 255:
+ raise dns.exception.SyntaxError, "HIT too long"
+ key = tok.get_string().decode('base64-codec')
+ servers = []
+ while 1:
+ (ttype, value) = tok.get()
+ if ttype == dns.tokenizer.EOL or ttype == dns.tokenizer.EOF:
+ break
+ server = dns.name.from_text(value, origin)
+ server.choose_relativity(origin, relativize)
+ servers.append(server)
+ return cls(rdclass, rdtype, hit, algorithm, key, servers)
+
+ from_text = classmethod(from_text)
+
+ 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, compress, origin)
+
+ 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]
+ current += lh
+ rdlen -= lh
+ key = wire[current : current + lk]
+ current += lk
+ rdlen -= lk
+ servers = []
+ while rdlen > 0:
+ (server, cused) = dns.name.from_wire(wire[: current + rdlen],
+ current)
+ current += cused
+ rdlen -= cused
+ if not origin is None:
+ server = server.relativize(origin)
+ servers.append(server)
+ return cls(rdclass, rdtype, hit, algorithm, key, servers)
+
+ from_wire = classmethod(from_wire)
+
+ 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
+
+ def _cmp(self, other):
+ b1 = cStringIO.StringIO()
+ lh = len(self.hit)
+ lk = len(self.key)
+ b1.write(struct.pack("!BBH", lh, self.algorithm, lk))
+ b1.write(self.hit)
+ b1.write(self.key)
+ b2 = cStringIO.StringIO()
+ lh = len(other.hit)
+ lk = len(other.key)
+ b2.write(struct.pack("!BBH", lh, other.algorithm, lk))
+ b2.write(other.hit)
+ b2.write(other.key)
+ v = cmp(b1.getvalue(), b2.getvalue())
+ if v != 0:
+ return v
+ ls = len(self.servers)
+ lo = len(other.servers)
+ count = min(ls, lo)
+ i = 0
+ while i < count:
+ v = cmp(self.servers[i], other.servers[i])
+ if v != 0:
+ return v
+ i += 1
+ return ls - lo
diff --git a/dns/rdtypes/ANY/__init__.py b/dns/rdtypes/ANY/__init__.py
index ef366ae..ea8ba13 100644
--- a/dns/rdtypes/ANY/__init__.py
+++ b/dns/rdtypes/ANY/__init__.py
@@ -25,6 +25,7 @@ __all__ = [
'DS',
'GPOS',
'HINFO',
+ 'HIP',
'ISDN',
'KEY',
'LOC',
diff --git a/tests/example b/tests/example
index c4183d3..e8fed11 100644
--- a/tests/example
+++ b/tests/example
@@ -222,3 +222,4 @@ nsec301 NSEC3 1 1 12 aabbccdd 2t7b4g4vsa5smi47k61mv5bv1a22bojr MX DNSKEY NS SO
nsec302 NSEC3 1 1 12 - 2t7b4g4vsa5smi47k61mv5bv1a22bojr MX DNSKEY NS SOA NSEC3PARAM RRSIG
nsec3param01 NSEC3PARAM 1 1 12 aabbccdd
nsec3param02 NSEC3PARAM 1 1 12 -
+hip01 HIP 2 200100107B1A74DF365639CC39F1D578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs1.example.com. rvs2
diff --git a/tests/example1.good b/tests/example1.good
index 5117b87..ca5ead6 100644
--- a/tests/example1.good
+++ b/tests/example1.good
@@ -41,6 +41,7 @@ f 300 IN A 73.80.65.52
gpos01 3600 IN GPOS -22.6882 116.8652 250.0
hinfo01 3600 IN HINFO "Generic PC clone" "NetBSD-1.4"
hinfo02 3600 IN HINFO "PC" "NetBSD"
+hip01 3600 IN HIP 2 200100107b1a74df365639cc39f1d578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs1.example.com. rvs2
ipseckey01 3600 IN IPSECKEY 10 1 2 192.0.2.38 AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==
ipseckey02 3600 IN IPSECKEY 10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==
ipseckey03 3600 IN IPSECKEY 10 3 2 mygateway.example.com. AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==
diff --git a/tests/example2.good b/tests/example2.good
index e1526af..c923c09 100644
--- a/tests/example2.good
+++ b/tests/example2.good
@@ -41,6 +41,7 @@ f.example. 300 IN A 73.80.65.52
gpos01.example. 3600 IN GPOS -22.6882 116.8652 250.0
hinfo01.example. 3600 IN HINFO "Generic PC clone" "NetBSD-1.4"
hinfo02.example. 3600 IN HINFO "PC" "NetBSD"
+hip01.example. 3600 IN HIP 2 200100107b1a74df365639cc39f1d578 AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cIvM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbWIy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+bSRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWxZ48AWkskmdHaVDP4BcelrTI3rMXdXF5D rvs1.example.com. rvs2.example.
ipseckey01.example. 3600 IN IPSECKEY 10 1 2 192.0.2.38 AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==
ipseckey02.example. 3600 IN IPSECKEY 10 0 2 . AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==
ipseckey03.example. 3600 IN IPSECKEY 10 3 2 mygateway.example.com. AQNRU3mG7TVTO2BkR47usntb102uFJtu gbo6BSGvgqt4AQ==