/* match the DNS name pattern from the peer certificate against our configured peer hostname */ static bool match_dns_pattern( const char *hostname, const char *pattern, int plen ) { int slen = (int) strlen(hostname); if (memchr( pattern, '*', plen ) == NULL) return (plen == slen && pn_strncasecmp( pattern, hostname, plen ) == 0); /* dns wildcarded pattern - RFC2818 */ char plabel[64]; /* max label length < 63 - RFC1034 */ char slabel[64]; while (plen > 0 && slen > 0) { const char *cptr; int len; cptr = (const char *) memchr( pattern, '.', plen ); len = (cptr) ? cptr - pattern : plen; if (len > (int) sizeof(plabel) - 1) return false; memcpy( plabel, pattern, len ); plabel[len] = 0; if (cptr) ++len; // skip matching '.' pattern += len; plen -= len; cptr = (const char *) memchr( hostname, '.', slen ); len = (cptr) ? cptr - hostname : slen; if (len > (int) sizeof(slabel) - 1) return false; memcpy( slabel, hostname, len ); slabel[len] = 0; if (cptr) ++len; // skip matching '.' hostname += len; slen -= len; char *star = strchr( plabel, '*' ); if (!star) { if (pn_strcasecmp( plabel, slabel )) return false; } else { *star = '\0'; char *prefix = plabel; int prefix_len = strlen(prefix); char *suffix = star + 1; int suffix_len = strlen(suffix); if (prefix_len && pn_strncasecmp( prefix, slabel, prefix_len )) return false; if (suffix_len && pn_strncasecmp( suffix, slabel + (strlen(slabel) - suffix_len), suffix_len )) return false; } } return plen == slen; }
// Look for symbol in the mech include list - not particlarly efficient, // but probably not used enough to matter. // // Note that if there is no inclusion list then every mech is implicitly included. bool pni_included_mech(const char *included_mech_list, pn_bytes_t s) { if (!included_mech_list) return true; const char * end_list = included_mech_list+strlen(included_mech_list); size_t len = s.size; const char *c = included_mech_list; while (c!=NULL) { // If there are not enough chars left in the list no matches if ((ptrdiff_t)len > end_list-c) return false; // Is word equal with a space or end of string afterwards? if (pn_strncasecmp(c, s.start, len)==0 && (c[len]==' ' || c[len]==0) ) return true; c = strchr(c, ' '); c = c ? c+1 : NULL; } return false; }