Commit Graph

30029 Commits

Author SHA1 Message Date
Luke Howard
317df4dbd4 kdc: remove pac_attributes_present field
Remove the unwieldy pac_attributes_present field from the request structure.

Instead, if PAC attributes are not present in the TGT, the default is to assume
they were set to KRB5_PAC_WAS_GIVEN_IMPLICITLY.
2021-12-23 13:26:40 +11:00
Luke Howard
ebd7092dff kdc: distinguish long-term key from replacing reply key
Distinguish pre-authentication mechanisms that replace the reply key from those
that use the client's long-term key. In the general case, one is the inverse of
the other, however KRB5_PADATA_ENCRYPTED_CHALLENGE replaces the reply-key with
one derived from the long-term key.

PA_REPLACE_REPLY_KEY indicates that the kvno should be set to zero in the
reply; the absence of PA_USES_LONG_TERM_KEY indicates that the client's
long-term key may be included in the PAC (PAC_CREDENTIAL_INFO with Samba only).

Corrects e8984871.
2021-12-23 11:24:35 +11:00
Luke Howard
bdb3e1020c Revert "kdc: distinguish long-term key from replacing reply key"
This reverts commit e89848719a.

(Reverting: typo.)
2021-12-23 11:24:00 +11:00
Luke Howard
e89848719a kdc: distinguish long-term key from replacing reply key
Distinguish pre-authentication mechanisms that replace the reply key from those
that use the client's long-term key. In the general case, one is the inverse of
the other, however KRB5_PADATA_ENCRYPTED_CHALLENGE replaces the reply-key with
one derived from the long-term key.

PA_REPLACE_REPLY_KEY indicates that the kvno should be set to zero in the
reply; the absence of PA_USES_LONG_TERM_KEY indicates that the client's
long-term key may be included in the PAC (PAC_CREDENTIAL_INFO with Samba only).
2021-12-23 11:21:30 +11:00
Luke Howard
357c73e013 kdc: avoid linear search of PA types
Store a dispatch table pointer for the used pre-authentication type to avoid
needing to traverse the table.
2021-12-23 11:04:38 +11:00
Luke Howard
f18c9e06a8 kdc: honor PAC_ATTRIBUTES in presented TGT
PACs are included when issuing TGTs, if there is no PAC_ATTRIBUTES buffer
(legacy behavior) or if the attributes buffer indicates the AS client requested
one.
2021-12-22 17:13:13 +11:00
Luke Howard
b4f3617964 kdc: don't add PAC_ATTRIBUTES PAC buffer for service tickets
Only include the PAC_ATTRIBUTES PAC info buffer if we are issuing a TGT, as its
contents are not relevant to application services. (The buffer contains a bit
indicating whether the client explicitly or implicitly requested a PAC.)
2021-12-22 16:38:52 +11:00
Luke Howard
b36ac3c15e kdc: don't add REQUESTOR_SID PAC buffer for service tickets
In the altsecid GSS pre-authentication authorizer plugin, don't add the
REQUESTOR_SID PAC info buffer unless the client requested a TGT. It is not
relevant to application services.
2021-12-22 16:37:32 +11:00
Luke Howard
c974f8625c krb5: PAC_EXTRA_LOGON_INFO_FLAGS_UPN_DEFAULTED fix
Only set the PAC_EXTRA_LOGON_INFO_FLAGS_UPN_DEFAULTED flag in the
UPN_DNS_INFO_EX PAC buffer, if the provided UPN matches the cname.

This is a NOOP at present, as no UPN is provided by the Heimdal KDC.
2021-12-22 16:37:24 +11:00
Luke Howard
692ed5e841 krb5: fix build regression in report_canonical_client_name
Fix build regression introduced in 5ba46072.
2021-12-22 15:01:54 +11:00
Luke Howard
7990dc287d asn1: use " instead of ' when quoting on Windows
NMAKE on Windows requires " instead of ' be used when quoting arguments. Fixes
regression introduced in fe095aa1c0.
2021-12-22 14:52:04 +11:00
Luke Howard
7cd99b86d3 roken: include MIT license text 2021-12-22 14:45:35 +11:00
Luke Howard
5ba4607277 krb5: report_canonical_client_name implies check_pac 2021-12-22 14:33:01 +11:00
Luke Howard
9aa67e58ba roken: don't call assert() before variable decl 2021-12-22 13:43:17 +11:00
Luke Howard
8590499b53 kdc: include SID in PAC with GSS authorizer
Update the sample GSS pre-authentication authorizer plugin to allow the PAC to
be pinned to the authenticating user's SID.

There is still a race condition between the time the user authenticates and the
time the SID is looked up via LDAP, but it should be sufficient as an example;
if more security is required, then users should be enrolled with their SIDs.
2021-12-22 10:36:26 +11:00
Luke Howard
a2c225fe0a kdc: add PA PAC finalize callback
Note the selected pre-authentication mechanism, and add a callback to allow the
pre-authentication mechanism to update the PAC immediately prior to signing.
2021-12-22 10:36:26 +11:00
Luke Howard
f7964251ff kdc: support for PAC_ATTRIBUTES_INFO
Add PAC_ATTRIBUTES_INFO to the PAC. This info buffer indicates whether the user
explicitly requested a PAC be present or absent.

Note: this changes the windc plugin ABI.
2021-12-22 10:36:26 +11:00
Luke Howard
e50033aec2 kdc: add canonical principal name to authz data
Use the UPN_DNS_INFO buffer of the PAC to include the canonical principal name.

Arguably we should use AD-LOGIN-ALIAS as defined in RFC6806, but we may not
always know all the principal's aliases, and this approach allows us to share
application service logic with Windows.
2021-12-22 10:36:26 +11:00
Luke Howard
0ab3b7b2dd krb5: support for canonical name in PAC
If the UPN_DNS_INFO buffer in the Windows PAC contains a canonical principal
name, use it in lieu of the ticket client name to determine the GSS-API
initiator name.
2021-12-22 10:36:26 +11:00
Luke Howard
b3bb3ac49d roken: add rk_clzll() helper function 2021-12-22 10:36:26 +11:00
Luke Howard
29cd8a46d8 krb5: zero memory in krb5_storage_emem() 2021-12-22 10:36:26 +11:00
Nicolas Williams
5528039a07 bx509d: Fix tests/kdc/check-bx509
Grep pattern needed updating.
2021-12-20 16:35:16 -06:00
Luke Howard
2bb85f61e9 roken: unbreak Windows build 2021-12-21 08:19:31 +11:00
Nicolas Williams
fe095aa1c0 krb5: Decorate Principal type with name attributes
See `asn1: Add --decorate=... for internal bookkeeping`, which adds an
option to `asn1_compile` for decorating SET/SEQUENCE types with fields
that are neither encoded nor decoded, but which _are_ copied and freed.

We'll use this to add name attributes to the `Principal` type (which is
used to represent Kerberos principal names in the krb5 GSS mechanism)
without having to rototill the GSS krb5 mechanism nor the krb5 library,
and without affecting the encodings of HDB entries (which happen to use
the `Principal` type).
2021-12-20 11:51:53 -06:00
Nicolas Williams
8962abdfbc asn1: Fix build (revert bits of 823fb8247) 2021-12-20 11:51:53 -06:00
Nicolas Williams
823fb82477 asn1: Add --decorate=... for internal bookkeeping
This option, `--decorate=TYPE-NAME:FIELD-TYPE:field-name[?]` allows one to add
a field to any struct generated by the ASN.1 compiler for any SET or SEQUENCE
type such that:

 - the field will     be freed by the `free_TYPE_NAME()` function
 - the field will     be copied by the `copy_TYPE_NAME()` function
 - the field will not be printed by the `print_TYPE_NAME()` function
 - the field will NOT be encoded or decoded

This is useful for internal bookkeeping.

The first use of this may well be for adding an optional field to
`Principal` where information about name attributes will be stored,
which will then allow us to have GSS name attributes for the krb5
mechanism w/o having to refactor the mechanism to use a different
structure for representing `gss_name_t` mechnames than the one currently
used (`Principal`; `krb5_principal` happens to be a typedef alias of
`Principal *`).

So w/o massive rototilling of the GSS krb5 mechanism we can have name
attributes, _and_ we'll also be able to have those in the krb5 API as
well w/o any massive rototilling there either.
2021-12-19 23:21:35 -06:00
Nicolas Williams
309d1192df asn1: Add module->JSON dump 2021-12-19 23:21:35 -06:00
Joseph Sutton
f5823216d0 kdc: Return error code from _kdc_check_pac() with an armor ticket
This allows a TGT_REVOKED error to be returned to match Windows
behaviour.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-20 14:34:21 +11:00
Joseph Sutton
b16f93240e kdc: Fix NULL pointer dereference on failure to verify armor ticket PAC
r->client_princ and r->server_princ are only set in the AS-REQ case, but
we perform the PAC check in the TGS-REQ case, so calling
krb5_unparse_name() will dereference a NULL pointer. Instead, use
r->cname and r->sname.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-20 14:34:21 +11:00
Luke Howard
2670599efa krb5: fix allocation error in krb5_mk_ncred()
ppdata in krb5_mk_ncred() should be the size of a krb5_data, not a pointer
2021-12-20 12:41:59 +11:00
Luke Howard
f555fdda7e hdb: fix allocation error in derive_keyset()
set_time in derive_keyset() should be the size of a KerberosTime, not a pointer
2021-12-20 12:40:28 +11:00
Luke Howard
45ea54a44a kdc: audit armor client principal name 2021-12-19 21:06:08 +11:00
Luke Howard
2730e12b6a hdb: SQLite HDB can handle enterprise principals
add HDB_CAP_F_HANDLE_ENTERPRISE_PRINCIPAL to the capability flags for the
SQLite backend, as it uses the common _hdb_fetch_kvno() helper which supports
enterprise principals.

Failure to set this flag resulted in hdb_fetch_kvno() incorrectly returning
HDB_ERR_WRONG_REALM when enterprise principals were being used, as the
enterprise name translation was instead done by _kdc_db_fetch(), thereby
squashing the enterprise name type (which otherwise would have set the
force_canonicalize option).
2021-12-19 21:05:57 +11:00
Luke Howard
7717cb71c3 tests: check TGS with GSS pre-authentication
Validate we can actually get a service ticket when GSS-API pre-authentication
is used, this exercises synthetic client validation.
2021-12-18 15:09:38 +11:00
Luke Howard
a3392b099e kdc: allow cross-realm FAST armor TGT
08e0305b introduced a patch to validate armor ticket PACs, but required that
the armor client principal was in the local realm (as it did not allow
_kdc_db_fetch() to fail).

Allow cross-realm FAST armor clients by using the same logic to look up the
client principal as the TGS itself does, i.e. use db_fetch_client() which
handles the case where the client is not local to the KDC.

Note: the armor PAC is only required to be validated when issuing a final,
non-referral service ticket, as this is the only point upon which device claims
should be inserted (according to my understanding).

Closes: #901
2021-12-18 15:09:38 +11:00
Luke Howard
e7588952ce kdc: add auth data type for synthetic principals
Add a new authorization data type to indicate a synthetic principal was used,
to allow synthetic clients acquired outside of PKINIT (e.g. with GSS-API
pre-authentication) to use the TGS.

Note: we continue to honor KRB5_AUTHDATA_INITIAL_VERIFIED_CAS to indicate that
it is OK for the client to be synthetic, even though it is only an indication
that the client *may* have been synthetic.
2021-12-18 15:09:38 +11:00
Nicolas Williams
23d96d822f klist: Check unparse_flags() result differently 2021-12-18 11:34:12 +11:00
Nicolas Williams
27d6526e3a kdc: Check unparse_flags() result differently 2021-12-18 11:34:12 +11:00
Nicolas Williams
90899b2361 kdc: parse_bytes() returns ssize_t 2021-12-18 11:34:12 +11:00
Nicolas Williams
50e08b4bc5 kcm: parse_bytes() returns ssize_t 2021-12-18 11:34:12 +11:00
Nicolas Williams
f91b171f04 hxtool: parse_bytes() now returns ssize_t 2021-12-18 11:34:12 +11:00
Nicolas Williams
e84bcc29d3 hx509: Flags are unsigned 2021-12-18 11:34:12 +11:00
Nicolas Williams
686d5116de roken: Unparse wider ints 2021-12-18 11:34:12 +11:00
Luke Howard
fc76c83ab1 Revert "tgs-rep: always return canonical realm when force_canonicalize set"
This reverts commit 6f81e4c93b.

This patch may have originated in Samba from before force_canonicalize was
supported. Because the server_principal argument to tgs_make_reply() is
canonicalized prior to calling (if the server entry has force_canonicalize
set), honoring it again in tgs_make_reply() is superfluous.
2021-12-18 11:32:49 +11:00
Luke Howard
1bf02337f0 krb5: note GSS-API can be used as PA plugin interface
Update README.fast to note that the GSS-API can be used as a pre-authentication
plugin interface.
2021-12-17 19:42:35 +11:00
Luke Howard
42797a1c18 krb5: fix regression in test_cc build
af923957 broke building test_cc if !KEY_UTILS
2021-12-17 18:57:13 +11:00
Luke Howard
e0929d16b7 kdc: don't leak msg in pa_enc_chal_validate()
Move initialization of msg in pa_enc_chal_validate() to avoid leak on invalid
password.
2021-12-17 13:41:55 +11:00
Luke Howard
a423193ce0 krb5: initialize tgs_req buffer in init_tgs_req()
Initialize the tgs_req buffer in init_tgs_req() so pointers are valid when
freed. Fixes regression introduced when Apple TGS-REQ FAST code was imported in
PR #805.
2021-12-17 13:37:05 +11:00
Joseph Sutton
08e0305b26 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>

Closes: #891
2021-12-17 13:34:58 +11:00
Isaac Boukris
6f81e4c93b tgs-rep: always return canonical realm when force_canonicalize set
This allows Samba to have a behaviour where
even if canonicalize flag is not set, the canonical realm
is returned, allowing a HDB module to require behaviour
that is the same as Windows.

Regression (for a HDB module wanting AD behaviour) was
introduced by commit:
378f34b4be

Signed-off-by: Isaac Boukris <iboukris@gmail.com>

[abartlet@samba.org Similar to Samba commit a9e6119ca0c2a78ef314c3162122539ee834aa04
 but made conditional on server->entry.flags.force_canonicalize to
 allow upstream submission]
2021-12-17 13:28:59 +11:00