Commit Graph

29786 Commits

Author SHA1 Message Date
Luke Howard
7db298668b kdc: fix pa_gss_authorize_cb calling convention
pa_gss_authorize_cb() needs to be marked KRB5_LIB_CALL to build on 32-bit
Windows
2021-08-12 18:13:45 +10:00
Luke Howard
95339c1068 gss: fix Windows preauth build issues
Fix lib/gssapi NTMakefile for GSS-API pre-authentication dependencies
2021-08-12 18:09:40 +10:00
Luke Howard
3302b38e53 gss: fix Windows preauth build issues
Fix kdc/kuser NTMakefiles for GSS-API pre-authentication dependencies
2021-08-12 17:57:17 +10:00
Luke Howard
49f3f5bd99 kdc: support for GSS-API pre-authentication
Add support for GSS-API pre-authentication to the KDC, using a simplified
variation of draft-perez-krb-wg-gss-preauth-02 that encodes GSS-API context
tokens directly in PADATA, and uses FX-COOKIE for state management.

More information on the protocol and implementation may be found in
lib/gssapi/preauth/README.md.
2021-08-12 17:37:01 +10:00
Luke Howard
15c82996a4 windows: add /td sha256 argument to signtool
Recent versions of signtool require an additional /td sha256 argument to
indicate the timestamp hash type.
2021-08-12 16:33:56 +10:00
Luke Howard
6e3bc8341c doc: make intermediate Windows help directory
The hx509 and heimdal subdirectories are required to exist before
Windows help compilation can proceed.
2021-08-12 16:33:51 +10:00
Luke Howard
89ff0eb462 asn1: ensure template generator includes ASN1CALL
Windows 32-bit builds were broken as the ASN1CALL calling convention
macro was not included in the output of gen_template.c, only in the
generated header.
2021-08-12 16:33:45 +10:00
Luke Howard
3a9e7346cc gss: cast HEIM_ERR_EOF to OM_uint32 before check (2)
In gss_import_cred(): HEIM_ERR_EOF is negative, cast to OM_uint32 before
checking against *minor_status
2021-08-12 09:20:22 +10:00
Luke Howard
3f4d894dd3 gss: cast HEIM_ERR_EOF to OM_uint32 before check
In gss_import_cred(): HEIM_ERR_EOF is negative, cast to OM_uint32 before
checking against *minor_status
2021-08-12 09:18:22 +10:00
Luke Howard
2f4619fbbd cf: check for undefined variables
The w32-hh-toc-from-info.pl script would fail with more recent versions
of Perl, as it attempted to access undefined variables.
2021-08-12 08:46:03 +10:00
Luke Howard
1175fa0435 gss: don't include mech_locl.h in spnego
including mech_locl.h in spnego/context_storage.c is unnecessary and
breaks the build on Windows
2021-08-11 19:12:11 +10:00
Luke Howard
0c74bec235 krb5: pass realm to _krb5_make_fast_ap_fxarmor()
Fix merge issue introduced in ef1d63a9 which did not update the call
site after updating the _krb5_make_fast_ap_fxarmor() prototype to take
the realm (used in the anonymous PKINIT case).
2021-08-11 19:09:18 +10:00
Luke Howard
ab3d52e1a2 base: use correct calling convention for log_file()
Use the correct HEIM_CALLCONV calling convention when setting log_file()
callback, otherwise Windows build fails.
2021-08-11 19:09:08 +10:00
Luke Howard
b216697924 kdc: use anonymous, not empty, cname when hiding
RFC 6113 5.4.2 says that when hiding client names in the outer reply of a FAST
response, the wellknown anonymous principal MUST be used.

The previous implementation returned an empty client name and realm, which may
not be expected by some clients.
2021-08-11 12:23:25 +10:00
Luke Howard
b510b90239 krb5: export krb5_time_abs for test_time
Function introduced in 8a4ce995 needs to be exported.
2021-08-10 20:47:44 +10:00
Luke Howard
a27a3af0c2 gss: store_spnego_context(): remove redundant overflow check
ctx->negoex_step is now a uint8_t, so it can never be bigger than 0xff. Remove
redundant overflow check.
2021-08-10 20:11:35 +10:00
Luke Howard
d34700b4d9 krb5: add extra sanity check in pk_verify_sign()
Assert either PKINIT signer certificate was validated, or caller requested no
KDC certificate validation.
2021-08-10 16:25:26 +10:00
Luke Howard
ef1d63a997 kinit: add --pk-anon-fast-armor option
Add the  --pk-anon-fast-armor option, which acquires a temporary anonymous
PKINIT TGT to use as a FAST armor key.
2021-08-10 15:30:45 +10:00
Luke Howard
43858eaf9b gss: add oid/buffer storage helpers to mechglue
The functions for storing and retrieving GSS OIDs and buffers from
krb5_storage, added in 6554dc69, are generally useful. Move those into private
_gss_mg_XXX() API and update gss_{export,import}_{cred,sec_context} to use them
where appropriate.
2021-08-10 10:16:54 +10:00
Luke Howard
490173b417 gss: free exported context buffer after use in store_negoex_auth_mech()
Code style/consistency: store_negoex_auth_mech() should free the exported
context buffer after use. There is no leak as the buffer was freed at the end
of the function.
2021-08-10 10:16:50 +10:00
Luke Howard
c953bc5e79 krb5: reintroduce deprecated krb5_addlog_func()
krb5_addlog_func() is used by Samba to obtain Kerberos log messages
and place them into the Samba logs.

Providing a hook down to the heim_addlog_func() is less disruptive
than needing to call multiple different APIs as Samba compiles
both with an included copy of Heimdal and against a system
Heimdal (when not an AD DC).

This API was deprecated and stubbed out in March 2020 by ea90ca8 and was
previously stable until 0c86917 (which looks like it should have been part of
e44c680).

Despite the need for the extra argument, which we add a test for, Samba would
prefer to keep the krb5_addlog_func() facility, so this adds it back.

Signed-off-by: Andrew Bartlett abartlet@samba.org
2021-08-09 23:27:22 +10:00
Andrew Bartlett
d5b6869dc7 Allow KDC to always return the salt in the PA-ETYPE-INFO[2]
This is to match the Windows KDC behaviour, optionally.

Samba will use this mode, as Samba has tests that show
the difference and is keen for bug-for-bug/byte-for-byte
rather than strict RFC compliance where there is a
reasonable choice.

The Samba test (for reference) is
samba.tests.krb5.as_canonicalization_tests

The behaviour was changed in:

commit de1f37a6aa
Author: Luke Howard <lukeh@padl.com>
Date:   Mon Jan 7 15:45:36 2019 +1100

    kdc: omit default salt from PA-ETYPE-INFO[2]

    If the salt for the AS-REP client key matches the default password salt for the
    client principal in the AS-REQ, then it can be omitted from the PA-ETYPE-INFO,
    PA-ETYPE-INFO2 (RFC4120) as the client will assume the default salt in its
    absence.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-09 23:20:08 +10:00
Luke Howard
f538f0e5c2 krb5: use new krb5_time_abs() function
From Apple Heimdal-597.121.1: replace calls to labs() with krb5_time_abs()
2021-08-09 21:46:39 +10:00
Luke Howard
57a1a66348 krb5: default to client realm in _krb5_get_krbtgt
If _krb5_get_krbtgt() is called with a NULL realm, use the realm of the ccache
client
2021-08-09 21:46:32 +10:00
Luke Howard
8a4ce9950f krb5: add krb5_time_abs() function
From Apple drop, add krb5_time_abs() which returns the absolute difference
between two timestamps
2021-08-09 21:46:24 +10:00
Andrew Bartlett
3587b8c08c Allow _gss_string_to_oid() without HAVE_DLOPEN
This function became used outside the protection of
HAVE_DLOPEN (which Samba sets) with:

commit 5966c00701
Author: Luke Howard <lukeh@padl.com>
Date:   Sun Aug 8 10:34:28 2021 +1000

    gss: add gss_mg_name_to_oid internal API

    Add a new function for future internal use, gss_mg_name_to_oid(), which takes
    either a dot-separated OID or a "short" mechanism name (such as
    "sanon-x25519"), and returns a mechanism OID.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-08-09 09:58:58 +10:00
Luke Howard
ab8d4f508e roken: fix dependency typo - s/vin_h/vis_h/
Should close #777, #794.
2021-08-08 19:54:25 +10:00
Luke Howard
f86fccb344 gss: add split token test to check-negoex
Add test for split tokens to SAnon in NegoEx/SPNEGO
2021-08-08 18:16:17 +10:00
Luke Howard
06232dfcce gss: fix import/export of accumulating contexts
gss_{import,export}_sec_context did not work with partially accumulating
contexts, where the initial context token had not been completely accumulated,

Further, in gss_import_sec_context(), ctx->gc_input.value was not allocated to
a buffer sufficiently large to accumulate the target length.
2021-08-08 14:46:49 +10:00
Luke Howard
3b1f9f0a3f gss: error out in test_context if unknown OID
Fix regression in previous commit: exit with an error if test_context is called
with an unknown mechanism type.
2021-08-08 13:45:32 +10:00
Luke Howard
18c18d84b1 gss: merge gss_name_to_oid and gss_mg_name_to_oid
The recently introduced gss_mg_name_to_oid() function supported looking up
dynamically loaded mechanisms by name, but did not support partial matches or
the legacy "Kerberos 5" name as supported by gss_name_to_oid().

Consolidate these into a single function, and also add support for dynamically
loaded mechanisms to gss_oid_to_name().

API behavior difference: the Kerberos mechanism is now referred to by "krb5"
rather tha "Kerberos 5", although for legacy compatibility gss_name_to_oid()
will recognize the old name. However, gss_oid_to_name() will return "krb5". The
anticipated impact is minimal as these are not standard GSS-APIs and do not
appear to have any public usage outside Heimdal.
2021-08-08 11:37:09 +10:00
Luke Howard
5966c00701 gss: add gss_mg_name_to_oid internal API
Add a new function for future internal use, gss_mg_name_to_oid(), which takes
either a dot-separated OID or a "short" mechanism name (such as
"sanon-x25519"), and returns a mechanism OID.
2021-08-08 10:34:28 +10:00
Luke Howard
65651c8106 krb5: mask should be uint64_t, not size_t
size_t is not 64 bits on all platforms
2021-08-07 19:25:22 +10:00
Luke Howard
9d16808515 krb5: mask integers to avoid unnecessary expansion
Sign-extension would expand the encoding of packed negative integers to one
greater than required.
2021-08-07 19:18:42 +10:00
Luke Howard
6554dc69b0 gss: allow partial accept context export in SPNEGO
Support for exporting partially established acceptor context tokens. With this,
an acceptor can send the initiator an encrypted state cookie containing the
exported context token.

(The concrete mechanism, of course, must either require a single round trip or
support partial context export itself. Kerberos and GSS EAP would work, but
Kerberos with GSS_C_DCE_STYLE would not, as currently implemented.)

Partial context export is not permitted for initiators.
2021-08-07 18:56:33 +10:00
Roland C. Dowdeswell
fe426f7a28 fix type s/MUTAL/MUTUAL/ in gssapi/krb5 2021-08-07 18:54:56 +10:00
Roland C. Dowdeswell
3a6229f64a gss_accept_sec_context: support reassembling split tokens.
Microsoft will sometimes split GSS tokens when they exceed a certain
size in some protocols.  This is specified in

	[MS-SPNG]: Simple and Protected GSS-API Negotiation
	Mechanism (SPNEGO) Extension

https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SPNG/%5bMS-SPNG%5d.pdf

sections 3.1.5.4 to 3.1.5.9.

We extend gss_accept_sec_context() to recognise partial tokens and
to accumulate the fragments until an entire token is available to
be processed.  If the entire token is not yet available,
GSS_S_CONTINUE_NEEDED is returned with a zero length output token.
This is specified in RFC2744 page 25-26 to indicate that no reply
need be sent.

We include updates to the test framework to test split tokens when
using SPNEGO.
2021-08-07 18:54:56 +10:00
Roland C. Dowdeswell
80f3194a76 gssapi/krb5/{export,import}_sec_context: make smaller tokens. 2021-08-07 18:54:56 +10:00
Roland C. Dowdeswell
a2cfd2a25c gssapi/krb5/{export,import}_sec_context: fix for init_sec_ctx
When using these functions with gss_init_sec_context(), we noticed
that some things were missing and some needed to be made optional.
ctx->order may be NULL, ctx->ac->authenticator needs to be filled
out, and ctx->state needs be stored.

Note: SPNEGO still needs a little more work.
2021-08-07 18:54:56 +10:00
Roland C. Dowdeswell
81a8b5069e krb5_storage: add a packed integer type as an endian. 2021-08-07 18:49:33 +10:00
Roland C. Dowdeswell
6ccb21827b gss-token: initialise input buffer to empty 2021-08-07 08:40:20 +10:00
Robbie Harwood
0cb54fa69e kdc: fix typo in moduli file loading error message 2021-08-07 07:52:46 +10:00
Luke Howard
7188969371 krb5: add krb5_store_bytes()
Similar to krb5_storage_write(), but returns an error rather than the number of
bytes written.
2021-08-06 19:32:49 +10:00
Luke Howard
4e359bd5ce krb5: add krb5_store_datalen()
Store a data blob to the storage. The data is stored with an int32 as
length plus the data (not padded).  This function only differs from
krb5_store_data() insofar as it takes a void * and a length as parameters.

Patch from Roland C. Dowdeswell <elric@imrryr.org>
2021-08-06 19:22:15 +10:00
Luke Howard
8330e45444 gss: set GSS_C_CHANNEL_BOUND_FLAG for SAnon
SAnon includes channel bindings as part of the key derivation function, so they
cannot be ignored. Always set GSS_C_CHANNEL_BOUND_FLAG in the SAnon acceptor.
2021-08-06 13:21:36 +10:00
Isaac Boukris
d83321fdf3 Add channel-bindings tests 2021-08-06 13:15:19 +10:00
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