1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 import base64
19 import calendar
20 import struct
21 import time
22
23 import dns.dnssec
24 import dns.exception
25 import dns.rdata
26 import dns.rdatatype
27
28
29 -class BadSigTime(dns.exception.DNSException):
30
31 """Time in DNS SIG or RRSIG resource record cannot be parsed."""
32
35 if len(what) != 14:
36 raise BadSigTime
37 year = int(what[0:4])
38 month = int(what[4:6])
39 day = int(what[6:8])
40 hour = int(what[8:10])
41 minute = int(what[10:12])
42 second = int(what[12:14])
43 return calendar.timegm((year, month, day, hour, minute, second,
44 0, 0, 0))
45
48 return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
49
50
51 -class RRSIG(dns.rdata.Rdata):
52
53 """RRSIG record
54
55 @ivar type_covered: the rdata type this signature covers
56 @type type_covered: int
57 @ivar algorithm: the algorithm used for the sig
58 @type algorithm: int
59 @ivar labels: number of labels
60 @type labels: int
61 @ivar original_ttl: the original TTL
62 @type original_ttl: long
63 @ivar expiration: signature expiration time
64 @type expiration: long
65 @ivar inception: signature inception time
66 @type inception: long
67 @ivar key_tag: the key tag
68 @type key_tag: int
69 @ivar signer: the signer
70 @type signer: dns.name.Name object
71 @ivar signature: the signature
72 @type signature: string"""
73
74 __slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl',
75 'expiration', 'inception', 'key_tag', 'signer',
76 'signature']
77
78 - def __init__(self, rdclass, rdtype, type_covered, algorithm, labels,
79 original_ttl, expiration, inception, key_tag, signer,
80 signature):
91
94
95 - def to_text(self, origin=None, relativize=True, **kw):
107
108 @classmethod
109 - def from_text(cls, rdclass, rdtype, tok, origin=None, relativize=True):
110 type_covered = dns.rdatatype.from_text(tok.get_string())
111 algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
112 labels = tok.get_int()
113 original_ttl = tok.get_ttl()
114 expiration = sigtime_to_posixtime(tok.get_string())
115 inception = sigtime_to_posixtime(tok.get_string())
116 key_tag = tok.get_int()
117 signer = tok.get_name()
118 signer = signer.choose_relativity(origin, relativize)
119 chunks = []
120 while 1:
121 t = tok.get().unescape()
122 if t.is_eol_or_eof():
123 break
124 if not t.is_identifier():
125 raise dns.exception.SyntaxError
126 chunks.append(t.value.encode())
127 b64 = b''.join(chunks)
128 signature = base64.b64decode(b64)
129 return cls(rdclass, rdtype, type_covered, algorithm, labels,
130 original_ttl, expiration, inception, key_tag, signer,
131 signature)
132
133 - def to_wire(self, file, compress=None, origin=None):
141
142 @classmethod
143 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin=None):
144 header = struct.unpack('!HBBIIIH', wire[current: current + 18])
145 current += 18
146 rdlen -= 18
147 (signer, cused) = dns.name.from_wire(wire[: current + rdlen], current)
148 current += cused
149 rdlen -= cused
150 if origin is not None:
151 signer = signer.relativize(origin)
152 signature = wire[current: current + rdlen].unwrap()
153 return cls(rdclass, rdtype, header[0], header[1], header[2],
154 header[3], header[4], header[5], header[6], signer,
155 signature)
156
159