Skip to content

Commit

Permalink
add explicit option for SubjectAltName:DNS check
Browse files Browse the repository at this point in the history
Patch by Ralf Paffrath
  • Loading branch information
Ralf Paffrath authored and Fabian Mauchle committed May 24, 2019
1 parent c0e313d commit 0784703
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
1 change: 1 addition & 0 deletions radsecproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ struct clsrvconf {
char *matchcertattr;
regex_t *certcnregex;
regex_t *certuriregex;
regex_t *certdnsregex;
char *confrewritein;
char *confrewriteout;
char *confrewriteusername;
Expand Down
42 changes: 27 additions & 15 deletions tlscommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ int verifyconfcert(X509 *cert, struct clsrvconf *conf) {
ok = 0;
}
}
if (conf->certdnsregex) {
debug(DBG_DBG, "verifyconfcert: matching subjectaltname DNS regex %s", conf->matchcertattr);
if (subjectaltnameregexp(cert, GEN_DNS, NULL, conf->certdnsregex) < 1) {
debug(DBG_WARN, "verifyconfcert: subjectaltname DNS not matching regex for host %s (%s)", conf->name, subject);
ok = 0;
}
}
free(subject);
return ok;
}
Expand Down Expand Up @@ -815,31 +822,36 @@ int addmatchcertattr(struct clsrvconf *conf) {
regex_t **r;

if (!strncasecmp(conf->matchcertattr, "CN:/", 4)) {
r = &conf->certcnregex;
v = conf->matchcertattr + 4;
r = &conf->certcnregex;
v = conf->matchcertattr + 4;
} else if (!strncasecmp(conf->matchcertattr, "SubjectAltName:URI:/", 20)) {
r = &conf->certuriregex;
v = conf->matchcertattr + 20;
} else
return 0;
r = &conf->certuriregex;
v = conf->matchcertattr + 20;
} else if (!strncasecmp(conf->matchcertattr, "SubjectAltName:DNS:/", 20)) {
r = &conf->certdnsregex;
v = conf->matchcertattr + 20;
}
else
return 0;

if (!*v)
return 0;
return 0;
/* regexp, remove optional trailing / if present */
if (v[strlen(v) - 1] == '/')
v[strlen(v) - 1] = '\0';
v[strlen(v) - 1] = '\0';
if (!*v)
return 0;
return 0;

*r = malloc(sizeof(regex_t));
if (!*r) {
debug(DBG_ERR, "malloc failed");
return 0;
debug(DBG_ERR, "malloc failed");
return 0;
}
if (regcomp(*r, v, REG_EXTENDED | REG_ICASE | REG_NOSUB)) {
free(*r);
*r = NULL;
debug(DBG_ERR, "failed to compile regular expression %s", v);
return 0;
free(*r);
*r = NULL;
debug(DBG_ERR, "failed to compile regular expression %s", v);
return 0;
}
return 1;
}
Expand Down

0 comments on commit 0784703

Please sign in to comment.