Commit Graph

1167 Commits

Author SHA1 Message Date
Nicolas Williams
0b137e3287 gss: Workaround valgrind "lifetime not equal" issue 2022-01-18 12:35:26 -06:00
Joseph Sutton
1c93a6ff26 heimdal: Avoid overflow when performing bitwise shift operations
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-01-18 00:31:45 -05:00
Nicolas Williams
00dd104b96 gsskrb5: Fix dead code issues in deleg cred path 2022-01-17 18:10:08 -06:00
Nicolas Williams
7fe5799090 gsskrb5: Fix dead code in get_transited() 2022-01-17 11:50:16 -06:00
Nicolas Williams
fe63ddc487 gsskrb5: Remove dead code in split_attr() 2022-01-17 11:01:19 -06:00
Jeffrey Altman
c822b9bc96 gssapi/krb5: _gsskrb5_inquire_name init 'major'
If no attributes are indicated 'major' is unset.  Default to
GSS_S_UNAVAILABLE.

Change-Id: I277ebdebab0fb0322b702638c57548d1f4c4be3d
2022-01-16 15:54:47 -05:00
Luke Howard
5a952ee7b5 krb5: decorate PrincipalNameAttrs with krb5_pac
Add krb5_pac to PrincipalNameAttrs to avoid needing to re-parse it each time
gss_get_name_attribute() is called.
2022-01-15 18:54:57 +11:00
Jeffrey Altman
9f3004bfd5 gssapi/krb5: _gsskrb5_export_sec_context copy/paste error
80f3194a76
("gssapi/krb5/{export,import}_sec_context: make smaller tokens.")
stored the source principal when it should have stored the target
principal.

Change-Id: Ife6b137f9fe8f63cdb78b4212f74d502080ec2a2
2022-01-14 23:01:30 -05:00
Nicolas Williams
55fa5bf7d2 gsskrb5: Fix warnings 2022-01-14 17:39:05 -06:00
Nicolas Williams
96b7ea671d gss: Fix warnings 2022-01-14 17:39:05 -06:00
Nicolas Williams
c607135a03 Use fallthrough statement attribute (moar) 2022-01-14 16:53:34 -06:00
Nicolas Williams
ddc6113610 Use fallthrough statement attribute 2022-01-14 16:32:58 -06:00
Nicolas Williams
472509fd46 gsskrb5: Do not leak authenticator on retry
We have a Heimdal special where when the acceptor sends back an error
token for clock skew or ticket-not-yet-valid errors then the acceptor
application will get GSS_S_CONTINUE_NEEDED from gss_accept_sec_context()
so that the initiator may retry with the same context.

But we were retaining the auth_context, which means that when the
initiator does send a new token, the acceptor leaks memory because
krb5_verify_ap_req2() doesn't clean up the auth_context on reuse.  The
end result is that we leak a lot in those cases.
2022-01-07 21:04:19 -06:00
Nicolas Williams
2d83a0b8cd gss: Make sure to indicate PAC buffers 2022-01-08 10:38:01 +11:00
Nicolas Williams
c2e3c5b66e gss: Add way to set authenticator authz-data
Now we can set Authenticator authorization-data with
gss_set_name_attribute().
2022-01-08 10:38:01 +11:00
Nicolas Williams
fe11481cc5 gss: Make krb5 name attrs table-driven
The implementation of GSS name attributes for Kerberos (or any mechanism
with more than a tiny handful) is much nicer as a table-driven
implementation.

We now have stubs for setting and deleting attributes as well, though
these currently always fail.
2022-01-08 10:38:01 +11:00
Nicolas Williams
2b9b701dc4 gss: Fix warnings (from be708ca3cf) 2022-01-06 16:21:55 -06:00
Nicolas Williams
3af6926c7d gss: Fix sign extension bug (from be708ca3cf)
When unsigned char values are shifted, they are promoted to int (unless
sizeof(int) == sizeof(char)).  This means that the change in be708ca3cf
ultimately leads to a sign extension bug.
2022-01-06 15:25:38 -06:00
Nicolas Williams
2375fa9d1e gss: Too many compilers don't support 'restrict' 2022-01-05 18:03:39 -06:00
Luke Howard
5cce73a6ef gss: expose canonical name from PAC if present
Expose canonical name via the canonical-name naming attribute.
2022-01-03 15:59:16 +11:00
Luke Howard
2a826d769f gss: expose PAC info buffers under urn:mspac:
Expose PAC info buffers using naming attributes prefixed with urn:mspac:,
aligned with MIT.
2022-01-03 15:59:16 +11:00
Nicolas Williams
be708ca3cf gsskrb5: Add simple name attributes support
This adds Kerberos mechanism support for:

 - composite principal name export/import
 - getting rudimentary name attributes from GSS names using
   gss_get_name_attribute():
    - all (raw) authorization data from the Ticket
    - all (raw) authorization data from the Authenticator
    - transit path
    - realm
    - component count
    - each component
 - gss_inquire_name()
 - gss_display_name_ext() (just for the hostbased service name type
                           though)

The test exercises almost all of the functionality, except for:

 - getting the PAC
 - getting authz-data from the Authenticator
 - getting the transit path

TBD (much) later:

 - amend test_context to do minimal name attribute checks as well
 - gss_set_name_attribute() (to request authz-data)
 - gss_delete_name_attribute()
 - getting specific authorization data elements via URN fragments (as
   opposed to all of them)
 - parsing the PAC, extracting SIDs (each one as a separate value)
 - some configurable local policy (?)
 - plugin interface for additional local policy
2022-01-01 23:30:15 -06:00
Nicolas Williams
09f3f96467 gsskrb5: Use optimistic anon PKINIT armored FAST 2021-12-30 18:54:54 +11:00
Nicolas Williams
83625d349e gss: Make initiator inq. ctx. return canon. target
Make gss_inquire_context() on the established context on the initiator
side return the canonical target acceptor name.
2021-12-06 17:39:22 -06:00
Nicolas Williams
5ace5f5a6a gss: Fix dst TGT deleg w/o dns_lookup_realm
Setting `dns_lookup_realm = false` in `[libdefaults]` and setting name
canon rules that force the empty realm causes destination-TGT delegation
to break because the client doesn't know the service's realm.

Because MIT and Heimdal check that the (unauthenticated plaintext)
sname/realm of the Ticket in the KDC reply matches the sname/srealm in
the enc-part of the KDC reply, we know we can trust the realm of the
ticket found in the ccache.  So use that.
2021-12-06 17:39:22 -06:00
Luke Howard
eb293680a8 gss: fix regression in non-8003 checksums
Samba3 sends an AP-REQ, rather than 8003, checksum in a Kerberos inital context
token. This regressed in #835 as we forgot to set the
KRB5_CRYPTO_FLAG_ALLOW_UNKEYED_CHECKSUM flag before processing the AP-REQ
checksum in this path.
2021-12-07 10:41:40 +11:00
Nicolas Williams
5f63215d0d Always perform == or != operation on cmp function result
Although not required to address bad code generation in
some versions of gcc 9 and 10, a coding style that requires
explicit comparison of the result to zero before use is
both clearer and would have avoided the generation of bad
code.

This change converts all use of cmp function usage from

```
    if (strcmp(a, b) || !strcmp(c, d)) ...
```

to

```
    if (strcmp(a, b) != 0 || strcmp(c, d)) == 0
```

for all C library cmp functions and related:

 - strcmp(), strncmp()
 - strcasecmp(), strncasecmp()
 - stricmp(), strnicmp()
 - memcmp()

Change-Id: Ic60c15e1e3a07e4faaf10648eefe3adae2543188
2021-11-24 22:30:44 -05:00
Jeffrey Altman
02200d55ea Address GCC Bug 95189 memcmp wrongly stripped like strcmp
As documented in Russell O'Connor's blog, Heimdal when compiled with
some versions of gcc 9 and 10 would generate incorrect behaviors from
_gssapi_verify_mic_arcfour(), _gssapi_unwrap_arcfour(),
_gssapi_unwrap_iov_arcfour() and _gssapi_unwrap_iov_arcfour().

As a result of the bug, code of the form

   if (memcmp(a, "\x00\x00\x00\x00"))

and

   cmp = memcmp(a, "\x00\x00\x00\x00")

will be compiled as if it were written as

   if (strcmp(a, "\x00\x00\x00\x00"))

and

   cmp = strcmp(a, "\x00\x00\x00\x00")

but not

   if (memcmp(a, "\x00\x00\x00\x00") != 0)

and

   cmp = (memcmp(a, "\x00\x00\x00\x00") != 0)

Bad code is generated whenever one of the parameters to memcmp()
is a constant with at least one NUL in the first four octets and
the return value is used immediated without a boolean comparison.

The gcc bug 95189 has since been fixed.

This change applies a defensive programming technique to avoid
the broken code generation.

Change-Id: I1db2a561735317cb6cac66a0ec9caf5443e65e03
Link: https://r6.ca/blog/20200929T023701Z.html
Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95189
Reported-by: Buck Huppmann (buckh@pobox.com) <buckh@pobox.com>
2021-11-24 22:30:44 -05:00
Jeffrey Altman
8123ffc3f2 _gssapi_unwrap_iov_arcfour remove duplicate code block
ad3acc2aef ("lib/gssapi/krb5:
implement gss_[un]wrap_iov[_length] with arcfour-hmac-md5")
introduced a duplicate block of code.

This change removes the unnecessary code duplication.

Change-Id: I557c590aea51b73dc25d6ce4be4ea84b9dfadd9f
2021-11-24 22:30:44 -05:00
Robert Crowston
5d462795ce Add stub for gss_acquire_cred_impersonate_name(). 2021-10-19 20:45:40 +11:00
Luke Howard
fc9f9b322a gss: implement gss_krb5_ccache_name()
Correctly implement gss_krb5_ccache_name() in terms of
gss_set_sec_context_option(GSS_KRB5_CCACHE_NAME_X). The previous implementation
was a NOOP.

Note: global ccache name should really be thread-specific rather than global.

Closes #803.
2021-09-06 13:26:55 +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
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
Roland C. Dowdeswell
fe426f7a28 fix type s/MUTAL/MUTUAL/ in gssapi/krb5 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
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
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
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
Nicolas Williams
7d50445d1b Generic: Fix warnings (fallthrough mosty) 2020-09-07 22:04:59 -05:00
Luke Howard
ad2a352600 gssapi/krb5: treat empty padding buffers as absent
For compatibility with SSPI, treat an empty padding buffer as equivalent to an
absent padding buffer (unelss the caller is requesting allocation).
2020-07-12 15:55:02 +10:00
Luke Howard
c105b15605 gssapi/krb5: ensure singleton buffer in _gk_find_buffer()
_gk_find_buffer() is used to locate singleton header, padding or trailer
buffers. Return NULL if multiple such buffers are found.
2020-07-12 15:54:52 +10:00
Jeffrey Altman
33ff163141 gss/krb5: acquire_cred_with_password set opt default flags
acquire_cred_with_password() must call
krb5_get_init_creds_opt_set_default_flags() to initialize the
krb5_get_init_creds option flags to the values obtained from
the krb5_context.

Change-Id: Icd8c500dd0787a781c2382284f19cef277b1d30b
2020-07-12 15:28:19 +10:00
Luke Howard
62d913a551 gssapi/krb5: use GSS_IOV_BUFFER_FLAG_ALLOCATE constants
GSS_IOV_BUFFER_TYPE_FLAG_ALLOCATE is deprecated as indicated in gssapi.h, use
GSS_IOV_BUFFER_FLAG_ALLOCATE instead
2020-07-12 14:26:14 +10:00
Luke Howard
4b543b727a gssapi/krb5: fix rc4-hmac gss_unwrap_iov() without DCE_STYLE
gss_unwrap_iov() with rc4-hmac (RFC4757) encryption types would fail unless
GSS_C_DCE_STYLE was specified, as an incorrect length was passed to
_gssapi_verify_mech_header(). (The correct length is the header length for
GSS_C_DCE_STYLE, and the wrap token length otherwise.)
2020-07-12 14:26:14 +10:00
Luke Howard
b73baa42ef gssapi/krb5: make PADDING buffer optional in GSS IOV API
RFC 4121/4757 don't require padding as they operate as stream ciphers. Make the
PADDING buffer optional when using these encryption types with gss_wrap_iov()
and gss_unwrap_iov().
2020-07-12 14:26:14 +10:00
Nicolas Williams
a684e001ba gsskrb5: Check dst-TGT pokicy at store time
Our initiator supports configuration-driven delegation of destination
TGTs.

This commit adds acceptor-side handling of destination TGT policy to
reject storing of non-destination TGTs when destination TGTs are
desired.

Currently we use the same appdefault for this.

Background:

    A root TGT is one of the form krbtgt/REALM@SAME-REALM.

    A destination TGT is a root TGT for the same realm as the acceptor
    service's realm.

    Normally clients delegate a root TGT for the client's realm.

    In some deployments clients may want to delegate destination TGTs as
    a form of constrained delegation: so that the destination service
    cannot use the delegated credential to impersonate the client
    principal to services in its home realm (due to KDC lineage/transit
    checks).  In those deployments there may not even be a route back to
    the KDCs of the client's realm, and attempting to use a
    non-destination TGT might even lead to timeouts.
2020-07-09 13:27:11 -05:00
Jeffrey Altman
99416eeead gssapi/krb5: delete_sec_context must close ccache if CLOSE_CCACHE
_gsskrb5_init_sec_context() when called with GSS_C_NO_CREDENTIAL
opens the default ccache and sets the CLOSE_CCACHE flag indicating
that the ccache lifetime is tied to the gsskrb5_ctx.   When
_gsskrb5_delete_sec_context() is called, it must close the ccache
if the CLOSE_CCACHE flag is set.  Otherwise, the ccache resources
will leak.

Leaked since 39fe446983.

Change-Id: I8d0faab1e844d68fe71b11b715f8d88fcd2f4af7
2020-06-29 11:40:48 -04:00