Update hostname validating function

Taken from https://bitbucket.org/brandon/backports.ssl_match_hostname/