Commit Graph

30021 Commits

Author SHA1 Message Date
Luke Howard
a208b9dcb7 Revert "kdc: fix regression when validating armor client"
This reverts commit 6b635f66de.
2021-12-16 16:44:48 +11:00
Joseph Sutton
91e86460cd kdc: Add krb5_is_enctype_old() to determine whether an enctype is older
AES256 and AES128 are newer enctypes because they are officially
specified in RFC4120 and RFC8009, while enctypes not officially
specified since RFC4120 are considered older. This function differs from
older_enctype() in that it does not report unknown or non-existent
enctypes as being 'newer'.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-16 16:11:29 +11:00
Joseph Sutton
87348cf27a kdc: Verify PAC in TGT provided for user-to-user authentication
Assists Samba to address CVE-2020-25719

It is critical to ensure that the name in the U2U TGT is still associated with
the account was issued to, so we must check the PAC to verify the SID.

Otherwise the SPN check via the S4U2Self hook might be mislead.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14873

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

(Similar to Samba commit 49a13f0fc942d1cfb767d5b6bf49d62241d52046)
2021-12-16 16:09:07 +11:00
Joseph Sutton
3e197ecbee kdc: Check name in request against name in user-to-user TGT
Assists Samba to address CVE-2020-25719

Again, this may be contary to RFC4120 3.3.3
https://datatracker.ietf.org/doc/html/rfc4120/#section-3.3.3
(clearer at the GSS spec here:
https://datatracker.ietf.org/doc/html/draft-swift-win2k-krb-user2user-03 )
as server-name is decribed as optional, however Windows AD and Samba
both require that the server-name exist and be a valid SPN matching
the provided TGT.

The lookup of SPN -> entry ensures that the SPN the client thought it
was connecting to was held by the target server. it could be the
typical user principal, or a service principal, but needs to be checked
for the client not to be fooled into connecting to the wrong service.

The check is the same as needed for S4U2Self so the same HDB hook is re-used.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14873

(Similar to Samba commit f08e6ac86226dcd939fd0e40b6f7dc80c5c00e79)
2021-12-16 16:09:07 +11:00
Joseph Sutton
4112f6fc79 kdc: Use sname from request rather than user-to-user TGT client name
Assists Samba to address CVE-2020-25719

This may be contary to RFC4120 3.3.3 at
https://datatracker.ietf.org/doc/html/rfc4120/#section-3.3.3
(clearer in the GSS mechanism here:
https://datatracker.ietf.org/doc/html/draft-swift-win2k-krb-user2user-03 )
as server-name is decribed as optional, however Windows AD and Samba
both require that the server-name exist and be a valid SPN matching
the provided TGT.

The lookup of SPN -> entry ensures that the SPN the client thought it
was connecting to was held by the target server. it could be the
typical user principal, or a service principal, but needs to be checked
for the client not to be fooled into connecting to the wrong service.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14873

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

(Similar to Samba commit fd50fecbe99ae4fc63843c796d0a516731a1fe6a)
2021-12-16 16:09:07 +11:00
Joseph Sutton
b768c78fca kdc: Move fetching krbtgt entry to before enctype selection
Assists Samba to address CVE-2020-25719

This allows us to use it when validating user-to-user.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14873

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

(Similar to Samba commit f170f1eb4989d7f337eed0f45a558fe5231ea367)
2021-12-16 16:09:07 +11:00
Joseph Sutton
5cb5b6d748 kdc: Check return code
Assists Samba to address CVE-2020-25719

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14873

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

(cherry-picked from Samba commit a5db5c7fa2bdf5c651f77749b4e79c515d164e4f)
2021-12-16 16:09:07 +11:00
Joseph Sutton
ea8e8a4a8a kdc: Avoid races and multiple DB lookups in s4u2self check
Assists Samba to address CVE-2020-25719

Passing in target_server as a string principal means that for
an alias we must looking up the DB twice.

This is subject to a race and is a poor use of resources,
so instead just pass in the record we
already got when trying to confirm that the server in
S4U2Self is the same as the requesting client.

We also avoid doing a name comparison if the HDB plugin provides
a validation hook, this allows the HDB layer more freedom
to choose how to handle things.

In Samba AD the client record has already been bound to the the
original client by the SID check in the PAC, so the record is
known to match the ticket.

Likewise by looking up server only once we ensure that the
keys looked up originally (to decrypt) are in the record
we confirm the SID for here.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14686

Signed-off-by: Andrew Bartlett <abartlet@samba.org>

(Based on Samba commit 05898cfb139ae0674c8251acc9d64c4c3d4c8376)
2021-12-16 16:09:07 +11:00
Luke Howard
6b635f66de kdc: fix regression when validating armor client
Resolving the FAST armor client principal must use the same logic as the AS
itself. Allow synthetic client principals when validating FAST armor TGTs.
2021-12-16 16:05:07 +11:00
Joseph Sutton
b8c58191dc kdc: Optionally require that PAC be be present
This is from Samba's patches for CVE-2020-25719.

This allows Heimdal to match AD behaviour, when configured,
for the behaviour after Microsoft's CVE-2021-42287 when
PacRequestorEnforcement is set to 2.

Samba BUG: https://bugzilla.samba.org/show_bug.cgi?id=14686
REF: https://support.microsoft.com/en-au/topic/kb5008380-authentication-updates-cve-2021-42287-9dafac11-e0d0-4cb8-959a-143bd0201041

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>

[abarlet@samba.org based on Samba commit
 756934f14cc87dc1adfd9315672ae5d49cb24d95
 and f7a2fef8f49a86f63c3dc2f6a2d7d979fb53238a]
2021-12-16 14:41:10 +11:00
Joseph Sutton
83a80cd53b kdc: Check PAC of armor tickets
Look up the client name of the armor TGT in the database, and check that
the PAC is valid.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-16 12:59:01 +11:00
Joseph Sutton
caf7e173a4 kdc: Make check_PAC() and verify_flags() accessible to KDC code
This allows them to be used for checking FAST armor TGTs.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-16 12:59:01 +11:00
Joseph Sutton
c0fa930590 kdc: Don't advertise padata types that will not be accepted
Instead of always advertising PADATA-ENCRYPTED-CHALLENGE, we only
advertise it if FAST is in use.

We also check configuration options to only advertise
PADATA-ENC-TIMESTAMP if it will be accepted based on whether FAST is
currently in use. This permits the non-RFC behaviour required to avoid
breaking earlier Heimdal clients.

This incorporates changes from Apple Heimdal-597.140.2.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-16 10:49:15 +11:00
Nicolas Williams
4aa8677081 kadm5: Use KADM5_PASS_Q_GENERIC 2021-12-16 10:40:01 +11:00
Nicolas Williams
437d4e95ec kadm5: Add KADM5_PASS_Q_GENERIC, note MIT diffs 2021-12-16 10:40:01 +11:00
Nicolas Williams
2a9e998072 krb5: Fix incorrect use of KRB5_ERR_NO_SERVICE 2021-12-16 10:40:01 +11:00
Nicolas Williams
9d426d20b5 krb5: Add missing errors from MIT krb5
Note that KRB5_ERR_NO_SERVICE changed value, as it was off by one.
2021-12-16 10:40:01 +11:00
Nicolas Williams
af923957f6 krb5: Make test_cc w/ KEYRING more reliable
Joining a new keyring session every time seems to make it better.
2021-12-15 16:55:46 -06:00
Nicolas Williams
3da32ef699 Revert "kinit: Try anon PKINIT armored FAST when possible"
This reverts commit 313caed18a.
2021-12-15 10:18:39 -06:00
Luke Howard
d6f9cec30f hdb: do not return HDB_ERR_WRONG_REALM if force_canon set
In hdb_fetch_kvno(), do not return HDB_ERR_WRONG_REALM if the backend set the
force_canonicalize flag

Closes: #886
2021-12-14 18:00:05 +11:00
Joseph Sutton
54129c319c kdc: Don't keep trying keys for encrypted-challenge if one decrypts but fails to verify
This also enables a KRB5KRB_AP_ERR_SKEW error to be returned to the
client.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 17:55:54 +11:00
Joseph Sutton
0ea840ebfc kdc: Check authdata in ticket rather than in request body
This matches Windows behaviour and the RFC6113 specification.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 17:36:10 +11:00
Nicolas Williams
313caed18a kinit: Try anon PKINIT armored FAST when possible 2021-12-14 17:32:20 +11:00
Nicolas Williams
a616cec9d8 kdc: Document enable-pkinit param 2021-12-14 17:32:20 +11:00
Nicolas Williams
660f875a34 kdc: Add [kdc] params to control PA-ENC-TIMESTAMP 2021-12-14 17:32:20 +11:00
Joseph Sutton
717ad8b043 kdc: Add support for explicit armoring from MS-KILE
Normally when FAST is used with a TGS-REQ, the armor key is implicitly
derived from the TGT rather than armor being explicitly present, as for
AS-REQs. However, Windows allows a TGS-REQ to be explicitly armored with
a computer's TGT, so that the armor key also depends on the ticket
session key.

This is used for compound identity, where the computer's group
membership and claims are added to the PAC of the resulting ticket.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 16:19:01 +11:00
Joseph Sutton
96ee28c32c kdc: Allow RODC-issued armor tickets
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 14:30:00 +11:00
Luke Howard
2087e07c1e kdc: update PAC hooks for Samba
Samba includes the user's long-term credentials (encrypted in the AS reply key)
to allow legacy authentication protocols such as NTLM to work even if the
pre-authentication mechanism replaced the reply key (as PKINIT does).

Samba also needs to know whether the client explicitly requested a PAC be
included (or excluded), in order to defer PAC exclusion until a service ticket
is issued (thereby avoiding a name binding attack if the user is renamed
between TGT and service ticket issuance).

References:

https://bugzilla.samba.org/show_bug.cgi?id=11441
https://bugzilla.samba.org/show_bug.cgi?id=14561

Closes: #864

Original authors:
 - Joseph Sutton <josephsutton@catalyst.net.nz>
 - Andrew Bartlett <abartlet@samba.org>
 - Stefan Metzmacher <metze@samba.org>
2021-12-14 13:51:53 +11:00
Luke Howard
fcd8e33a98 tests: use KRB5_CALLCONV for windc test plugin 2021-12-14 13:51:53 +11:00
Joseph Sutton
814e58fda8 heimdal: Make _krb5_pac_get_kdc_checksum_info() into a global function
This lets us call it from Samba.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>

[abartlet@samba.org Similar to Samba commit 3bdce12789af1e7a7aba56691f184625a432410d
 but also fixed for caller in Heimdal windc plugin tests]
2021-12-14 13:44:01 +11:00
Joseph Sutton
2f21cf9933 kdc: Fix leak
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 13:24:02 +11:00
Joseph Sutton
f1255da03c krb5: Check asprintf return value
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-13 21:20:10 -05:00
Joseph Sutton
b8f8906822 asn1: Fix binary search off-by-one read
Previously, if left==right==A1_HEADER_LEN(tos), this would read past the
end of the template array. Now we treat [left, right) as a half-open
interval and no longer try to read from 'right'.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-13 19:18:24 -06:00
Luke Howard
d8af2eb730 kdc: don't leak armor crypto in TGS path
9b55215a added support for FAST in the TGS (#805) but forgot to free the armor
crypto context.
2021-12-14 12:12:40 +11:00
Luke Howard
f95f4bc99e krb5: require strengthen_key when FAST + GSS PA
Always require a strengthen key to be used if GSS pre-authentication is used
within FAST. TRhis avoids a MITM attack that could result in unintended
privilege escalation, should a KDC add additional positive authorization data
from the armor ticket to the issued ticket.

An upcoming revision of the draft will reflect this.
2021-12-14 09:03:42 +11:00
Luke Howard
007cc9fdc3 kdc: remove temporary krb5_context variable
Use r->context (from request) instead of a temporary context variable, where
available.
2021-12-14 09:03:42 +11:00
Luke Howard
22c7e85c57 kinit: add --kdc-hostname option 2021-12-14 09:03:42 +11:00
Luke Howard
2b95853df4 kdc: salt FAST cookie key with client name 2021-12-14 09:03:42 +11:00
Luke Howard
9b55215a2a kdc: sync KDC FAST with Heimdal-597.121.1
Import KDC FAST from Apple's Heimdal-597.121.1, adding support for:

  - PA-ENC-CHALLENGE
  - reply key strengthening
  - FAST authentication in TGS

kuser: Apple sync (squash)

krb5_init_creds_store_config/krb5_init_creds_warn_user in kinit
2021-12-14 09:03:42 +11:00
Luke Howard
47282cae34 krb5: import Heimdal-597.121.1 AS/TGS client
Sync with most changes in AS/TGS client from Apple's Heimdal-597.121.1
(opensource.apple.com).

Changes include:

 - FAST support in TGS client
 - Refactored pre-auth client to be more easily extensible
 - Pin KDC host and AD site name in API calls

Note the completely refactored TGS client loop is not imported as that was
considered too intrusive.
2021-12-14 09:03:42 +11:00
Nicolas Williams
b5a58df8eb krb5: Document return of krb5_cc_get_config() 2021-12-10 17:20:05 -06:00
Nicolas Williams
f44596b14b krb5: Fix null deref in krb5_init_creds_free() 2021-12-10 17:20:05 -06:00
Luke Howard
cfa49a461c krb5: do not pack ccapi on Apple Silicon
Fix fb6f89f2 so #pragma(pop) is also similarly guarded to exclude ARM
2021-12-10 11:11:16 +11:00
Luke Howard
eb85614c24 Revert "s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows"
This reverts commit 24a7a82e82.

After further discussion in #863, the alignment (which differs according to
info buffer type) should be handled by the caller.
2021-12-10 11:02:17 +11:00
Joseph Sutton
24a7a82e82 s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14642

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from Samba commit 28a5a586c8e9cd155d676dcfcb81a2587ace99d1)
2021-12-09 09:53:03 +11:00
Luke Howard
c7a8ee1439 kdc: update windc header guard to reflect filename
Change HEIMDAL_KRB5_PAC_PLUGIN_H to HEIMDAL_KDC_WINDC_PLUGIN_H, reflecting
current plugin API file name.
2021-12-08 15:28:00 +11:00
Joseph Sutton
9b62d72d51 heimdal:kdc: Match Windows error code for unsupported critical FAST options
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:31:58 +11:00
Joseph Sutton
527906c821 heimdal:kdc: Properly check for unsupported critical FAST options
Decoding a FAST request will only give us the FastOptions flags that are
explicitly declared in the ASN1 source. This meant that the check for
unsupported mandatory options would never succeed, and an unsupported
option would go undetected.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:31:58 +11:00
Joseph Sutton
d2dc61c720 heimdal: Initialise KDC reply
The reply structure was not being zero-initialised in all cases, leading
to crashes or possible heap corruption on error paths when we later
freed it.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:03:22 +11:00
Nicolas Williams
83625d349e gss: Make initiator inq. ctx. return canon. target
Make gss_inquire_context() on the established context on the initiator
side return the canonical target acceptor name.
2021-12-06 17:39:22 -06:00