Blame SOURCES/dnspython-1.10.1-tlsa.patch

80f6bf
commit 38d5ea59581275eafcf55f2d677056875483fa2f
80f6bf
Author: Pieter Lexis <pieter@plexis.eu>
80f6bf
Date:   Mon Sep 17 23:58:20 2012 +0200
80f6bf
80f6bf
    Add TLSA (RFC 6698) record type
80f6bf
80f6bf
diff --git a/dns/rdatatype.py b/dns/rdatatype.py
80f6bf
index 380cfcd..f64307a 100644
80f6bf
--- a/dns/rdatatype.py
80f6bf
+++ b/dns/rdatatype.py
80f6bf
@@ -78,6 +78,7 @@ DNSKEY = 48
80f6bf
 DHCID = 49
80f6bf
 NSEC3 = 50
80f6bf
 NSEC3PARAM = 51
80f6bf
+TLSA = 52
80f6bf
 HIP = 55
80f6bf
 SPF = 99
80f6bf
 UNSPEC = 103
80f6bf
@@ -140,6 +141,7 @@ _by_text = {
80f6bf
     'DHCID' : DHCID,
80f6bf
     'NSEC3' : NSEC3,
80f6bf
     'NSEC3PARAM' : NSEC3PARAM,
80f6bf
+    'TLSA' : TLSA,
80f6bf
     'HIP' : HIP,
80f6bf
     'SPF' : SPF,
80f6bf
     'UNSPEC' : UNSPEC,
80f6bf
diff --git a/dns/rdtypes/ANY/TLSA.py b/dns/rdtypes/ANY/TLSA.py
80f6bf
new file mode 100644
80f6bf
index 0000000..6ca8c0a
80f6bf
--- /dev/null
80f6bf
+++ b/dns/rdtypes/ANY/TLSA.py
80f6bf
@@ -0,0 +1,89 @@
80f6bf
+# Copyright (C) 2005-2007, 2009-2011 Nominum, Inc.
80f6bf
+#
80f6bf
+# Permission to use, copy, modify, and distribute this software and its
80f6bf
+# documentation for any purpose with or without fee is hereby granted,
80f6bf
+# provided that the above copyright notice and this permission notice
80f6bf
+# appear in all copies.
80f6bf
+#
80f6bf
+# THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
80f6bf
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
80f6bf
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
80f6bf
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
80f6bf
+# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
80f6bf
+# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
80f6bf
+# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
80f6bf
+
80f6bf
+import struct
80f6bf
+
80f6bf
+import dns.rdata
80f6bf
+import dns.rdatatype
80f6bf
+
80f6bf
+class TLSA(dns.rdata.Rdata):
80f6bf
+    """TLSA record
80f6bf
+
80f6bf
+    @ivar usage: The certificate usage
80f6bf
+    @type usage: int
80f6bf
+    @ivar selector: The selector field
80f6bf
+    @type selector: int
80f6bf
+    @ivar mtype: The 'matching type' field
80f6bf
+    @type mtype: int
80f6bf
+    @ivar cert: The 'Certificate Association Data' field
80f6bf
+    @type cert: string
80f6bf
+    @see: RFC 6698"""
80f6bf
+
80f6bf
+    __slots__ = ['usage', 'selector', 'mtype', 'cert']
80f6bf
+
80f6bf
+    def __init__(self, rdclass, rdtype, usage, selector,
80f6bf
+                 mtype, cert):
80f6bf
+        super(TLSA, self).__init__(rdclass, rdtype)
80f6bf
+        self.usage = usage
80f6bf
+        self.selector = selector
80f6bf
+        self.mtype = mtype
80f6bf
+        self.cert = cert
80f6bf
+
80f6bf
+    def to_text(self, origin=None, relativize=True, **kw):
80f6bf
+        return '%d %d %d %s' % (self.usage,
80f6bf
+                                self.selector,
80f6bf
+                                self.mtype,
80f6bf
+                                dns.rdata._hexify(self.cert,
80f6bf
+                                               chunksize=128))
80f6bf
+
80f6bf
+    def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
80f6bf
+        usage = tok.get_uint8()
80f6bf
+        selector = tok.get_uint8()
80f6bf
+        mtype = tok.get_uint8()
80f6bf
+        cert_chunks = []
80f6bf
+        while 1:
80f6bf
+            t = tok.get().unescape()
80f6bf
+            if t.is_eol_or_eof():
80f6bf
+                break
80f6bf
+            if not t.is_identifier():
80f6bf
+                raise dns.exception.SyntaxError
80f6bf
+            cert_chunks.append(t.value)
80f6bf
+        cert = ''.join(cert_chunks)
80f6bf
+        cert = cert.decode('hex_codec')
80f6bf
+        return cls(rdclass, rdtype, usage, selector, mtype, cert)
80f6bf
+
80f6bf
+    from_text = classmethod(from_text)
80f6bf
+
80f6bf
+    def to_wire(self, file, compress = None, origin = None):
80f6bf
+        header = struct.pack("!BBB", self.usage, self.selector, self.mtype)
80f6bf
+        file.write(header)
80f6bf
+        file.write(self.cert)
80f6bf
+
80f6bf
+    def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
80f6bf
+        header = struct.unpack("!BBB", wire[current : current + 3])
80f6bf
+        current += 3
80f6bf
+        rdlen -= 3
80f6bf
+        cert = wire[current : current + rdlen].unwrap()
80f6bf
+        return cls(rdclass, rdtype, header[0], header[1], header[2], cert)
80f6bf
+
80f6bf
+    from_wire = classmethod(from_wire)
80f6bf
+
80f6bf
+    def _cmp(self, other):
80f6bf
+        hs = struct.pack("!BBB", self.usage, self.selector, self.mtype)
80f6bf
+        ho = struct.pack("!BBB", other.usage, other.selector, other.mtype)
80f6bf
+        v = cmp(hs, ho)
80f6bf
+        if v == 0:
80f6bf
+            v = cmp(self.cert, other.cert)
80f6bf
+        return v
80f6bf
diff --git a/dns/rdtypes/ANY/__init__.py b/dns/rdtypes/ANY/__init__.py
80f6bf
index 721e9dd..cfb0be6 100644
80f6bf
--- a/dns/rdtypes/ANY/__init__.py
80f6bf
+++ b/dns/rdtypes/ANY/__init__.py
80f6bf
@@ -33,6 +33,7 @@ __all__ = [
80f6bf
     'NSEC',
80f6bf
     'NSEC3',
80f6bf
     'NSEC3PARAM',
80f6bf
+    'TLSA',
80f6bf
     'PTR',
80f6bf
     'RP',
80f6bf
     'RRSIG',
80f6bf
diff --git a/tests/example b/tests/example
80f6bf
index 2f753a2..71fb8e6 100644
80f6bf
--- a/tests/example
80f6bf
+++ b/tests/example
80f6bf
@@ -165,6 +165,9 @@ srv02			SRV	65535 65535 65535 old-slow-box.example.com.
80f6bf
 $TTL 301	; 5 minutes 1 second
80f6bf
 t			A	73.80.65.49
80f6bf
 $TTL 3600	; 1 hour
80f6bf
+tlsa1			TLSA	3 1 1 01a9cdf989b504fe5dca90c0d2167b6550570734f7c763e09fdf88904e06157065
80f6bf
+tlsa2			TLSA	1 0 1 efddf0d915c7bdc5782c0881e1b2a95ad099fbdd06d7b1f77982d9364338d955
80f6bf
+tlsa3			TLSA	1 0 2 81ee7f6c0ecc6b09b7785a9418f54432de630dd54dc6ee9e3c49de547708d236d4c413c3e97e44f969e635958aa410495844127c04883503e5b024cf7a8f6a94
80f6bf
 txt01			TXT	"foo"
80f6bf
 txt02			TXT	"foo" "bar"
80f6bf
 txt03			TXT	"foo"
80f6bf
diff --git a/tests/example1.good b/tests/example1.good
80f6bf
index 0834d17..4c2d01a 100644
80f6bf
--- a/tests/example1.good
80f6bf
+++ b/tests/example1.good
80f6bf
@@ -90,6 +90,9 @@ srv01 3600 IN SRV 0 0 0 .
80f6bf
 srv02 3600 IN SRV 65535 65535 65535 old-slow-box.example.com.
80f6bf
 sshfp1 3600 IN SSHFP 1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab
80f6bf
 t 301 IN A 73.80.65.49
80f6bf
+tlsa1 3600 IN TLSA 3 1 1 01a9cdf989b504fe5dca90c0d2167b6550570734f7c763e09fdf88904e06157065
80f6bf
+tlsa2 3600 IN TLSA 1 0 1 efddf0d915c7bdc5782c0881e1b2a95ad099fbdd06d7b1f77982d9364338d955
80f6bf
+tlsa3 3600 IN TLSA 1 0 2 81ee7f6c0ecc6b09b7785a9418f54432de630dd54dc6ee9e3c49de547708d236d4c413c3e97e44f969e635958aa410495844127c04883503e5b024cf7a8f6a94
80f6bf
 txt01 3600 IN TXT "foo"
80f6bf
 txt02 3600 IN TXT "foo" "bar"
80f6bf
 txt03 3600 IN TXT "foo"
80f6bf
diff --git a/tests/example2.good b/tests/example2.good
80f6bf
index de4bcd5..1bf6b59 100644
80f6bf
--- a/tests/example2.good
80f6bf
+++ b/tests/example2.good
80f6bf
@@ -90,6 +90,9 @@ srv01.example. 3600 IN SRV 0 0 0 .
80f6bf
 srv02.example. 3600 IN SRV 65535 65535 65535 old-slow-box.example.com.
80f6bf
 sshfp1.example. 3600 IN SSHFP 1 1 aa549bfe898489c02d1715d97d79c57ba2fa76ab
80f6bf
 t.example. 301 IN A 73.80.65.49
80f6bf
+tlsa1.example. 3600 IN TLSA 3 1 1 01a9cdf989b504fe5dca90c0d2167b6550570734f7c763e09fdf88904e06157065
80f6bf
+tlsa2.example. 3600 IN TLSA 1 0 1 efddf0d915c7bdc5782c0881e1b2a95ad099fbdd06d7b1f77982d9364338d955
80f6bf
+tlsa3.example. 3600 IN TLSA 1 0 2 81ee7f6c0ecc6b09b7785a9418f54432de630dd54dc6ee9e3c49de547708d236d4c413c3e97e44f969e635958aa410495844127c04883503e5b024cf7a8f6a94
80f6bf
 txt01.example. 3600 IN TXT "foo"
80f6bf
 txt02.example. 3600 IN TXT "foo" "bar"
80f6bf
 txt03.example. 3600 IN TXT "foo"