Commit Graph

17575 Commits

Author SHA1 Message Date
Nicolas Williams
686d5116de roken: Unparse wider ints 2021-12-18 11:34:12 +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
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
Andrew Bartlett
93deac696f hdb: Improve naming of constants for hdb_auth_status()
We drop the unused HDB_AUTH_INVALID_SIGNATURE and
rebase the set to start at an invalid 0.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-12-17 13:19:52 +11:00
Andrew Bartlett
bf39060696 hdb: Add clear comments on what the various HDB_AUTH* values mean
Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-12-17 13:19:52 +11:00
Andrew Bartlett
842b856e4c kdc: Pass extra information to hdb_auth_status() to log success and failures
We now pass on the original client name and the client address to allow
consistent audit logging in Samba across multiple protocols.

We also log the authentication duration.

This is not a general purpose profiling solution, but in Smaba
these JSON logs are already being generated and stored, so this
is worth adding.

Some administrators are very keen to know how long authentication
takes, particularly due to long replication transactions in other
Samba processes.

We use config->db[0] to find the first database to record incorrect
users.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
(Similar to Samba commit f498ba77df2313e78863e5f2706840c43e232a96 and
 bb2a1c6b3eaccf114ac3f3b5b51f57828a04996)
[metze@samba.org: improved for heimdal upstream]
Signed-off-by: Stefan Metzmacher <metze@samba.org>
[abartlet@samba.org: improved again for Heimdal based on feedback]
2021-12-17 13:19:52 +11:00
Joseph Sutton
91e86460cd kdc: Add krb5_is_enctype_old() to determine whether an enctype is older
AES256 and AES128 are newer enctypes because they are officially
specified in RFC4120 and RFC8009, while enctypes not officially
specified since RFC4120 are considered older. This function differs from
older_enctype() in that it does not report unknown or non-existent
enctypes as being 'newer'.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-16 16:11:29 +11:00
Joseph Sutton
3e197ecbee kdc: Check name in request against name in user-to-user TGT
Assists Samba to address CVE-2020-25719

Again, this may be contary to RFC4120 3.3.3
https://datatracker.ietf.org/doc/html/rfc4120/#section-3.3.3
(clearer at the GSS spec here:
https://datatracker.ietf.org/doc/html/draft-swift-win2k-krb-user2user-03 )
as server-name is decribed as optional, however Windows AD and Samba
both require that the server-name exist and be a valid SPN matching
the provided TGT.

The lookup of SPN -> entry ensures that the SPN the client thought it
was connecting to was held by the target server. it could be the
typical user principal, or a service principal, but needs to be checked
for the client not to be fooled into connecting to the wrong service.

The check is the same as needed for S4U2Self so the same HDB hook is re-used.

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

(Similar to Samba commit f08e6ac86226dcd939fd0e40b6f7dc80c5c00e79)
2021-12-16 16:09:07 +11:00
Joseph Sutton
ea8e8a4a8a kdc: Avoid races and multiple DB lookups in s4u2self check
Assists Samba to address CVE-2020-25719

Passing in target_server as a string principal means that for
an alias we must looking up the DB twice.

This is subject to a race and is a poor use of resources,
so instead just pass in the record we
already got when trying to confirm that the server in
S4U2Self is the same as the requesting client.

We also avoid doing a name comparison if the HDB plugin provides
a validation hook, this allows the HDB layer more freedom
to choose how to handle things.

In Samba AD the client record has already been bound to the the
original client by the SID check in the PAC, so the record is
known to match the ticket.

Likewise by looking up server only once we ensure that the
keys looked up originally (to decrypt) are in the record
we confirm the SID for here.

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

Signed-off-by: Andrew Bartlett <abartlet@samba.org>

(Based on Samba commit 05898cfb139ae0674c8251acc9d64c4c3d4c8376)
2021-12-16 16:09:07 +11:00
Nicolas Williams
4aa8677081 kadm5: Use KADM5_PASS_Q_GENERIC 2021-12-16 10:40:01 +11:00
Nicolas Williams
437d4e95ec kadm5: Add KADM5_PASS_Q_GENERIC, note MIT diffs 2021-12-16 10:40:01 +11:00
Nicolas Williams
2a9e998072 krb5: Fix incorrect use of KRB5_ERR_NO_SERVICE 2021-12-16 10:40:01 +11:00
Nicolas Williams
9d426d20b5 krb5: Add missing errors from MIT krb5
Note that KRB5_ERR_NO_SERVICE changed value, as it was off by one.
2021-12-16 10:40:01 +11:00
Nicolas Williams
af923957f6 krb5: Make test_cc w/ KEYRING more reliable
Joining a new keyring session every time seems to make it better.
2021-12-15 16:55:46 -06:00
Luke Howard
d6f9cec30f hdb: do not return HDB_ERR_WRONG_REALM if force_canon set
In hdb_fetch_kvno(), do not return HDB_ERR_WRONG_REALM if the backend set the
force_canonicalize flag

Closes: #886
2021-12-14 18:00:05 +11:00
Nicolas Williams
a616cec9d8 kdc: Document enable-pkinit param 2021-12-14 17:32:20 +11:00
Nicolas Williams
660f875a34 kdc: Add [kdc] params to control PA-ENC-TIMESTAMP 2021-12-14 17:32:20 +11:00
Joseph Sutton
717ad8b043 kdc: Add support for explicit armoring from MS-KILE
Normally when FAST is used with a TGS-REQ, the armor key is implicitly
derived from the TGT rather than armor being explicitly present, as for
AS-REQs. However, Windows allows a TGS-REQ to be explicitly armored with
a computer's TGT, so that the armor key also depends on the ticket
session key.

This is used for compound identity, where the computer's group
membership and claims are added to the PAC of the resulting ticket.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-14 16:19:01 +11:00
Joseph Sutton
814e58fda8 heimdal: Make _krb5_pac_get_kdc_checksum_info() into a global function
This lets us call it from Samba.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>

[abartlet@samba.org Similar to Samba commit 3bdce12789af1e7a7aba56691f184625a432410d
 but also fixed for caller in Heimdal windc plugin tests]
2021-12-14 13:44:01 +11:00
Joseph Sutton
f1255da03c krb5: Check asprintf return value
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-13 21:20:10 -05:00
Joseph Sutton
b8f8906822 asn1: Fix binary search off-by-one read
Previously, if left==right==A1_HEADER_LEN(tos), this would read past the
end of the template array. Now we treat [left, right) as a half-open
interval and no longer try to read from 'right'.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-13 19:18:24 -06:00
Luke Howard
f95f4bc99e krb5: require strengthen_key when FAST + GSS PA
Always require a strengthen key to be used if GSS pre-authentication is used
within FAST. TRhis avoids a MITM attack that could result in unintended
privilege escalation, should a KDC add additional positive authorization data
from the armor ticket to the issued ticket.

An upcoming revision of the draft will reflect this.
2021-12-14 09:03:42 +11:00
Luke Howard
9b55215a2a kdc: sync KDC FAST with Heimdal-597.121.1
Import KDC FAST from Apple's Heimdal-597.121.1, adding support for:

  - PA-ENC-CHALLENGE
  - reply key strengthening
  - FAST authentication in TGS

kuser: Apple sync (squash)

krb5_init_creds_store_config/krb5_init_creds_warn_user in kinit
2021-12-14 09:03:42 +11:00
Luke Howard
47282cae34 krb5: import Heimdal-597.121.1 AS/TGS client
Sync with most changes in AS/TGS client from Apple's Heimdal-597.121.1
(opensource.apple.com).

Changes include:

 - FAST support in TGS client
 - Refactored pre-auth client to be more easily extensible
 - Pin KDC host and AD site name in API calls

Note the completely refactored TGS client loop is not imported as that was
considered too intrusive.
2021-12-14 09:03:42 +11:00
Nicolas Williams
b5a58df8eb krb5: Document return of krb5_cc_get_config() 2021-12-10 17:20:05 -06:00
Nicolas Williams
f44596b14b krb5: Fix null deref in krb5_init_creds_free() 2021-12-10 17:20:05 -06:00
Luke Howard
cfa49a461c krb5: do not pack ccapi on Apple Silicon
Fix fb6f89f2 so #pragma(pop) is also similarly guarded to exclude ARM
2021-12-10 11:11:16 +11:00
Luke Howard
eb85614c24 Revert "s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows"
This reverts commit 24a7a82e82.

After further discussion in #863, the alignment (which differs according to
info buffer type) should be handled by the caller.
2021-12-10 11:02:17 +11:00
Joseph Sutton
24a7a82e82 s4/heimdal/lib/krb5/pac.c: Align PAC buffers to match Windows
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14642

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
(cherry picked from Samba commit 28a5a586c8e9cd155d676dcfcb81a2587ace99d1)
2021-12-09 09:53:03 +11:00
Joseph Sutton
9b62d72d51 heimdal:kdc: Match Windows error code for unsupported critical FAST options
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:31:58 +11:00
Joseph Sutton
527906c821 heimdal:kdc: Properly check for unsupported critical FAST options
Decoding a FAST request will only give us the FastOptions flags that are
explicitly declared in the ASN1 source. This meant that the check for
unsupported mandatory options would never succeed, and an unsupported
option would go undetected.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:31:58 +11:00
Joseph Sutton
d2dc61c720 heimdal: Initialise KDC reply
The reply structure was not being zero-initialised in all cases, leading
to crashes or possible heap corruption on error paths when we later
freed it.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2021-12-07 15:03:22 +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
Nicolas Williams
bba573f286 krb5: 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
6f7c6a7f67 krb5: Fix out-of-tree SQLite3 ccache perms issue
SQLite3 defaults to 0644 unless overridden, relying on the process'
umask to make that tighter.

Our in-tree SQLite3 uses 0600 as the permissions for DB files it
creates.

Out-of-tree builds of SQLite3 probably get the 0644 default.

We can't change the umask in libraries -- it's not thread-safe.

So this commit changes the SCC ccache type's default ccname to include
an intermediate directory which is created with `mkdir(2)` with
permissions set to 0700, then it chmods the DB file to 0644.
2021-11-30 11:34:04 -06:00
Nicolas Williams
a025788a37 krb5: Make test_cc run keyctl new_session 2021-11-30 11:42:00 -05:00
Nicolas Williams
90db9b96a4 krb5: Make test_cc not step on user ccaches
And cleanup on exit.
2021-11-30 11:42:00 -05:00
Nicolas Williams
6918322c79 krb5: Fix FILE ccache my_basename() bug 2021-11-30 11:42:00 -05:00
Nicolas Williams
bacc484b2a krb5: Fix umask issue with SQLite3 2021-11-30 11:42:00 -05:00
Nicolas Williams
aeac1186c8 sqlite: Be thread-safe on Windows too 2021-11-30 11:42:00 -05:00
Nicolas Williams
250eee7acf sqlite: Use 0600
The in-tree SQLite3 is used for HDB and ccache -- these should have
0600 permissions.

Of course, if we're using an out-of-tree SQLite3, then we need to rely
on the process' umask, but we use SQLite3 in libraries, where we can't
set the umask...

What to do?

TBD:

 - On Windows: nothing to do.

 - On Unix: if SQLite3 is out of tree then [v]fork() to create the
   connection then close, then connect again after??

   Or... maybe make sure to create an intermediate directory with 0700
   permissions?
2021-11-30 11:42:00 -05:00
Nicolas Williams
beae9c3c43 roken: Use ptsname_r() if we have it 2021-11-30 11:42:00 -05:00
Nicolas Williams
c84384c544 krb5: Fix doxygen comments 2021-11-30 11:42:00 -05:00
Nicolas Williams
63034f36ae base: Fix doxygen comments 2021-11-30 11:42:00 -05:00
Luke Howard
8a54096266 hx509: revert UTF-8 change to hx509 test data
76860287 changed all KTH copyrights to use UTF-8, but that broke test_cms.
Revert that commit as applied to the test data.
2021-11-30 12:12:47 +11:00
Andrew Bartlett
7686028718 Use UTF-8 in KTH copyright notice
Samba is starting to protect against bi-di attacks and the starting point
is to require that input files be fully UTF-8.  In 2021 this is a reasonable
starting point anyway.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-11-29 12:50:26 +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