diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/asn1/asn1_obj.cpp | 3 | ||||
-rw-r--r-- | src/lib/asn1/asn1_oid.h | 2 | ||||
-rw-r--r-- | src/lib/asn1/oids.cpp | 2 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.cpp | 57 | ||||
-rw-r--r-- | src/lib/x509/x509_dn.h | 11 |
5 files changed, 62 insertions, 13 deletions
diff --git a/src/lib/asn1/asn1_obj.cpp b/src/lib/asn1/asn1_obj.cpp index 815bc4ef8..824355264 100644 --- a/src/lib/asn1/asn1_obj.cpp +++ b/src/lib/asn1/asn1_obj.cpp @@ -136,6 +136,9 @@ std::string asn1_tag_to_string(ASN1_Tag type) case Botan::BMP_STRING: return "BMP STRING"; + case Botan::UNIVERSAL_STRING: + return "UNIVERSAL STRING"; + case Botan::UTC_TIME: return "UTC TIME"; diff --git a/src/lib/asn1/asn1_oid.h b/src/lib/asn1/asn1_oid.h index f3ff36ce2..1c8959d99 100644 --- a/src/lib/asn1/asn1_oid.h +++ b/src/lib/asn1/asn1_oid.h @@ -78,7 +78,7 @@ class BOTAN_PUBLIC_API(2,0) OID final : public ASN1_Object * Construct an OID from a string. * @param str a string in the form "a.b.c" etc., where a,b,c are numbers */ - OID(const std::string& str = ""); + explicit OID(const std::string& str = ""); explicit OID(std::initializer_list<uint32_t> init) : m_id(init) {} private: diff --git a/src/lib/asn1/oids.cpp b/src/lib/asn1/oids.cpp index 80f079395..844cdff79 100644 --- a/src/lib/asn1/oids.cpp +++ b/src/lib/asn1/oids.cpp @@ -28,7 +28,7 @@ class OID_Map final lock_guard_type<mutex_type> lock(m_mutex); auto i = m_str2oid.find(str); if(i == m_str2oid.end()) - m_str2oid.insert(std::make_pair(str, oid.to_string())); + m_str2oid.insert(std::make_pair(str, oid)); } void add_oid2str(const OID& oid, const std::string& str) diff --git a/src/lib/x509/x509_dn.cpp b/src/lib/x509/x509_dn.cpp index 106190011..6e2707673 100644 --- a/src/lib/x509/x509_dn.cpp +++ b/src/lib/x509/x509_dn.cpp @@ -184,16 +184,54 @@ 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; + // If they are not the same size, choose the smaller as the "lessor" + if(attr1.size() < attr2.size()) + return true; + if(attr1.size() > attr2.size()) + return false; - for(auto p1 = attr1.begin(); p1 != attr1.end(); ++p1) + // We know they are the same # of elements, now compare the OIDs: + auto p1 = attr1.begin(); + auto p2 = attr2.begin(); + + while(p1 != attr1.end() && p2 != attr2.end()) { - 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; + if(p1->first != p2->first) + { + return (p1->first < p2->first); + } + + ++p1; + ++p2; } + + // We know this is true because maps have the same size + BOTAN_ASSERT_NOMSG(p1 == attr1.end()); + BOTAN_ASSERT_NOMSG(p2 == attr2.end()); + + // Now we know all elements have the same OIDs, compare + // their string values: + + p1 = attr1.begin(); + p2 = attr2.begin(); + while(p1 != attr1.end() && p2 != attr2.end()) + { + BOTAN_DEBUG_ASSERT(p1->first == p2->first); + + // They may be binary different but same by X.500 rules, check this + if(!x500_name_cmp(p1->second, p2->second)) + { + // If they are not (by X.500) the same string, pick the + // lexicographic first as the lessor + return (p1->second < p2->second); + } + + ++p1; + ++p2; + } + + // if we reach here, then the DNs should be identical + BOTAN_DEBUG_ASSERT(dn1 == dn2); return false; } @@ -250,7 +288,10 @@ void X509_DN::decode_from(BER_Decoder& source) OID oid; ASN1_String str; - rdn.start_cons(SEQUENCE).decode(oid).decode(str).end_cons(); + rdn.start_cons(SEQUENCE) + .decode(oid) + .decode(str) // TODO support Any + .end_cons().verify_end("Invalid X509_DN, data follows RDN"); add_attribute(oid, str); } diff --git a/src/lib/x509/x509_dn.h b/src/lib/x509/x509_dn.h index f47099c9a..db608ff26 100644 --- a/src/lib/x509/x509_dn.h +++ b/src/lib/x509/x509_dn.h @@ -87,9 +87,14 @@ class BOTAN_PUBLIC_API(2,0) X509_DN final : public ASN1_Object std::vector<uint8_t> m_dn_bits; }; -bool BOTAN_PUBLIC_API(2,0) operator==(const X509_DN&, const X509_DN&); -bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_DN&, const X509_DN&); -bool BOTAN_PUBLIC_API(2,0) operator<(const X509_DN&, const X509_DN&); +bool BOTAN_PUBLIC_API(2,0) operator==(const X509_DN& dn1, const X509_DN& dn2); +bool BOTAN_PUBLIC_API(2,0) operator!=(const X509_DN& dn1, const X509_DN& dn2); + +/* +The ordering here is arbitrary and may change from release to release. +It is intended for allowing DNs as keys in std::map and similiar containers +*/ +bool BOTAN_PUBLIC_API(2,0) operator<(const X509_DN& dn1, const X509_DN& dn2); BOTAN_PUBLIC_API(2,0) std::ostream& operator<<(std::ostream& out, const X509_DN& dn); BOTAN_PUBLIC_API(2,0) std::istream& operator>>(std::istream& in, X509_DN& dn); |