1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 import calendar
17 import struct
18 import time
19
20 import dns.dnssec
21 import dns.exception
22 import dns.rdata
23 import dns.rdatatype
24
26 """Time in DNS SIG or RRSIG resource record cannot be parsed."""
27
29 if len(what) != 14:
30 raise BadSigTime
31 year = int(what[0:4])
32 month = int(what[4:6])
33 day = int(what[6:8])
34 hour = int(what[8:10])
35 minute = int(what[10:12])
36 second = int(what[12:14])
37 return calendar.timegm((year, month, day, hour, minute, second,
38 0, 0, 0))
39
41 return time.strftime('%Y%m%d%H%M%S', time.gmtime(what))
42
43 -class RRSIG(dns.rdata.Rdata):
44 """RRSIG record
45
46 @ivar type_covered: the rdata type this signature covers
47 @type type_covered: int
48 @ivar algorithm: the algorithm used for the sig
49 @type algorithm: int
50 @ivar labels: number of labels
51 @type labels: int
52 @ivar original_ttl: the original TTL
53 @type original_ttl: long
54 @ivar expiration: signature expiration time
55 @type expiration: long
56 @ivar inception: signature inception time
57 @type inception: long
58 @ivar key_tag: the key tag
59 @type key_tag: int
60 @ivar signer: the signer
61 @type signer: dns.name.Name object
62 @ivar signature: the signature
63 @type signature: string"""
64
65 __slots__ = ['type_covered', 'algorithm', 'labels', 'original_ttl',
66 'expiration', 'inception', 'key_tag', 'signer',
67 'signature']
68
69 - def __init__(self, rdclass, rdtype, type_covered, algorithm, labels,
70 original_ttl, expiration, inception, key_tag, signer,
71 signature):
82
85
86 - def to_text(self, origin=None, relativize=True, **kw):
98
99 - def from_text(cls, rdclass, rdtype, tok, origin = None, relativize = True):
100 type_covered = dns.rdatatype.from_text(tok.get_string())
101 algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
102 labels = tok.get_int()
103 original_ttl = tok.get_ttl()
104 expiration = sigtime_to_posixtime(tok.get_string())
105 inception = sigtime_to_posixtime(tok.get_string())
106 key_tag = tok.get_int()
107 signer = tok.get_name()
108 signer = signer.choose_relativity(origin, relativize)
109 chunks = []
110 while 1:
111 t = tok.get().unescape()
112 if t.is_eol_or_eof():
113 break
114 if not t.is_identifier():
115 raise dns.exception.SyntaxError
116 chunks.append(t.value)
117 b64 = ''.join(chunks)
118 signature = b64.decode('base64_codec')
119 return cls(rdclass, rdtype, type_covered, algorithm, labels,
120 original_ttl, expiration, inception, key_tag, signer,
121 signature)
122
123 from_text = classmethod(from_text)
124
125 - def to_wire(self, file, compress = None, origin = None):
133
134 - def from_wire(cls, rdclass, rdtype, wire, current, rdlen, origin = None):
135 header = struct.unpack('!HBBIIIH', wire[current : current + 18])
136 current += 18
137 rdlen -= 18
138 (signer, cused) = dns.name.from_wire(wire[: current + rdlen], current)
139 current += cused
140 rdlen -= cused
141 if not origin is None:
142 signer = signer.relativize(origin)
143 signature = wire[current : current + rdlen].unwrap()
144 return cls(rdclass, rdtype, header[0], header[1], header[2],
145 header[3], header[4], header[5], header[6], signer,
146 signature)
147
148 from_wire = classmethod(from_wire)
149
152