]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Allow zero cksumtype in krb5_k_verify_checksum() 422/head
authorGreg Hudson <ghudson@mit.edu>
Fri, 4 Mar 2016 18:25:28 +0000 (13:25 -0500)
committerGreg Hudson <ghudson@mit.edu>
Wed, 9 Mar 2016 18:32:19 +0000 (13:32 -0500)
A checksum type of 0 means to use the mandatory checksum type in
krb5_k_make_checksum(), krb5_k_make_checksum_iov(), and
krb5_k_verify_checksum_iov().  Extend this meaning to
krb5_k_verify_checksum() for the checksum type in the krb5_checksum
argument.  This change also applies to krb5_c_verify_checksum().

Add code to t_cksums.c to test checksum verification, including with
checksum type 0 for applicable test cases.

ticket: 8375 (new)

src/include/krb5/krb5.hin
src/lib/crypto/crypto_tests/t_cksums.c
src/lib/crypto/krb/verify_checksum.c

index 851cea373404b0d2e327c5ccbbf47768c5189d29..0a0d272ca1bd5619c8a626ffcc46e3e9e32079f2 100644 (file)
@@ -904,8 +904,10 @@ krb5_c_make_checksum(krb5_context context, krb5_cksumtype cksumtype,
  *
  * This function verifies that @a cksum is a valid checksum for @a data.  If
  * the checksum type of @a cksum is a keyed checksum, @a key is used to verify
- * the checksum.  The actual checksum key will be derived from @a key and @a
- * usage if key derivation is specified for the checksum type.
+ * the checksum.  If the checksum type in @a cksum is 0 and @a key is not NULL,
+ * the mandatory checksum type for @a key will be used.  The actual checksum
+ * key will be derived from @a key and @a usage if key derivation is specified
+ * for the checksum type.
  *
  * @note This function is similar to krb5_k_verify_checksum(), but operates
  * on keyblock @a key.
@@ -1470,8 +1472,10 @@ krb5_k_make_checksum_iov(krb5_context context, krb5_cksumtype cksumtype,
  *
  * This function verifies that @a cksum is a valid checksum for @a data.  If
  * the checksum type of @a cksum is a keyed checksum, @a key is used to verify
- * the checksum.  The actual checksum key will be derived from @a key and @a
- * usage if key derivation is specified for the checksum type.
+ * the checksum.  If the checksum type in @a cksum is 0 and @a key is not NULL,
+ * the mandatory checksum type for @a key will be used.  The actual checksum
+ * key will be derived from @a key and @a usage if key derivation is specified
+ * for the checksum type.
  *
  * @note This function is similar to krb5_c_verify_checksum(), but operates
  * on opaque @a key.
index cad16f759446d68d64a1dde24b9afa6b9f9dd923..7c4c6dbb67b36243d8e2c7fa853d2934fe11cadc 100644 (file)
@@ -174,7 +174,8 @@ main(int argc, char **argv)
     krb5_keyblock kb, *kbp;
     krb5_data plain;
     krb5_checksum cksum;
-    krb5_boolean verbose = FALSE;
+    krb5_cksumtype mtype;
+    krb5_boolean valid, verbose = FALSE;
     int status = 0;
 
     if (argc >= 2 && strcmp(argv[1], "-v") == 0)
@@ -214,6 +215,31 @@ main(int argc, char **argv)
             if (!verbose)
                 break;
         }
+
+        /* Test that the checksum verifies successfully. */
+        ret = krb5_c_verify_checksum(context, kbp, test->usage, &plain, &cksum,
+                                     &valid);
+        assert(!ret);
+        if (!valid) {
+            printf("test %d verify failed\n", (int)i);
+            status = 1;
+            if (!verbose)
+                break;
+        }
+
+        if (kbp != NULL) {
+            ret = krb5int_c_mandatory_cksumtype(context, kbp->enctype, &mtype);
+            assert(!ret);
+            if (test->sumtype == mtype) {
+                /* Test that a checksum type of 0 uses the mandatory checksum
+                 * type for the key. */
+                cksum.checksum_type = 0;
+                ret = krb5_c_verify_checksum(context, kbp, test->usage, &plain,
+                                             &cksum, &valid);
+                assert(!ret && valid);
+            }
+        }
+
         krb5_free_checksum_contents(context, &cksum);
     }
     return status;
index 45b33f4244c908d0216faaa9e08661647e7b5008..09425ea7aa904759068a22f50708789ef31c1c69 100644 (file)
@@ -33,6 +33,7 @@ krb5_k_verify_checksum(krb5_context context, krb5_key key,
                        const krb5_checksum *cksum, krb5_boolean *valid)
 {
     const struct krb5_cksumtypes *ctp;
+    krb5_cksumtype cksumtype;
     krb5_crypto_iov iov;
     krb5_error_code ret;
     krb5_data cksum_data;
@@ -41,7 +42,15 @@ krb5_k_verify_checksum(krb5_context context, krb5_key key,
     iov.flags = KRB5_CRYPTO_TYPE_DATA;
     iov.data = *data;
 
-    ctp = find_cksumtype(cksum->checksum_type);
+    /* A 0 checksum type means use the mandatory checksum. */
+    cksumtype = cksum->checksum_type;
+    if (cksumtype == 0 && key != NULL) {
+        ret = krb5int_c_mandatory_cksumtype(context, key->keyblock.enctype,
+                                            &cksumtype);
+        if (ret)
+            return ret;
+    }
+    ctp = find_cksumtype(cksumtype);
     if (ctp == NULL)
         return KRB5_BAD_ENCTYPE;