vici: Support multiple named raw ublic keys

This commit is contained in:
Andreas Steffen
2016-01-10 00:12:57 +01:00
parent 2aa2b17d41
commit ffd29ab30a
+19 -15
View File
@@ -1542,39 +1542,43 @@ CALLBACK(peer_sn, bool,
.request = peer->request, .request = peer->request,
.cfg = auth_cfg_create(), .cfg = auth_cfg_create(),
}; };
auth_rule_t rule;
certificate_t *cert; certificate_t *cert;
pubkey_cert_t *pubkey_cert;
identification_t *id; identification_t *id;
enumerator_t *enumerator;
bool default_id = FALSE;
if (!message->parse(message, ctx, NULL, auth_kv, auth_li, &auth)) if (!message->parse(message, ctx, NULL, auth_kv, auth_li, &auth))
{ {
auth.cfg->destroy(auth.cfg); auth.cfg->destroy(auth.cfg);
return FALSE; return FALSE;
} }
cert = auth.cfg->get(auth.cfg, AUTH_RULE_SUBJECT_CERT);
id = auth.cfg->get(auth.cfg, AUTH_RULE_IDENTITY); id = auth.cfg->get(auth.cfg, AUTH_RULE_IDENTITY);
if (cert) enumerator = auth.cfg->create_enumerator(auth.cfg);
while (enumerator->enumerate(enumerator, &rule, &cert))
{ {
if (id) if (rule == AUTH_RULE_SUBJECT_CERT && !default_id)
{ {
if (cert->get_type(cert) == CERT_TRUSTED_PUBKEY && if (id == NULL)
id->get_type != ID_ANY)
{ {
pubkey_cert_t *pubkey_cert; id = cert->get_subject(cert);
DBG1(DBG_CFG, " id not specified, defaulting to"
/* the id is set for informational purposes, only */ " cert subject '%Y'", id);
auth.cfg->add(auth.cfg, AUTH_RULE_IDENTITY, id->clone(id));
default_id = TRUE;
}
else if (cert->get_type(cert) == CERT_TRUSTED_PUBKEY &&
id->get_type != ID_ANY)
{
/* set the subject of all raw public keys to the id */
pubkey_cert = (pubkey_cert_t*)cert; pubkey_cert = (pubkey_cert_t*)cert;
pubkey_cert->set_subject(pubkey_cert, id); pubkey_cert->set_subject(pubkey_cert, id);
} }
} }
else
{
id = cert->get_subject(cert);
DBG1(DBG_CFG, " id not specified, defaulting to cert id '%Y'",
id);
auth.cfg->add(auth.cfg, AUTH_RULE_IDENTITY, id->clone(id));
}
} }
enumerator->destroy(enumerator);
if (strcasepfx(name, "local")) if (strcasepfx(name, "local"))
{ {