Botan  1.10.9
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::X509_CRL Class Reference

#include <x509_crl.h>

Inheritance diagram for Botan::X509_CRL:
Botan::X509_Object

Classes

struct  X509_CRL_Error
 

Public Member Functions

MemoryVector< byteauthority_key_id () const
 
MemoryVector< byteBER_encode () const
 
bool check_signature (class Public_Key &key) const
 
bool check_signature (class Public_Key *key) const
 
u32bit crl_number () const
 
void encode (Pipe &out, X509_Encoding encoding=PEM) const
 
std::vector< CRL_Entryget_revoked () const
 
std::string hash_used_for_signature () const
 
X509_DN issuer_dn () const
 
X509_Time next_update () const
 
std::string PEM_encode () const
 
MemoryVector< bytesignature () const
 
AlgorithmIdentifier signature_algorithm () const
 
MemoryVector< bytetbs_data () const
 
X509_Time this_update () const
 
 X509_CRL (DataSource &source, bool throw_on_unknown_critical=false)
 
 X509_CRL (const std::string &filename, bool throw_on_unknown_critical=false)
 

Static Public Member Functions

static MemoryVector< bytemake_signed (class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &tbs)
 

Protected Member Functions

void do_decode ()
 

Protected Attributes

MemoryVector< bytesig
 
AlgorithmIdentifier sig_algo
 
MemoryVector< bytetbs_bits
 

Detailed Description

This class represents X.509 Certificate Revocation Lists (CRLs).

Definition at line 20 of file x509_crl.h.

Constructor & Destructor Documentation

Botan::X509_CRL::X509_CRL ( DataSource source,
bool  throw_on_unknown_critical = false 
)

Construct a CRL from a data source.

Parameters
sourcethe data source providing the DER or PEM encoded CRL.
throw_on_unknown_criticalshould we throw an exception if an unknown CRL extension marked as critical is encountered.

Definition at line 20 of file x509_crl.cpp.

References Botan::X509_Object::do_decode().

20  :
21  X509_Object(in, "X509 CRL/CRL"), throw_on_unknown_critical(touc)
22  {
23  do_decode();
24  }
Botan::X509_CRL::X509_CRL ( const std::string &  filename,
bool  throw_on_unknown_critical = false 
)

Construct a CRL from a file containing the DER or PEM encoded CRL.

Parameters
filenamethe name of the CRL file
throw_on_unknown_criticalshould we throw an exception if an unknown CRL extension marked as critical is encountered.

Definition at line 29 of file x509_crl.cpp.

References Botan::X509_Object::do_decode().

29  :
30  X509_Object(in, "CRL/X509 CRL"), throw_on_unknown_critical(touc)
31  {
32  do_decode();
33  }

Member Function Documentation

MemoryVector< byte > Botan::X509_CRL::authority_key_id ( ) const

Get the AuthorityKeyIdentifier of this CRL.

Returns
this CRLs AuthorityKeyIdentifier

Definition at line 118 of file x509_crl.cpp.

References Botan::Data_Store::get1_memvec().

Referenced by Botan::X509_Store::add_crl().

119  {
120  return info.get1_memvec("X509v3.AuthorityKeyIdentifier");
121  }
MemoryVector< byte > get1_memvec(const std::string &) const
Definition: datastor.cpp:103
MemoryVector< byte > Botan::X509_Object::BER_encode ( ) const
inherited
Returns
BER encoding of this

Definition at line 100 of file x509_obj.cpp.

References Botan::BIT_STRING, Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::get_contents(), Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, Botan::X509_Object::sig, Botan::X509_Object::sig_algo, Botan::DER_Encoder::start_cons(), and Botan::X509_Object::tbs_bits.

Referenced by Botan::X509_Object::encode(), Botan::X509_Object::PEM_encode(), and Botan::CMS_Encoder::sign().

101  {
102  return DER_Encoder()
103  .start_cons(SEQUENCE)
104  .start_cons(SEQUENCE)
105  .raw_bytes(tbs_bits)
106  .end_cons()
107  .encode(sig_algo)
108  .encode(sig, BIT_STRING)
109  .end_cons()
110  .get_contents();
111  }
MemoryVector< byte > tbs_bits
Definition: x509_obj.h:102
AlgorithmIdentifier sig_algo
Definition: x509_obj.h:101
MemoryVector< byte > sig
Definition: x509_obj.h:102
bool Botan::X509_Object::check_signature ( class Public_Key key) const
inherited

Check the signature on this data

Parameters
keythe public key purportedly used to sign this data
Returns
true if the signature is valid, otherwise false

Definition at line 178 of file x509_obj.cpp.

References Botan::Public_Key::algo_name(), Botan::DER_SEQUENCE, Botan::IEEE_1363, Botan::OIDS::lookup(), Botan::Public_Key::message_parts(), Botan::AlgorithmIdentifier::oid, Botan::X509_Object::sig_algo, Botan::X509_Object::signature(), Botan::split_on(), Botan::X509_Object::tbs_data(), and Botan::PK_Verifier::verify_message().

Referenced by Botan::X509_Object::check_signature().

179  {
180  try {
181  std::vector<std::string> sig_info =
183 
184  if(sig_info.size() != 2 || sig_info[0] != pub_key.algo_name())
185  return false;
186 
187  std::string padding = sig_info[1];
188  Signature_Format format =
189  (pub_key.message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363;
190 
191  PK_Verifier verifier(pub_key, padding, format);
192 
193  return verifier.verify_message(tbs_data(), signature());
194  }
195  catch(...)
196  {
197  return false;
198  }
199  }
Signature_Format
Definition: pubkey.h:24
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
AlgorithmIdentifier sig_algo
Definition: x509_obj.h:101
std::string lookup(const OID &oid)
Definition: oids.cpp:31
MemoryVector< byte > signature() const
Definition: x509_obj.cpp:132
MemoryVector< byte > tbs_data() const
Definition: x509_obj.cpp:124
bool Botan::X509_Object::check_signature ( class Public_Key key) const
inherited

Check the signature on this data

Parameters
keythe public key purportedly used to sign this data the pointer will be deleted after use
Returns
true if the signature is valid, otherwise false

Definition at line 169 of file x509_obj.cpp.

References Botan::X509_Object::check_signature().

170  {
171  std::auto_ptr<Public_Key> key(pub_key);
172  return check_signature(*key);
173  }
bool check_signature(class Public_Key &key) const
Definition: x509_obj.cpp:178
u32bit Botan::X509_CRL::crl_number ( ) const

Get the serial number of this CRL.

Returns
CRLs serial number

Definition at line 126 of file x509_crl.cpp.

References Botan::Data_Store::get1_u32bit().

Referenced by Botan::X509_CA::update_crl().

127  {
128  return info.get1_u32bit("X509v3.CRLNumber");
129  }
u32bit get1_u32bit(const std::string &, u32bit=0) const
Definition: datastor.cpp:120
void Botan::X509_Object::do_decode ( )
protectedinherited

Definition at line 221 of file x509_obj.cpp.

Referenced by Botan::PKCS10_Request::PKCS10_Request(), Botan::X509_Certificate::X509_Certificate(), and X509_CRL().

222  {
223  try {
224  force_decode();
225  }
226  catch(Decoding_Error& e)
227  {
228  throw Decoding_Error(PEM_label_pref + " decoding failed (" +
229  e.what() + ")");
230  }
231  catch(Invalid_Argument& e)
232  {
233  throw Decoding_Error(PEM_label_pref + " decoding failed (" +
234  e.what() + ")");
235  }
236  }
std::invalid_argument Invalid_Argument
Definition: exceptn.h:20
void Botan::X509_Object::encode ( Pipe out,
X509_Encoding  encoding = PEM 
) const
inherited

Encode this to a pipe

Deprecated:
use BER_encode or PEM_encode instead
Parameters
outthe pipe to write to
encodingthe encoding to use

Definition at line 89 of file x509_obj.cpp.

References Botan::X509_Object::BER_encode(), Botan::PEM, Botan::X509_Object::PEM_encode(), and Botan::Pipe::write().

90  {
91  if(encoding == PEM)
92  out.write(this->PEM_encode());
93  else
94  out.write(this->BER_encode());
95  }
std::string PEM_encode() const
Definition: x509_obj.cpp:116
MemoryVector< byte > BER_encode() const
Definition: x509_obj.cpp:100
std::vector< CRL_Entry > Botan::X509_CRL::get_revoked ( ) const

Get the entries of this CRL in the form of a vector.

Returns
vector containing the entries of this CRL.

Definition at line 102 of file x509_crl.cpp.

Referenced by Botan::X509_Store::add_crl(), and Botan::X509_CA::update_crl().

103  {
104  return revoked;
105  }
std::string Botan::X509_Object::hash_used_for_signature ( ) const
inherited
Returns
hash algorithm that was used to generate signature

Definition at line 148 of file x509_obj.cpp.

References Botan::OID::as_string(), Botan::OIDS::lookup(), Botan::AlgorithmIdentifier::oid, Botan::parse_algorithm_name(), Botan::X509_Object::sig_algo, and Botan::split_on().

149  {
150  std::vector<std::string> sig_info =
152 
153  if(sig_info.size() != 2)
154  throw Internal_Error("Invalid name format found for " +
156 
157  std::vector<std::string> pad_and_hash =
158  parse_algorithm_name(sig_info[1]);
159 
160  if(pad_and_hash.size() != 2)
161  throw Internal_Error("Invalid name format " + sig_info[1]);
162 
163  return pad_and_hash[1];
164  }
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:96
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:152
AlgorithmIdentifier sig_algo
Definition: x509_obj.h:101
std::string lookup(const OID &oid)
Definition: oids.cpp:31
std::string as_string() const
Definition: asn1_oid.cpp:50
X509_DN Botan::X509_CRL::issuer_dn ( ) const

Get the issuer DN of this CRL.

Returns
CRLs issuer DN

Definition at line 110 of file x509_crl.cpp.

References Botan::create_dn().

Referenced by Botan::Certificate_Store_Memory::add_crl(), and Botan::X509_Store::add_crl().

111  {
112  return create_dn(info);
113  }
X509_DN create_dn(const Data_Store &info)
Definition: x509cert.cpp:414
MemoryVector< byte > Botan::X509_Object::make_signed ( class PK_Signer signer,
RandomNumberGenerator rng,
const AlgorithmIdentifier alg_id,
const MemoryRegion< byte > &  tbs 
)
staticinherited

Create a signed X509 object.

Parameters
signerthe signer used to sign the object
rngthe random number generator to use
alg_idthe algorithm identifier of the signature scheme
tbsthe tbs bits to be signed
Returns
signed X509 object

Definition at line 204 of file x509_obj.cpp.

References Botan::BIT_STRING, Botan::DER_Encoder::encode(), Botan::DER_Encoder::get_contents(), Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, Botan::PK_Signer::sign_message(), and Botan::DER_Encoder::start_cons().

Referenced by Botan::X509::create_cert_req(), and Botan::X509_CA::make_cert().

208  {
209  return DER_Encoder()
210  .start_cons(SEQUENCE)
211  .raw_bytes(tbs_bits)
212  .encode(algo)
213  .encode(signer->sign_message(tbs_bits, rng), BIT_STRING)
214  .end_cons()
215  .get_contents();
216  }
MemoryVector< byte > tbs_bits
Definition: x509_obj.h:102
RandomNumberGenerator * rng
Definition: global_rng.cpp:165
X509_Time Botan::X509_CRL::next_update ( ) const

Get the CRL's nextUpdate value.

Returns
CRLs nextdUpdate

Definition at line 142 of file x509_crl.cpp.

References Botan::Data_Store::get1().

Referenced by Botan::X509_Store::add_crl().

143  {
144  return info.get1("X509.CRL.end");
145  }
std::string get1(const std::string &) const
Definition: datastor.cpp:87
std::string Botan::X509_Object::PEM_encode ( ) const
inherited
Returns
PEM encoding of this

Definition at line 116 of file x509_obj.cpp.

References Botan::X509_Object::BER_encode(), and Botan::PEM_Code::encode().

Referenced by Botan::X509_Object::encode().

117  {
118  return PEM_Code::encode(BER_encode(), PEM_label_pref);
119  }
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:19
MemoryVector< byte > BER_encode() const
Definition: x509_obj.cpp:100
MemoryVector< byte > Botan::X509_Object::signature ( ) const
inherited
Returns
signature on tbs_data()

Definition at line 132 of file x509_obj.cpp.

References Botan::X509_Object::sig.

Referenced by Botan::X509_Object::check_signature().

133  {
134  return sig;
135  }
MemoryVector< byte > sig
Definition: x509_obj.h:102
AlgorithmIdentifier Botan::X509_Object::signature_algorithm ( ) const
inherited
Returns
signature algorithm that was used to generate signature

Definition at line 140 of file x509_obj.cpp.

References Botan::X509_Object::sig_algo.

Referenced by Botan::X509_Certificate::to_string().

141  {
142  return sig_algo;
143  }
AlgorithmIdentifier sig_algo
Definition: x509_obj.h:101
MemoryVector< byte > Botan::X509_Object::tbs_data ( ) const
inherited

The underlying data that is to be or was signed

Returns
data that is or was signed

Definition at line 124 of file x509_obj.cpp.

References Botan::ASN1::put_in_sequence(), and Botan::X509_Object::tbs_bits.

Referenced by Botan::X509_Object::check_signature().

125  {
127  }
MemoryVector< byte > tbs_bits
Definition: x509_obj.h:102
SecureVector< byte > put_in_sequence(const MemoryRegion< byte > &contents)
Definition: asn1_int.cpp:34
X509_Time Botan::X509_CRL::this_update ( ) const

Get the CRL's thisUpdate value.

Returns
CRLs thisUpdate

Definition at line 134 of file x509_crl.cpp.

References Botan::Data_Store::get1().

Referenced by Botan::Certificate_Store_Memory::add_crl(), and Botan::X509_Store::add_crl().

135  {
136  return info.get1("X509.CRL.start");
137  }
std::string get1(const std::string &) const
Definition: datastor.cpp:87

Member Data Documentation

MemoryVector<byte> Botan::X509_Object::sig
protectedinherited
AlgorithmIdentifier Botan::X509_Object::sig_algo
protectedinherited
MemoryVector<byte> Botan::X509_Object::tbs_bits
protectedinherited

Definition at line 102 of file x509_obj.h.

Referenced by Botan::X509_Object::BER_encode(), and Botan::X509_Object::tbs_data().


The documentation for this class was generated from the following files: