Commit Graph

504 Commits

Author SHA1 Message Date
Nicolas Williams
20b2dda743 kdc: Quiet a static analyzer warning 2023-01-04 01:36:02 -06:00
Stefan Metzmacher
422419ddde kdc: add missing enctype = p[i] assignments to _kdc_find_etype()
This is needed when a service provides support for newer entry.etypes
without having a key for that encryption type yet.

It is triggered with svc_use_strongest_session_key=TRUE.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 08:50:28 -05:00
Joseph Sutton
05e589d247 kdc: Check generate_pac() return code
If the function fails, we should not issue a ticket missing the PAC.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-11-17 07:52:06 -05:00
Luke Howard
df655cecd1 kdc: allow audit plugins to influence return code
Honor the return code of _kdc_audit_request(), propagating if non-zero. Note
that this is principally intended to allow the audit plugin to return
HDB_ERR_NOT_FOUND_HERE, which influences whether the KDC sends an error reply
or not. If the audit plugin also wishes to rewrite r->error_code, it must do so
separately.

Closes: #964
2022-03-03 10:10:37 +11:00
Stefan Metzmacher
11d8a053f5 kdc-plugin: also pass astgs_request_t to the pac related functions
This is more consistent and allows the pac hooks to be more flexible.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-03-03 09:58:48 +11:00
Nicolas Williams
419610aa14 kdc: HDB max_life/max_renew == 0 -> unlimited 2022-02-15 20:16:29 -06:00
Nicolas Williams
e7e2c7a145 kdc: Honor "unlimited" max_life/max_renew 2022-02-15 16:56:27 -06:00
Luke Howard
144caf67fa kdc: add wrappers for heimbase object accessors
Add libkdc wrappers for heimbase object accessors so plugins can use audit and
request attribute APIs without consuming libheimbase. Exposed API surface is
minimal and is limited to reading array collections, and reading/creating base
and custom types.
2022-01-28 17:24:57 -06:00
Jeffrey Altman
eb08f2ecdd kdc: _kdc_find_etype if is_preauth must use long term keys
is_preauth (KFE_IS_PREAUTH is set) might require replying with
PA-ETYPE-INFO[2] which requires use of the long-term keys.
Without this change is_default_salt_p() can be called with 'key'
eq NULL.

Change-Id: I513fa768680225d4501d8b390e349a011666d90c
2022-01-24 10:41:51 -05:00
Luke Howard
ed4fe65794 base: change ret fieldname to error_code in request struct 2022-01-20 17:23:24 +11:00
Nicolas Williams
f155150969 kdc: Rewrite get_pa_etype_info and set_salt_padata
We weren't checking for errors, and we weren't using the convience
SEQUENCE OF add_METHOD_DATA() and add_ETYPE_INFO() functions generated
by the ASN.1 compiler.  Using those utilities made get_pa_etype_info()
and make_etype_info_entry() sufficiently simpler that merging the two
makes for simpler, more readable code.
2022-01-18 09:14:29 -05:00
Luke Howard
94ed961d02 kdc: make auditing API public
Samba plugins will need to use auditing API without including krb5-private.h,
so make the auditing APIs public.
2022-01-18 16:09:50 +11:00
Luke Howard
4befd3e355 kdc: remove krb5_ prefix for KDC attribute functions
We will use the kdc_ rather than krb5_kdc_ prefix for new public APIs exported
from libkdc. Amend the recently introduced
request_{get,set,copy,delete}_attribute APIs to conform.
2022-01-17 23:50:04 -05:00
Jeffrey Altman
4b6fb5ab1a kdc: _kdc_find_etype prevent NULL dereference
If use_strongest_session_key and no keys are found the return
code will be set to KRB5KDC_ERR_ETYPE_NOSUPP.  However, before
exiting if the principal is a weak exception then the return
code will be set to success and a NULL key pointer will be
dereferenced.   Skip the weak exception check if the return
code is non-zero.

Change-Id: I36d0e1b179b3392171ad6767c75111d59c3f2f7d
2022-01-17 21:51:57 -05:00
Nicolas Williams
7cfab00e37 kdc: One more memcmp() implicit comparison to 0 2022-01-17 15:17:33 -06:00
Joseph Sutton
9a0372d992 kdc: Still prefer encryption types with "not default" salts except for des-cbc-crc
Samba clients are often machine accounts with non-default salts that
will fail if they can't use the AES encryption type they know the KDC
supports.  The problem is that arcfour-hmac-md5 has no salt so was
being used in preference.

Samba started to fail when

kdc_config->preauth_use_strongest_session_key = true;

was forced into the KDC configuration.

The history here is an attempt to avoid Kerberos v4 salts in des-cbc-crc
keys, but this instead broke Samba clients with AES-keys on machine accounts
as these have a non-default salt by default.  These accounts were incorrectly
restricted to arcfour-hmac-md5 and they didn't like that.

A broader fix than Samba commit 8e1efd8bd3bf698dc0b6ed2081919f49b1412b53

REF: https://lists.samba.org/archive/samba/2021-October/237844.html

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

Change-Id: Ia8908a5a2eef107e6b133d7f0e4343c1988c18bb
2022-01-17 15:42:03 -05:00
Nicolas Williams
3e51a0b84a kdc: Quiet a coverity warning 2022-01-17 11:04:21 -06:00
Nicolas Williams
4d5c5c6737 kdc: Add missing encryption retval check 2022-01-17 10:47:41 -06:00
Jeffrey Altman
1685c34b0d remove (krb5_enctype) cast for ETYPE_xxx
Now that ETYPE_xxx names are macros to the KRB5_ENCTYPE_xxx
symbols there is no longer a need to cast to (krb5_enctype).

Change-Id: Ib561f6e45346abac7a53eb1db0bfef60ee3bcb74
2022-01-15 22:05:50 -05:00
Luke Howard
0e8c4ccc6e hdb: eliminate hdb_entry_ex
Remove hdb_entry_ex and revert to the original design of hdb_entry (except with
an additional context member in hdb_entry which is managed by the free_entry
method in HDB).
2022-01-15 18:54:57 +11:00
Luke Howard
c5551775e2 hdb: decorate HDB_entry with context member
Decorate HDB_entry with context and move free_entry callback into HDB structure
itself. Requires updating hdb_free_entry() signature to include HDB parameter.
A follow-up commit will consolidate hdb_entry_ex (which has a single hdb_entry
member) into hdb_entry.
2022-01-15 18:54:57 +11:00
Luke Howard
6530021f09 kdc: move auth event definitions into KDC header
Move KDC auth event macro definitions out of hdb.h and into a new KDC header,
kdc-audit.h.
2022-01-13 14:51:31 +11:00
Luke Howard
1dd5aa2f5d kdc: don't leak etype/error message in pa_enc_ts_validate()
Recent auditing changes (b1dcc1a4) introduced a leak into pa_enc_ts_validate()
where the encryption type name and error message could be leaked.

This patch fixes a compile error in the original commit.
2022-01-08 14:12:26 +11:00
Luke Howard
6f0727fa00 Revert "kdc: don't leak etype/error message in pa_enc_ts_validate()"
This reverts commit ed2579e8af.
2022-01-08 14:12:06 +11:00
Luke Howard
ed2579e8af kdc: don't leak etype/error message in pa_enc_ts_validate()
Recent auditing changes (b1dcc1a4) introduced a leak into pa_enc_ts_validate()
where the encryption type name and error message could be leaked.
2022-01-08 14:10:51 +11:00
Luke Howard
78ad37ee47 kdc: use r->canon_client_princ field in AS
r->canon_client_princ is always an alias to r->client->entry.principal in the
AS, but use it for consistency with the TGS. (In the TGS, it may also come from
te PAC.)
2022-01-05 13:01:06 +11:00
Luke Howard
0287558838 kdc: move Services for User implementation out of krb5tgs.c
Move the Services for User (SFU/S4U) implementation -- protocol transition and
constrained delegation -- into its own compilation unit, with an interface that
only takes an astgs_request_t, so it can be easily factored out into a plugin
module in the future.

This refactoring is also careful to update all client names in the request
structure after the SFU/S4U validation has successfully completed.
2022-01-05 13:01:06 +11:00
Luke Howard
06f8985c55 hdb: consolidate preauth audit event types
Instead of having distinct preauth success/failure events for different
mechanisms, have a single event; the mechanism can be disambiguated by querying
the HDB_REQUEST_KV_PA_NAME key.

Note: there is still an explicit event for long-term key-based success/failure
in order to help the backend implement lockout.

Audit failure (HDB_AUTH_EVENT_PREAUTH_FAILED) in the main preauth loop, rather
than in each mechanism. Success is still audited in the mechanism to allow
client pre-authentication success to be noted even if something subsequent
(e.g. encoding a reply, memory allocation) fails. The generic catch-all for
success remains.
2022-01-05 09:42:03 +11:00
Luke Howard
68c4fd6572 kdc: audit preauth event only at end of PA loop
Don't audit preauth event if the preauth mech returns
KRB5_KDC_ERR_MORE_PREAUTH_DATA_REQUIRED; only set the event on (final) failure
or success.
2022-01-05 09:37:55 +11:00
Luke Howard
ce58eb9081 kdc: annotate libkdc Windows function annotations
Annotate libkdc APIs with KDC_LIB_{CALL,FUNCTION} to ensure correct calling
convention and optimized DLL importing on Windows.

Ensure Windows and libtool export tables are consistent.
2022-01-04 12:27:43 +11:00
Luke Howard
a8ff420b16 kdc: add attribute dictionary to kdc_request_t
Add a heim_dict_t to the KDC request structure for use by pre-authentication
mechanisms and plugins.
2022-01-04 12:27:43 +11:00
Luke Howard
b27026996a base: s/addkv_{bool,number,object}/setkv
Now heim_audit_addkv() correctly supports multiple values, the other functions
that (by design) replace existing values with a single value should use the
heim_audit_setkv prefix.

A subsequent commit could add variants that support multiple values for
non-string types.
2022-01-04 09:07:10 +11:00
Luke Howard
a4c6b81ce9 kdc: add audit plugin API to windc API
Allow the windc plugin to also implement an audit callback. As part of this
change, both the HDB and windc audit function signatures are changed to return
void.
2022-01-03 16:17:01 +11:00
Luke Howard
d683780b1d kdc: separate PKINIT/GSS authorization failure
Create a new audit event for PKINIT/GSS authorization (impersonation) failure
2022-01-02 15:25:52 +11:00
Luke Howard
a9c6bc2bf2 kdc: audit "yes" boolean values as booleans
Audit boolean values that were logged as "yes" as boolean values; this will
change audit log values to "true" instead, so this patch may be omitted.
2022-01-02 15:25:52 +11:00
Luke Howard
e15e711b13 kdc: remove auth_event_details audit key
The auth event details audit key (formerly, parameter to auth_status)
contained, variously, an encryption type name; a PKINIT client certificate
name; or, a GSS initiator name. Audit these instead using individual keys that
reflect the values' contents.
2022-01-02 15:25:52 +11:00
Luke Howard
93c8d57091 kdc: call HDB audit function in both AS and TGS
Call the HDB audit method, if present, in both AS and TGS, immediately prior to
generating an error response to send to the clinet.
2022-01-02 15:25:52 +11:00
Luke Howard
1e1c5dbbfc kdc: make error code available to audit function
Set r->ret in the request before calling the HDB audit method.
2022-01-02 15:25:52 +11:00
Luke Howard
cc0874d410 kdc: preserve value types in auditing
Preserve integer/boolean audit values as their native types; convert to strings
when logging only. This commit goes some way towards unifying the two auditing
APIs.
2022-01-02 15:25:52 +11:00
Luke Howard
b1dcc1a474 kdc: refactor Samba-specific auditing API in terms of existing API
Make Samba-specific HDB auth status API a wrapper on the existing auditing API,
with a view towards unifying the two APIs in a future commit.

The term "auth status" is replaced with "auth event", and the HDB auth_status
method is replaced with a more general purpose audit method which has access to
the entire request structure.
2022-01-02 15:25:52 +11:00
Luke Howard
52b1dffa63 kdc: return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN (PA)
Return KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN, not HDB_ERR_NOENTRY, if a client
principal could not be found during pre-authentication.

This fixes a regression introduced with synthetic principals in 00358252d3.
2022-01-01 08:41:13 -05:00
Nicolas Williams
fb3ea5b943 kdc: Add ret to common svc req elements
We're logging SUCCESS even when the KDC sends error replies.  That's
because we're returning success to process_request() even when we send
errors to clients.  The error we want to send to the client, and that we
succeed or fail to send it, are different statuses.

Also, further move things into `r` and out of function arguments.
2021-12-27 10:16:58 +11:00
Luke Howard
f49e99e15f kdc: remove e_text argument to _kdc_encode_reply()
e_text is part of astgs_request_t, so it doesn't need to be an explicit
argument to _kdc_encode_reply()
2021-12-23 17:49:36 -06:00
Luke Howard
b6be850e0d kdc: remove outpadata from astgs_request_t
Remove the outpadata field from astgs_request_t, because it's not something we
wish to expose publically (yet it is something that Samba needs in the
client_access plugin API, to add Windows error information).

Instead, allocate rep->padata at the start of AS/TGS request handling, and
ensure it is valid for the lifetime of the request until it is encoded (at
which point it will be freed and set to NULL if zero length, to avoid sending a
zero length METHOD-DATA to the client).

(The previous approach of setting rep->padata to point to &r->outpadata was
fragile, because it required clearing the pointer before freeing the KDC-REP.)
2021-12-23 17:49:36 -06:00
Luke Howard
64dad876a4 kdc: simplify client_access windc plugin API
Make client_access plugin API take a single argument, astgs_request_t. Note: in
order to avoid making r->outpadata public (it's an internal buffer), but allow
Samba to modify the reply pa data, some pointer magic is required.
2021-12-23 17:49:36 -06:00
Luke Howard
e81bcb71f3 kdc: add finalize_reply API to windc plugin
Allow a windc plugin to finalize the KDC reply (including the encrypted ticket
and reply parts) before encoding for transmission.
2021-12-23 17:49:36 -06:00
Luke Howard
6b312659cb kdc: use PAC from request in _kdc_gss_finalize_pac()
Pass astgs_request_t to _kdc_gss_finalize_pac() in order to harmonize with
other functions.
2021-12-23 17:49:36 -06:00
Luke Howard
d3549c4ab7 kdc: remove superflous request arg to _kdc_check_access()
KDC_REQ is accessible as r->req
2021-12-23 17:49:36 -06:00
Luke Howard
805ea5e0a0 kdc: use rep/et/ek fields in astgs_request_t
Use rep/et/ek fields in astgs_request_t that were previously present but not
globally used.
2021-12-23 17:49:36 -06:00
Luke Howard
2e8b172f38 kdc: move PAC into astgs_request_t structure 2021-12-23 17:49:36 -06:00