diff options
author | Jack Lloyd <[email protected]> | 2015-10-26 11:24:33 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2015-10-26 11:24:33 -0400 |
commit | b877cf604e0059b2e2db83c69f696d8bf35631d9 (patch) | |
tree | fd0337a52f98b99f949cc7bfb15c0fcd83b14863 /src/lib/utils | |
parent | 72c9080ba4d5da0c0f15c850be79431c4fe8639f (diff) | |
parent | f0967b61945326de6244801f5b1276ac36d7a30e (diff) |
Merge pull request #313 from randombit/path-validation-fixes
Fix cert validation bugs found by 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); + } |