Botan  1.11.4
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Botan::X509_Object Class Referenceabstract

#include <x509_obj.h>

Inheritance diagram for Botan::X509_Object:
Botan::ASN1_Object Botan::PKCS10_Request Botan::X509_Certificate Botan::X509_CRL

Public Member Functions

std::vector< byteBER_encode () const
 
bool check_signature (const Public_Key &key) const
 
bool check_signature (const Public_Key *key) const
 
void decode_from (class BER_Decoder &from) override
 
void encode_into (class DER_Encoder &to) const override
 
std::string hash_used_for_signature () const
 
std::string PEM_encode () const
 
std::vector< bytesignature () const
 
AlgorithmIdentifier signature_algorithm () const
 
std::vector< bytetbs_data () const
 
virtual ~X509_Object ()
 

Static Public Member Functions

static std::vector< bytemake_signed (class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const secure_vector< byte > &tbs)
 

Protected Member Functions

void do_decode ()
 
 X509_Object (DataSource &src, const std::string &pem_labels)
 
 X509_Object (const std::string &file, const std::string &pem_labels)
 
 X509_Object (const std::vector< byte > &vec, const std::string &labels)
 
 X509_Object ()
 

Protected Attributes

std::vector< bytesig
 
AlgorithmIdentifier sig_algo
 
std::vector< bytetbs_bits
 

Detailed Description

This class represents abstract X.509 signed objects as in the X.500 SIGNED macro

Definition at line 23 of file x509_obj.h.

Constructor & Destructor Documentation

virtual Botan::X509_Object::~X509_Object ( )
inlinevirtual

Definition at line 89 of file x509_obj.h.

89 {}
Botan::X509_Object::X509_Object ( DataSource src,
const std::string &  pem_labels 
)
protected

Definition at line 24 of file x509_obj.cpp.

25  {
26  init(stream, labels);
27  }
Botan::X509_Object::X509_Object ( const std::string &  file,
const std::string &  pem_labels 
)
protected

Definition at line 32 of file x509_obj.cpp.

33  {
34  DataSource_Stream stream(file, true);
35  init(stream, labels);
36  }
Botan::X509_Object::X509_Object ( const std::vector< byte > &  vec,
const std::string &  labels 
)
protected

Definition at line 41 of file x509_obj.cpp.

42  {
43  DataSource_Memory stream(&vec[0], vec.size());
44  init(stream, labels);
45  }
Botan::X509_Object::X509_Object ( )
inlineprotected

Definition at line 96 of file x509_obj.h.

96 {}

Member Function Documentation

std::vector< byte > Botan::X509_Object::BER_encode ( ) const
Returns
BER encoding of this

Definition at line 114 of file x509_obj.cpp.

References encode_into(), and Botan::DER_Encoder::get_contents_unlocked().

Referenced by Botan::X509_Certificate::fingerprint(), and PEM_encode().

115  {
116  DER_Encoder der;
117  encode_into(der);
118  return der.get_contents_unlocked();
119  }
bool Botan::X509_Object::check_signature ( const Public_Key key) const

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 186 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, sig_algo, signature(), Botan::split_on(), tbs_data(), and Botan::PK_Verifier::verify_message().

Referenced by check_signature(), and Botan::x509_path_validate().

187  {
188  try {
189  std::vector<std::string> sig_info =
191 
192  if(sig_info.size() != 2 || sig_info[0] != pub_key.algo_name())
193  return false;
194 
195  std::string padding = sig_info[1];
196  Signature_Format format =
197  (pub_key.message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363;
198 
199  PK_Verifier verifier(pub_key, padding, format);
200 
201  return verifier.verify_message(tbs_data(), signature());
202  }
203  catch(std::exception& e)
204  {
205  return false;
206  }
207  }
bool Botan::X509_Object::check_signature ( const Public_Key key) const

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 177 of file x509_obj.cpp.

References check_signature().

178  {
179  std::unique_ptr<const Public_Key> key(pub_key);
180  return check_signature(*key);
181  }
void Botan::X509_Object::decode_from ( class BER_Decoder from)
overridevirtual

Decode whatever this object is from from

Parameters
fromthe BER_Decoder that will be read from

Implements Botan::ASN1_Object.

Definition at line 99 of file x509_obj.cpp.

References Botan::BIT_STRING, Botan::BER_Decoder::decode(), Botan::BER_Decoder::end_cons(), Botan::BER_Decoder::raw_bytes(), Botan::SEQUENCE, sig, sig_algo, Botan::BER_Decoder::start_cons(), tbs_bits, and Botan::BER_Decoder::verify_end().

100  {
101  from.start_cons(SEQUENCE)
102  .start_cons(SEQUENCE)
103  .raw_bytes(tbs_bits)
104  .end_cons()
105  .decode(sig_algo)
106  .decode(sig, BIT_STRING)
107  .verify_end()
108  .end_cons();
109  }
void Botan::X509_Object::do_decode ( )
protected

Definition at line 229 of file x509_obj.cpp.

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

230  {
231  try {
232  force_decode();
233  }
234  catch(Decoding_Error& e)
235  {
236  throw Decoding_Error(PEM_label_pref + " decoding failed (" +
237  e.what() + ")");
238  }
239  catch(Invalid_Argument& e)
240  {
241  throw Decoding_Error(PEM_label_pref + " decoding failed (" +
242  e.what() + ")");
243  }
244  }
void Botan::X509_Object::encode_into ( class DER_Encoder to) const
overridevirtual

Encode whatever this object is into to

Parameters
tothe DER_Encoder that will be written to

Implements Botan::ASN1_Object.

Definition at line 85 of file x509_obj.cpp.

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

Referenced by BER_encode().

86  {
87  to.start_cons(SEQUENCE)
88  .start_cons(SEQUENCE)
89  .raw_bytes(tbs_bits)
90  .end_cons()
91  .encode(sig_algo)
92  .encode(sig, BIT_STRING)
93  .end_cons();
94  }
std::string Botan::X509_Object::hash_used_for_signature ( ) const
Returns
hash algorithm that was used to generate signature

Definition at line 156 of file x509_obj.cpp.

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

Referenced by Botan::x509_path_validate().

157  {
158  std::vector<std::string> sig_info =
160 
161  if(sig_info.size() != 2)
162  throw Internal_Error("Invalid name format found for " +
164 
165  std::vector<std::string> pad_and_hash =
166  parse_algorithm_name(sig_info[1]);
167 
168  if(pad_and_hash.size() != 2)
169  throw Internal_Error("Invalid name format " + sig_info[1]);
170 
171  return pad_and_hash[1];
172  }
std::vector< byte > Botan::X509_Object::make_signed ( class PK_Signer signer,
RandomNumberGenerator rng,
const AlgorithmIdentifier alg_id,
const secure_vector< byte > &  tbs 
)
static

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 212 of file x509_obj.cpp.

References Botan::BIT_STRING, Botan::DER_Encoder::encode(), Botan::DER_Encoder::get_contents_unlocked(), 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().

216  {
217  return DER_Encoder()
218  .start_cons(SEQUENCE)
219  .raw_bytes(tbs_bits)
220  .encode(algo)
221  .encode(signer->sign_message(tbs_bits, rng), BIT_STRING)
222  .end_cons()
223  .get_contents_unlocked();
224  }
std::string Botan::X509_Object::PEM_encode ( ) const
Returns
PEM encoding of this

Definition at line 124 of file x509_obj.cpp.

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

125  {
126  return PEM_Code::encode(BER_encode(), PEM_label_pref);
127  }
std::vector< byte > Botan::X509_Object::signature ( ) const
Returns
signature on tbs_data()

Definition at line 140 of file x509_obj.cpp.

References sig.

Referenced by check_signature().

141  {
142  return sig;
143  }
AlgorithmIdentifier Botan::X509_Object::signature_algorithm ( ) const
Returns
signature algorithm that was used to generate signature

Definition at line 148 of file x509_obj.cpp.

References sig_algo.

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

149  {
150  return sig_algo;
151  }
std::vector< byte > Botan::X509_Object::tbs_data ( ) const

The underlying data that is to be or was signed

Returns
data that is or was signed

Definition at line 132 of file x509_obj.cpp.

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

Referenced by check_signature().

133  {
135  }

Member Data Documentation

std::vector<byte> Botan::X509_Object::sig
protected
AlgorithmIdentifier Botan::X509_Object::sig_algo
protected
std::vector<byte> Botan::X509_Object::tbs_bits
protected

Definition at line 98 of file x509_obj.h.

Referenced by decode_from(), encode_into(), Botan::X509_Certificate::operator<(), and tbs_data().


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