Commit Graph

146 Commits

Author SHA1 Message Date
Michael Tokarev
c80c04b235 spelling fixes (underun prefered relase encyption confunder)
[abartlet@samba.org: From Samba debian package at
 https://salsa.debian.org/samba-team/samba/-/blob/master/debian/patches/heimdal-spelling.patch?ref_type=heads]

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2024-06-16 23:28:43 -04:00
Robert Manner
bcbe816962 spnego/context_storage: undef sc_flags (for hpux)
On hpux this is seems to be a define from sys/signal.h:

which renders the variable name invalid.
2023-02-06 18:17:48 -06:00
Nicolas Williams
5725353a36 negoex: Fix incorrect ENOMEM check in storage_from_memory() 2023-01-04 16:21:34 -06:00
Nicolas Williams
16c9813140 negoex: Quiet a static analyzer false positive 2023-01-04 00:43:43 -06:00
Nicolas Williams
7c519d9c34 negoex: Fix use-after-free 2023-01-04 00:43:43 -06:00
Nicolas Williams
df81ad1c93 spnego: Quiet warning in ret_spnego_context() 2023-01-04 00:43:43 -06:00
Luke Howard
7f2cf34b1d gss: _gss_negoex_accept make error const
krb5_get_error_message() returns a const char *, not a char *. Amends
Change-Id I464b3c5.
2022-01-17 15:46:45 +11:00
Luke Howard
ce0ba125d9 gss: _gss_negoex_init make error const
krb5_get_error_message() returns a const char *, not a char *. Amends
Change-Id I870ed0b.
2022-01-17 15:46:41 +11:00
Jeffrey Altman
6e8ab0c204 lib/gssapi/spnego: _gss_negoex_accept do not leak error message
Change-Id: I464b3c5e5b96b36da2cda71b1dacc8ad971fda35
2022-01-16 23:04:54 -05:00
Jeffrey Altman
ac53ce5c99 lib/gssapi/spnego: _gss_negoex_init do not leak error message
Change-Id: I870ed0bd8de7bc6ab5b8cf7c6d3816d04de354fa
2022-01-16 23:02:38 -05:00
Jeffrey Altman
8254c01ae7 lib/gssapi/spnego: accept_sec_context free 'supported_mechs'
If no preferred mechanism was found 'supported_mechs' was leaked.

Change-Id: I2982f94d7e9569461f562987609ff7bff57b3f88
2022-01-16 22:57:15 -05:00
Nicolas Williams
2f31063e97 spnego: Minor style cleanup 2021-11-11 22:41:13 -06:00
Nicolas Williams
7a19658c1f spnego: Fix NULL deref
Reported to Heimdal by Michał Kępień <michal@isc.org>.

From the report:

Acknowledgement
---------------

This flaw was found while working on addressing ZDI-CAN-12302: ISC BIND
TKEY Query Heap-based Buffer Overflow Remote Code Execution
Vulnerability, which was reported to ISC by Trend Micro's Zero Day
Initiative.
2021-11-11 22:41:13 -06:00
Robert Crowston
5d462795ce Add stub for gss_acquire_cred_impersonate_name(). 2021-10-19 20:45:40 +11:00
Luke Howard
06e6113960 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
2021-10-11 14:57:09 +11: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
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
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
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
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
55a553c56d gss: don't use mechglue private header in SPNEGO
Unbreak last commit, including mech_locl.h in SPNEGO appears to break Windows
builds
2020-04-27 15:10:29 +10:00
Luke Howard
7cdc9934b1 gss: initialize output parameters in NegoEx
NegoEx failed to initialize output parameters in _gss_negoex_{init,accept}
which could lead it to crash if the underlying mechanism returned an error.
2020-04-27 14:38:33 +10:00
Nicolas Williams
1a8855e6c4 spnego: Also use mechglue names 2020-04-25 21:22:32 -05:00
Luke Howard
8d19f3f47f gss: pass mechanism error tokens through SPNEGO
Fix for issue #486 based on a patch by Nico Williams.

A GSS-API acceptor can return an error token to be sent to the initiator. Our
SPNEGO implementation discarded these when sending a SPNEGO reject response.
This patch fixes the SPNEGO acceptor to convey those in the SPNEGO response.

The SPNEGO initiator is also updated to not bail out early on receiving a
SPNEGO reject response from the acceptor, but instead pass the response token
(if any) to gss_init_sec_context(). A reject response with no response token
will continue to return an error.
2020-04-24 15:07:55 +10:00
Nicolas Williams
a54761d68a Properly implement neg_mechs & GM_USE_MG_CRED
SPNEGO was already using union creds.  Now make the mechglue know about
it, delete all of the cred-related SPNEGO stubs that are now not called
(lib/gssapi/spnego/cred_stubs.c), and implement gss_get/set_neg_mechs()
by storing the OID set in the union cred.

This commit was essentially authored as much if not more by Luke Howard
<lukeh at padl.com> as much as by the listed author.
2020-04-21 00:21:32 -05:00
Luke Howard
2c8fa27224 gss: use _gss_secure_release_buffer_[set]
Use new helper APIs for securely zeroing and releasing buffers and buffer sets.
2020-04-15 16:23:17 +10:00
Luke Howard
b73c9cc063 gss: add support for gss_duplicate_cred() in SPNEGO
The SPNEGO dispatch table does not include gss_duplicate_cred(). It can call
directly into the mechglue because a SPNEGO credential is a mechglue
credential.
2020-04-13 21:06:42 +10:00
Luke Howard
9eb01c66e9 gss: remove superfluous SPNEGO cred wrappers
SPNEGO credentials are mechglue credentials. SPNEGO credential wrapper
functions can be replaced with direct calls into the mechglue, unless a
specific check is required to avoid infinite recursion (as is the case where
the mechglue enumerates all mechanism when passed a null credential handle).
2020-04-13 21:06:37 +10:00
Luke Howard
7df0195c26 gss: fix downlevel Windows interop regression
The recent changes to SPNEGO removed support for GSS_C_PEER_HAS_UPDATED_SPNEGO,
through which the Kerberos mechanism could indicate to SPNEGO that the peer did
not suffer from SPNEGO conformance bugs present in some versions of Windows.*

This patch restores this workaround, documented in [MS-SPNG] Appendix A <7>
Section 3.1.5.1. Whilst improving interoperability with these admittedly now
unsupported versions of Windows, it does introduce a risk that Kerberos with
pre-AES ciphers could be negotiated in lieu of a stronger and more preferred
mechanism.

Note: this patch inverts the mechanism interface from
GSS_C_PEER_HAS_UPDATED_SPNEGO to GSS_C_INQ_PEER_HAS_BUGGY_SPNEGO, so that new
mechanisms (which did not ship with these older versions of Windows) are not
required to implement it.

* Windows 2000, Windows 2003, and Windows XP
2020-04-13 10:26:38 +10:00
Luke Howard
3b7aae7fce gss: order SPNEGO proposed mechs by req_flags
Sort the list of mechanisms proposed by the initiator so that mechanisms are
preferred by their advertised support for GSS flags. For example, if
GSS_C_MUTUAL_FLAG is requested, a mechanism that offers GSS_C_MA_AUTH_TARG will
be preferred over one that doesn't. The flag/mechanism attribute combinations
are also assigned a weight (mutual trumps anonymous, for example).
2020-04-12 13:25:09 -05:00
Nicolas Williams
7bf4d76e75 krb5: Improve cccol sub naming; add gss_store_cred_into2()
- Formalize the TYPE:collection_name:subsidiary_name naming scheme for
   ccaches in ccache collections
    - KEYRING: ccaches are weird because they have one more optional field: the
      "anchor", so rather than just assume a naming convention everywhere, we
      add new functions as well
 - Add krb5_cc_{resolve,default}_sub() that allows one to specify a
   "subsidiary" ccache name in a collection separately from the
   collection name
 - Add krb5_cc_{resolve,default}_for() which take a principal name,
   unparse it, and use it as the subsidiary ccache name (with colons
   replaced)
 - Make kinit use the new interfaces
 - Add missing DIR ccache iteration functionality
 - Revamps test_cc
 - Add krb5_cc_get_collection() and krb5_cc_get_subsidiary()
 - Bump the ccops SPI version number
 - Add gss_store_cred_into2()
 - Make MEMORY:anonymous not linked into the global MEMORY ccache
   collection, and uses this for delegated cred handles

TBD:

 - Split this up into a krb5 change and gss mech_krb5 change?
 - Add krb5_cc_init_and_store() utility, per Greg's suggestion?
2020-03-02 17:48:04 -06:00
Luke Howard
921d528d8b gss: add mechanism-force-mechListMIC hook to SPNEGO
NTLM erroneously requires a mechListMIC at the SPNEGO layer if an internal MIC
in the NTLM protocol was used. Add a private interface between SPNEGO and the
Samba NTLM mechanism to allow the mechanism to signal that a mechListMIC is
required even if it otherwise would not be.

This interface is the same as that supported by MIT.

Note that only the Samba NTLM mechanism currently implements this feature, it
is not implemented by the Heimdal NTLM mechanism (which does not support NTLM
authenticate message MICs).
2020-02-04 17:28:35 +11:00
Luke Howard
5d1a33f780 gss: don't explicitly reorder krb5 to front of spnego
Previously krb5 was tried explicitly, but now the internal mech list is
reordered so that krb5 is first, this should no longer be required. This
permits an application to specify another mechanism as preferred over krb5
using gss_set_neg_mechs().
2020-02-04 17:28:35 +11:00
Luke Howard
161f846d76 gss: harmonize negState with RFC 4178
RFC 4178 4.2.2 uses the field name negState rather than negResult in
NegTokenResp, to denote the negotiation state. Harmonize with this, also
replacing the underscores in accept-completed and accepet-incomplete to match
the RFC.
2020-02-04 17:28:35 +11:00
Luke Howard
3e69aacbe2 gss: harmonize SPNEGO with [MS-SPNG]
In [MS-SPNG], the Microsoft extension is defined as NegTokenInit2 rather than
NegTokenInitWin. Harmonize with the specification.
2020-02-04 17:28:35 +11:00
Luke Howard
044c1c6b63 gss: don't generate mechListMIC in SPNEGO if it is safe to omit it 2020-02-04 17:28:35 +11:00
Luke Howard
4fb6a6adc9 gss: port NegoEx implementation from MIT
An implementation of draft-zhu-negoex-04 for MIT Kerberos was developed in
2011. This has been recently integrated, with many fixes from Greg Hudson. This
commit ports it to Heimdal. The implementation has been interoperability tested
with MIT Kerberos and Windows, using the GSS EAP mechanism developed as part of
the Moonshot project.

The SPNEGO code was also updated to import the state machine from Apple which
improves mechListMIC processing and avoids discarding initial context tokens
generated during mechanism probing, that can be used for optimistic tokens.

Finally, to aid in testing, the GSS-API mechanism glue configuration file can
be changed using the environment variable GSS_MECH_CONFIG. This environment
variable name, along with the format of the configuration file, is compatible
with MIT (although it would be difficult for a single mechanism binary to
support both implementations).
2020-02-04 17:28:35 +11:00
Luke Howard
ae5c60286a gss: remove SPNEGO name wrappers
Wrapping GSS names at the SPNEGO level serves no purpose; remove it and return
mechglue names directly. This required a small change to the NTLM mechanism to
allow NULL names to be passed to its release name function.
2020-02-04 17:28:35 +11:00
Luke Howard
83d2951c0d gssapi: SPNEGO does not reset NTLM RC4 state (#509) 2019-01-06 20:50:24 -06:00
Luke Howard
735039dbdc gssapi: implement gss_set_neg_mechs() (#495)
Implementation of gss_set_neg_mechs() and gss_get_neg_mechs() as defined in RFC
4178. New gss_release_cred_by_mech() API for dropping a credential from a
mechanism glue credential.
2019-01-04 15:50:11 +11:00
Luke Howard
dfaaf9c93f gssapi: honor acceptor credential in SPNEGO (#506)
SPNEGO uses the callback function acceptor_approved() in order to determine
which mechanisms to advertise to the initiator in the case that the initiator
sent an empty initial context token. Prior to this commit, that function was
not passed in the acceptor credential (if present), so always uses a default
credential. For correctness, we should only advertise the availability of
mechanisms for which we have a credential.
2019-01-04 15:49:44 +11:00
Luke Howard
e0bb9c10ca gssapi: credential store extensions (#451)
Implement the GSS-API credential store API extensions defined by MIT here:

https://k5wiki.kerberos.org/wiki/Projects/Credential_Store_extensions

Note: we kill off gss_acquire_cred_ext() here. This was never a public API,
although mechanisms could have implemented it and I briefly used it in my
BrowserID prototype mechanism. gss_acquire_cred_ext_from() occupies the place
in the dispatch table where gss_acquire_cred_ext() used to, but this structure
was never visible outside Heimdal (i.e. it is only used by internal
mechanisms);

(Mechanisms that need to accept arbitrary key/value dictionaries from
applications should now implement gss_acquire_cred_from().)
2019-01-03 14:38:39 -06:00
Luke Howard
a7d42cdf6b gssapi: honor initiator credential in SPNEGO (#506)
SPNEGO uses the callback function initiator_approved() in order to determine
mechanism availability. Prior to this commit, is not passed in the initiator
credential, so it always uses a default credential. This breaks SPNEGO if a
non-default credential (such as one acquired with
gss_acquire_cred_with_password()) is used. This commit addresses this.
2019-01-03 23:25:30 +11:00
Nicolas Williams
e6d1c10808 Rewrite gss_add_cred() (fix #413)
It turns out gss_add_cred() really needed a complete rewrite.  It's much
better to first have a gss_duplicate_cred() (which has been needed for
other reasons anyways), and use that when the input_cred_handle is not
GSS_C_NO_CREDENTIAL and output_cred_handle is not NULL, then mutate that
duplicate credential handle (or the input_cred_handle if
output_cred_handle is NULL).
2018-12-28 19:26:25 -06:00
Luke Howard
4a93c4774a gss: intern OIDs (#447)
Intern OIDs so that gss_release_oid() can be a NOOP.
2018-12-18 23:28:38 -06:00
Daria Phoebe Brashear
b12e01035c gss: _locl.h files should include local copy of -private.h files
apparently some versions of heimdal installed mech private headers.
don't inadvertantly end up with it in your path from a previous version
2018-04-19 13:12:59 -04:00
Nicolas Williams
7dfad1ab0b Use secure_getenv() instead of issuid() 2017-04-17 18:02:30 -04:00
Nicolas Williams
52a562a3a4 Misc fixes (coverity) 2016-11-18 22:21:45 -06:00
Nicolas Williams
774f166e31 First attempt s/\<const gss_.*_t/gss_const_.*_t/g 2013-06-02 15:30:58 -05:00