Commit Graph

29690 Commits

Author SHA1 Message Date
Isaac Boukris
f84a98bd5f Add client_aware_channel_bindings option
Add client support for KERB_AP_OPTIONS_CBT from MS-KILE.
2021-08-06 13:15:19 +10:00
Isaac Boukris
a4527a28a3 Implement KERB_AP_OPTIONS_CBT (server side)
if the client asserted knowledge of channel-bindings by
passing KERB_AP_OPTIONS_CBT, and the server passed bindings,
require the bindings to match.
2021-08-06 13:15:19 +10:00
Isaac Boukris
51ce4c8d15 gssapi: add channel-bound return flag
In gss_accept_sec_context, return a new flag to let
the caller know that bindings were provided and verified.
2021-08-06 13:15:19 +10:00
Andrew Bartlett
33fccb8bbe heimdal: Match windows and return KRB5KDC_ERR_CLIENT_REVOKED when the account is locked out
Windows does not check the password on an account that has been locked.

Heimdal does not implement locked_out, however the Samba hdb
backend does, and needs this checked before passwords (for bad
password lockout), not after in kdc_check_access().

Based on work to update Samba to current Heimdal by
Gary Lockyer <gary@catalyst.net.nz> and including cherry-pick of
Samba commit 580a705b83014e94556b9d5a8877406816e02190 which noted
that we need to return KRB5KDC_ERR_CLIENT_REVOKED to match Windows.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-06 12:48:12 +10:00
Andrew Bartlett
f03983b64d HEIMDAL: Require armor_server to be a krbtgt name, not just a server name
Samba has a different lookup path for krbtgt/ principals.

armor_server is in this case the same as the server in a normal
TGS-REQ, just inside the FAST armor, so needs to have the same
lookup properties as the TGS-REQ does.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-06 12:43:17 +10:00
Andrew Bartlett
61f1be93e3 kdc: Provide flag to hint to KDC that this is a FAST key lookup
For Samba the fast key is not stored in the replicated DB, so
this helps Samba find it in the Samba hdb module.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-06 12:43:17 +10:00
Luke Howard
5ba7f270eb kdc: return revoked error if principal locked out
According to #788, Windows clients expect a revoked error to be returned if the
client or service is locked out, rather than a generic policy error. This
should not affect non-Windows paths as the locked_out HDB entry flag is
otherwise not used by Heimdal.
2021-08-06 12:34:52 +10:00
Andrew Bartlett
75829cad18 Avoid -Werror=strict-overflow on in rk_dns_srv_order()
In a strict Samba build with -Werror=strict-overflow on Ubuntu 18.04
with gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
we see

../../source4/heimdal/lib/roken/resolve.c: In function ‘rk_dns_srv_order’:
../../source4/heimdal/lib/roken/resolve.c:639:7: error: assuming signed overflow does not occur when simplifying conditional to constant [-Werror=strict-overflow]
     if(num_srv == 0)
       ^
cc1: all warnings being treated as errors

This avoids the issue by additionally setting a distinct flag.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-06 12:24:04 +10:00
Luke Howard
034bc1649d gss: avoid overflow in gss_inquire_cred()
See #791

Make found a boolean rather than a count of found mechanisms.
2021-08-06 12:23:50 +10:00
Luke Howard
5a56198161 hdb: fix leaks in alias handling
fetch_entry_or_alias() in libhdb failed to free the alias DB value or
principal, causing a leak
2021-08-05 17:08:53 +10:00
Luke Howard
510ee92c11 gss: treat empty cred store as GSS_C_NO_CRED_STORE
In acquire_mech_cred(), treat a credential store with no elements as equivalent
to GSS_C_NO_CRED_STORE, allowing a mechanism's gss_acquire_cred()
implementation to be called.
2021-08-05 15:53:18 +10:00
Luke Howard
3604497fda kdc: zero KDCFastState padata before free 2021-08-04 18:01:48 +10:00
Luke Howard
04e3ea4307 kdc: don't leak FAST req_body checksum buffer
The temporary buffer used to checksum the KDC-REQ body in
_kdc_fast_unwrap_request() was not freed.
2021-08-03 17:30:06 +10:00
Luke Howard
d672e49231 gss: don't leak NTLM cred on failure
Do not leak partially complete credential handle in _gss_ntlm_get_user_cred()
2021-08-02 17:09:55 +10:00
Luke Howard
73224fef5a gss: zero spnego mechanism token error buffer
Ensure mechanism error token buffer, which is allocated on the stack, is zero'd
out before freeing containing ASN.1 structure
2021-08-02 15:55:10 +10:00
Luke Howard
33cc416e36 hx509: don't leak context default_trust_anchors 2021-08-02 15:13:20 +10:00
Luke Howard
221c295d5d gss: honor GM_USE_MG_NAME in gss_accept_sec_context()
GM_USE_MG_NAME was not honored in the case where the mechanism emitted a name,
but the caller of gss_accept_sec_context() did not request it be returned. This
would result in m->gm_release_name() being called on the mechglue name, which
would crash either because that function pointer was NULL or because it would
have expected a mechanism name.
2021-08-01 22:12:25 +10:00
Luke Howard
b8728cae14 asn1: GSER is RFC3641, not RFC2641
Update README.md.
2021-07-09 20:04:56 +10:00
Luke Howard
f72627c3f0 gss: make IS_DCE_STYLE an inline function
To avoid future regressions such as the one corrected in 0dd19003, make
IS_DCE_STYLE() an inline function (rather than a macro) so that its
argument is typed.
2021-07-08 00:00:44 +10:00
Luke Howard
0dd1900308 gss: fix regression in rc4-hmac krb5 DCE unwrap
4b543b7 introduced a regression in the krb5 mechanism's gss_unwrap for
DCE applications, owing to IS_DCE_STYLE() being called with a krb5
instead of mechanism context handle.
2021-07-07 23:51:06 +10:00
Andrew Bartlett
c6df77a2cb Initialise err in hdb_create()
On Ubuntu 20.04 with gcc version 9.3.0 during a strict
Samba build with -Werror=maybe-uninitialized we get:

../../source4/heimdal/lib/hdb/hdb.c: In function ‘hdb_create’:
../../source4/heimdal/lib/hdb/hdb.c:831:13: error: ‘ret’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  831 |     if (*db && ret == 0)
      |         ~~~~^~~~~~~~~~~
cc1: all warnings being treated as errors

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-07-06 10:06:54 +10:00
Andrew Bartlett
2ee8834696 Add const to _kdc_set_e_text()
On Ubuntu 20.04 with gcc version 9.3.0 in a Samba compile
using -Wdiscarded-qualifiers and -Werror we get:

../../source4/heimdal/kdc/kerberos5.c:2516:21: warning: passing argument 2 of ‘_kdc_set_e_text’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
 2516 |  _kdc_set_e_text(r, "Client have no reply key");
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~
../../source4/heimdal/kdc/kerberos5.c:428:42: note: expected ‘char *’ but argument is of type ‘const char *’
  428 | _kdc_set_e_text(astgs_request_t r, char *fmt, ...)
      |                                    ~~~~~~^~~

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-06-30 12:47:41 +10:00
Andrew Bartlett
8caadcd9fc Fix user2user principal (again)
73debbc166 accidentially reverted
the critical part of 040a093654,
presumably during conflict resolution.

Found by a strict Samba compile during import of current Heimdal.

See #780

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-06-30 12:46:18 +10:00
Nicolas Williams
8875cb656b kdc: Fix warnings for synthetic principals 2021-06-29 17:02:17 -05:00
Nicolas Williams
73debbc166 kdc: Audit more TGS failure reasons 2021-06-29 14:52:07 -05:00
Nicolas Williams
855b27ccfb httpkadmind: Allow host SPNs to fetch selves
Combined with the synthetic_clients feature, this will allow hosts that
have a PKINIT-worthy client certificate with a SAN with their host
principals to create their own principals and "extract" their host
keytabs.  Together with some other PKIX credential bootstrapping
protocol, this can help hosts bootstrap Kerberos host credentials.
2021-06-29 14:52:07 -05:00
Nicolas Williams
00358252d3 kdc: Add synthetic PKINIT principals option 2021-06-29 14:52:07 -05:00
Andrew Bartlett
4a5fc6bcde Move out: label to inside #endif of HAVE_DLOPEN
Samba compiles Heimdal internally without HAVE_DLOPEN to keep
to internally supplied mechanisms and plugins.

Samba compiles with strict warning flags and on Ubuntu 20.04
with gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) we see:

../../source4/heimdal/lib/gssapi/mech/gss_mech_switch.c: In function ‘_gss_load_mech’:
../../source4/heimdal/lib/gssapi/mech/gss_mech_switch.c:462:1: error: label ‘out’ defined but not used [-Werror=unused-label]
  462 | out:
      | ^~~
cc1: all warnings being treated as errors

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-06-25 09:44:53 +10:00
Andrew Bartlett
040a093654 Provide the correct principal name to verify_flags() for user2user tickets
When b->kdc_options.enc_tkt_in_skey is set, the variable 'spn'
provided to verify_flags() for the purpose of logging is not
yet set, it is still NULL from the initialiser.

On Samba we see, when compiling with -O3 and strict warning rules with
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04):

$ make -k
PYTHONHASHSEED=1 WAF_MAKE=1  ./buildtools/bin/waf build
Waf: Entering directory `/home/abartlet/heimdal-import/samba/bin/default'
	Selected embedded Heimdal build
[2822/4527] Compiling source4/heimdal/kdc/krb5tgs.c
In function ‘verify_flags’,
    inlined from ‘verify_flags’ at ../../source4/heimdal/kdc/krb5tgs.c:625:1,
    inlined from ‘tgs_build_reply.isra.0’ at ../../source4/heimdal/kdc/krb5tgs.c:1671:8:
../../source4/heimdal/kdc/krb5tgs.c:635:2: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  635 |  kdc_log(context, config, 4, "Ticket not valid (%s)", pstr);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In function ‘verify_flags’,
    inlined from ‘tgs_build_reply.isra.0’ at ../../source4/heimdal/kdc/krb5tgs.c:1671:8:
../../source4/heimdal/kdc/krb5tgs.c:631:2: error: ‘%s’ directive argument is null [-Werror=format-overflow=]
  631 |  kdc_log(context, config, 4, "Ticket expired (%s)", pstr);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Essentially, with an optimising compiler, the funciton is inlined
and the compiler notices that the kdc_log() argument is always NULL.

Based on patches by Stefan Metzmacher <metze@samba.org>
in his master-heimdal branch at:
https://git.samba.org/?p=metze/samba/wip.git;a=commitdiff;h=2ac326b9cb8f896f874edfa6725f087034270322#patch2
https://git.samba.org/?p=metze/samba/wip.git;a=shortlog;h=refs/heads/master-heimdal

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-06-23 11:56:04 +10:00
Nicolas Williams
8ac3452fd7 kadmin: Add missing attributes; sort units
Sorting the units fixes a bug introduced in:

    ae8908bf8 kadmin: Add disallow-client attribute

that I had fixed via:

    f6ac4ee86 roken: Fix parse flags bug

which wasn't a bug at all.
2021-06-22 14:47:38 -05:00
Nicolas Williams
ae8908bf81 kadmin: Add disallow-client attribute
This is useful for services that need not be clients.  For example, an
untrusted service that need only accept authentication from clients,
but not initiate authentication to other services.
2021-06-22 13:01:24 -05:00
Nicolas Williams
f6ac4ee864 roken: Fix parse flags bug 2021-06-22 13:01:24 -05:00
Nicolas Williams
1870584d22 kdc: Fix _kdc_audit_addaddrs() buglet 2021-06-21 23:38:16 -05:00
Luke Howard
0452d8c601 krb5: check return value in krb5_get[_cache]_next()
krb5_get_next() and krb5_get_cache_next() do not check for krb5_kcm_call()
returning non-zero before accessing the repsonse data; they only handle the
case where the return value is KRB5_CC_END.

Return immediately if the return value of krb5_kcm_call() is not KRB5_CC_END or
0. This was fixed in the Apple code.
2021-06-16 12:09:19 +10:00
Nicolas Williams
be3a640b69 kinit: Fix --anonymous renewal bug
`kinit --anonymous ... some long running command here` will eventually
fail to renew the anon TGT.
2021-05-21 11:00:58 -05:00
Luke Howard
718e3f8b68 hx509: correct ASN.1 OID typo for SHA-384
A copy and paste error initialized the SHA-384 structure in libhx509
with the OID for SHA-512.

Fixes: 776
2021-05-19 14:41:03 +10:00
Luke Howard
497a561b4d gss: avoid string concatenation warning in error message init
Some compilers with -Wstring-concatenation enabled warned about a suspicious
concatenation of string literals in the initialization of the GSS-API error
message array.

At the expense of a long line, avoid this warning but explicitly concatenating
the offending string literal.

Fixes: #775
2021-05-17 10:09:01 +10:00
Luke Howard
f67dd0f903 roken: move Heimdal vis.h extensions to separate header
vis.h is not built on platforms (such as macOS) that already have
that header, which resulted in prototypes for Heimdal-specific
vis.h extensions being absent.

Move those prototypes to a separate header, vis-extras.h, which
must be explicitly included in order to use the Heimdal extensions.
2021-05-17 10:05:58 +10:00
Nicolas Williams
cc5bd3a6c0 kdc: Improve warn_ticket_addresses feature (fix bug) 2021-05-14 17:02:08 -05:00
Nicolas Williams
9ce3cbbf2a kdc: Improve warn_ticket_addresses feature
- Don't log "Request from wrong address (ignoring)".
 - Add "wrongaddr=yes" kv to final log message.
 - Add request and ticket addresses (up to 3) to final log message.
2021-05-12 17:56:26 -05:00
Nicolas Williams
8807a0aad9 bx509d: Use /get-tgt lifetime q-param 2021-05-06 23:13:31 -05:00
Nicolas Williams
5aaf12351a iprop: More default HDB type fixes 2021-05-04 14:53:40 -05:00
Nicolas Williams
0c1cd18e03 iprop: Fix default dbname choice on initial prop
If a DB does not already exist, ipropd-slave will use the compiled
default, which is not necessarily what is desired or configured in
`[kdc]`.

This change makes `hdb_default_db()` return the first dbanme in the
`[kdc]` configuration, falling back on `HDB_DEFAULT_DB`.

Also, this adds a `--database` option to `ipropd-slave`.
2021-05-03 15:02:43 -05:00
Nicolas Williams
e609e61f21 bx509d: Set Content-Type and Cache-Control 2021-04-30 16:02:18 -05:00
Nicolas Williams
b1b993b231 httpkadmind: Use no-store rather than no-cache 2021-04-30 15:46:20 -05:00
Nicolas Williams
034413892e roken: Fix Makefile race 2021-04-26 14:40:00 -05:00
Nicolas Williams
1e65ebd5eb asn1: Fix Windows build 2021-04-25 10:45:43 -05:00
Nicolas Williams
ec171ef0b6 asn1: Add missing file gen_print.c 2021-04-25 10:45:43 -05:00
Nicolas Williams
e80ac3ae22 kdc: Install bx509d and httpkadmind man pages 2021-04-23 22:15:51 -05:00
Nicolas Williams
5c93af553b asn1: Build both backends
The codegen backend is faster than the template backend, even for
modules that don't use IOS.  On x64 we see the template backend being
4% slower for TGS requests using the kdc-tester program.

So let's build both, libasn1 (codegen) and libasn1template when
configured with --disable-asn1-templating, but make sure that the
asn1_print utility is linked with libasn1template.

Eventually we'll want to either optimize the template backend better,
or add IOS and JSON printing support to the codegen backend.
2021-04-23 22:15:51 -05:00