/* * Compare two X509_DNs for equality */ bool operator==(const X509_DN& dn1, const X509_DN& dn2) { typedef std::multimap<OID, std::string>::const_iterator rdn_iter; std::multimap<OID, std::string> attr1 = dn1.get_attributes(); std::multimap<OID, std::string> attr2 = dn2.get_attributes(); if(attr1.size() != attr2.size()) return false; rdn_iter p1 = attr1.begin(); rdn_iter p2 = attr2.begin(); while(true) { if(p1 == attr1.end() && p2 == attr2.end()) break; if(p1 == attr1.end()) return false; if(p2 == attr2.end()) return false; if(p1->first != p2->first) return false; if(!x500_name_cmp(p1->second, p2->second)) return false; ++p1; ++p2; } return true; }
/* * Induce an arbitrary ordering on DNs */ bool operator<(const X509_DN& dn1, const X509_DN& dn2) { auto attr1 = dn1.get_attributes(); auto attr2 = dn2.get_attributes(); if(attr1.size() < attr2.size()) return true; if(attr1.size() > attr2.size()) return false; for(auto p1 = attr1.begin(); p1 != attr1.end(); ++p1) { auto p2 = attr2.find(p1->first); if(p2 == attr2.end()) return false; if(p1->second > p2->second) return false; if(p1->second < p2->second) return true; } return false; }
std::vector<X509_DN> Certificate_Store_In_SQL::all_subjects() const { std::vector<X509_DN> ret; auto stmt = m_database->new_statement("SELECT subject_dn FROM " + m_prefix + "certificates"); while(stmt->step()) { auto blob = stmt->get_blob(0); BER_Decoder dec(blob.first,blob.second); X509_DN dn; dn.decode_from(dec); ret.push_back(dn); } return ret; }
/* * Compare two X509_DNs */ bool operator<(const X509_DN& dn1, const X509_DN& dn2) { typedef std::multimap<OID, std::string>::const_iterator rdn_iter; std::multimap<OID, std::string> attr1 = dn1.get_attributes(); std::multimap<OID, std::string> attr2 = dn2.get_attributes(); if(attr1.size() < attr2.size()) return true; if(attr1.size() > attr2.size()) return false; for(rdn_iter p1 = attr1.begin(); p1 != attr1.end(); ++p1) { std::multimap<OID, std::string>::const_iterator p2; p2 = attr2.find(p1->first); if(p2 == attr2.end()) return false; if(p1->second > p2->second) return false; if(p1->second < p2->second) return true; } return false; }
/* * Compare two X509_DNs for equality */ bool operator==(const X509_DN& dn1, const X509_DN& dn2) { auto attr1 = dn1.get_attributes(); auto attr2 = dn2.get_attributes(); if(attr1.size() != attr2.size()) return false; auto p1 = attr1.begin(); auto p2 = attr2.begin(); while(true) { if(p1 == attr1.end() && p2 == attr2.end()) break; if(p1 == attr1.end()) return false; if(p2 == attr2.end()) return false; if(p1->first != p2->first) return false; if(!x500_name_cmp(p1->second, p2->second)) return false; ++p1; ++p2; } return true; }
void GeneralName::decode_from(class BER_Decoder& ber) { BER_Object obj = ber.get_next_object(); if((obj.class_tag != CONTEXT_SPECIFIC) && (obj.class_tag != (CONTEXT_SPECIFIC | CONSTRUCTED))) throw Decoding_Error("Invalid class tag while decoding GeneralName"); const ASN1_Tag tag = obj.type_tag; if(tag == 1 || tag == 2 || tag == 6) { m_name = Charset::transcode(ASN1::to_string(obj),LATIN1_CHARSET,LOCAL_CHARSET); if(tag == 1) { m_type = "RFC822"; } else if(tag == 2) { m_type = "DNS"; } else if(tag == 6) { m_type = "URI"; } } else if(tag == 4) { X509_DN dn; std::multimap<std::string, std::string> nam; BER_Decoder dec(obj.value); std::stringstream ss; dn.decode_from(dec); ss << dn; m_name = ss.str(); m_type = "DN"; } else if(tag == 7) { if(obj.value.size() == 8) { const std::vector<byte> ip(obj.value.begin(),obj.value.begin() + 4); const std::vector<byte> net(obj.value.begin() + 4,obj.value.end()); m_type = "IP"; m_name = ipv4_to_string(load_be<u32bit>(ip.data(),0)) + "/" + ipv4_to_string(load_be<u32bit>(net.data(),0)); } else if(obj.value.size() == 32) { throw Decoding_Error("Unsupported IPv6 name constraint"); } else { throw Decoding_Error("Invalid IP name constraint size " + std::to_string(obj.value.size())); } } else { throw Decoding_Error("Found unknown GeneralName type"); } }