Botan  2.4.0
Crypto and TLS for C++11
Public Member Functions | Static Public Member Functions | List of all members
Botan::Cert_Extension::Name_Constraints Class Referencefinal

#include <x509_ext.h>

Inheritance diagram for Botan::Cert_Extension::Name_Constraints:
Botan::Certificate_Extension

Public Member Functions

Name_Constraintscopy () const override
 
const NameConstraintsget_name_constraints () const
 
 Name_Constraints ()=default
 
 Name_Constraints (const NameConstraints &nc)
 
OID oid_of () const override
 
void validate (const X509_Certificate &subject, const X509_Certificate &issuer, const std::vector< std::shared_ptr< const X509_Certificate >> &cert_path, std::vector< std::set< Certificate_Status_Code >> &cert_status, size_t pos) override
 

Static Public Member Functions

static OID static_oid ()
 

Detailed Description

Name Constraints

Definition at line 480 of file x509_ext.h.

Constructor & Destructor Documentation

◆ Name_Constraints() [1/2]

Botan::Cert_Extension::Name_Constraints::Name_Constraints ( )
default

◆ Name_Constraints() [2/2]

Botan::Cert_Extension::Name_Constraints::Name_Constraints ( const NameConstraints nc)
inline

Definition at line 487 of file x509_ext.h.

487 : m_name_constraints(nc) {}

Member Function Documentation

◆ copy()

Name_Constraints* Botan::Cert_Extension::Name_Constraints::copy ( ) const
inlineoverridevirtual

Make a copy of this extension

Returns
copy of this

Implements Botan::Certificate_Extension.

Definition at line 483 of file x509_ext.h.

484  { return new Name_Constraints(m_name_constraints); }

◆ get_name_constraints()

const NameConstraints& Botan::Cert_Extension::Name_Constraints::get_name_constraints ( ) const
inline

Definition at line 494 of file x509_ext.h.

494 { return m_name_constraints; }

◆ oid_of()

OID Botan::Cert_Extension::Name_Constraints::oid_of ( ) const
inlineoverridevirtual
Returns
OID representing this extension

Implements Botan::Certificate_Extension.

Definition at line 497 of file x509_ext.h.

497 { return static_oid(); }

◆ static_oid()

static OID Botan::Cert_Extension::Name_Constraints::static_oid ( )
inlinestatic

Definition at line 496 of file x509_ext.h.

496 { return OID("2.5.29.30"); }

◆ validate()

void Botan::Cert_Extension::Name_Constraints::validate ( const X509_Certificate subject,
const X509_Certificate issuer,
const std::vector< std::shared_ptr< const X509_Certificate >> &  cert_path,
std::vector< std::set< Certificate_Status_Code >> &  cert_status,
size_t  pos 
)
overridevirtual

Reimplemented from Botan::Certificate_Extension.

Definition at line 593 of file x509_ext.cpp.

References Botan::X509_Certificate::is_CA_cert(), Botan::X509_Certificate::is_critical(), and Botan::NAME_CONSTRAINT_ERROR.

597  {
598  if(!m_name_constraints.permitted().empty() || !m_name_constraints.excluded().empty())
599  {
600  if(!subject.is_CA_cert() || !subject.is_critical("X509v3.NameConstraints"))
601  cert_status.at(pos).insert(Certificate_Status_Code::NAME_CONSTRAINT_ERROR);
602 
603  const bool issuer_name_constraint_critical =
604  issuer.is_critical("X509v3.NameConstraints");
605 
606  const bool at_self_signed_root = (pos == cert_path.size() - 1);
607 
608  // Check that all subordinate certs pass the name constraint
609  for(size_t j = 0; j <= pos; ++j)
610  {
611  if(pos == j && at_self_signed_root)
612  continue;
613 
614  bool permitted = m_name_constraints.permitted().empty();
615  bool failed = false;
616 
617  for(auto c: m_name_constraints.permitted())
618  {
619  switch(c.base().matches(*cert_path.at(j)))
620  {
621  case GeneralName::MatchResult::NotFound:
622  case GeneralName::MatchResult::All:
623  permitted = true;
624  break;
625  case GeneralName::MatchResult::UnknownType:
626  failed = issuer_name_constraint_critical;
627  permitted = true;
628  break;
629  default:
630  break;
631  }
632  }
633 
634  for(auto c: m_name_constraints.excluded())
635  {
636  switch(c.base().matches(*cert_path.at(j)))
637  {
638  case GeneralName::MatchResult::All:
639  case GeneralName::MatchResult::Some:
640  failed = true;
641  break;
642  case GeneralName::MatchResult::UnknownType:
643  failed = issuer_name_constraint_critical;
644  break;
645  default:
646  break;
647  }
648  }
649 
650  if(failed || !permitted)
651  {
652  cert_status.at(j).insert(Certificate_Status_Code::NAME_CONSTRAINT_ERROR);
653  }
654  }
655  }
656  }
const std::vector< GeneralSubtree > & excluded() const
const std::vector< GeneralSubtree > & permitted() const

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