Skip to content

Commit

Permalink
Merge e616857 into 7606d70
Browse files Browse the repository at this point in the history
  • Loading branch information
randombit committed May 10, 2024
2 parents 7606d70 + e616857 commit 5172451
Show file tree
Hide file tree
Showing 7 changed files with 272 additions and 193 deletions.
16 changes: 7 additions & 9 deletions src/lib/x509/alt_name.cpp
Expand Up @@ -27,7 +27,7 @@ void AlternativeName::add_email(std::string_view addr) {

void AlternativeName::add_dns(std::string_view dns) {
if(!dns.empty()) {
m_dns.insert(std::string(dns));
m_dns.insert(tolower_string(dns));
}
}

Expand All @@ -39,10 +39,8 @@ void AlternativeName::add_dn(const X509_DN& dn) {
m_dn_names.insert(dn);
}

void AlternativeName::add_ip_address(std::string_view ip) {
if(!ip.empty()) {
m_ip_addr.insert(std::string(ip));
}
void AlternativeName::add_ipv4_address(uint32_t ip) {
m_ipv4_addr.insert(ip);
}

bool AlternativeName::has_items() const {
Expand All @@ -55,7 +53,7 @@ bool AlternativeName::has_items() const {
if(!this->email().empty()) {
return true;
}
if(!this->ip_address().empty()) {
if(!this->ipv4_address().empty()) {
return true;
}
if(!this->directory_names().empty()) {
Expand Down Expand Up @@ -111,8 +109,8 @@ void AlternativeName::encode_into(DER_Encoder& der) const {
der.add_object(ASN1_Type(6), ASN1_Class::ContextSpecific, str.value());
}

for(const auto& ip : m_ip_addr) {
auto ip_buf = store_be(string_to_ipv4(ip));
for(uint32_t ip : m_ipv4_addr) {
auto ip_buf = store_be(ip);
der.add_object(ASN1_Type(7), ASN1_Class::ContextSpecific, ip_buf.data(), 4);
}

Expand Down Expand Up @@ -161,7 +159,7 @@ void AlternativeName::decode_from(BER_Decoder& source) {
} else if(obj.is_a(7, ASN1_Class::ContextSpecific)) {
if(obj.length() == 4) {
const uint32_t ip = load_be<uint32_t>(obj.bits(), 0);
this->add_ip_address(ipv4_to_string(ip));
this->add_ipv4_address(ip);
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/lib/x509/asn1_alt_name.cpp
Expand Up @@ -9,6 +9,7 @@
#include <botan/pkix_types.h>

#include <botan/internal/fmt.h>
#include <botan/internal/parsing.h>
#include <sstream>

namespace Botan {
Expand All @@ -30,7 +31,7 @@ AlternativeName::AlternativeName(std::string_view email_addr,
add_uri(uri);
}
if(!ip.empty()) {
add_ip_address(ip);
add_ipv4_address(string_to_ipv4(ip));
}
}

Expand All @@ -54,7 +55,7 @@ void AlternativeName::add_attribute(std::string_view type, std::string_view valu
ss >> dn;
this->add_dn(dn);
} else if(type == "IP") {
this->add_ip_address(value);
this->add_ipv4_address(string_to_ipv4(value));
} else {
throw Not_Implemented(fmt("Unknown AlternativeName name type {}", type));
}
Expand Down Expand Up @@ -88,8 +89,8 @@ std::multimap<std::string, std::string> AlternativeName::contents() const {
names.emplace("URI", nm);
}

for(const auto& nm : this->ip_address()) {
names.emplace("IP", nm);
for(uint32_t ipv4 : this->ipv4_address()) {
names.emplace("IP", ipv4_to_string(ipv4));
}

for(const auto& nm : this->directory_names()) {
Expand Down Expand Up @@ -145,7 +146,11 @@ std::vector<std::string> AlternativeName::get_attribute(std::string_view attr) c

return ret;
} else if(attr == "IP") {
return set_to_vector(this->ip_address());
std::vector<std::string> ip_str;
for(uint32_t ipv4 : this->ipv4_address()) {
ip_str.push_back(ipv4_to_string(ipv4));
}
return ip_str;
} else {
return {};
}
Expand Down

0 comments on commit 5172451

Please sign in to comment.