| Home | Trees | Indices | Help |
|
|---|
|
|
1 # Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license
2
3 # Copyright (C) 2003-2007, 2009-2011 Nominum, Inc.
4 #
5 # Permission to use, copy, modify, and distribute this software and its
6 # documentation for any purpose with or without fee is hereby granted,
7 # provided that the above copyright notice and this permission notice
8 # appear in all copies.
9 #
10 # THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES
11 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR
13 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
16 # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18 import struct
19 import base64
20
21 import dns.exception
22 import dns.dnssec
23 import dns.rdata
24 import dns.tokenizer
25
26 _ctype_by_value = {
27 1: 'PKIX',
28 2: 'SPKI',
29 3: 'PGP',
30 253: 'URI',
31 254: 'OID',
32 }
33
34 _ctype_by_name = {
35 'PKIX': 1,
36 'SPKI': 2,
37 'PGP': 3,
38 'URI': 253,
39 'OID': 254,
40 }
48
55
58
59 """CERT record
60
61 @ivar certificate_type: certificate type
62 @type certificate_type: int
63 @ivar key_tag: key tag
64 @type key_tag: int
65 @ivar algorithm: algorithm
66 @type algorithm: int
67 @ivar certificate: the certificate or CRL
68 @type certificate: string
69 @see: RFC 2538"""
70
71 __slots__ = ['certificate_type', 'key_tag', 'algorithm', 'certificate']
72
75 super(CERT, self).__init__(rdclass, rdtype)
76 self.certificate_type = certificate_type
77 self.key_tag = key_tag
78 self.algorithm = algorithm
79 self.certificate = certificate
80
82 certificate_type = _ctype_to_text(self.certificate_type)
83 return "%s %d %s %s" % (certificate_type, self.key_tag,
84 dns.dnssec.algorithm_to_text(self.algorithm),
85 dns.rdata._base64ify(self.certificate))
86
87 @classmethod
89 certificate_type = _ctype_from_text(tok.get_string())
90 key_tag = tok.get_uint16()
91 algorithm = dns.dnssec.algorithm_from_text(tok.get_string())
92 if algorithm < 0 or algorithm > 255:
93 raise dns.exception.SyntaxError("bad algorithm type")
94 chunks = []
95 while 1:
96 t = tok.get().unescape()
97 if t.is_eol_or_eof():
98 break
99 if not t.is_identifier():
100 raise dns.exception.SyntaxError
101 chunks.append(t.value.encode())
102 b64 = b''.join(chunks)
103 certificate = base64.b64decode(b64)
104 return cls(rdclass, rdtype, certificate_type, key_tag,
105 algorithm, certificate)
106
108 prefix = struct.pack("!HHB", self.certificate_type, self.key_tag,
109 self.algorithm)
110 file.write(prefix)
111 file.write(self.certificate)
112
113 @classmethod
115 prefix = wire[current: current + 5].unwrap()
116 current += 5
117 rdlen -= 5
118 if rdlen < 0:
119 raise dns.exception.FormError
120 (certificate_type, key_tag, algorithm) = struct.unpack("!HHB", prefix)
121 certificate = wire[current: current + rdlen].unwrap()
122 return cls(rdclass, rdtype, certificate_type, key_tag, algorithm,
123 certificate)
124
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0.1 on Sat Dec 8 10:59:55 2018 | http://epydoc.sourceforge.net |