monotone

monotone Mtn Source Tree

Root/botan/x509_crl.cpp

1/*************************************************
2* X.509 CRL Source File *
3* (C) 1999-2006 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 X509_Time start, end;
54
55 tbs_crl.decode(dn_issuer);
56 tbs_crl.decode(start);
57 tbs_crl.decode(end);
58
59 info.add(dn_issuer.contents());
60 info.add("X509.CRL.start", start.readable_string());
61 info.add("X509.CRL.end", end.readable_string());
62
63 BER_Object next = tbs_crl.get_next_object();
64
65 if(next.type_tag == SEQUENCE && next.class_tag == CONSTRUCTED)
66 {
67 BER_Decoder cert_list(next.value);
68
69 while(cert_list.more_items())
70 {
71 CRL_Entry entry;
72 cert_list.decode(entry);
73 revoked.push_back(entry);
74 }
75 next = tbs_crl.get_next_object();
76 }
77
78 if(next.type_tag == 0 &&
79 next.class_tag == ASN1_Tag(CONSTRUCTED | CONTEXT_SPECIFIC))
80 {
81 BER_Decoder crl_options(next.value);
82
83 std::string action = global_config().option("x509/crl/unknown_critical");
84 if(action != "throw" && action != "ignore")
85 throw Invalid_Argument("Bad value of x509/crl/unknown_critical: "
86 + action);
87
88 Extensions extensions(action == "throw");
89
90 crl_options.decode(extensions).verify_end();
91
92 extensions.contents_to(info, info);
93
94 next = tbs_crl.get_next_object();
95 }
96
97 if(next.type_tag != NO_OBJECT)
98 throw X509_CRL_Error("Unknown tag in CRL");
99
100 tbs_crl.verify_end();
101 }
102
103/*************************************************
104* Return the list of revoked certificates *
105*************************************************/
106std::vector<CRL_Entry> X509_CRL::get_revoked() const
107 {
108 return revoked;
109 }
110
111/*************************************************
112* Return the distinguished name of the issuer *
113*************************************************/
114X509_DN X509_CRL::issuer_dn() const
115 {
116 return create_dn(info);
117 }
118
119/*************************************************
120* Return the key identifier of the issuer *
121*************************************************/
122MemoryVector<byte> X509_CRL::authority_key_id() const
123 {
124 return info.get1_memvec("X509v3.AuthorityKeyIdentifier");
125 }
126
127/*************************************************
128* Return the CRL number of this CRL *
129*************************************************/
130u32bit X509_CRL::crl_number() const
131 {
132 return info.get1_u32bit("X509v3.CRLNumber");
133 }
134
135/*************************************************
136* Return the issue data of the CRL *
137*************************************************/
138X509_Time X509_CRL::this_update() const
139 {
140 return info.get1("X509.CRL.start");
141 }
142
143/*************************************************
144* Return the date when a new CRL will be issued *
145*************************************************/
146X509_Time X509_CRL::next_update() const
147 {
148 return info.get1("X509.CRL.end");
149 }
150
151}

Archive Download this file

Branches

Tags

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