hdb: Move virtual principals into HDB layer
This is a large commit that adds several features: - Revamps and moves virtual host-based service principal functionality from kdc/ to lib/hdb/ so that it may be automatically visible to lib/kadm5/, as well as kadmin(1)/kadmind(8) and ktutil(1). The changes are backwards-incompatible. - Completes support for documenting a service principal's supported enctypes in its HDB entry independently of its long-term keys. This will reduce HDB bloat by not requiring that service principals have more long-term keys than they need just to document the service's supported enctypes. - Adds support for storing krb5.conf content in principals' HDB entries. This may eventually be used for causing Heimdal KDC services to reconfigure primary/secondary roles automatically by discovering the configured primary in an HDB entry for the realm. For now this will be used to help reduce the amount of configuration needed by clients of an upcoming HTTP binding of the kadmin service.
This commit is contained in:
114
lib/hdb/keys.c
114
lib/hdb/keys.c
@@ -217,6 +217,15 @@ hdb_prune_keys_kvno(krb5_context context, hdb_entry *entry, int kvno)
|
||||
size_t nelem;
|
||||
size_t i;
|
||||
|
||||
/*
|
||||
* XXX Pruning old keys for namespace principals may not be desirable, but!
|
||||
* as long as the `set_time's of the base keys for a namespace principal
|
||||
* match the `epoch's of the corresponding KeyRotation periods, it will be
|
||||
* perfectly acceptable to prune old [base] keys for namespace principals
|
||||
* just as for any other principal. Therefore, we may not need to make any
|
||||
* changes here w.r.t. namespace principals.
|
||||
*/
|
||||
|
||||
ext = hdb_find_extension(entry, choice_HDB_extension_data_hist_keys);
|
||||
if (ext == NULL)
|
||||
return 0;
|
||||
@@ -279,6 +288,53 @@ hdb_prune_keys(krb5_context context, hdb_entry *entry)
|
||||
return hdb_prune_keys_kvno(context, entry, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function adds a keyset to an HDB entry's key history.
|
||||
*
|
||||
* @param context Context
|
||||
* @param entry HDB entry
|
||||
* @param kvno Key version number of the key to add to the history
|
||||
* @param key The Key to add
|
||||
*/
|
||||
krb5_error_code
|
||||
hdb_add_history_keyset(krb5_context context,
|
||||
hdb_entry *entry,
|
||||
const hdb_keyset *ks)
|
||||
{
|
||||
size_t i;
|
||||
HDB_Ext_KeySet *hist_keys;
|
||||
HDB_extension ext;
|
||||
HDB_extension *extp;
|
||||
krb5_error_code ret;
|
||||
|
||||
memset(&ext, 0, sizeof (ext));
|
||||
|
||||
extp = hdb_find_extension(entry, choice_HDB_extension_data_hist_keys);
|
||||
if (extp == NULL) {
|
||||
ext.mandatory = FALSE;
|
||||
ext.data.element = choice_HDB_extension_data_hist_keys;
|
||||
ext.data.u.hist_keys.len = 0;
|
||||
ext.data.u.hist_keys.val = 0;
|
||||
extp = &ext;
|
||||
}
|
||||
hist_keys = &extp->data.u.hist_keys;
|
||||
|
||||
for (i = 0; i < hist_keys->len; i++) {
|
||||
if (hist_keys->val[i].kvno == ks->kvno) {
|
||||
/* Replace existing */
|
||||
free_hdb_keyset(&hist_keys->val[i]);
|
||||
ret = copy_hdb_keyset(ks, &hist_keys->val[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i >= hist_keys->len)
|
||||
ret = add_HDB_Ext_KeySet(hist_keys, ks); /* Append new */
|
||||
if (ret == 0 && extp == &ext)
|
||||
ret = hdb_replace_extension(context, entry, &ext);
|
||||
free_HDB_extension(&ext);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function adds an HDB entry's current keyset to the entry's key
|
||||
* history. The current keyset is left alone; the caller is responsible
|
||||
@@ -286,65 +342,30 @@ hdb_prune_keys(krb5_context context, hdb_entry *entry)
|
||||
*
|
||||
* @param context Context
|
||||
* @param entry HDB entry
|
||||
*
|
||||
* @return Zero on success, or an error code otherwise.
|
||||
*/
|
||||
krb5_error_code
|
||||
hdb_add_current_keys_to_history(krb5_context context, hdb_entry *entry)
|
||||
{
|
||||
krb5_boolean replace = FALSE;
|
||||
krb5_error_code ret;
|
||||
HDB_extension *ext;
|
||||
HDB_Ext_KeySet *keys;
|
||||
hdb_keyset newkeyset;
|
||||
hdb_keyset ks;
|
||||
time_t newtime;
|
||||
|
||||
if (entry->keys.len == 0)
|
||||
return 0; /* nothing to do */
|
||||
|
||||
ext = hdb_find_extension(entry, choice_HDB_extension_data_hist_keys);
|
||||
if (ext == NULL) {
|
||||
replace = TRUE;
|
||||
ext = calloc(1, sizeof (*ext));
|
||||
if (ext == NULL)
|
||||
return krb5_enomem(context);
|
||||
|
||||
ext->data.element = choice_HDB_extension_data_hist_keys;
|
||||
}
|
||||
keys = &ext->data.u.hist_keys;
|
||||
|
||||
ext->mandatory = FALSE;
|
||||
|
||||
/*
|
||||
* Copy in newest old keyset
|
||||
*/
|
||||
ret = hdb_entry_get_pw_change_time(entry, &newtime);
|
||||
if (ret)
|
||||
goto out;
|
||||
return ret;
|
||||
|
||||
memset(&newkeyset, 0, sizeof(newkeyset));
|
||||
newkeyset.keys = entry->keys;
|
||||
newkeyset.kvno = entry->kvno;
|
||||
newkeyset.set_time = &newtime;
|
||||
ks.keys = entry->keys;
|
||||
ks.kvno = entry->kvno;
|
||||
ks.set_time = &newtime;
|
||||
|
||||
ret = add_HDB_Ext_KeySet(keys, &newkeyset);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
if (replace) {
|
||||
/* hdb_replace_extension() deep-copies ext; what a waste */
|
||||
ret = hdb_replace_extension(context, entry, ext);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = hdb_prune_keys(context, entry);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
out:
|
||||
if (replace && ext) {
|
||||
free_HDB_extension(ext);
|
||||
free(ext);
|
||||
}
|
||||
ret = hdb_add_history_keyset(context, entry, &ks);
|
||||
if (ret == 0)
|
||||
ret = hdb_prune_keys(context, entry);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -355,6 +376,8 @@ hdb_add_current_keys_to_history(krb5_context context, hdb_entry *entry)
|
||||
* @param entry HDB entry
|
||||
* @param kvno Key version number of the key to add to the history
|
||||
* @param key The Key to add
|
||||
*
|
||||
* @return Zero on success, or an error code otherwise.
|
||||
*/
|
||||
krb5_error_code
|
||||
hdb_add_history_key(krb5_context context, hdb_entry *entry, krb5_kvno kvno, Key *key)
|
||||
@@ -404,7 +427,6 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This function changes an hdb_entry's kvno, swapping the current key
|
||||
* set with a historical keyset. If no historical keys are found then
|
||||
|
Reference in New Issue
Block a user