monotone

monotone Mtn Source Tree

Root/botan/x509_ext.h

1/*************************************************
2* X.509 Certificate Extensions Header File *
3* (C) 1999-2006 The Botan Project *
4*************************************************/
5
6#ifndef BOTAN_X509_EXTENSIONS_H__
7#define BOTAN_X509_EXTENSIONS_H__
8
9#include <botan/asn1_int.h>
10#include <botan/asn1_oid.h>
11#include <botan/asn1_obj.h>
12#include <botan/datastor.h>
13#include <botan/enums.h>
14
15namespace Botan {
16
17/*************************************************
18* X.509 Certificate Extension *
19*************************************************/
20class Certificate_Extension
21 {
22 public:
23 OID oid_of() const;
24
25 virtual Certificate_Extension* copy() const = 0;
26
27 virtual void contents_to(Data_Store&, Data_Store&) const = 0;
28 virtual std::string config_id() const = 0;
29 virtual std::string oid_name() const = 0;
30
31 virtual ~Certificate_Extension() {}
32 protected:
33 friend class Extensions;
34 virtual bool should_encode() const { return true; }
35 virtual MemoryVector<byte> encode_inner() const = 0;
36 virtual void decode_inner(const MemoryRegion<byte>&) = 0;
37 };
38
39/*************************************************
40* X.509 Certificate Extension List *
41*************************************************/
42class Extensions : public ASN1_Object
43 {
44 public:
45 void encode_into(class DER_Encoder&) const;
46 void decode_from(class BER_Decoder&);
47
48 void contents_to(Data_Store&, Data_Store&) const;
49
50 void add(Certificate_Extension* extn)
51 { extensions.push_back(extn); }
52
53 Extensions& operator=(const Extensions& e)
54 { return copy_this(e); }
55
56 Extensions(bool st = true) : should_throw(st) {}
57 Extensions(const Extensions& e) : ASN1_Object() { copy_this(e); }
58 ~Extensions();
59 private:
60 Extensions& copy_this(const Extensions&);
61 std::vector<Certificate_Extension*> extensions;
62 bool should_throw;
63 };
64
65namespace Cert_Extension {
66
67/*************************************************
68* Basic Constraints Extension *
69*************************************************/
70class Basic_Constraints : public Certificate_Extension
71 {
72 public:
73 Basic_Constraints* copy() const
74 { return new Basic_Constraints(is_ca, path_limit); }
75
76 Basic_Constraints(bool ca = false, u32bit limit = 0) :
77 is_ca(ca), path_limit(limit) {}
78
79 bool get_is_ca() const { return is_ca; }
80 u32bit get_path_limit() const;
81 private:
82 std::string config_id() const { return "basic_constraints"; }
83 std::string oid_name() const { return "X509v3.BasicConstraints"; }
84
85 MemoryVector<byte> encode_inner() const;
86 void decode_inner(const MemoryRegion<byte>&);
87 void contents_to(Data_Store&, Data_Store&) const;
88
89 bool is_ca;
90 u32bit path_limit;
91 };
92
93/*************************************************
94* Key Usage Constraints Extension *
95*************************************************/
96class Key_Usage : public Certificate_Extension
97 {
98 public:
99 Key_Usage* copy() const { return new Key_Usage(constraints); }
100
101 Key_Usage(Key_Constraints c = NO_CONSTRAINTS) : constraints(c) {}
102
103 Key_Constraints get_constraints() const { return constraints; }
104 private:
105 std::string config_id() const { return "key_usage"; }
106 std::string oid_name() const { return "X509v3.KeyUsage"; }
107
108 bool should_encode() const { return (constraints != NO_CONSTRAINTS); }
109 MemoryVector<byte> encode_inner() const;
110 void decode_inner(const MemoryRegion<byte>&);
111 void contents_to(Data_Store&, Data_Store&) const;
112
113 Key_Constraints constraints;
114 };
115
116/*************************************************
117* Subject Key Identifier Extension *
118*************************************************/
119class Subject_Key_ID : public Certificate_Extension
120 {
121 public:
122 Subject_Key_ID* copy() const { return new Subject_Key_ID(key_id); }
123
124 Subject_Key_ID() {}
125 Subject_Key_ID(const MemoryRegion<byte>&);
126
127 MemoryVector<byte> get_key_id() const { return key_id; }
128 private:
129 std::string config_id() const { return "subject_key_id"; }
130 std::string oid_name() const { return "X509v3.SubjectKeyIdentifier"; }
131
132 bool should_encode() const { return (key_id.size() > 0); }
133 MemoryVector<byte> encode_inner() const;
134 void decode_inner(const MemoryRegion<byte>&);
135 void contents_to(Data_Store&, Data_Store&) const;
136
137 MemoryVector<byte> key_id;
138 };
139
140/*************************************************
141* Authority Key Identifier Extension *
142*************************************************/
143class Authority_Key_ID : public Certificate_Extension
144 {
145 public:
146 Authority_Key_ID* copy() const { return new Authority_Key_ID(key_id); }
147
148 Authority_Key_ID() {}
149 Authority_Key_ID(const MemoryRegion<byte>& k) : key_id(k) {}
150
151 MemoryVector<byte> get_key_id() const { return key_id; }
152 private:
153 std::string config_id() const { return "authority_key_id"; }
154 std::string oid_name() const { return "X509v3.AuthorityKeyIdentifier"; }
155
156 bool should_encode() const { return (key_id.size() > 0); }
157 MemoryVector<byte> encode_inner() const;
158 void decode_inner(const MemoryRegion<byte>&);
159 void contents_to(Data_Store&, Data_Store&) const;
160
161 MemoryVector<byte> key_id;
162 };
163
164/*************************************************
165* Alternative Name Extension Base Class *
166*************************************************/
167class Alternative_Name : public Certificate_Extension
168 {
169 public:
170 AlternativeName get_alt_name() const { return alt_name; }
171
172 protected:
173 Alternative_Name(const AlternativeName&,
174 const std::string&, const std::string&);
175
176 Alternative_Name(const std::string&, const std::string&);
177 private:
178 std::string config_id() const { return config_name_str; }
179 std::string oid_name() const { return oid_name_str; }
180
181 bool should_encode() const { return alt_name.has_items(); }
182 MemoryVector<byte> encode_inner() const;
183 void decode_inner(const MemoryRegion<byte>&);
184 void contents_to(Data_Store&, Data_Store&) const;
185
186 std::string config_name_str, oid_name_str;
187 AlternativeName alt_name;
188 };
189
190/*************************************************
191* Subject Alternative Name Extension *
192*************************************************/
193class Subject_Alternative_Name : public Alternative_Name
194 {
195 public:
196 Subject_Alternative_Name* copy() const
197 { return new Subject_Alternative_Name(get_alt_name()); }
198
199 Subject_Alternative_Name(const AlternativeName& = AlternativeName());
200 };
201
202/*************************************************
203* Issuer Alternative Name Extension *
204*************************************************/
205class Issuer_Alternative_Name : public Alternative_Name
206 {
207 public:
208 Issuer_Alternative_Name* copy() const
209 { return new Issuer_Alternative_Name(get_alt_name()); }
210
211 Issuer_Alternative_Name(const AlternativeName& = AlternativeName());
212 };
213
214/*************************************************
215* Extended Key Usage Extension *
216*************************************************/
217class Extended_Key_Usage : public Certificate_Extension
218 {
219 public:
220 Extended_Key_Usage* copy() const { return new Extended_Key_Usage(oids); }
221
222 Extended_Key_Usage() {}
223 Extended_Key_Usage(const std::vector<OID>& o) : oids(o) {}
224
225 std::vector<OID> get_oids() const { return oids; }
226 private:
227 std::string config_id() const { return "extended_key_usage"; }
228 std::string oid_name() const { return "X509v3.ExtendedKeyUsage"; }
229
230 bool should_encode() const { return (oids.size() > 0); }
231 MemoryVector<byte> encode_inner() const;
232 void decode_inner(const MemoryRegion<byte>&);
233 void contents_to(Data_Store&, Data_Store&) const;
234
235 std::vector<OID> oids;
236 };
237
238/*************************************************
239* Certificate Policies Extension *
240*************************************************/
241class Certificate_Policies : public Certificate_Extension
242 {
243 public:
244 Certificate_Policies* copy() const
245 { return new Certificate_Policies(oids); }
246
247 Certificate_Policies() {}
248 Certificate_Policies(const std::vector<OID>& o) : oids(o) {}
249
250 std::vector<OID> get_oids() const { return oids; }
251 private:
252 std::string config_id() const { return "policy_info"; }
253 std::string oid_name() const { return "X509v3.CertificatePolicies"; }
254
255 bool should_encode() const { return (oids.size() > 0); }
256 MemoryVector<byte> encode_inner() const;
257 void decode_inner(const MemoryRegion<byte>&);
258 void contents_to(Data_Store&, Data_Store&) const;
259
260 std::vector<OID> oids;
261 };
262
263/*************************************************
264* CRL Number Extension *
265*************************************************/
266class CRL_Number : public Certificate_Extension
267 {
268 public:
269 CRL_Number* copy() const;
270
271 CRL_Number() : has_value(false), crl_number(0) {}
272 CRL_Number(u32bit n) : has_value(true), crl_number(n) {}
273
274 u32bit get_crl_number() const;
275 private:
276 std::string config_id() const { return "crl_number"; }
277 std::string oid_name() const { return "X509v3.CRLNumber"; }
278
279 bool should_encode() const { return has_value; }
280 MemoryVector<byte> encode_inner() const;
281 void decode_inner(const MemoryRegion<byte>&);
282 void contents_to(Data_Store&, Data_Store&) const;
283
284 bool has_value;
285 u32bit crl_number;
286 };
287
288/*************************************************
289* CRL Entry Reason Code Extension *
290*************************************************/
291class CRL_ReasonCode : public Certificate_Extension
292 {
293 public:
294 CRL_ReasonCode* copy() const { return new CRL_ReasonCode(reason); }
295
296 CRL_ReasonCode(CRL_Code r = UNSPECIFIED) : reason(r) {}
297
298 CRL_Code get_reason() const { return reason; }
299 private:
300 std::string config_id() const { return "crl_reason"; }
301 std::string oid_name() const { return "X509v3.ReasonCode"; }
302
303 bool should_encode() const { return (reason != UNSPECIFIED); }
304 MemoryVector<byte> encode_inner() const;
305 void decode_inner(const MemoryRegion<byte>&);
306 void contents_to(Data_Store&, Data_Store&) const;
307
308 CRL_Code reason;
309 };
310
311}
312
313}
314
315#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status