monotone

monotone Mtn Source Tree

Root/botan/x509_crl.cpp

1/*************************************************
2* X.509 CRL Source File *
3* (C) 1999-2007 The Botan Project *
4*************************************************/
5
6#include <botan/x509_crl.h>
7#include <botan/x509_ext.h>
8#include <botan/ber_dec.h>
9#include <botan/parsing.h>
10#include <botan/bigint.h>
11#include <botan/config.h>
12#include <botan/oids.h>
13
14namespace Botan {
15
16/*************************************************
17* Load a X.509 CRL *
18*************************************************/
19X509_CRL::X509_CRL(DataSource& in) : X509_Object(in, "X509 CRL/CRL")
20 {
21 do_decode();
22 }
23
24/*************************************************
25* Load a X.509 CRL *
26*************************************************/
27X509_CRL::X509_CRL(const std::string& in) : X509_Object(in, "CRL/X509 CRL")
28 {
29 do_decode();
30 }
31
32/*************************************************
33* Decode the TBSCertList data *
34*************************************************/
35void X509_CRL::force_decode()
36 {
37 BER_Decoder tbs_crl(tbs_bits);
38
39 u32bit version;
40 tbs_crl.decode_optional(version, INTEGER, UNIVERSAL);
41
42 if(version != 0 && version != 1)
43 throw X509_CRL_Error("Unknown X.509 CRL version " +
44 to_string(version+1));
45
46 AlgorithmIdentifier sig_algo_inner;
47 tbs_crl.decode(sig_algo_inner);
48
49 if(sig_algo != sig_algo_inner)
50 throw X509_CRL_Error("Algorithm identifier mismatch");
51
52 X509_DN dn_issuer;
53 tbs_crl.decode(dn_issuer);
54 info.add(dn_issuer.contents());
55
56 X509_Time start, end;
57 tbs_crl.decode(start).decode(end);
58 info.add("X509.CRL.start", start.readable_string());
59 info.add("X509.CRL.end", end.readable_string());
60
61 BER_Object next = tbs_crl.get_next_object();
62
63 if(next.type_tag == SEQUENCE && next.class_tag == CONSTRUCTED)
64 {
65 BER_Decoder cert_list(next.value);
66
67 while(cert_list.more_items())
68 {
69 CRL_Entry entry;
70 cert_list.decode(entry);
71 revoked.push_back(entry);
72 }
73 next = tbs_crl.get_next_object();
74 }
75
76 if(next.type_tag == 0 &&
77 next.class_tag == ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
78 {
79 BER_Decoder crl_options(next.value);
80
81 std::string action = global_config().option("x509/crl/unknown_critical");
82 if(action != "throw" && action != "ignore")
83 throw Invalid_Argument("Bad value of x509/crl/unknown_critical: "
84 + action);
85
86 Extensions extensions(action == "throw");
87
88 crl_options.decode(extensions).verify_end();
89
90 extensions.contents_to(info, info);
91
92 next = tbs_crl.get_next_object();
93 }
94
95 if(next.type_tag != NO_OBJECT)
96 throw X509_CRL_Error("Unknown tag in CRL");
97
98 tbs_crl.verify_end();
99 }
100
101/*************************************************
102* Return the list of revoked certificates *
103*************************************************/
104std::vector<CRL_Entry> X509_CRL::get_revoked() const
105 {
106 return revoked;
107 }
108
109/*************************************************
110* Return the distinguished name of the issuer *
111*************************************************/
112X509_DN X509_CRL::issuer_dn() const
113 {
114 return create_dn(info);
115 }
116
117/*************************************************
118* Return the key identifier of the issuer *
119*************************************************/
120MemoryVector<byte> X509_CRL::authority_key_id() const
121 {
122 return info.get1_memvec("X509v3.AuthorityKeyIdentifier");
123 }
124
125/*************************************************
126* Return the CRL number of this CRL *
127*************************************************/
128u32bit X509_CRL::crl_number() const
129 {
130 return info.get1_u32bit("X509v3.CRLNumber");
131 }
132
133/*************************************************
134* Return the issue data of the CRL *
135*************************************************/
136X509_Time X509_CRL::this_update() const
137 {
138 return info.get1("X509.CRL.start");
139 }
140
141/*************************************************
142* Return the date when a new CRL will be issued *
143*************************************************/
144X509_Time X509_CRL::next_update() const
145 {
146 return info.get1("X509.CRL.end");
147 }
148
149}

Archive Download this file

Branches

Tags

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