diff options
author | Simon Josefsson <simon@josefsson.org> | 2008-02-26 12:18:59 +0100 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2008-02-26 12:18:59 +0100 |
commit | 51c160b7d279f2b93b5318f23ce091fd42ef3230 (patch) | |
tree | 009acca8438645d659a042c4ad975f815f6ce7d8 /lib/gnutls_str.c | |
parent | cf78e90a0250b74256335781e2924064ebbb32a1 (diff) | |
download | gnutls-51c160b7d279f2b93b5318f23ce091fd42ef3230.tar.gz |
Move rfc2818.h hostname comparison to gnutls_str.h and update callers.
Diffstat (limited to 'lib/gnutls_str.c')
-rw-r--r-- | lib/gnutls_str.c | 45 |
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/gnutls_str.c b/lib/gnutls_str.c index 5bf13042c7..1002abfd96 100644 --- a/lib/gnutls_str.c +++ b/lib/gnutls_str.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2004, 2005, 2007 Free Software Foundation + * Copyright (C) 2002, 2004, 2005, 2007, 2008 Free Software Foundation * * Author: Nikos Mavrogiannopoulos * @@ -314,3 +314,46 @@ _gnutls_hex2bin (const opaque * hex_data, int hex_size, opaque * bin_data, return 0; } + + +/* compare hostname against certificate, taking account of wildcards + * return 1 on success or 0 on error + */ +int +_gnutls_hostname_compare (const char *certname, const char *hostname) +{ + const char *cmpstr1, *cmpstr2; + + if (strlen (certname) == 0 || strlen (hostname) == 0) + return 0; + + if (strlen (certname) > 2 && strncmp (certname, "*.", 2) == 0) + { + /* a wildcard certificate */ + + cmpstr1 = certname + 1; + + /* find the first dot in hostname, compare from there on */ + cmpstr2 = strchr (hostname, '.'); + + if (cmpstr2 == NULL) + { + /* error, the hostname we're connecting to is only a local part */ + return 0; + } + + if (strcasecmp (cmpstr1, cmpstr2) == 0) + { + return 1; + } + + return 0; + } + + if (strcasecmp (certname, hostname) == 0) + { + return 1; + } + + return 0; +} |