Blame SOURCES/Mark-deprecated-enctypes-when-used.patch

afd354
From 6306a2a8697c94f968a02d66204f7d357aa0e7f6 Mon Sep 17 00:00:00 2001
afd354
From: Robbie Harwood <rharwood@redhat.com>
afd354
Date: Thu, 10 Jan 2019 16:34:54 -0500
afd354
Subject: [PATCH] Mark deprecated enctypes when used
afd354
afd354
Preface ETYPE_DEPRECATED enctypes with "DEPRECATED:" in klist output,
afd354
KDC logs, and kadmin interactions.  Also complain in krb5kdc when the
afd354
stash file has a deprecated enctype or a deprecated enctype is
afd354
requested with -k.
afd354
afd354
ticket: 8773 (new)
afd354
(cherry picked from commit 8d8e68283b599e680f9fe45eff8af397e827bd6c)
afd354
---
afd354
 src/clients/klist/klist.c      | 14 ++++++++++----
afd354
 src/kadmin/cli/kadmin.c        |  6 +++++-
afd354
 src/kdc/kdc_util.c             |  9 +++++++++
afd354
 src/kdc/main.c                 | 19 +++++++++++++++++++
afd354
 src/tests/gssapi/t_enctypes.py | 15 +++++++++------
afd354
 src/tests/t_keyrollover.py     |  8 +++++---
afd354
 src/tests/t_sesskeynego.py     |  4 ++--
afd354
 7 files changed, 59 insertions(+), 16 deletions(-)
afd354
afd354
diff --git a/src/clients/klist/klist.c b/src/clients/klist/klist.c
afd354
index 70adb54e8..8c307151a 100644
afd354
--- a/src/clients/klist/klist.c
afd354
+++ b/src/clients/klist/klist.c
afd354
@@ -571,11 +571,17 @@ static char *
afd354
 etype_string(krb5_enctype enctype)
afd354
 {
afd354
     static char buf[100];
afd354
-    krb5_error_code ret;
afd354
+    char *bp = buf;
afd354
+    size_t deplen, buflen = sizeof(buf);
afd354
 
afd354
-    ret = krb5_enctype_to_name(enctype, FALSE, buf, sizeof(buf));
afd354
-    if (ret)
afd354
-        snprintf(buf, sizeof(buf), "etype %d", enctype);
afd354
+    if (krb5int_c_deprecated_enctype(enctype)) {
afd354
+        deplen = strlcpy(bp, "DEPRECATED:", buflen);
afd354
+        buflen -= deplen;
afd354
+        bp += deplen;
afd354
+    }
afd354
+
afd354
+    if (krb5_enctype_to_name(enctype, FALSE, bp, buflen))
afd354
+        snprintf(bp, buflen, "etype %d", enctype);
afd354
     return buf;
afd354
 }
afd354
 
afd354
diff --git a/src/kadmin/cli/kadmin.c b/src/kadmin/cli/kadmin.c
afd354
index ed581ee79..cc74921bf 100644
afd354
--- a/src/kadmin/cli/kadmin.c
afd354
+++ b/src/kadmin/cli/kadmin.c
afd354
@@ -1451,12 +1451,16 @@ kadmin_getprinc(int argc, char *argv[])
afd354
         for (i = 0; i < dprinc.n_key_data; i++) {
afd354
             krb5_key_data *key_data = &dprinc.key_data[i];
afd354
             char enctype[BUFSIZ], salttype[BUFSIZ];
afd354
+            char *deprecated = "";
afd354
 
afd354
             if (krb5_enctype_to_name(key_data->key_data_type[0], FALSE,
afd354
                                      enctype, sizeof(enctype)))
afd354
                 snprintf(enctype, sizeof(enctype), _("<Encryption type 0x%x>"),
afd354
                          key_data->key_data_type[0]);
afd354
-            printf("Key: vno %d, %s", key_data->key_data_kvno, enctype);
afd354
+            if (krb5int_c_deprecated_enctype(key_data->key_data_type[0]))
afd354
+                deprecated = "DEPRECATED:";
afd354
+            printf("Key: vno %d, %s%s", key_data->key_data_kvno, deprecated,
afd354
+                   enctype);
afd354
             if (key_data->key_data_ver > 1 &&
afd354
                 key_data->key_data_type[1] != KRB5_KDB_SALTTYPE_NORMAL) {
afd354
                 if (krb5_salttype_to_string(key_data->key_data_type[1],
afd354
diff --git a/src/kdc/kdc_util.c b/src/kdc/kdc_util.c
afd354
index f5c581c82..96c88edc1 100644
afd354
--- a/src/kdc/kdc_util.c
afd354
+++ b/src/kdc/kdc_util.c
afd354
@@ -1048,11 +1048,20 @@ static krb5_error_code
afd354
 enctype_name(krb5_enctype ktype, char *buf, size_t buflen)
afd354
 {
afd354
     char *name;
afd354
+    size_t len;
afd354
 
afd354
     if (buflen == 0)
afd354
         return EINVAL;
afd354
     *buf = '\0'; /* ensure these are always valid C-strings */
afd354
 
afd354
+    if (krb5int_c_deprecated_enctype(ktype)) {
afd354
+        len = strlcpy(buf, "DEPRECATED:", buflen);
afd354
+        if (len >= buflen)
afd354
+            return ENOMEM;
afd354
+        buflen -= len;
afd354
+        buf += len;
afd354
+    }
afd354
+
afd354
     /* rfc4556 recommends that clients wishing to indicate support for these
afd354
      * pkinit algorithms include them in the etype field of the AS-REQ. */
afd354
     if (ktype == ENCTYPE_DSA_SHA1_CMS)
afd354
diff --git a/src/kdc/main.c b/src/kdc/main.c
afd354
index 663fd6303..60092a0df 100644
afd354
--- a/src/kdc/main.c
afd354
+++ b/src/kdc/main.c
afd354
@@ -210,12 +210,23 @@ init_realm(kdc_realm_t * rdp, krb5_pointer aprof, char *realm,
afd354
     char                *svalue = NULL;
afd354
     const char          *hierarchy[4];
afd354
     krb5_kvno       mkvno = IGNORE_VNO;
afd354
+    char ename[32];
afd354
 
afd354
     memset(rdp, 0, sizeof(kdc_realm_t));
afd354
     if (!realm) {
afd354
         kret = EINVAL;
afd354
         goto whoops;
afd354
     }
afd354
+
afd354
+    if (def_enctype != ENCTYPE_UNKNOWN &&
afd354
+        krb5int_c_deprecated_enctype(def_enctype)) {
afd354
+        if (krb5_enctype_to_name(def_enctype, FALSE, ename, sizeof(ename)))
afd354
+            ename[0] = '\0';
afd354
+        fprintf(stderr,
afd354
+                _("Requested master password enctype %s in %s is DEPRECATED!"),
afd354
+                ename, realm);
afd354
+    }
afd354
+
afd354
     hierarchy[0] = KRB5_CONF_REALMS;
afd354
     hierarchy[1] = realm;
afd354
     hierarchy[3] = NULL;
afd354
@@ -370,6 +381,14 @@ init_realm(kdc_realm_t * rdp, krb5_pointer aprof, char *realm,
afd354
         goto whoops;
afd354
     }
afd354
 
afd354
+    if (krb5int_c_deprecated_enctype(rdp->realm_mkey.enctype)) {
afd354
+        if (krb5_enctype_to_name(rdp->realm_mkey.enctype, FALSE, ename,
afd354
+                                 sizeof(ename)))
afd354
+            ename[0] = '\0';
afd354
+        fprintf(stderr, _("Stash file %s uses DEPRECATED enctype %s!"),
afd354
+                rdp->realm_stash, ename);
afd354
+    }
afd354
+
afd354
     if ((kret = krb5_db_fetch_mkey_list(rdp->realm_context, rdp->realm_mprinc,
afd354
                                         &rdp->realm_mkey))) {
afd354
         kdc_err(rdp->realm_context, kret,
afd354
diff --git a/src/tests/gssapi/t_enctypes.py b/src/tests/gssapi/t_enctypes.py
afd354
index 5d9f80e04..ca3d32d21 100755
afd354
--- a/src/tests/gssapi/t_enctypes.py
afd354
+++ b/src/tests/gssapi/t_enctypes.py
afd354
@@ -9,8 +9,11 @@ from k5test import *
afd354
 aes256 = 'aes256-cts-hmac-sha1-96'
afd354
 aes128 = 'aes128-cts-hmac-sha1-96'
afd354
 des3 = 'des3-cbc-sha1'
afd354
+d_des3 = 'DEPRECATED:des3-cbc-sha1'
afd354
 des3raw = 'des3-cbc-raw'
afd354
+d_des3raw = 'DEPRECATED:des3-cbc-raw'
afd354
 rc4 = 'arcfour-hmac'
afd354
+d_rc4 = 'DEPRECATED:arcfour-hmac'
afd354
 
afd354
 # These tests make assumptions about the default enctype lists, so set
afd354
 # them explicitly rather than relying on the library defaults.
afd354
@@ -92,7 +95,7 @@ test_err('acc aes128', None, 'aes128-cts',
afd354
 # no acceptor subkey will be generated because we can't upgrade to a
afd354
 # CFX enctype.
afd354
 test('init des3', 'des3', None,
afd354
-     tktenc=aes256, tktsession=des3,
afd354
+     tktenc=aes256, tktsession=d_des3,
afd354
      proto='rfc1964', isubkey=des3raw, asubkey=None)
afd354
 
afd354
 # Force the ticket session key to be rc4, so we can test some subkey
afd354
@@ -103,7 +106,7 @@ realm.run([kadminl, 'setstr', realm.host_princ, 'session_enctypes', 'rc4'])
afd354
 # [aes256 aes128 des3] and the acceptor should upgrade to an aes256
afd354
 # subkey.
afd354
 test('upgrade noargs', None, None,
afd354
-     tktenc=aes256, tktsession=rc4,
afd354
+     tktenc=aes256, tktsession=d_rc4,
afd354
      proto='cfx', isubkey=rc4, asubkey=aes256)
afd354
 
afd354
 # If the initiator won't permit rc4 as a session key, it won't be able
afd354
@@ -113,14 +116,14 @@ test_err('upgrade init aes', 'aes', None, 'no support for encryption type')
afd354
 # If the initiator permits rc4 but prefers aes128, it will send an
afd354
 # upgrade list of [aes128] and the acceptor will upgrade to aes128.
afd354
 test('upgrade init aes128+rc4', 'aes128-cts rc4', None,
afd354
-     tktenc=aes256, tktsession=rc4,
afd354
+     tktenc=aes256, tktsession=d_rc4,
afd354
      proto='cfx', isubkey=rc4, asubkey=aes128)
afd354
 
afd354
 # If the initiator permits rc4 but prefers des3, it will send an
afd354
 # upgrade list of [des3], but the acceptor won't generate a subkey
afd354
 # because des3 isn't a CFX enctype.
afd354
 test('upgrade init des3+rc4', 'des3 rc4', None,
afd354
-     tktenc=aes256, tktsession=rc4,
afd354
+     tktenc=aes256, tktsession=d_rc4,
afd354
      proto='rfc1964', isubkey=rc4, asubkey=None)
afd354
 
afd354
 # If the acceptor permits only aes128, subkey negotiation will fail
afd354
@@ -134,14 +137,14 @@ test_err('upgrade acc aes128', None, 'aes128-cts',
afd354
 # If the acceptor permits rc4 but prefers aes128, it will negotiate an
afd354
 # upgrade to aes128.
afd354
 test('upgrade acc aes128 rc4', None, 'aes128-cts rc4',
afd354
-     tktenc=aes256, tktsession=rc4,
afd354
+     tktenc=aes256, tktsession=d_rc4,
afd354
      proto='cfx', isubkey=rc4, asubkey=aes128)
afd354
 
afd354
 # In this test, the initiator and acceptor each prefer an AES enctype
afd354
 # to rc4, but they can't agree on which one, so no subkey is
afd354
 # generated.
afd354
 test('upgrade mismatch', 'aes128-cts rc4', 'aes256-cts rc4',
afd354
-     tktenc=aes256, tktsession=rc4,
afd354
+     tktenc=aes256, tktsession=d_rc4,
afd354
      proto='rfc1964', isubkey=rc4, asubkey=None)
afd354
 
afd354
 success('gss_krb5_set_allowable_enctypes tests')
afd354
diff --git a/src/tests/t_keyrollover.py b/src/tests/t_keyrollover.py
afd354
index 7c8d828f0..4af6804f2 100755
afd354
--- a/src/tests/t_keyrollover.py
afd354
+++ b/src/tests/t_keyrollover.py
afd354
@@ -22,8 +22,9 @@ realm.run([kvno, princ1])
afd354
 realm.run([kadminl, 'purgekeys', realm.krbtgt_princ])
afd354
 # Make sure an old TGT fails after purging old TGS key.
afd354
 realm.run([kvno, princ2], expected_code=1)
afd354
-msg = 'krbtgt/%s@%s\n\tEtype (skey, tkt): des-cbc-crc, des-cbc-crc' % \
afd354
-    (realm.realm, realm.realm)
afd354
+ddes = "DEPRECATED:des-cbc-crc"
afd354
+msg = 'krbtgt/%s@%s\n\tEtype (skey, tkt): %s, %s' % \
afd354
+    (realm.realm, realm.realm, ddes, ddes)
afd354
 realm.run([klist, '-e'], expected_msg=msg)
afd354
 
afd354
 # Check that new key actually works.
afd354
@@ -48,7 +49,8 @@ realm.run([kadminl, 'cpw', '-randkey', '-keepold', '-e', 'aes256-cts',
afd354
            realm.krbtgt_princ])
afd354
 realm.run([kadminl, 'modprinc', '-kvno', '1', realm.krbtgt_princ])
afd354
 out = realm.run([kadminl, 'getprinc', realm.krbtgt_princ])
afd354
-if 'vno 1, aes256' not in out or 'vno 1, des3' not in out:
afd354
+if 'vno 1, aes256-cts' not in out or \
afd354
+   'vno 1, DEPRECATED:des3-cbc-sha1' not in out:
afd354
     fail('keyrollover: setup for TGS enctype test failed')
afd354
 # Now present the DES3 ticket to the KDC and make sure it's rejected.
afd354
 realm.run([kvno, realm.host_princ], expected_code=1)
afd354
diff --git a/src/tests/t_sesskeynego.py b/src/tests/t_sesskeynego.py
afd354
index 448092387..da02f224a 100755
afd354
--- a/src/tests/t_sesskeynego.py
afd354
+++ b/src/tests/t_sesskeynego.py
afd354
@@ -62,11 +62,11 @@ test_kvno(realm, 'aes128-cts-hmac-sha1-96', 'aes256-cts-hmac-sha1-96')
afd354
 # 3b: Negotiate rc4-hmac session key when principal only has aes256 long-term.
afd354
 realm.run([kadminl, 'setstr', 'server', 'session_enctypes',
afd354
            'rc4-hmac,aes128-cts,aes256-cts'])
afd354
-test_kvno(realm, 'arcfour-hmac', 'aes256-cts-hmac-sha1-96')
afd354
+test_kvno(realm, 'DEPRECATED:arcfour-hmac', 'aes256-cts-hmac-sha1-96')
afd354
 
afd354
 # 3c: Test des-cbc-crc default assumption.
afd354
 realm.run([kadminl, 'delstr', 'server', 'session_enctypes'])
afd354
-test_kvno(realm, 'des-cbc-crc', 'aes256-cts-hmac-sha1-96')
afd354
+test_kvno(realm, 'DEPRECATED:des-cbc-crc', 'aes256-cts-hmac-sha1-96')
afd354
 realm.stop()
afd354
 
afd354
 # Last go: test that we can disable the des-cbc-crc assumption