diff options
author | Jack Lloyd <[email protected]> | 2015-10-23 15:32:15 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-10-23 15:32:15 -0400 |
commit | 3e44cbed78eb528daa38f9837d67aa0471ee7bd2 (patch) | |
tree | 01539aa0dd511db79e6d218394ea3fd51db94756 /src/lib/utils | |
parent | 69a5a56b38a309241126641149471a36137507a0 (diff) |
Fix cert validation bugs found by x509test.
Add test suite with certs from x509test
Diffstat (limited to 'src/lib/utils')
-rw-r--r-- | src/lib/utils/parsing.cpp | 23 | ||||
-rw-r--r-- | src/lib/utils/parsing.h | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp index ea89c8e5f..40eae656a 100644 --- a/src/lib/utils/parsing.cpp +++ b/src/lib/utils/parsing.cpp @@ -1,6 +1,6 @@ /* * Various string utils and parsing functions -* (C) 1999-2007,2013,2014 Jack Lloyd +* (C) 1999-2007,2013,2014,2015 Jack Lloyd * (C) 2015 Simon Warta (Kullo GmbH) * * Botan is released under the Simplified BSD License (see license.txt) @@ -333,4 +333,25 @@ std::string replace_char(const std::string& str, char from_char, char to_char) return out; } +bool host_wildcard_match(const std::string& issued, const std::string& host) + { + if(issued == host) + return true; + + if(issued.size() > 2 && issued[0] == '*' && issued[1] == '.') + { + size_t host_i = host.find('.'); + if(host_i == std::string::npos || host_i == host.size() - 1) + return false; + + const std::string host_base = host.substr(host_i + 1); + const std::string issued_base = issued.substr(2); + + if(host_base == issued_base) + return true; + } + + return false; + } + } diff --git a/src/lib/utils/parsing.h b/src/lib/utils/parsing.h index 25416d43a..db8db198e 100644 --- a/src/lib/utils/parsing.h +++ b/src/lib/utils/parsing.h @@ -128,6 +128,8 @@ std::map<std::string, std::string> BOTAN_DLL read_cfg(std::istream& is); std::string BOTAN_DLL clean_ws(const std::string& s); +bool BOTAN_DLL host_wildcard_match(const std::string& wildcard, const std::string& host); + } |