Implement * notation for hosts

This commit is contained in:
2022-01-13 18:02:07 +01:00
parent 6ab65abec9
commit cd3bc9aa90
2 changed files with 6 additions and 8 deletions

View File

@ -37,6 +37,10 @@ host_config *get_host_config(const char *host) {
host_config *hc = &config->hosts[i]; host_config *hc = &config->hosts[i];
if (hc->type == CONFIG_TYPE_UNSET) break; if (hc->type == CONFIG_TYPE_UNSET) break;
if (strcmp(hc->name, host) == 0) return hc; if (strcmp(hc->name, host) == 0) return hc;
if (hc->name[0] == '*' && hc->name[1] == '.') {
const char *pos = strstr(host, hc->name + 1);
if (pos != NULL && strlen(pos) == strlen(hc->name + 1)) return hc;
}
} }
return NULL; return NULL;
} }

View File

@ -50,14 +50,8 @@ void openssl_init() {
static int ssl_servername_cb(SSL *ssl, int *ad, void *arg) { static int ssl_servername_cb(SSL *ssl, int *ad, void *arg) {
const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); const char *servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
if (servername != NULL) { if (servername != NULL) {
for (int i = 0; i < CONFIG_MAX_HOST_CONFIG; i++) { const host_config *conf = get_host_config(servername);
const host_config *conf = &config->hosts[i]; if (conf != NULL) SSL_set_SSL_CTX(ssl, contexts[conf->cert]);
if (conf->type == CONFIG_TYPE_UNSET) break;
if (strcmp(conf->name, servername) == 0) {
SSL_set_SSL_CTX(ssl, contexts[conf->cert]);
break;
}
}
} }
return SSL_TLSEXT_ERR_OK; return SSL_TLSEXT_ERR_OK;
} }