metze/heimdal/wip.git
2 years agotests/gss: use --iterate-acceptor-keytab to resolve "Decrypt integrity check" heimdal-no-transit-check
Stefan Metzmacher [Tue, 12 Nov 2019 15:34:45 +0000 (16:34 +0100)]
tests/gss: use --iterate-acceptor-keytab to resolve "Decrypt integrity check"

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi: add --iterate-acceptor-keytab option to test_context.c
Stefan Metzmacher [Tue, 12 Nov 2019 15:14:50 +0000 (16:14 +0100)]
lib/gssapi: add --iterate-acceptor-keytab option to test_context.c

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi/krb5: add GSS_KRB5_CRED_ITERATE_ACCEPTOR_KEYTAB_X
Stefan Metzmacher [Thu, 22 Aug 2019 08:30:01 +0000 (10:30 +0200)]
lib/gssapi/krb5: add GSS_KRB5_CRED_ITERATE_ACCEPTOR_KEYTAB_X

This allows krb5_rd_req_in_set_iterate_keytab() to be used via the
gssapi layer.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/krb5: add krb5_rd_req_in_set_iterate_keytab()
Stefan Metzmacher [Sat, 20 Jul 2019 10:15:04 +0000 (10:15 +0000)]
lib/krb5: add krb5_rd_req_in_set_iterate_keytab()

A caller might not know the kvno maintained by the KDC.
And most often there's need to know it.

So this function makes it possible to force the keytab
iteration in order to get a consistent behavior.
Otherwise it's possible to get a different behavior
if the guessed kvno in the keytab accidentally matches
the kvno of the ticket and we'll give up if the
key is not able to decrypt the ticket.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/krb5: let krb5_rd_req_ctx() fallback only on KRB5KRB_AP_ERR_BAD_INTEGRITY
Stefan Metzmacher [Sat, 20 Jul 2019 10:15:04 +0000 (10:15 +0000)]
lib/krb5: let krb5_rd_req_ctx() fallback only on KRB5KRB_AP_ERR_BAD_INTEGRITY

This avoids hidding a real error like KRB5KRB_AP_ERR_ILL_CR_TKT.

We only want to retry with the next key if the decryption
failed.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/gss: add tests to demonstrate problems with kvno missmatches in keytabs
Stefan Metzmacher [Tue, 12 Nov 2019 14:48:20 +0000 (15:48 +0100)]
tests/gss: add tests to demonstrate problems with kvno missmatches in keytabs

The kvno numbering can differ between KDC and acceptor, that should not
be a problem. As often the kvno is internal to the KDC. Active Directory
KDCs don't provide a reliable way for a principal to request its own
current kvno (access to the msDS-KeyVersionNumber attribute is not
reliable available!).

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/gss: test with acceptor skip transit check
Isaac Boukris [Mon, 7 Oct 2019 08:44:32 +0000 (11:44 +0300)]
tests/gss: test with acceptor skip transit check

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

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi: add --acceptor-skip-transit-check option to test_context.c
Stefan Metzmacher [Thu, 29 Aug 2019 13:38:11 +0000 (15:38 +0200)]
lib/gssapi: add --acceptor-skip-transit-check option to test_context.c

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi/krb5: add GSS_KRB5_CRED_SKIP_TRANSIT_CHECK_X
Stefan Metzmacher [Fri, 18 Aug 2017 13:33:17 +0000 (15:33 +0200)]
lib/gssapi/krb5: add GSS_KRB5_CRED_SKIP_TRANSIT_CHECK_X

This allows KRB5_VERIFY_AP_REQ_SKIP_TRANSITED_CHECK (on the acceptor)
to be controlled via the gssapi layer.

Members of Active Directory domains should just rely on there
KDCs (domain controllers) to do SID-Filtering (and name checking)
on trust boundaries, I have verified this with a modified Samba KDC
and a Windows 2012R2 DC. The Windows DC rejects invalid cross-realm tickets
with KRB5KDC_ERR_POLICY, before generating a new (service or referral)
ticket. So any service ticket is already policy checked by the KDC
even if this does not result in setting the transited_policy_checked in the ticket.

This means an accepting service can tell gss_accept_sec_context()
to skip any transited checking, as the trust topoligy is only
fully known to the KDC anyway.

The detailed background for this can be found in the bug report
and the mailing list:
https://lists.samba.org/archive/samba-technical/2019-September/thread.html#134285
https://lists.samba.org/archive/samba-technical/2019-November/thread.html#134553
http://mailman.mit.edu/pipermail/krbdev/ should also have references.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/krb5: add [libdefaults] acceptor_skip_transit_check and KRB5_VERIFY_AP_REQ_SKIP_T...
Stefan Metzmacher [Fri, 18 Aug 2017 13:33:17 +0000 (15:33 +0200)]
lib/krb5: add [libdefaults] acceptor_skip_transit_check and KRB5_VERIFY_AP_REQ_SKIP_TRANSITED_CHECK

In active directory a domain member replies on (trusts) the [K]DCs
of the domain. It's the job of the [K]DCs to only generate useful
tickets as they know about the trust topology.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/krb5: add krb5_rd_req_in_set_verify_ap_req_flags()
Stefan Metzmacher [Fri, 18 Aug 2017 13:33:17 +0000 (15:33 +0200)]
lib/krb5: add krb5_rd_req_in_set_verify_ap_req_flags()

In the next commits we want to be able to pass down
things like KRB5_VERIFY_AP_REQ_NO_TRANSITED_CHECK.

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi: make use of gss_acquire_cred_from() in test_context.c
Stefan Metzmacher [Thu, 29 Aug 2019 13:38:11 +0000 (15:38 +0200)]
lib/gssapi: make use of gss_acquire_cred_from() in test_context.c

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

Pair-Programmed-With: Isaac Boukris <iboukris@gmail.com>

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi: maintain a global acceptor_cred in test_context.c
Stefan Metzmacher [Thu, 29 Aug 2019 13:38:11 +0000 (15:38 +0200)]
lib/gssapi: maintain a global acceptor_cred in test_context.c

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

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/gss: add transited trust gss tests
Isaac Boukris [Mon, 7 Oct 2019 08:44:32 +0000 (11:44 +0300)]
tests/gss: add transited trust gss tests

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

Pair-Programmed-With: Stefan Metzmacher <metze@samba.org>

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agokdc: add transited-policy option always-disabled
Isaac Boukris [Mon, 7 Oct 2019 08:45:31 +0000 (11:45 +0300)]
kdc: add transited-policy option always-disabled

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

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
2 years agotests/gss: let "make -C tests/gss check TESTS=check-context" work alone
Stefan Metzmacher [Tue, 12 Nov 2019 12:14:24 +0000 (13:14 +0100)]
tests/gss: let "make -C tests/gss check TESTS=check-context" work alone

Without this it only works in combination, e.g.

make -C tests/gss check TESTS="check-basic check-context"

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agolib/gssapi/oid.txt: fix comment and regenerate gssapi_oid.h
Stefan Metzmacher [Mon, 5 Jul 2021 11:04:39 +0000 (13:04 +0200)]
lib/gssapi/oid.txt: fix comment and regenerate gssapi_oid.h

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2 years agoFix spelling/grammar in various PKINIT messages
Robert Crowston [Thu, 14 Oct 2021 23:01:16 +0000 (00:01 +0100)]
Fix spelling/grammar in various PKINIT messages

Only error messages and code comments touched.

2 years agokdc: Fix check-pkinit UPN test misquoting
Nicolas Williams [Fri, 15 Oct 2021 18:59:07 +0000 (13:59 -0500)]
kdc: Fix check-pkinit UPN test misquoting

2 years agohdb: update HDB_F_SYNTHETIC_OK description
Luke Howard [Fri, 15 Oct 2021 00:12:06 +0000 (11:12 +1100)]
hdb: update HDB_F_SYNTHETIC_OK description

Note that HDB_F_SYNTHETIC_OK is also used for GSS-API pre-authentication as
well as PKINIT.

Fixes: #812
2 years agobase: Fix leak on ENOMEM
Nicolas Williams [Mon, 11 Oct 2021 02:35:48 +0000 (21:35 -0500)]
base: Fix leak on ENOMEM

2 years agokdc: Fix leak and loss of kdc_check_flags() reason
Nicolas Williams [Mon, 11 Oct 2021 02:36:28 +0000 (21:36 -0500)]
kdc: Fix leak and loss of kdc_check_flags() reason

We were losing and leaking the reason for which kdc_check_flags() was
rejecting any S4U requests, yielding incomplete error messages.

The issue is that kdc_check_flags() wants to check the client and server
principals in the input state structure, but doesn't know about
impersonated principal name, and so we want to pass it a state structure
that has the impersonated instead of the impersonator client name.  This
is a bad design, but I'm ignoring that for now and just fixing this one
leak.

2 years agokdc: Fix leak on TGS referral
Nicolas Williams [Mon, 11 Oct 2021 02:18:51 +0000 (21:18 -0500)]
kdc: Fix leak on TGS referral

2 years agokrb5: Fix PAC signature leak affecting KDC
Nicolas Williams [Mon, 11 Oct 2021 02:55:59 +0000 (21:55 -0500)]
krb5: Fix PAC signature leak affecting KDC

2 years agokrb5: Document TGS HDB entry alias referral feature
Nicolas Williams [Fri, 8 Oct 2021 07:23:44 +0000 (02:23 -0500)]
krb5: Document TGS HDB entry alias referral feature

2 years agokdc: Test referrals via HDB entry aliases
Nicolas Williams [Fri, 8 Oct 2021 07:02:17 +0000 (02:02 -0500)]
kdc: Test referrals via HDB entry aliases

When a principal name is an alias of another in a different realm, the
KDC will return a referral to that realm.  Test that.

2 years agokadmin: Add add_alias, del_alias
Nicolas Williams [Thu, 7 Oct 2021 02:59:43 +0000 (21:59 -0500)]
kadmin: Add add_alias, del_alias

2 years agohdb: Support referrals via aliases
Nicolas Williams [Thu, 7 Oct 2021 03:06:46 +0000 (22:06 -0500)]
hdb: Support referrals via aliases

The TGS will issue referrals based on [domain_realm] mappings.

With this change the TGS will also issue referrals based on HDB entry
aliases.

The TGS needed no changes for this, only support in lib/hdb was missing.

All we had to do was return HDB_ERR_WRONG_REALM from hdb_fetch_kvno()
when the given principal is an alias and its canonical name's realm is
different from the alias'.

This feature is important because the KDC currently does not re-read
krb5.conf and must be restarted for changes to e.g., [domain_realm]
mappings to take effect.  As well, making krb5.conf changes to all the
KDCs for a realm would need to be arranged.  But with aliases in the
HDB, these problems go away.

Relatedly, we should really have an option to store the KDC's entire
configuration in the HDB...

Futures:

 - Add support for aliasing of entire namespaces via HDB aliases with
   WELLKNOWN namespace name forms.  This will round out domain-to-realm
   mapping configuration support via HDB.

2 years agohdb: Deleting aliases corrupts iprop log
Nicolas Williams [Fri, 8 Oct 2021 23:09:24 +0000 (18:09 -0500)]
hdb: Deleting aliases corrupts iprop log

Deleting an alias causes the HDB_entry_alias entry value encoding to be
written to the iprop log, which later cannot be decoded as an HDB_entry.
Meanwhile, the alias is removed from the HDB but not from the list of
aliases in the canonical principal's HDB entry.

This commit makes deletion of alias names an error.

2 years agokadm5: Fix KRB5_TL_LAST_PWD_CHANGE handling
Nicolas Williams [Fri, 8 Oct 2021 07:01:29 +0000 (02:01 -0500)]
kadm5: Fix KRB5_TL_LAST_PWD_CHANGE handling

2 years agokadm5: Teach perform_tl_data() about aliases
Nicolas Williams [Fri, 8 Oct 2021 07:00:53 +0000 (02:00 -0500)]
kadm5: Teach perform_tl_data() about aliases

Sort of.  It already knew.

We have a mess where new things get sent to the server as
KRB5_TL_EXTENSION, but old things get sent to the client as whatever
appropriate KRB5_TL we have, and... we call perform_tl_data() on all TL,
but we don't remove unmodified TL on the client side, and...

Anyways.  This commit is a band-aid, but it works.

2 years agokrb5: Fix krb5.conf.5 man page bug
Nicolas Williams [Fri, 8 Oct 2021 07:23:26 +0000 (02:23 -0500)]
krb5: Fix krb5.conf.5 man page bug

2 years agogss: _gss_spnego_set_sec_context_option return
Luke Howard [Mon, 11 Oct 2021 03:57:09 +0000 (14:57 +1100)]
gss: _gss_spnego_set_sec_context_option return

Fix _gss_spnego_set_sec_context_option() to return GSS_S_UNAVAILABLE if no
context handle is provided, so that mechglue will skip to the next mechanism.
There are no globally settable options on SPNEGO itself.

Fixes: #803
2 years agotests: fix recent test from using system klist
Isaac Boukris [Thu, 7 Oct 2021 12:36:14 +0000 (15:36 +0300)]
tests: fix recent test from using system klist

Closes: #842
2 years agokrb5: skip cache check in S4U2Proxy requests
Isaac Boukris [Mon, 27 Sep 2021 23:55:00 +0000 (02:55 +0300)]
krb5: skip cache check in S4U2Proxy requests

2 years agogss_preauth: remove protocol changes section from README
Luke Howard [Thu, 23 Sep 2021 21:38:10 +0000 (07:38 +1000)]
gss_preauth: remove protocol changes section from README

Heimdal implements draft-perez-krb-wg-gss-preauth-03 without protocol changes
(the draft was updated to match the implementation)

2 years agotests: ticket acquired by AS cannot be used as evidence
Isaac Boukris [Thu, 23 Sep 2021 12:07:03 +0000 (15:07 +0300)]
tests: ticket acquired by AS cannot be used as evidence

2 years agotests: check PAC client name in the non-canon case
Isaac Boukris [Thu, 23 Sep 2021 11:51:19 +0000 (14:51 +0300)]
tests: check PAC client name in the non-canon case

and fixed the existing test to match the actual behavior,
I think it used to fail just because it used enterprise name
style without specifying it.

2 years agodoc: add draft-perez-krb-wg-gss-preauth-03.txt
Luke Howard [Thu, 23 Sep 2021 09:16:22 +0000 (19:16 +1000)]
doc: add draft-perez-krb-wg-gss-preauth-03.txt

draft-perez-krb-wg-gss-preauth-03.txt documents the version of GSS-API
pre-authentication implemented by Heimdal at the point of this commit.

2 years agokdc: correctly generate PAC TGS signature
Luke Howard [Thu, 23 Sep 2021 07:51:51 +0000 (17:51 +1000)]
kdc: correctly generate PAC TGS signature

When generating an AS-REQ, the TGS signature was incorrectly generated using
the server key, which would fail to validate if the server was not also the
TGS. Fix this.

Patch from Isaac Bourkis <iboukris@gmail.com>.

2 years agokdc: move _kdc_verify_checksum() to misc.c
Luke Howard [Thu, 23 Sep 2021 07:41:43 +0000 (17:41 +1000)]
kdc: move _kdc_verify_checksum() to misc.c

2 years agokdc: use ticket client name when signing PAC
Luke Howard [Thu, 23 Sep 2021 04:39:35 +0000 (14:39 +1000)]
kdc: use ticket client name when signing PAC

The principal in the PAC_LOGON_NAME buffer is expected to match the client name
in the ticket. Previously we were setting this to the canonical client name,
which would have broken PAC validation if the client did not request name
canonicalization

2 years agoroken: fix theoretical leak introduced in 7fbe7be6
Luke Howard [Thu, 23 Sep 2021 00:32:45 +0000 (10:32 +1000)]
roken: fix theoretical leak introduced in 7fbe7be6

split_spec() should free output parameters if it fails. This was not a leak in
practice because its single caller cleaned up anyway, but cleaning up for good
hygiene.

2 years agovarious: squash MSVC uninitialized variable warnings (C4701)
Luke Howard [Mon, 13 Sep 2021 13:32:09 +0000 (23:32 +1000)]
various: squash MSVC uninitialized variable warnings (C4701)

Initialize some variables to silence some false positive MSVC warnings.

2 years agoasn1: initialize L in ASN1_MALLOC_ENCODE
Luke Howard [Mon, 13 Sep 2021 14:25:10 +0000 (00:25 +1000)]
asn1: initialize L in ASN1_MALLOC_ENCODE

MSVC complains about uninitialized variables, set (L) to zero in failure case
from ASN1_MALLOC_ENCODE()

2 years agokrb5: return KRB5KRB_AP_ERR_INAPP_CKSUM if PAC checksum fails
Luke Howard [Fri, 17 Sep 2021 03:57:57 +0000 (13:57 +1000)]
krb5: return KRB5KRB_AP_ERR_INAPP_CKSUM if PAC checksum fails

Return KRB5KRB_AP_ERR_INAPP_CKSUM instead of EINVAL when verifying a PAC, if
the checksum is absent or unkeyed.

2 years agokdc: map KRB5_PROG_SUMTYPE_NOSUPP to KRB5KDC_ERR_SUMTYPE_NOSUPP
Luke Howard [Tue, 21 Sep 2021 08:09:25 +0000 (18:09 +1000)]
kdc: map KRB5_PROG_SUMTYPE_NOSUPP to KRB5KDC_ERR_SUMTYPE_NOSUPP

RFC4120 says KRB5KDC_ERR_SUMTYPE_NOSUPP should be returned if the KDC does not
support a given checksum type. Return this instead of KRB5_PROG_SUMTYPE_NOSUPP
by introducing a new wrapper function, _kdc_verify_checksum().

2 years agokrb5: make keyed checksums mandatory where possible
Luke Howard [Fri, 17 Sep 2021 01:03:35 +0000 (11:03 +1000)]
krb5: make keyed checksums mandatory where possible

Make keyed checksums mandatory when generating and verifying checksums, with
the following exceptions:

* the checksum is being generated or verified as part of encrypting data for
  a legacy (DES) encryption type

* the KRB5_CRYPTO_FLAG_ALLOW_UNKEYED_CHECKSUM flag was set on the crypto
  context, used to allow unkeyed checksums in krb5 authenticators

By making unkeyed checksums opt-in, we eliminate a class of potential
vulnerabilities where callers could pass unkeyed checksums.

Any code that uses the mandatory checksum type for a given non-legacy
encryption type should not be affected by this change. It could potentially
break, say, a client trying to do FAST with DES keys but, that should not be
supported (because FAST KDCs also support AES).

Closes: #835
2 years agoroken: check strdup succeeds in roken_gethostby_setup()
Luke Howard [Mon, 20 Sep 2021 07:58:19 +0000 (17:58 +1000)]
roken: check strdup succeeds in roken_gethostby_setup()

Closes: #824
2 years agokrb5: rework PAC validation loop
Isaac Boukris [Sun, 19 Sep 2021 12:16:58 +0000 (15:16 +0300)]
krb5: rework PAC validation loop

Avoid allocating the PAC on error.

Closes: #836
2 years agokrb5: allow NULL parameter to krb5_pac_free()
Isaac Boukris [Sun, 19 Sep 2021 12:04:14 +0000 (15:04 +0300)]
krb5: allow NULL parameter to krb5_pac_free()

2 years agokrb5: fix test_pac format string
Luke Howard [Sun, 19 Sep 2021 04:01:04 +0000 (14:01 +1000)]
krb5: fix test_pac format string

Don't pass a potentially (although in reality, not) untrusted string to
krb5_err(); cleanup error handling.

2 years agokrb5: add pac ticket-signature unit tests
Isaac Boukris [Mon, 23 Aug 2021 23:28:22 +0000 (02:28 +0300)]
krb5: add pac ticket-signature unit tests

2 years agokdc: sign ticket using Windows PAC
Isaac Boukris [Fri, 13 Aug 2021 09:44:37 +0000 (12:44 +0300)]
kdc: sign ticket using Windows PAC

Split Windows PAC signing and verification logic, as the signing has to be when
the ticket is ready.

Create sign and verify the PAC KDC signature if the plugin did not, allowing
for S4U2Proxy to work, instead of KRB5SignedPath.

Use the header key to verify PAC server signature, as the same key used to
encrypt/decrypt the ticket should be used for PAC server signature, like U2U
tickets are signed witht the tgt session-key and not with the longterm key,
and so krbtgt should be no different and the header key should be used.

Lookup the delegated client in DB instead of passing the delegator DB entry.

Add PAC ticket-signatures and related functions.

Note: due to the change from KRB5SignedPath to PAC, S4U2Proxy requests
against new KDC will not work if the evidence ticket was acquired from
an old KDC, and vide versa.

Closes: #767
2 years agokdc: remove KRB5SignedPath, to be replaced with PAC
Isaac Boukris [Mon, 28 Dec 2020 20:07:10 +0000 (22:07 +0200)]
kdc: remove KRB5SignedPath, to be replaced with PAC

KRB5SignedPath was a Heimdal-specific authorization data element used to
protect the authenticity of evidence tickets when used in constrained
delegation (without a Windows PAC).

Remove this, to be replaced with the Windows PAC which itself now supports
signing the entire ticket in the TGS key.

2 years agotests: default verify_pac to true in test_ap-req
Isaac Boukris [Wed, 14 Jul 2021 14:09:06 +0000 (17:09 +0300)]
tests: default verify_pac to true in test_ap-req

2 years agotests: fix a typo in test_ap_req
Isaac Boukris [Wed, 14 Jul 2021 12:23:11 +0000 (15:23 +0300)]
tests: fix a typo in test_ap_req

2 years agotests: add PAC test for CVE-2020-17049 (bronze bit)
Isaac Boukris [Tue, 13 Jul 2021 11:03:30 +0000 (14:03 +0300)]
tests: add PAC test for CVE-2020-17049 (bronze bit)

2 years agotests: add S4U2Proxy test with foreign client
Isaac Boukris [Fri, 13 Aug 2021 11:22:43 +0000 (14:22 +0300)]
tests: add S4U2Proxy test with foreign client

Add S4U2Proxy test with foreign client and evidence ticket acquired via TGS

2 years agotests: add S4U2Proxy tests with TGS evidence ticket
Isaac Boukris [Sun, 9 Jun 2019 22:51:55 +0000 (22:51 +0000)]
tests: add S4U2Proxy tests with TGS evidence ticket

This was broken with KRB5SignedPath but now that we switch to PAC
we get it fixed without KDC changes, so we can just test it.

See also PR #599 from where these tests were taken.

2 years agokrb5: specify krb5_enomem() calling convention
Luke Howard [Thu, 16 Sep 2021 04:59:25 +0000 (14:59 +1000)]
krb5: specify krb5_enomem() calling convention

krb5_enomem() was lacking a calling convention decoration, breaking Windows
consumers if __cdecl was not the default calling convention. Add KRB5_LIB_CALL
to make it consistent with other library functions.

Closes: #834
2 years agoroken: Improve test-getuserinfo
Nicolas Williams [Wed, 15 Sep 2021 21:05:30 +0000 (16:05 -0500)]
roken: Improve test-getuserinfo

2 years agoroken: Do not pass NULL to getpwnam_r()
Nicolas Williams [Wed, 15 Sep 2021 15:41:32 +0000 (10:41 -0500)]
roken: Do not pass NULL to getpwnam_r()

2 years agoasn1: Also decode ProxyCertInfo
Nicolas Williams [Wed, 15 Sep 2021 15:46:03 +0000 (10:46 -0500)]
asn1: Also decode ProxyCertInfo

2 years agokdc: don't leak sec_context_token on checksum fail
Luke Howard [Mon, 13 Sep 2021 09:51:58 +0000 (19:51 +1000)]
kdc: don't leak sec_context_token on checksum fail

When validating the KDC-REQ-BODY checksum introduced in 0ed4d90a, don't leak
the sec_context_token retrieved from the FX-COOKIE if checksum verifications
fails.

2 years agokrb5: KRB5_KRBHST_TKTBRIDGEAP
Luke Howard [Tue, 10 Aug 2021 09:18:36 +0000 (19:18 +1000)]
krb5: KRB5_KRBHST_TKTBRIDGEAP

Add a new krbhst type, KRB5_KRBHST_TKTBRIDGEAP to krb5_krbhst_init_flags(),
that looks for the DNS SRV record kerberos-tkt-bridge. This is to support a new
PADL project.

2 years agokdc: validate KDC-REQ-BODY invariance in GSS preauth
Luke Howard [Mon, 13 Sep 2021 06:17:18 +0000 (16:17 +1000)]
kdc: validate KDC-REQ-BODY invariance in GSS preauth

Whilst channel bindings are used to bind the KDC-REQ-BODY to the GSS-API
context, we need to also bind the KDC-REQ-BODY across multiple requests in a
pre-authentication conversation.

Do this by making a digest of the first KDC-REQ-BODY (with the nonce zeroed, as
this may change), and verifying it in each subsequent request.

2 years agokrb5: add unkeyed SHA-2 checksum types
Luke Howard [Mon, 13 Sep 2021 07:07:13 +0000 (17:07 +1000)]
krb5: add unkeyed SHA-2 checksum types

Add unkeyed checksum types for SHA-256, SHA-384 and SHA-512, for future
internal use. They are assigned private (negative) checksum types and must
never appear in cleartext on the wire.

2 years agokdc: avoid re-encoding KDC-REQ-BODY
Luke Howard [Mon, 13 Sep 2021 03:50:45 +0000 (13:50 +1000)]
kdc: avoid re-encoding KDC-REQ-BODY

Use --preserve-binary=KDC-REQ-BODY option to ASN.1 compiler to avoid
re-encoding KDC-REQ-BODYs for verification in GSS preauth, TGS and PKINIT.

2 years agoRevert "krb5: zero nonce before encoding for GSS preauth"
Luke Howard [Mon, 13 Sep 2021 03:39:58 +0000 (13:39 +1000)]
Revert "krb5: zero nonce before encoding for GSS preauth"

This reverts commit 34b374b5e4c9097fdb94e8c34fb973352e687faa.

We are revising the GSS-API pre-authentication draft to include the nonce from
the first request in the GSS channel bindings, to avoid re-encoding issues that
may surface with Kerberos implementations that do not correctly implement DER.

2 years agoyyerror: update to POSIX standard
heitbaum [Thu, 9 Sep 2021 14:28:16 +0000 (00:28 +1000)]
yyerror: update to POSIX standard

To comply with the latest POSIX standard, in Yacc compatibility mode
(options `-y`/`--yacc`) Bison now generates prototypes for yyerror and
yylex.  In some situations, this is breaking compatibility: if the user
has already declared these functions but with some differences (e.g., to
declare them as static, or to use specific attributes), the generated
parser will fail to compile.  To disable these prototypes, #define yyerror
(to `yyerror`), and likewise for yylex.

refer: https://git.savannah.gnu.org/cgit/bison.git/tree/NEWS

GNU Bison 3.8

2 years agoappveyor: Fix build
heitbaum [Thu, 9 Sep 2021 21:49:21 +0000 (07:49 +1000)]
appveyor: Fix build

Update from bison 3.5 to 3.5.4 which is available at the repositories

2 years agodoc: use top-level Wiki URL
Luke Howard [Wed, 8 Sep 2021 02:25:37 +0000 (12:25 +1000)]
doc: use top-level Wiki URL

Top-level Wiki URL at https://github.com/heimdal/heimdal/wiki is a better
starting point for build instructions.

2 years agodoc: update build instructions URL
Luke Howard [Wed, 8 Sep 2021 02:22:25 +0000 (12:22 +1000)]
doc: update build instructions URL

h5l.org no longer exists, update build instructions to point to GitHub Wiki

Closes: #773
2 years agokrb5: zero nonce before encoding for GSS preauth
Luke Howard [Tue, 7 Sep 2021 04:31:12 +0000 (14:31 +1000)]
krb5: zero nonce before encoding for GSS preauth

Zero nonce before encoding KDC-REQ-BODY to be used as channel binding
application data in GSS-API pre-authentication. This is because the nonce may
change between AS-REQs and the channel binding data should be invariant between
calls to GSS_Init_sec_context().

2 years agoCheck CLANG_FORMAT is executable.
Robert Crowston [Wed, 18 Aug 2021 14:18:01 +0000 (15:18 +0100)]
Check CLANG_FORMAT is executable.

If clang-format is not available, AC_CHECK_PROG sets CLANG_FORMAT=no,
not empty string. This results in an error at build time for those
without clang-format installed. Instead check if the program is
executable.

2 years agoOnly #include <malloc.h> if it is available.
Robert Crowston [Fri, 20 Aug 2021 15:02:38 +0000 (16:02 +0100)]
Only #include <malloc.h> if it is available.

e.g., OpenBSD does not provide this header.

2 years agokrb5: update krb5.conf(5) with RFC8009 enctypes
Luke Howard [Mon, 6 Sep 2021 03:31:03 +0000 (13:31 +1000)]
krb5: update krb5.conf(5) with RFC8009 enctypes

Add aes256-cts-hmac-sha384-192 and aes128-cts-hmac-sha256-128 to krb5.conf(5).

Closes #815.

2 years agogss: implement gss_krb5_ccache_name()
Luke Howard [Mon, 6 Sep 2021 03:22:53 +0000 (13:22 +1000)]
gss: implement gss_krb5_ccache_name()

Correctly implement gss_krb5_ccache_name() in terms of
gss_set_sec_context_option(GSS_KRB5_CCACHE_NAME_X). The previous implementation
was a NOOP.

Note: global ccache name should really be thread-specific rather than global.

Closes #803.

2 years agokdc: correct logic error in altsecid_gss_preauth_authorizer
Luke Howard [Tue, 31 Aug 2021 11:06:32 +0000 (11:06 +0000)]
kdc: correct logic error in altsecid_gss_preauth_authorizer

check for the absence, not presence, of a GSS credential before acquiring one

2 years agokdc: add sample GSS preauth authorization plugin
Luke Howard [Tue, 31 Aug 2021 07:58:07 +0000 (07:58 +0000)]
kdc: add sample GSS preauth authorization plugin

Add a sample GSS preauth authorization plugin, which will be built and
installed if OpenLDAP is available, but otherwise not enabled (by virtue of not
being installed into the plugin directory).

The plugin authorizes federated GSS preauth clients by querying an Active
Directory domain controller for the altSecurityIdentities attribute.

Once the user entry is found, the name is canonicalized by reading the
sAMAccountName attribute and concatenating it with the KDC realm.

2 years agogss_preauth: Fix build race
Nicolas Williams [Sun, 29 Aug 2021 18:50:39 +0000 (13:50 -0500)]
gss_preauth: Fix build race

2 years agogss_preauth: fix header dependency
Luke Howard [Sat, 28 Aug 2021 06:35:05 +0000 (16:35 +1000)]
gss_preauth: fix header dependency

2 years agogss_preauth: remove gss_preauth.h
Luke Howard [Fri, 27 Aug 2021 09:51:32 +0000 (19:51 +1000)]
gss_preauth: remove gss_preauth.h

Remove gss_preauth.h, it is now auto-generated.

2 years agoasn1: correctly check gmtime_s() return value
Luke Howard [Fri, 27 Aug 2021 06:08:54 +0000 (16:08 +1000)]
asn1: correctly check gmtime_s() return value

gmtime_s(), used on Windows, returns an errno_t not a struct tm *.

The previous code caused strftime() to dereference a NULL struct tm *.

2 years agogss: move GSS pre-auth helpers to convenience lib
Luke Howard [Fri, 27 Aug 2021 04:20:01 +0000 (14:20 +1000)]
gss: move GSS pre-auth helpers to convenience lib

GSS pre-auth helpers do not belong in libgssapi, so move them to a separate
convenience library.

2 years agokdc: fix _kdc_set_e_text argument in previous commit
Luke Howard [Fri, 27 Aug 2021 05:11:54 +0000 (15:11 +1000)]
kdc: fix _kdc_set_e_text argument in previous commit

"r" is the realm, not the TGS request; that is priv

2 years agokdc: KRB5KDC_ERR_{C,S}_PRINCIPAL_UNKNOWN if missing field
Luke Howard [Fri, 27 Aug 2021 01:44:21 +0000 (11:44 +1000)]
kdc: KRB5KDC_ERR_{C,S}_PRINCIPAL_UNKNOWN if missing field

If missing cname or sname in AS-REQ, return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN and
KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN. This matches MIT behaviour.

2 years agokdc: validate sname in TGS-REQ
Luke Howard [Fri, 27 Aug 2021 01:42:48 +0000 (11:42 +1000)]
kdc: validate sname in TGS-REQ

In tgs_build_reply(), validate the server name in the TGS-REQ is present before
dereferencing.

2 years agoRevert "gss: Fix leak of output_token in GSS PA"
Nicolas Williams [Thu, 26 Aug 2021 06:06:33 +0000 (01:06 -0500)]
Revert "gss: Fix leak of output_token in GSS PA"

This reverts commit 041907d51794f44ba3d1a52163c61108eb9a39e1.

2 years agohx509: For times before 2050 use UTCTime (fix pasto)
Nicolas Williams [Thu, 26 Aug 2021 03:49:14 +0000 (22:49 -0500)]
hx509: For times before 2050 use UTCTime (fix pasto)

2 years agogss: Fix leak of output_token in GSS PA
Nicolas Williams [Thu, 26 Aug 2021 03:53:33 +0000 (22:53 -0500)]
gss: Fix leak of output_token in GSS PA

2 years agoAvoid -Werror=address by skipping pointless _mg_buffer_zero()
Andrew Bartlett [Wed, 25 Aug 2021 23:22:46 +0000 (11:22 +1200)]
Avoid -Werror=address by skipping pointless _mg_buffer_zero()

We do not need to zero out the local variable output_token
if we do not later call gss_release_buffer() on it.

This aovids a -Werror=address compile failure under the
strict compiler options Samba uses when compiled on Ubuntu
20.04 with gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

In file included from ../../source4/heimdal/lib/gssapi/preauth/pa_client.c:34:
../../source4/heimdal/lib/gssapi/preauth/pa_client.c:148:21: error: the address of ‘output_token’ will always evaluate as ‘true’ [-Werror=address]
  148 |     _mg_buffer_zero(&output_token);
      |                     ^
../../source4/heimdal/lib/gssapi/mech/mech_locl.h:72:7: note: in definition of macro ‘_mg_buffer_zero’
   72 |   if (buffer) {   \
      |       ^~~~~~

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2 years agohx509: Use preferred attribute string types
Nicolas Williams [Wed, 25 Aug 2021 22:00:12 +0000 (17:00 -0500)]
hx509: Use preferred attribute string types

The DC (domainComponent) attribute wants to be an IA5String.

This really doesn't matter, but if we want to conform to the spec (RFC 4519,
referenced by RFC 5280), then we have to do this.

2 years agohx509: For times before 2050 use UTCTime
Nicolas Williams [Wed, 25 Aug 2021 21:48:10 +0000 (16:48 -0500)]
hx509: For times before 2050 use UTCTime

2 years agoasn1: Update comment in rfc2459.asn1
Nicolas Williams [Wed, 25 Aug 2021 20:42:24 +0000 (15:42 -0500)]
asn1: Update comment in rfc2459.asn1

2 years agogss: Fix build for GSS preauth helpers
Nicolas Williams [Wed, 25 Aug 2021 20:41:35 +0000 (15:41 -0500)]
gss: Fix build for GSS preauth helpers

2 years agokrb5: export krb5_set_log_dest()
Luke Howard [Tue, 17 Aug 2021 02:42:43 +0000 (12:42 +1000)]
krb5: export krb5_set_log_dest()

krb5_set_log_dest() was not exported. Export it.

2 years agogss: check for NULL before calling dlclose()
Luke Howard [Thu, 19 Aug 2021 10:39:58 +0000 (10:39 +0000)]
gss: check for NULL before calling dlclose()

Calling dlclose(NULL) on some recent versions of Linux appears to cause the
process to segfault.

2 years agokrb5: fix prototype in pa_gss_finish()
Luke Howard [Tue, 17 Aug 2021 22:17:04 +0000 (08:17 +1000)]
krb5: fix prototype in pa_gss_finish()

Fix merge issue that arose after merging another fix from the
lukeh/gss-preauth-apple branch.