Remove verify_master_key from the DAL table, as well as its associated
authorGreg Hudson <ghudson@mit.edu>
Fri, 2 Jul 2010 19:09:20 +0000 (19:09 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 2 Jul 2010 19:09:20 +0000 (19:09 +0000)
libkdb5 interface.  Callers can (and mostly already do) use
krb5_fetch_mkey_list to verify master keyblocks.  Adjust tests/create,
tests/verify, and kdb5_util dump to do so.

ticket: 6749
status: open

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24166 dc483132-0cff-0310-8789-dd5450dbe970

12 files changed:
src/include/kdb.h
src/kadmin/dbutil/dump.c
src/kadmin/dbutil/kdb5_util.c
src/kdc/main.c
src/lib/kadm5/srv/server_kdb.c
src/lib/kdb/kdb5.c
src/lib/kdb/kdb_default.c
src/lib/kdb/libkdb5.exports
src/plugins/kdb/db2/db2_exp.c
src/plugins/kdb/ldap/ldap_exp.c
src/tests/create/kdb5_mkdums.c
src/tests/verify/kdb5_verify.c

index a2c496967c46ea338f52f5867951011cab4c18f9..856cf0bdf64ed529a729cb05bb4eedcde22f3e75 100644 (file)
@@ -476,10 +476,6 @@ krb5_error_code krb5_db_fetch_mkey  ( krb5_context   context,
                                       krb5_kvno     *kvno,
                                       krb5_data     *salt,
                                       krb5_keyblock *key);
-krb5_error_code krb5_db_verify_master_key ( krb5_context   kcontext,
-                                            krb5_principal mprinc,
-                                            krb5_kvno      kvno,
-                                            krb5_keyblock  *mkey );
 krb5_error_code
 krb5_db_fetch_mkey_list( krb5_context    context,
                          krb5_principal  mname,
@@ -716,12 +712,6 @@ krb5_db_def_fetch_mkey( krb5_context   context,
                         krb5_kvno     *kvno,
                         char          *db_args);
 
-krb5_error_code
-krb5_def_verify_master_key( krb5_context   context,
-                            krb5_principal mprinc,
-                            krb5_kvno      kvno,
-                            krb5_keyblock *mkey);
-
 krb5_error_code
 krb5_def_fetch_mkey_list( krb5_context            context,
                           krb5_principal        mprinc,
@@ -1162,19 +1152,6 @@ typedef struct _kdb_vftabl {
                                         krb5_keyblock *key, krb5_kvno *kvno,
                                         char *db_args);
 
-    /*
-     * Optional with default: Verify that the keyblock mkey is a valid master
-     * key for the realm.  This function used to be used by the KDC and
-     * kadmind, but is now used only by kdb5_util dump -mkey_convert.
-     *
-     * The default implementation retrieves the master key principal and
-     * attempts to decrypt its key with mkey.  This only works for the current
-     * master keyblock.
-     */
-    krb5_error_code (*verify_master_key)(krb5_context kcontext,
-                                         krb5_principal mprinc, krb5_kvno kvno,
-                                         krb5_keyblock *mkey);
-
     /*
      * Optional with default: Given a keyblock for some version of the
      * database's master key, fetch the decrypted master key values from the
@@ -1182,9 +1159,12 @@ typedef struct _kdb_vftabl {
      * *mkeys_list using a libkdb5 function which uses the standard free()
      * function, so the module must not use a custom allocator.
      *
-     * The default implementation tries the key against the current master key
-     * data and all KRB5_TL_MKEY_AUX values, which contain copies of the master
-     * keys encrypted with old master keys.
+     * The caller may not know the version number of the master key it has, in
+     * which case it will pass IGNORE_VNO.
+     *
+     * The default implementation ignores kvno and tries the key against the
+     * current master key data and all KRB5_TL_MKEY_AUX values, which contain
+     * copies of the master keys encrypted with old master keys.
      */
     krb5_error_code (*fetch_master_key_list)(krb5_context kcontext,
                                              krb5_principal mname,
index 64c63afb19fabc91a907a802a7c78fbd685c90d9..baebf4c6e1c72b034926d1d9c0ad14c62319c781 100644 (file)
@@ -1082,6 +1082,7 @@ dump_db(argc, argv)
     kdb_log_context     *log_ctx;
     char                **db_args = 0; /* XXX */
     unsigned int        ipropx_version = IPROPX_VERSION_0;
+    krb5_keylist_node *mkeys;
 
     /*
      * Parse the arguments.
@@ -1185,15 +1186,15 @@ dump_db(argc, argv)
                         "while reading master key");
                 exit(1);
             }
-            retval = krb5_db_verify_master_key(util_context,
-                                               master_princ,
-                                               IGNORE_VNO,
-                                               &master_keyblock);
+            retval = krb5_db_fetch_mkey_list(util_context, master_princ,
+                                             &master_keyblock, IGNORE_VNO,
+                                             &mkeys);
             if (retval) {
                 com_err(progname, retval,
                         "while verifying master key");
                 exit(1);
             }
+            krb5_db_free_mkey_list(util_context, mkeys);
         }
         new_master_keyblock.enctype = global_params.enctype;
         if (new_master_keyblock.enctype == ENCTYPE_UNKNOWN)
index 035a8c0ff5a467576f7a490fb1a4e3b84bb5b4d1..09b0d0704cd434d4159a741d00657172bf9f0ff4 100644 (file)
@@ -491,16 +491,6 @@ static int open_db_and_mkey()
             return(0);
         }
     }
-#if 0 /************** Begin IFDEF'ed OUT *******************************/
-    /* krb5_db_fetch_mkey_list will verify the mkey */
-    if ((retval = krb5_db_verify_master_key(util_context, master_princ,
-                                            master_kvno, &master_keyblock))) {
-        com_err(progname, retval, "while verifying master key");
-        exit_status++;
-        krb5_free_keyblock_contents(util_context, &master_keyblock);
-        return(1);
-    }
-#endif /**************** END IFDEF'ed OUT *******************************/
 
     if ((retval = krb5_db_fetch_mkey_list(util_context, master_princ,
                                           &master_keyblock, master_kvno,
index c3270a9694172245c5ef0c37f23cc9add99401b2..60c48aea65c7df23ba216759a287eae2d8a24dda 100644 (file)
@@ -423,23 +423,6 @@ init_realm(kdc_realm_t *rdp, char *realm, char *def_mpname,
                 rdp->realm_mpname, realm);
         goto whoops;
     }
-#if 0 /************** Begin IFDEF'ed OUT *******************************/
-    /*
-     * Commenting krb5_db_verify_master_key out because it requires the most
-     * current mkey which may not be the case here.  The call to
-     * krb5_db_fetch_mkey_list() will end up verifying that the mkey is viable
-     * anyway.
-     */
-    /* Verify the master key */
-    if ((kret = krb5_db_verify_master_key(rdp->realm_context,
-                                          rdp->realm_mprinc,
-                                          IGNORE_VNO,
-                                          &rdp->realm_mkey))) {
-        kdc_err(rdp->realm_context, kret,
-                "while verifying master key for realm %s", realm);
-        goto whoops;
-    }
-#endif /**************** END IFDEF'ed OUT *******************************/
 
     if ((kret = krb5_db_fetch_mkey_list(rdp->realm_context, rdp->realm_mprinc,
                                         &rdp->realm_mkey, mkvno, &rdp->mkey_list))) {
index 768c8f7395bc68f9e105d52080a922e501e59e68..d986b626e631fffa9930bad120037a5f9849773d 100644 (file)
@@ -72,18 +72,6 @@ krb5_error_code kdb_init_master(kadm5_server_handle_t handle,
     if (ret)
         goto done;
 
-#if 0 /************** Begin IFDEF'ed OUT *******************************/
-    /*
-     * krb5_db_fetch_mkey_list will verify mkey so don't call
-     * krb5_db_verify_master_key()
-     */
-    if ((ret = krb5_db_verify_master_key(handle->context, master_princ,
-                                         IGNORE_VNO, &master_keyblock))) {
-        krb5_db_fini(handle->context);
-        return ret;
-    }
-#endif /**************** END IFDEF'ed OUT *******************************/
-
     if ((ret = krb5_db_fetch_mkey_list(handle->context, master_princ,
                                        &master_keyblock, mkvno, &master_keylist))) {
         krb5_db_fini(handle->context);
index f1bd58119a11f1ea09d2a49d9e8c98075699f8f8..8a199845776c362938460d13739c822810d0fdbe 100644 (file)
@@ -252,8 +252,6 @@ kdb_setup_opt_functions(db_library lib)
         lib->vftabl.get_master_key_list = kdb_def_get_mkey_list;
     if (lib->vftabl.fetch_master_key == NULL)
         lib->vftabl.fetch_master_key = krb5_db_def_fetch_mkey;
-    if (lib->vftabl.verify_master_key == NULL)
-        lib->vftabl.verify_master_key = krb5_def_verify_master_key;
     if (lib->vftabl.fetch_master_key_list == NULL)
         lib->vftabl.fetch_master_key_list = krb5_def_fetch_mkey_list;
     if (lib->vftabl.store_master_key_list == NULL)
@@ -1277,23 +1275,6 @@ clean_n_exit:
     return retval;
 }
 
-krb5_error_code
-krb5_db_verify_master_key(krb5_context     kcontext,
-                          krb5_principal   mprinc,
-                          krb5_kvno        kvno,
-                          krb5_keyblock  * mkey)
-{
-    krb5_error_code status = 0;
-    kdb_vftabl *v;
-
-    status = get_vftabl(kcontext, &v);
-    if (status)
-        return status;
-    if (v->verify_master_key == NULL)
-        return KRB5_KDB_DBTYPE_NOSUP;
-    return v->verify_master_key(kcontext, mprinc, kvno, mkey);
-}
-
 krb5_error_code
 krb5_dbe_fetch_act_key_list(krb5_context         context,
                             krb5_principal       princ,
index e8fe54ff1f267922ebb0df446f4860c660a8b0fc..d78c13cb1b5a28b140d965e5b082f50a03520b52 100644 (file)
@@ -434,63 +434,6 @@ krb5_db_def_fetch_mkey(krb5_context   context,
         return 0;
 }
 
-/*
- * Note, this verifies that the input mkey is currently protecting all the mkeys
- */
-krb5_error_code
-krb5_def_verify_master_key(krb5_context    context,
-                           krb5_principal  mprinc,
-                           krb5_kvno       kvno,
-                           krb5_keyblock   *mkey)
-{
-    krb5_error_code retval;
-    krb5_db_entry master_entry;
-    int nprinc;
-    krb5_boolean more;
-    krb5_keyblock tempkey;
-
-    nprinc = 1;
-    if ((retval = krb5_db_get_principal(context, mprinc,
-                                        &master_entry, &nprinc, &more)))
-        return(retval);
-
-    if (nprinc != 1) {
-        if (nprinc)
-            krb5_db_free_principal(context, &master_entry, nprinc);
-        return(KRB5_KDB_NOMASTERKEY);
-    } else if (more) {
-        krb5_db_free_principal(context, &master_entry, nprinc);
-        return(KRB5KDC_ERR_PRINCIPAL_NOT_UNIQUE);
-    }
-
-    if ((retval = krb5_dbe_decrypt_key_data(context, mkey,
-                                            &master_entry.key_data[0],
-                                            &tempkey, NULL))) {
-        krb5_db_free_principal(context, &master_entry, nprinc);
-        return retval;
-    }
-
-    if (mkey->length != tempkey.length ||
-        memcmp((char *)mkey->contents,
-               (char *)tempkey.contents,mkey->length)) {
-        retval = KRB5_KDB_BADMASTERKEY;
-    }
-
-    if (kvno != IGNORE_VNO &&
-        kvno != (krb5_kvno) master_entry.key_data->key_data_kvno) {
-        retval = KRB5_KDB_BADMASTERKEY;
-        krb5_set_error_message (context, retval,
-                                "User specified mkeyVNO (%u) does not match master key princ's KVNO (%u)",
-                                kvno, master_entry.key_data->key_data_kvno);
-    }
-
-    zap((char *)tempkey.contents, tempkey.length);
-    free(tempkey.contents);
-    krb5_db_free_principal(context, &master_entry, nprinc);
-
-    return retval;
-}
-
 krb5_error_code
 krb5_def_fetch_mkey_list(krb5_context        context,
                          krb5_principal        mprinc,
index c32a8db5ed87240053caa70e1739c8bae6b112ff..4111ef0f096bab09a5178aa2c924442093201e66 100644 (file)
@@ -27,7 +27,6 @@ krb5_db_setup_mkey_name
 krb5_db_unlock
 krb5_db_store_master_key
 krb5_db_store_master_key_list
-krb5_db_verify_master_key
 krb5_dbe_apw
 krb5_dbe_ark
 krb5_dbe_cpw
index 87a3bf0f906bf9d59826c936a389fd3ba1241037..aabeb9d03b877c22a15d851801ea6bea39688ad1 100644 (file)
@@ -246,7 +246,7 @@ kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_db2, kdb_function_table) = {
     /* free */                          krb5_db2_free,
     /* set_master_key_list */           wrap_krb5_db2_set_mkey_list,
     /* get_master_key_list */           wrap_krb5_db2_get_mkey_list,
-    /* blah blah blah */ 0,0,0,0,0,0,0,
+    /* blah blah blah */ 0,0,0,0,0,0,
     /* promote_db */                    wrap_krb5_db2_promote_db,
     0, 0,
     /* invoke */                        wrap_krb5_db2_invoke
index 4d071dc49c0ac800a750fd6cea8131952e081223..0fb014a89f63f95ed3f16ba0dc6333748c23daaa 100644 (file)
@@ -76,7 +76,6 @@ kdb_vftabl PLUGIN_SYMBOL_NAME(krb5_ldap, kdb_function_table) = {
     /* get_master_key_list */               krb5_ldap_get_mkey_list,
     /* store_master_key */                  NULL,
     /* fetch_master_key */                  NULL /* krb5_ldap_fetch_mkey */,
-    /* verify_master_key */                 NULL /* krb5_ldap_verify_master_key */,
     /* fetch_master_key_list */             NULL,
     /* store_master_key_list */             NULL,
     /* Search enc type */                   NULL,
index 3179b968ef14feb098513608ed9a71481c8c9104..0d860b909117877311d08531c36600e215f83d86 100644 (file)
@@ -336,6 +336,7 @@ set_dbname_help(pname, dbname)
     krb5_boolean more;
     krb5_data pwd, scratch;
     char *args[2];
+    krb5_keylist_node *mkeys;
 
     /* assemble & parse the master key name */
 
@@ -392,12 +393,14 @@ set_dbname_help(pname, dbname)
     /* Done with args */
     free(args[0]);
 
-    if ((retval = krb5_db_verify_master_key(test_context, master_princ,
-                                            IGNORE_VNO, &master_keyblock))){
+    if ((retval = krb5_db_fetch_mkey_list(test_context, master_princ,
+                                          &master_keyblock, IGNORE_VNO,
+                                          &mkeys))){
         com_err(pname, retval, "while verifying master key");
         (void) krb5_db_fini(test_context);
         return(1);
     }
+    krb5_db_free_mkey_list(test_context, mkeys);
     nentries = 1;
     if ((retval = krb5_db_get_principal(test_context, master_princ,
                                         &master_entry, &nentries, &more))) {
index 2e465f36f771336331ab5ff8fb2270c339de8c47..5fdab77c03b56760722c172866afb35ba09eb9d7 100644 (file)
@@ -368,6 +368,7 @@ set_dbname_help(context, pname, dbname)
     krb5_boolean more;
     krb5_data pwd, scratch;
     char *args[2];
+    krb5_keylist_node *mkeys;
 
     /* assemble & parse the master key name */
 
@@ -419,12 +420,14 @@ set_dbname_help(context, pname, dbname)
         com_err(pname, retval, "while initializing database");
         return(1);
     }
-    if ((retval = krb5_db_verify_master_key(context, master_princ,
-                                            IGNORE_VNO, &master_keyblock))) {
+    if ((retval = krb5_db_fetch_mkey_list(context, master_princ,
+                                          &master_keyblock, IGNORE_VNO,
+                                          &mkeys))) {
         com_err(pname, retval, "while verifying master key");
         (void) krb5_db_fini(context);
         return(1);
     }
+    krb5_db_free_mkey_list(context, mkeys);
     nentries = 1;
     if ((retval = krb5_db_get_principal(context, master_princ, &master_entry,
                                         &nentries, &more))) {