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