Commit Graph

29970 Commits

Author SHA1 Message Date
Nicolas Williams
0c7b06f9ca cf: Check cc support of -Werror=enum-conversion 2022-01-13 15:33:04 -06:00
Marc Dionne
fc4b3ce49b hcrypto: Fix return type for null_Init, null_Update and null_Final
The hc_evp_md_init, hc_evp_md_update and hc_evp_md_final typedefs
are defined as functions returning an int, but null_Init, null_Update
and null_Final are defined as void, and cast with the typedef when
assigned to the function vector.

This might result in some uninitialized value being returned to the
caller, if some of them make use of the return value.  It also causes
warnings if the -Wcast-function-type warning is enabled.

Change the type to in to match the typedef, and return 1 (success).
2022-01-13 16:00:50 -05:00
Luke Howard
6530021f09 kdc: move auth event definitions into KDC header
Move KDC auth event macro definitions out of hdb.h and into a new KDC header,
kdc-audit.h.
2022-01-13 14:51:31 +11:00
Nicolas Williams
04523254c1 asn1: Restore styling of generated sources 2022-01-11 17:45:27 -06:00
Nicolas Williams
ff4033eb59 asn1: Fix Windows build 2022-01-11 17:15:59 -06:00
Nicolas Williams
6ee1554f3e Ignore enum-conversion errors
This is not a very good fix, though the warnings remain.  Such errors
can in principle be a problem because in C there is no standard enum
sizing.

In this case we have two enums with the same elements and so the same
size, so it's clearly not a problem.
2022-01-11 17:15:59 -06:00
Nicolas Williams
284b29a85c asn1: Fix missing LIB_heimbase dependency 2022-01-11 10:55:19 -06:00
Nicolas Williams
40d1271094 asn1: Expand decoration w/ C types
This commits allows `heim_object_t` as a type and causes the generated
code to use the `heim_retain()` and `heim_release()` functions for
copying and releasing values of such types.

Also, now one can have more than one decoration per-type.
2022-01-11 10:21:05 -06:00
Luke Howard
ef906991fd asn1: don't include decoration header for void *
If the decorated external type is a void *, don't include the decoration
header in the ASN.1 header, only in the template implementation. This allows
the copy constructor and destructor to be implementation private.
2022-01-11 09:57:11 -06:00
Nicolas Williams
df3e08485b asn1: Add support for decoration w/ external types
This adds support for asn1_compile --decorate=... variation that causes
decoration of an ASN.1 SET/SEQUENCE type with a field of a non-ASN.1
type.

This means we can now have an ASN.1 type to represent a request that can
then have a "hidden" field -- hidden in that it is neither encoded nor
decoded.  This field will be copied and freed when the decoration is of
an ASN.1 type or of a external, C type that comes with copy constructor
and destructor functions.  Decoration with a `void *` field which is
neither copied nor freed is also supported.

We may end up using this to, for example, replace the `hdb_entry_ex`
type by decorating `HDB_entry` with a C type that points to the `HDB` in
which the entry was found or to which it should be written.
2022-01-11 09:57:11 -06:00
Luke Howard
10fc7730d0 kdc: send request, not TGS, server name in TGS errors
Return the request server principal name in TGS errors rather than the TGS
server name.
2022-01-10 15:29:49 +11:00
Luke Howard
40e4a4df09 kdc: use astgs_request_t for client/server name (TGS)
Store the client and server principal name from the TGT and request
(respectively) in the astgs_request_t rather than using local variables.
2022-01-10 15:29:49 +11:00
Luke Howard
2520c30b28 base: harmonize implementation/headers
heim_retain() should both accept and return a heim_object_t; harmonize this
across header and implementation
2022-01-08 17:40:22 +11:00
Luke Howard
a96f87c4ab asn1: don't clobber checked in files in clean target
Fix regression introduced in 9427796f, where checked in files matching asn1_*.c
would be clobbered by "make clean".

Change-Id: Ifc4bbe3c46dd357fdd642040ad964c7cfe1d395c
2022-01-08 17:38:46 +11:00
Luke Howard
1dd5aa2f5d kdc: don't leak etype/error message in pa_enc_ts_validate()
Recent auditing changes (b1dcc1a4) introduced a leak into pa_enc_ts_validate()
where the encryption type name and error message could be leaked.

This patch fixes a compile error in the original commit.
2022-01-08 14:12:26 +11:00
Luke Howard
6f0727fa00 Revert "kdc: don't leak etype/error message in pa_enc_ts_validate()"
This reverts commit ed2579e8af.
2022-01-08 14:12:06 +11:00
Luke Howard
ed2579e8af kdc: don't leak etype/error message in pa_enc_ts_validate()
Recent auditing changes (b1dcc1a4) introduced a leak into pa_enc_ts_validate()
where the encryption type name and error message could be leaked.
2022-01-08 14:10:51 +11: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
Luke Howard
27d62bb27e gss: avoid showing PAC in test_context if anon
The Heimdal KDC does not add a PAC if an anonymous ticket was issued. As such,
test_context should not expect PAC naming attributes to be present if the
--anonymous option was passed. (This is irrelevant for now as GSS_C_ANON_FLAG
is not honored by the krb5 mechanism.)
2022-01-08 10:12:07 +11:00
Luke Howard
402884a310 gss: validate attr enumeration in test_context
Ensure the "urn:mspac:client-info" name attribute is enumerated by
gss_inquire_name(), as well as being available via gss_get_name_attribute().
2022-01-08 09:38:30 +11:00
Luke Howard
e5e87497b1 hdb: use memset_s to zero HDB keys 2022-01-08 08:49:45 +11:00
Nicolas Williams
768d193e01 krb5: Fix warnings (from 54581d2d) 2022-01-06 16:24:08 -06: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
Luke Howard
e06eeb5256 roken: use %zu format string for size_t 2022-01-06 22:36:48 +11:00
Luke Howard
90704baf76 asn1: use %zu format string for size_t 2022-01-06 17:52:09 +11:00
Luke Howard
0a4830068f roken: use %zu format string for size_t 2022-01-06 17:52:00 +11:00
Luke Howard
97cca6f921 base: use uintptr_t for hash type
Use uintptr_t for hash type; this is consistent with CoreFoundation, which uses
32-bit integers on 32-bit platforms for the hash code, and 64-bit integers on
64-bit platforms. (libheimbase is modelled on CoreFoundation.)

Previously we used unsigned long, which would have the same behavior on
LP32/LP64 systems, but not on Windows (where unsigned long is 32-bits on 64-bit
platforms).
2022-01-06 17:21:06 +11:00
Jeffrey Altman
6b788c2378 lib/asn1: template cast integer const to uintptr_t then void ptr
Cast integer constants to (void *) with an intermediate cast to
(uintptr_t).   On Windows this avoid warnings about a signed
integer being cast to a pointer of larger size.

No functional change.

Change-Id: I7289fb772870c5f492c1a8b988e0d80cf008b7f4
2022-01-05 19:56:43 -05:00
Nicolas Williams
2375fa9d1e gss: Too many compilers don't support 'restrict' 2022-01-05 18:03:39 -06:00
Nicolas Williams
01b1916ec2 asn1: Close _files output last 2022-01-05 17:50:00 -06:00
Jeffrey Altman
9427796f1a Generate .x source files as .c source files
The generated .x source and .hx header files are plain C source files.
Generate them as .c source files and avoid unnecessary file copying
and special makefile rules.

Change-Id: Ifc4bbe3c46dd357fdd642040ad964c7cfe1d395c
2022-01-05 17:36:24 -06:00
Nicolas Williams
4919daa7ab appveyor: Use VS 2019 image to get working msys2
The msys2 installation on Appveyor's Windows build images older than
Visual Studio 2019 are hopelessly out of date.

Diagnostics from the msys2 crew:

 - https://github.com/msys2/MSYS2-packages/issues/2785
 - 5fc9d54289

Ticket opened with Appveyor about this:

 - https://help.appveyor.com/discussions/problems/31153-default-windows-image-msys2-repos-out-of-date
2022-01-05 12:59:35 -06:00
Jeffrey Altman
fb1ded497a lib/asn1: gen_template cast integer const to uintptr_t then void ptr
When generating code cast integer constants to (void *) with an
intermediate cast to (uintptr_t).   On Windows this avoid hundreds
of warnings about a signed integer being cast to a pointer of larger
size.

No functional change.

Change-Id: Ifd2acd0cfe99a7859aad58e79ab0f0c12b28fdeb
2022-01-05 12:58:48 -06:00
Jeffrey Altman
42ad8b4c55 lib/asn1: build static runtime version of libasn1 on Windows
This commit builds a static runtime version of the asn1 library
which is required for some thirdparty applications.

  LIBASN1_S   =$(LIBDIR)\libasn1_s.lib

This differs from libasn1.lib which is compiled to use the
dynamic runtime.

Change-Id: Ib04f5b53a7f16d7bbe9d2debb75e944322a6792a
2022-01-05 12:58:48 -06:00
Jeffrey Altman
6694f98791 lib/asn1: gen require ASN1_LIB be defined on Windows when compiling
Instead of defining ASN1_LIB in each of the generated ASN1 source
files require that the generated source file be compiled with the
ASN1_LIB symbol defined (on Windows).  All of the compiled objects
linked into the same library which might be accessing an ASN1 exported
symbol must have ASN1_LIB defined to ensure that the use of the
exported symbols will not be via an import.

Change-Id: Ie38c105d1d376419717fce0830dc28f5b82547d4
2022-01-05 12:58:48 -06:00
Jeffrey Altman
4f4d1a0288 lib/hdb: define LIB_ASN1 on Windows if ASN1 generated objects
The LIB_ASN1 definition instructs the library objects to access
exported ASN1 generated DATA symbols as internal symbols.

Change-Id: I58b055808893c6f3af48fc2dd997e0dedea2ffcb
2022-01-05 12:58:48 -06:00
Jeffrey Altman
3efca1e98a lib/gssapi: define LIB_ASN1 on Windows if ASN1 generated objects
The LIB_ASN1 definition instructs the library objects to access
exported ASN1 generated DATA symbols as internal symbols.

Change-Id: Ia8c674c879c9bc46ca9dc7f249114f22b1d0dfd5
2022-01-05 12:58:48 -06:00
Jeffrey Altman
0a7d227788 lib/asn1: define LIB_ASN1 when building Windows ASN1 libraries
The LIB_ASN1 definition instructs the library objects to access
exported DATA symbols as internal symbols.

Change-Id: Ifbc80a4e3c357cb323f7763c116101ae495b11df
2022-01-05 12:58:48 -06:00
Jeffrey Altman
a4ba38ff7e asn1: NTMakefile include oid_resolution.obj in LIBASN1_OBJS
oid_resolution.obj does not depend upon $(LIBASN1_OBJ) object
files.  It depends upon the generated .x files produced by
asn1_compile.exe when building $(gen_files_xxx).   Create a
new list of those dependencies explicitly for oid_resolution.obj.

Change-Id: I09a4dc9efb7a84e68da939b6a3ec5f55354c02ee
2022-01-05 12:58:48 -06:00
Luke Howard
ec866e635e Windows 10 SDK build fixes
Build without Win32.mak, and using Universal C Runtime (UCRT)

windows: Check for APPVER, not VCVER for UCRT

When deciding whether UCRT is used (and thus no CRT merge modules), check for
Windows 10 rather than the version of Visual Studio, as we may be building with
an older SDK.
2022-01-05 12:58:48 -06:00
Luke Howard
7cc4b7a9e6 kdc: KDC plugin API contract notes
Add some notes about the KDC plugin API contract, and require plugins to
explicitly indicate which version of the API they support (remove the macro
alias for the current version).
2022-01-05 13:08:11 +11:00
Luke Howard
78ad37ee47 kdc: use r->canon_client_princ field in AS
r->canon_client_princ is always an alias to r->client->entry.principal in the
AS, but use it for consistency with the TGS. (In the TGS, it may also come from
te PAC.)
2022-01-05 13:01:06 +11:00
Luke Howard
0287558838 kdc: move Services for User implementation out of krb5tgs.c
Move the Services for User (SFU/S4U) implementation -- protocol transition and
constrained delegation -- into its own compilation unit, with an interface that
only takes an astgs_request_t, so it can be easily factored out into a plugin
module in the future.

This refactoring is also careful to update all client names in the request
structure after the SFU/S4U validation has successfully completed.
2022-01-05 13:01:06 +11:00
Luke Howard
06f8985c55 hdb: consolidate preauth audit event types
Instead of having distinct preauth success/failure events for different
mechanisms, have a single event; the mechanism can be disambiguated by querying
the HDB_REQUEST_KV_PA_NAME key.

Note: there is still an explicit event for long-term key-based success/failure
in order to help the backend implement lockout.

Audit failure (HDB_AUTH_EVENT_PREAUTH_FAILED) in the main preauth loop, rather
than in each mechanism. Success is still audited in the mechanism to allow
client pre-authentication success to be noted even if something subsequent
(e.g. encoding a reply, memory allocation) fails. The generic catch-all for
success remains.
2022-01-05 09:42:03 +11:00
Luke Howard
68c4fd6572 kdc: audit preauth event only at end of PA loop
Don't audit preauth event if the preauth mech returns
KRB5_KDC_ERR_MORE_PREAUTH_DATA_REQUIRED; only set the event on (final) failure
or success.
2022-01-05 09:37:55 +11:00
Luke Howard
d90718c9b6 base: set HEIM_JSON_F_NO_DATA_DICT in heim_audit_setkv_object()
Fixes pretty-printing data print to work with heim_audit_setkv_object() as well
as heim_audit_addkv_object().
2022-01-04 06:30:32 +00:00