diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/asn1/asn1_alt_name.h | 47 | ||||
-rw-r--r-- | src/lib/x509/asn1_alt_name.cpp (renamed from src/lib/asn1/asn1_alt_name.cpp) | 39 | ||||
-rw-r--r-- | src/lib/x509/asn1_alt_name.h | 58 | ||||
-rw-r--r-- | src/lib/x509/ocsp.h | 1 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.cpp (renamed from src/lib/asn1/x509_dn.cpp) | 27 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.h (renamed from src/lib/asn1/x509_dn.h) | 22 |
6 files changed, 115 insertions, 79 deletions
diff --git a/src/lib/asn1/asn1_alt_name.h b/src/lib/asn1/asn1_alt_name.h deleted file mode 100644 index 9a9b759d7..000000000 --- a/src/lib/asn1/asn1_alt_name.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -* Common ASN.1 Objects -* (C) 1999-2007 Jack Lloyd -* 2007 Yves Jerschow -* -* Botan is released under the Simplified BSD License (see license.txt) -*/ - -#ifndef BOTAN_ASN1_ALT_NAME_H_ -#define BOTAN_ASN1_ALT_NAME_H_ - -#include <botan/asn1_obj.h> -#include <botan/asn1_str.h> -#include <botan/asn1_oid.h> -#include <map> - -namespace Botan { - -/** -* Alternative Name -*/ -class BOTAN_PUBLIC_API(2,0) AlternativeName final : public ASN1_Object - { - public: - void encode_into(class DER_Encoder&) const override; - void decode_from(class BER_Decoder&) override; - - std::multimap<std::string, std::string> contents() const; - - void add_attribute(const std::string&, const std::string&); - std::multimap<std::string, std::string> get_attributes() const; - - void add_othername(const OID&, const std::string&, ASN1_Tag); - std::multimap<OID, ASN1_String> get_othernames() const; - - bool has_items() const; - - AlternativeName(const std::string& = "", const std::string& = "", - const std::string& = "", const std::string& = ""); - private: - std::multimap<std::string, std::string> m_alt_info; - std::multimap<OID, ASN1_String> m_othernames; - }; - -} - -#endif diff --git a/src/lib/asn1/asn1_alt_name.cpp b/src/lib/x509/asn1_alt_name.cpp index 940312886..8b3d2d6e9 100644 --- a/src/lib/asn1/asn1_alt_name.cpp +++ b/src/lib/x509/asn1_alt_name.cpp @@ -52,17 +52,17 @@ AlternativeName::AlternativeName(const std::string& email_addr, * Add an attribute to an alternative name */ void AlternativeName::add_attribute(const std::string& type, - const std::string& str) + const std::string& value) { - if(type.empty() || str.empty()) + if(type.empty() || value.empty()) return; auto range = m_alt_info.equal_range(type); for(auto j = range.first; j != range.second; ++j) - if(j->second == str) + if(j->second == value) return; - multimap_insert(m_alt_info, type, str); + multimap_insert(m_alt_info, type, value); } /* @@ -77,22 +77,6 @@ void AlternativeName::add_othername(const OID& oid, const std::string& value, } /* -* Get the attributes of this alternative name -*/ -std::multimap<std::string, std::string> AlternativeName::get_attributes() const - { - return m_alt_info; - } - -/* -* Get the otherNames -*/ -std::multimap<OID, ASN1_String> AlternativeName::get_othernames() const - { - return m_othernames; - } - -/* * Return all of the alternative names */ std::multimap<std::string, std::string> AlternativeName::contents() const @@ -108,6 +92,21 @@ std::multimap<std::string, std::string> AlternativeName::contents() const return names; } +bool AlternativeName::has_field(const std::string& attr) const + { + auto range = m_alt_info.equal_range(attr); + return (range.first != range.second); + } + +std::vector<std::string> AlternativeName::get_attribute(const std::string& attr) const + { + std::vector<std::string> results; + auto range = m_alt_info.equal_range(attr); + for(auto i = range.first; i != range.second; ++i) + results.push_back(i->second); + return results; + } + /* * Return if this object has anything useful */ diff --git a/src/lib/x509/asn1_alt_name.h b/src/lib/x509/asn1_alt_name.h new file mode 100644 index 000000000..81f933ea0 --- /dev/null +++ b/src/lib/x509/asn1_alt_name.h @@ -0,0 +1,58 @@ +/* +* (C) 1999-2007 Jack Lloyd +* 2007 Yves Jerschow +* +* Botan is released under the Simplified BSD License (see license.txt) +*/ + +#ifndef BOTAN_X509_ALT_NAME_H_ +#define BOTAN_X509_ALT_NAME_H_ + +#include <botan/asn1_obj.h> +#include <botan/asn1_str.h> +#include <botan/asn1_oid.h> +#include <map> + +namespace Botan { + +/** +* Alternative Name +*/ +class BOTAN_PUBLIC_API(2,0) AlternativeName final : public ASN1_Object + { + public: + void encode_into(class DER_Encoder&) const override; + void decode_from(class BER_Decoder&) override; + + std::multimap<std::string, std::string> contents() const; + + bool has_field(const std::string& attr) const; + std::vector<std::string> get_attribute(const std::string& attr) const; + + void add_attribute(const std::string& type, const std::string& value); + void add_othername(const OID& oid, const std::string& value, ASN1_Tag type); + + const std::multimap<std::string, std::string>& get_attributes() const + { + return m_alt_info; + } + + const std::multimap<OID, ASN1_String>& get_othernames() const + { + return m_othernames; + } + + bool has_items() const; + + AlternativeName(const std::string& email_addr = "", + const std::string& uri = "", + const std::string& dns = "", + const std::string& ip_address = ""); + private: + std::multimap<std::string, std::string> m_alt_info; + std::multimap<OID, ASN1_String> m_othernames; + }; + +} + +#endif diff --git a/src/lib/x509/ocsp.h b/src/lib/x509/ocsp.h index 254de5038..33177dc59 100644 --- a/src/lib/x509/ocsp.h +++ b/src/lib/x509/ocsp.h @@ -10,6 +10,7 @@ #include <botan/cert_status.h> #include <botan/ocsp_types.h> +#include <botan/x509_dn.h> namespace Botan { diff --git a/src/lib/asn1/x509_dn.cpp b/src/lib/x509/x509_dn.cpp index dd92b25ec..ce1300e53 100644 --- a/src/lib/asn1/x509_dn.cpp +++ b/src/lib/x509/x509_dn.cpp @@ -83,6 +83,25 @@ std::multimap<std::string, std::string> X509_DN::contents() const return retval; } +bool X509_DN::has_field(const std::string& attr) const + { + const OID oid = OIDS::lookup(deref_info_field(attr)); + auto range = m_dn_info.equal_range(oid); + return (range.first != range.second); + } + +std::string X509_DN::get_first_attribute(const std::string& attr) const + { + const OID oid = OIDS::lookup(deref_info_field(attr)); + + auto range = m_dn_info.equal_range(oid); + + if(range.first != m_dn_info.end()) + return range.first->second.value(); + + return ""; + } + /* * Get a single attribute type */ @@ -98,10 +117,7 @@ std::vector<std::string> X509_DN::get_attribute(const std::string& attr) const return values; } -/* -* Return the BER encoded data, if any -*/ -std::vector<uint8_t> X509_DN::get_bits() const +const std::vector<uint8_t>& X509_DN::get_bits() const { return m_dn_bits; } @@ -278,6 +294,9 @@ std::string to_short_form(const std::string& long_id) if(long_id == "X520.CommonName") return "CN"; + if(long_id == "X520.Country") + return "C"; + if(long_id == "X520.Organization") return "O"; diff --git a/src/lib/asn1/x509_dn.h b/src/lib/x509/x509_dn.h index 09f8cf16b..cbd89de7c 100644 --- a/src/lib/asn1/x509_dn.h +++ b/src/lib/x509/x509_dn.h @@ -25,23 +25,29 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object void encode_into(class DER_Encoder&) const override; void decode_from(class BER_Decoder&) override; - std::multimap<OID, std::string> get_attributes() const; - std::vector<std::string> get_attribute(const std::string&) const; + bool has_field(const std::string& attr) const; + std::vector<std::string> get_attribute(const std::string& attr) const; + + std::string get_first_attribute(const std::string& attr) const; + std::multimap<OID, std::string> get_attributes() const; std::multimap<std::string, std::string> contents() const; - void add_attribute(const std::string&, const std::string&); - void add_attribute(const OID&, const std::string&); + void add_attribute(const std::string& key, const std::string& val); + void add_attribute(const OID& oid, const std::string& val); - static std::string deref_info_field(const std::string&); + static std::string deref_info_field(const std::string& key); - std::vector<uint8_t> get_bits() const; + /* + * Return the BER encoded data, if any + */ + const std::vector<uint8_t>& get_bits() const; bool empty() const { return m_dn_info.empty(); } X509_DN() = default; - explicit X509_DN(const std::multimap<OID, std::string>&); - explicit X509_DN(const std::multimap<std::string, std::string>&); + explicit X509_DN(const std::multimap<OID, std::string>& vals); + explicit X509_DN(const std::multimap<std::string, std::string>& vals); private: std::multimap<OID, ASN1_String> m_dn_info; std::vector<uint8_t> m_dn_bits; |