Botan  2.7.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
Botan::PKCS10_Request Class Referencefinal

#include <pkcs10.h>

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

Public Member Functions

std::vector< uint8_t > BER_encode () const
 
std::string challenge_password () const
 
bool check_signature (const Public_Key &key) const
 
bool check_signature (const Public_Key *key) const
 
Key_Constraints constraints () const
 
void decode_from (class BER_Decoder &from) override
 
void encode_into (class DER_Encoder &to) const override
 
std::vector< OIDex_constraints () const
 
const Extensionsextensions () const
 
std::string hash_used_for_signature () const
 
bool is_CA () const
 
size_t path_limit () const
 
std::string PEM_encode () const
 
 PKCS10_Request (DataSource &source)
 
 PKCS10_Request (const std::vector< uint8_t > &vec)
 
const std::vector< uint8_t > & raw_public_key () const
 
const std::vector< uint8_t > & signature () const
 
const AlgorithmIdentifiersignature_algorithm () const
 
const std::vector< uint8_t > & signed_body () const
 
const AlternativeNamesubject_alt_name () const
 
const X509_DNsubject_dn () const
 
Public_Keysubject_public_key () const
 
std::vector< uint8_t > tbs_data () const
 
Certificate_Status_Code verify_signature (const Public_Key &key) const
 

Static Public Member Functions

static std::unique_ptr< PK_Signerchoose_sig_format (AlgorithmIdentifier &sig_algo, const Private_Key &key, RandomNumberGenerator &rng, const std::string &hash_fn, const std::string &padding_algo)
 
static PKCS10_Request create (const Private_Key &key, const X509_DN &subject_dn, const Extensions &extensions, const std::string &hash_fn, RandomNumberGenerator &rng, const std::string &padding_scheme="", const std::string &challenge="")
 
static std::vector< uint8_t > make_signed (class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &tbs)
 

Protected Member Functions

void load_data (DataSource &src)
 

Detailed Description

PKCS #10 Certificate Request.

Definition at line 28 of file pkcs10.h.

Constructor & Destructor Documentation

◆ PKCS10_Request() [1/2]

Botan::PKCS10_Request::PKCS10_Request ( DataSource source)
explicit

Create a PKCS#10 Request from a data source.

Parameters
sourcethe data source providing the DER encoded request

Definition at line 38 of file pkcs10.cpp.

References Botan::X509_Object::load_data().

Referenced by create().

39  {
40  load_data(src);
41  }
void load_data(DataSource &src)
Definition: x509_obj.cpp:53

◆ PKCS10_Request() [2/2]

Botan::PKCS10_Request::PKCS10_Request ( const std::vector< uint8_t > &  vec)
explicit

Create a PKCS#10 Request from binary data.

Parameters
veca std::vector containing the DER value

Definition at line 43 of file pkcs10.cpp.

References Botan::X509_Object::load_data().

44  {
45  DataSource_Memory src(vec.data(), vec.size());
46  load_data(src);
47  }
void load_data(DataSource &src)
Definition: x509_obj.cpp:53

Member Function Documentation

◆ BER_encode()

std::vector< uint8_t > Botan::ASN1_Object::BER_encode ( ) const
inherited

Return the encoding of this object. This is a convenience method when just one object needs to be serialized. Use DER_Encoder for complicated encodings.

Definition at line 16 of file asn1_obj.cpp.

References Botan::ASN1_Object::encode_into().

Referenced by Botan::PSSR::config_for_x509(), Botan::Certificate_Store_In_SQL::find_all_certs(), Botan::Certificate_Store_In_SQL::find_cert(), Botan::X509_Certificate::fingerprint(), Botan::Certificate_Store_In_SQL::insert_cert(), Botan::X509_Object::PEM_encode(), and Botan::Certificate_Store_In_SQL::revoke_cert().

17  {
18  std::vector<uint8_t> output;
19  DER_Encoder der(output);
20  this->encode_into(der);
21  return output;
22  }
virtual void encode_into(DER_Encoder &to) const =0

◆ challenge_password()

std::string Botan::PKCS10_Request::challenge_password ( ) const

Get the challenge password for this request

Returns
challenge password for this request

Definition at line 212 of file pkcs10.cpp.

213  {
214  return data().m_challenge;
215  }

◆ check_signature() [1/2]

bool Botan::X509_Object::check_signature ( const 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::VERIFIED, and Botan::X509_Object::verify_signature().

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

179  {
180  const Certificate_Status_Code code = verify_signature(pub_key);
181  return (code == Certificate_Status_Code::VERIFIED);
182  }
Certificate_Status_Code verify_signature(const Public_Key &key) const
Definition: x509_obj.cpp:184
Certificate_Status_Code
Definition: cert_status.h:18

◆ check_signature() [2/2]

bool Botan::X509_Object::check_signature ( const Public_Key key) const
inherited

Check the signature on this data

Parameters
keythe public key purportedly used to sign this data the object will be deleted after use (this should have been a std::unique_ptr<Public_Key>)
Returns
true if the signature is valid, otherwise false

Definition at line 170 of file x509_obj.cpp.

References Botan::X509_Object::check_signature(), and Botan::X509_Object::PEM_label().

171  {
172  if(!pub_key)
173  throw Exception("No key provided for " + PEM_label() + " signature check");
174  std::unique_ptr<const Public_Key> key(pub_key);
175  return check_signature(*key);
176  }
virtual std::string PEM_label() const =0
bool check_signature(const Public_Key &key) const
Definition: x509_obj.cpp:178

◆ choose_sig_format()

std::unique_ptr< PK_Signer > Botan::X509_Object::choose_sig_format ( AlgorithmIdentifier sig_algo,
const Private_Key key,
RandomNumberGenerator rng,
const std::string &  hash_fn,
const std::string &  padding_algo 
)
staticinherited

Definition at line 366 of file x509_obj.cpp.

References Botan::DER_SEQUENCE, Botan::IEEE_1363, and Botan::Public_Key::message_parts().

Referenced by Botan::choose_sig_format(), and create().

371  {
372  const Signature_Format format = (key.message_parts() > 1) ? DER_SEQUENCE : IEEE_1363;
373 
374  const std::string emsa = choose_sig_algo(sig_algo, key, hash_fn, padding_algo);
375 
376  return std::unique_ptr<PK_Signer>(new PK_Signer(key, rng, emsa, format));
377  }
Signature_Format
Definition: pubkey.h:27

◆ constraints()

Key_Constraints Botan::PKCS10_Request::constraints ( ) const

Get the key constraints for the key associated with this PKCS#10 object.

Returns
key constraints

Definition at line 261 of file pkcs10.cpp.

References extensions(), Botan::Cert_Extension::Key_Usage::get_constraints(), Botan::OIDS::lookup(), and Botan::NO_CONSTRAINTS.

262  {
263  if(auto ext = extensions().get(OIDS::lookup("X509v3.KeyUsage")))
264  {
265  return dynamic_cast<Cert_Extension::Key_Usage&>(*ext).get_constraints();
266  }
267 
268  return NO_CONSTRAINTS;
269  }
const Extensions & extensions() const
Definition: pkcs10.cpp:253
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ create()

PKCS10_Request Botan::PKCS10_Request::create ( const Private_Key key,
const X509_DN subject_dn,
const Extensions extensions,
const std::string &  hash_fn,
RandomNumberGenerator rng,
const std::string &  padding_scheme = "",
const std::string &  challenge = "" 
)
static

Create a new PKCS10 certificate request

Parameters
keythe key that will be included in the certificate request
subject_dnthe DN to be placed in the request
extensionsextensions to include in the request
hash_fnthe hash function to use to create the signature
rnga random number generator
padding_schemeif set specifies the padding scheme, otherwise an algorithm-specific default is used.
challengea challenge string to be included in the PKCS10 request, sometimes used for revocation purposes.

Definition at line 58 of file pkcs10.cpp.

References Botan::X509_Object::choose_sig_format(), Botan::DIRECTORY_STRING, Botan::PEM_Code::encode(), Botan::DER_Encoder::encode(), Botan::DER_Encoder::end_cons(), Botan::DER_Encoder::end_explicit(), extensions(), Botan::DER_Encoder::get_contents(), Botan::X509_Object::make_signed(), PKCS10_Request(), Botan::DER_Encoder::raw_bytes(), Botan::SEQUENCE, Botan::DER_Encoder::start_cons(), subject_dn(), and Botan::Public_Key::subject_public_key().

Referenced by Botan::X509::create_cert_req().

65  {
66  const std::map<std::string,std::string> sig_opts = { {"padding", padding_scheme} };
67 
68  AlgorithmIdentifier sig_algo;
69  std::unique_ptr<PK_Signer> signer = choose_sig_format(sig_algo, key, rng, hash_fn, padding_scheme);
70 
71  const size_t PKCS10_VERSION = 0;
72 
73  DER_Encoder tbs_req;
74 
75  tbs_req.start_cons(SEQUENCE)
76  .encode(PKCS10_VERSION)
77  .encode(subject_dn)
78  .raw_bytes(key.subject_public_key())
79  .start_explicit(0);
80 
81  if(challenge.empty() == false)
82  {
83  ASN1_String challenge_str(challenge, DIRECTORY_STRING);
84 
85  tbs_req.encode(
86  Attribute("PKCS9.ChallengePassword",
87  DER_Encoder().encode(challenge_str).get_contents_unlocked()
88  )
89  );
90  }
91 
92  tbs_req.encode(
93  Attribute("PKCS9.ExtensionRequest",
94  DER_Encoder()
95  .start_cons(SEQUENCE)
97  .end_cons()
98  .get_contents_unlocked()
99  )
100  )
101  .end_explicit()
102  .end_cons();
103 
104  const std::vector<uint8_t> req =
105  X509_Object::make_signed(signer.get(), rng, sig_algo,
106  tbs_req.get_contents());
107 
108  return PKCS10_Request(req);
109  }
static std::vector< uint8_t > make_signed(class PK_Signer *signer, RandomNumberGenerator &rng, const AlgorithmIdentifier &alg_id, const secure_vector< uint8_t > &tbs)
Definition: x509_obj.cpp:270
const Extensions & extensions() const
Definition: pkcs10.cpp:253
static std::unique_ptr< PK_Signer > choose_sig_format(AlgorithmIdentifier &sig_algo, const Private_Key &key, RandomNumberGenerator &rng, const std::string &hash_fn, const std::string &padding_algo)
Definition: x509_obj.cpp:366
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43
const X509_DN & subject_dn() const
Definition: pkcs10.cpp:220
PKCS10_Request(DataSource &source)
Definition: pkcs10.cpp:38
CK_ATTRIBUTE Attribute
Definition: p11.h:845

◆ decode_from()

void Botan::X509_Object::decode_from ( class BER_Decoder from)
overridevirtualinherited

Decode a BER encoded X509_Object See ASN1_Object::decode_from()

Implements Botan::ASN1_Object.

Definition at line 107 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, and Botan::BER_Decoder::start_cons().

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

108  {
109  from.start_cons(SEQUENCE)
110  .start_cons(SEQUENCE)
111  .raw_bytes(m_tbs_bits)
112  .end_cons()
113  .decode(m_sig_algo)
114  .decode(m_sig, BIT_STRING)
115  .end_cons();
116 
117  force_decode();
118  }

◆ encode_into()

void Botan::X509_Object::encode_into ( class DER_Encoder to) const
overridevirtualinherited

DER encode an X509_Object See ASN1_Object::encode_into()

Implements Botan::ASN1_Object.

Definition at line 93 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, Botan::X509_Object::signature(), Botan::X509_Object::signature_algorithm(), Botan::X509_Object::signed_body(), and Botan::DER_Encoder::start_cons().

94  {
95  to.start_cons(SEQUENCE)
96  .start_cons(SEQUENCE)
97  .raw_bytes(signed_body())
98  .end_cons()
99  .encode(signature_algorithm())
100  .encode(signature(), BIT_STRING)
101  .end_cons();
102  }
const AlgorithmIdentifier & signature_algorithm() const
Definition: x509_obj.h:48
const std::vector< uint8_t > & signature() const
Definition: x509_obj.h:38
const std::vector< uint8_t > & signed_body() const
Definition: x509_obj.h:43

◆ ex_constraints()

std::vector< OID > Botan::PKCS10_Request::ex_constraints ( ) const

Get the extendend key constraints (if any).

Returns
extended key constraints

Definition at line 274 of file pkcs10.cpp.

References extensions(), Botan::Cert_Extension::Extended_Key_Usage::get_oids(), and Botan::OIDS::lookup().

275  {
276  if(auto ext = extensions().get(OIDS::lookup("X509v3.ExtendedKeyUsage")))
277  {
278  return dynamic_cast<Cert_Extension::Extended_Key_Usage&>(*ext).get_oids();
279  }
280 
281  return {};
282  }
const Extensions & extensions() const
Definition: pkcs10.cpp:253
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ extensions()

const Extensions & Botan::PKCS10_Request::extensions ( ) const

Get the X509v3 extensions.

Returns
X509v3 extensions

Definition at line 253 of file pkcs10.cpp.

Referenced by constraints(), create(), ex_constraints(), is_CA(), and path_limit().

254  {
255  return data().m_extensions;
256  }

◆ hash_used_for_signature()

std::string Botan::X509_Object::hash_used_for_signature ( ) const
inherited
Returns
hash algorithm that was used to generate signature

Definition at line 139 of file x509_obj.cpp.

References Botan::OID::as_string(), Botan::AlgorithmIdentifier::get_oid(), hash_algo, Botan::OIDS::lookup(), Botan::parse_algorithm_name(), Botan::X509_Object::signature_algorithm(), and Botan::split_on().

140  {
141  const OID& oid = m_sig_algo.get_oid();
142  const std::vector<std::string> sig_info = split_on(OIDS::lookup(oid), '/');
143 
144  if(sig_info.size() == 1 && sig_info[0] == "Ed25519")
145  return "SHA-512";
146  else if(sig_info.size() != 2)
147  throw Internal_Error("Invalid name format found for " + oid.as_string());
148 
149  if(sig_info[1] == "EMSA4")
150  {
151  return OIDS::lookup(decode_pss_params(signature_algorithm().get_parameters()).hash_algo.get_oid());
152  }
153  else
154  {
155  const std::vector<std::string> pad_and_hash =
156  parse_algorithm_name(sig_info[1]);
157 
158  if(pad_and_hash.size() != 2)
159  {
160  throw Internal_Error("Invalid name format " + sig_info[1]);
161  }
162 
163  return pad_and_hash[1];
164  }
165  }
const AlgorithmIdentifier & signature_algorithm() const
Definition: x509_obj.h:48
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:144
std::vector< std::string > parse_algorithm_name(const std::string &namex)
Definition: parsing.cpp:91
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23
const OID & get_oid() const
Definition: alg_id.h:37
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ is_CA()

bool Botan::PKCS10_Request::is_CA ( ) const

Find out whether this is a CA request.

Returns
true if it is a CA request, false otherwise.

Definition at line 287 of file pkcs10.cpp.

References extensions(), Botan::Cert_Extension::Basic_Constraints::get_is_ca(), and Botan::OIDS::lookup().

288  {
289  if(auto ext = extensions().get(OIDS::lookup("X509v3.BasicConstraints")))
290  {
291  return dynamic_cast<Cert_Extension::Basic_Constraints&>(*ext).get_is_ca();
292  }
293 
294  return false;
295  }
const Extensions & extensions() const
Definition: pkcs10.cpp:253
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ load_data()

void Botan::X509_Object::load_data ( DataSource src)
protectedinherited

Decodes from src as either DER or PEM data, then calls force_decode()

Definition at line 53 of file x509_obj.cpp.

References Botan::X509_Object::alternate_PEM_labels(), Botan::PEM_Code::decode(), Botan::X509_Object::decode_from(), Botan::PEM_Code::matches(), Botan::ASN1::maybe_BER(), Botan::X509_Object::PEM_label(), and Botan::Exception::what().

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

54  {
55  try {
56  if(ASN1::maybe_BER(in) && !PEM_Code::matches(in))
57  {
58  BER_Decoder dec(in);
59  decode_from(dec);
60  }
61  else
62  {
63  std::string got_label;
64  DataSource_Memory ber(PEM_Code::decode(in, got_label));
65 
66  if(got_label != PEM_label())
67  {
68  bool is_alternate = false;
69  for(std::string alt_label : alternate_PEM_labels())
70  {
71  if(got_label == alt_label)
72  {
73  is_alternate = true;
74  break;
75  }
76  }
77 
78  if(!is_alternate)
79  throw Decoding_Error("Unexpected PEM label for " + PEM_label() + " of " + got_label);
80  }
81 
82  BER_Decoder dec(ber);
83  decode_from(dec);
84  }
85  }
86  catch(Decoding_Error& e)
87  {
88  throw Decoding_Error(PEM_label() + " decoding failed: " + e.what());
89  }
90  }
virtual std::vector< std::string > alternate_PEM_labels() const
Definition: x509_obj.h:114
virtual std::string PEM_label() const =0
bool maybe_BER(DataSource &source)
Definition: asn1_obj.cpp:219
void decode_from(class BER_Decoder &from) override
Definition: x509_obj.cpp:107
bool matches(DataSource &source, const std::string &extra, size_t search_range)
Definition: pem.cpp:142
secure_vector< uint8_t > decode(DataSource &source, std::string &label)
Definition: pem.cpp:68

◆ make_signed()

std::vector< uint8_t > Botan::X509_Object::make_signed ( class PK_Signer signer,
RandomNumberGenerator rng,
const AlgorithmIdentifier alg_id,
const secure_vector< uint8_t > &  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 270 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, Botan::PK_Signer::sign_message(), Botan::X509_Object::signature(), and Botan::DER_Encoder::start_cons().

Referenced by create(), and Botan::X509_CA::make_cert().

274  {
275  const std::vector<uint8_t> signature = signer->sign_message(tbs_bits, rng);
276 
277  std::vector<uint8_t> output;
278  DER_Encoder(output)
279  .start_cons(SEQUENCE)
280  .raw_bytes(tbs_bits)
281  .encode(algo)
282  .encode(signature, BIT_STRING)
283  .end_cons();
284 
285  return output;
286  }
const std::vector< uint8_t > & signature() const
Definition: x509_obj.h:38

◆ path_limit()

size_t Botan::PKCS10_Request::path_limit ( ) const

Return the constraint on the path length defined in the BasicConstraints extension.

Returns
path limit

Definition at line 300 of file pkcs10.cpp.

References extensions(), Botan::Cert_Extension::Basic_Constraints::get_is_ca(), Botan::Cert_Extension::Basic_Constraints::get_path_limit(), and Botan::OIDS::lookup().

301  {
302  if(auto ext = extensions().get(OIDS::lookup("X509v3.BasicConstraints")))
303  {
304  Cert_Extension::Basic_Constraints& basic_constraints = dynamic_cast<Cert_Extension::Basic_Constraints&>(*ext);
305  if(basic_constraints.get_is_ca())
306  {
307  return basic_constraints.get_path_limit();
308  }
309  }
310 
311  return 0;
312  }
const Extensions & extensions() const
Definition: pkcs10.cpp:253
std::string lookup(const OID &oid)
Definition: oids.cpp:113

◆ PEM_encode()

std::string Botan::X509_Object::PEM_encode ( ) const
inherited
Returns
PEM encoding of this

Definition at line 123 of file x509_obj.cpp.

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

124  {
126  }
virtual std::string PEM_label() const =0
std::vector< uint8_t > BER_encode() const
Definition: asn1_obj.cpp:16
std::string encode(const uint8_t der[], size_t length, const std::string &label, size_t width)
Definition: pem.cpp:43

◆ raw_public_key()

const std::vector< uint8_t > & Botan::PKCS10_Request::raw_public_key ( ) const

Get the raw DER encoded public key.

Returns
raw DER encoded public key

Definition at line 228 of file pkcs10.cpp.

Referenced by Botan::X509_CA::sign_request(), and subject_public_key().

229  {
230  return data().m_public_key_bits;
231  }

◆ signature()

const std::vector<uint8_t>& Botan::X509_Object::signature ( ) const
inlineinherited

◆ signature_algorithm()

const AlgorithmIdentifier& Botan::X509_Object::signature_algorithm ( ) const
inlineinherited
Returns
signature algorithm that was used to generate signature

Definition at line 48 of file x509_obj.h.

Referenced by Botan::X509_Object::encode_into(), Botan::X509_Object::hash_used_for_signature(), Botan::X509_Certificate::operator==(), Botan::X509_Certificate::to_string(), Botan::X509_Object::verify_signature(), and Botan::X509_CA::X509_CA().

48 { return m_sig_algo; }

◆ signed_body()

const std::vector<uint8_t>& Botan::X509_Object::signed_body ( ) const
inlineinherited
Returns
signed body

Definition at line 43 of file x509_obj.h.

Referenced by Botan::X509_Object::encode_into(), Botan::X509_Certificate::operator<(), and Botan::X509_Certificate::operator==().

43 { return m_tbs_bits; }

◆ subject_alt_name()

const AlternativeName & Botan::PKCS10_Request::subject_alt_name ( ) const

Get the subject alternative name.

Returns
subject alternative name.

Definition at line 245 of file pkcs10.cpp.

246  {
247  return data().m_alt_name;
248  }

◆ subject_dn()

const X509_DN & Botan::PKCS10_Request::subject_dn ( ) const

Get the subject DN.

Returns
subject DN

Definition at line 220 of file pkcs10.cpp.

Referenced by create(), and Botan::X509_CA::sign_request().

221  {
222  return data().m_subject_dn;
223  }

◆ subject_public_key()

Public_Key * Botan::PKCS10_Request::subject_public_key ( ) const

Get the subject public key.

Returns
subject public key

Definition at line 236 of file pkcs10.cpp.

References Botan::X509::load_key(), and raw_public_key().

237  {
238  DataSource_Memory source(raw_public_key());
239  return X509::load_key(source);
240  }
const std::vector< uint8_t > & raw_public_key() const
Definition: pkcs10.cpp:228
Public_Key * load_key(DataSource &source)
Definition: x509_key.cpp:37

◆ tbs_data()

std::vector< uint8_t > 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 131 of file x509_obj.cpp.

References Botan::ASN1::put_in_sequence().

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

132  {
133  return ASN1::put_in_sequence(m_tbs_bits);
134  }
std::vector< uint8_t > put_in_sequence(const std::vector< uint8_t > &contents)
Definition: asn1_obj.cpp:192

◆ verify_signature()

Certificate_Status_Code Botan::X509_Object::verify_signature ( const Public_Key key) const
inherited

Check the signature on this data

Parameters
keythe public key purportedly used to sign this data
Returns
status of the signature - OK if verified or otherwise an indicator of the problem preventing verification.

Definition at line 184 of file x509_obj.cpp.

References Botan::Public_Key::algo_name(), Botan::DER_SEQUENCE, Botan::AlgorithmIdentifier::get_oid(), hash_algo, Botan::IEEE_1363, Botan::OIDS::lookup(), Botan::Public_Key::message_parts(), Botan::AlgorithmIdentifier::parameters, Botan::X509_Object::signature(), Botan::SIGNATURE_ALGO_BAD_PARAMS, Botan::SIGNATURE_ALGO_UNKNOWN, Botan::X509_Object::signature_algorithm(), Botan::SIGNATURE_ERROR, Botan::split_on(), Botan::X509_Object::tbs_data(), Botan::ASN1::to_string(), Botan::UNTRUSTED_HASH, Botan::VERIFIED, and Botan::PK_Verifier::verify_message().

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

185  {
186  const std::vector<std::string> sig_info =
187  split_on(OIDS::lookup(m_sig_algo.get_oid()), '/');
188 
189  if(sig_info.size() < 1 || sig_info.size() > 2 || sig_info[0] != pub_key.algo_name())
191 
192  std::string padding;
193  if(sig_info.size() == 2)
194  padding = sig_info[1];
195  else if(sig_info[0] == "Ed25519")
196  padding = "Pure";
197  else
199 
200  const Signature_Format format =
201  (pub_key.message_parts() >= 2) ? DER_SEQUENCE : IEEE_1363;
202 
203  if(padding == "EMSA4")
204  {
205  // "MUST contain RSASSA-PSS-params"
206  if(signature_algorithm().parameters.empty())
207  {
209  }
210 
211  Pss_params pss_parameter = decode_pss_params(signature_algorithm().parameters);
212 
213  // hash_algo must be SHA1, SHA2-224, SHA2-256, SHA2-384 or SHA2-512
214  const std::string hash_algo = OIDS::lookup(pss_parameter.hash_algo.oid);
215  if(hash_algo != "SHA-160" &&
216  hash_algo != "SHA-224" &&
217  hash_algo != "SHA-256" &&
218  hash_algo != "SHA-384" &&
219  hash_algo != "SHA-512")
220  {
222  }
223 
224  const std::string mgf_algo = OIDS::lookup(pss_parameter.mask_gen_algo.oid);
225  if(mgf_algo != "MGF1")
226  {
228  }
229 
230  // For MGF1, it is strongly RECOMMENDED that the underlying hash function be the same as the one identified by hashAlgorithm
231  // Must be SHA1, SHA2-224, SHA2-256, SHA2-384 or SHA2-512
232  if(pss_parameter.mask_gen_hash.oid != pss_parameter.hash_algo.oid)
233  {
235  }
236 
237  if(pss_parameter.trailer_field != 1)
238  {
240  }
241 
242  // salt_len is actually not used for verification. Length is inferred from the signature
243  padding += "(" + hash_algo + "," + mgf_algo + "," + std::to_string(pss_parameter.salt_len) + ")";
244  }
245 
246  try
247  {
248  PK_Verifier verifier(pub_key, padding, format);
249  const bool valid = verifier.verify_message(tbs_data(), signature());
250 
251  if(valid)
253  else
255  }
256  catch(Algorithm_Not_Found&)
257  {
259  }
260  catch(...)
261  {
262  // This shouldn't happen, fallback to generic signature error
264  }
265  }
const AlgorithmIdentifier & signature_algorithm() const
Definition: x509_obj.h:48
std::vector< uint8_t > parameters
Definition: alg_id.h:46
std::vector< std::string > split_on(const std::string &str, char delim)
Definition: parsing.cpp:144
Signature_Format
Definition: pubkey.h:27
std::string to_string(const BER_Object &obj)
Definition: asn1_obj.cpp:210
const std::vector< uint8_t > & signature() const
Definition: x509_obj.h:38
std::vector< uint8_t > tbs_data() const
Definition: x509_obj.cpp:131
AlgorithmIdentifier hash_algo
Definition: x509_obj.cpp:23
const OID & get_oid() const
Definition: alg_id.h:37
std::string lookup(const OID &oid)
Definition: oids.cpp:113

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