Commit Graph

30450 Commits

Author SHA1 Message Date
Nicolas Williams
c015db46da windows: Do not make test in kadmin/
Somehow the dreaded C1041 error pops up.
2022-10-03 09:44:22 -05:00
Nicolas Williams
ceec364ed4 ktutil: Add import command and other improvements
- Add an import command that imports JSON as output by
   `ktutil list --json --keys`.

   This is enables one to filter/edit keytabs with jq!

 - Add a `merge` alias for the `copy` command, since that's effectively
   what it does.

 - Add a `--copy-duplicates` option to the `copy`/`merge` command.

 - Add a `--no-create` option to the `get` command.

 - Add a `--no-change-keys` option to the `get` command.

 - Make `add` complain if it can't finish writing to the keytab.
2022-10-03 09:44:22 -05:00
Nicolas Williams
69dc89b39a ktutil: Add list --json option 2022-10-03 09:44:22 -05:00
Nicolas Williams
6297b76362 klist: Real JSON output 2022-10-03 09:44:22 -05:00
Nicolas Williams
f90f055659 iprop: Enable secondary KDC bootstrapping w/ PKINIT
With this change it's possible to bootstrap a KDC using a client
certificate with a PKINIT SAN for iprop/fqdn.  Given such a certificate
one could run ipropd-slave via kinit to pull down the initial copy of
the HDB, then start the KDC services using the HDBGET: keytab.

That should make bootstrapping new secondary KDCs very easy.

One could bootstrap the KDC with such a certificate using, e.g.,
Safeboot (https://github.com/osresearch/safeboot), enrolling the host as
a KDC.
2022-10-02 22:46:37 -05:00
Nicolas Williams
56c6120522 httpkadmind: Make more like bx509d internally
- Correct handling of POST (before POSTs with non-zero-length bodies
   would cause the server to close the connection).

 - Add CSRF features from bx509d.
2022-10-02 22:46:37 -05:00
Nicolas Williams
ae527bf97c bx509d: Add /get-tgts batch end-point
In order to support batch jobs systems that run many users' jobs and
which jobs need credentials, we add a /get-tgts end-point that is a
batched version of the /get-tgt end-point.  This end-point returns JSON.

Also, we make GETs optional, default to not-allowed in preference of
POSTs.

We also correct handling of POST (before POSTs with non-zero-length bodies
would cause the server to close the connection), and add additional CSRF
protection features, including the ability to disable all GET requests
for /get-keys and /get-config.
2022-10-02 22:46:37 -05:00
Nicolas Williams
323f4631a4 krb5: Do not clobber keytab entry timestamps
We set the timestamp field of krb5_keytab_entry in every case in-tree,
so we should not clobber it in krb5_kt_add_entry().  This is very
important in the context of virtual service principals, as the timestamp
of the keys in the keytab is a clue to when they must be refetched!
2022-10-02 22:46:37 -05:00
Nicolas Williams
1429814eda base: HEIM_JSON_F_TRY_DECODE_DATA cannot work
The idea with HEIM_JSON_F_TRY_DECODE_DATA is that on parsing of JSON
texts, if we find a base64-encoded string, decode it.  But a lot of
strings that aren't base64-encoded can be decoded anyways, leaving a
mess.

Insted we should -in a future commit- implement this only for the string
values of "heimdal-type-data-76d7fca2-d0da-4b20-a126-1a10f8a0eae6" names
in singleton objects.
2022-10-02 22:46:37 -05:00
Nicolas Williams
ed4b50720d base: Export type ID enum
Otherwise we really can't use the heimbase CF types outside lib/base!
2022-10-02 22:46:37 -05:00
Nicolas Williams
8364bdd8f3 base: Add JSON string non-ASCII escaping options
- Add HEIM_JSON_F_ESCAPE_NON_ASCII to indicate that non-ASCII must be
   escaped as \uXXXX.

 - Add HEIM_JSON_F_NO_ESCAPE_NON_ASCII to force non-escaping of BMP
   codepoints.

 - If the locale's codeset is not UTF-8 and
   HEIM_JSON_F_NO_ESCAPE_NON_ASCII is not set, then set
   HEIM_JSON_F_ESCAPE_NON_ASCII.
2022-10-02 22:46:37 -05:00
Nicolas Williams
03f06b9472 base: Prettier JSON output / options
- Add flags for indenting with 2, 4, or 8 spaces, still defaulting to
   tabs if none of those are set.

 - Don't emit a newline before emitting scalar values in dicts.
2022-10-01 00:15:37 -05:00
Nicolas Williams
c6a46f0c96 base: Implement JSON string escaping
We encode JSON in the KDC's audit logs, and soon in bx509d's /get-tgts.
Therefore, we should be reasonable in terms of what we encode.
2022-09-29 17:05:24 -05:00
Joseph Sutton
7ae4292986 lib/krb5: Fix leak in error path
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-27 17:35:38 +10:00
Stefan Metzmacher
c4216b17a8 kdc: add enable_fast option (enabled by default)
This makes it possible to disable fast if needed,
which is very good for regression tests.
Samba disables this in a few test environments with this
option.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15002
BUG: https://bugzilla.samba.org/show_bug.cgi?id=15005

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-09-25 21:13:01 +10:00
Rod Widdowson
348a03e48e Documentation changes for the Windows Build
- Fix markup
- Specific quoted command line for Visual Studio
  build
- Caveat about line ending for gawk
- Add comments about python versions
- makeinfo.exe is no longer available from cygwin
- Add some words about APPVER setting
2022-09-24 20:21:09 +10:00
Sergei Trofimovich
cd3b6e5a41 hdb: fix ldap module build (missing 'is_file_based' and 'can_taste' initializers)
Without the change the build fails as:

      CC       hdb-ldap.lo
    hdb-ldap.c:2109:5: warning: initialization of 'unsigned char:1' from 'krb5_error_code (*)(struct krb5_context_data *, void **)' {aka 'int (*)(struct krb5_context_data *, void **)'} makes integer from pointer without a cast [-Wint-conversion]
     2109 |     init,
          |     ^~~~
    hdb-ldap.c:2109:5: note: (near initialization for 'hdb_ldapi_interface.is_file_based')
    hdb-ldap.c:2109:5: error: initializer element is not computable at load time
    hdb-ldap.c:2109:5: note: (near initialization for 'hdb_ldapi_interface.is_file_based')
    hdb-ldap.c:2110:5: warning: initialization of 'unsigned char:1' from 'void (*)(void *)' makes integer from pointer without a cast [-Wint-conversion]
     2110 |     fini,
          |     ^~~~
    hdb-ldap.c:2110:5: note: (near initialization for 'hdb_ldapi_interface.can_taste')
    hdb-ldap.c:2110:5: error: initializer element is not computable at load time
    hdb-ldap.c:2110:5: note: (near initialization for 'hdb_ldapi_interface.can_taste')
    hdb-ldap.c:2111:5: warning: initialization of 'krb5_error_code (*)(struct krb5_context_data *, void **)' {aka 'int (*)(struct krb5_context_data *, void **)'} from incompatible pointer type 'char *' [-Wincompatible-pointer-types]
     2111 |     "ldapi",
          |     ^~~~~~~
    hdb-ldap.c:2111:5: note: (near initialization for 'hdb_ldapi_interface.init')
    hdb-ldap.c:2112:5: warning: initialization of 'void (*)(void *)' from incompatible pointer type 'krb5_error_code (*)(struct krb5_context_data *, HDB **, const char *)' {aka 'int (*)(struct krb5_context_data *, HDB **, const char *)'} [-Wincompatible-pointer-types]
     2112 |     hdb_ldapi_create
          |     ^~~~~~~~~~~~~~~~
    hdb-ldap.c:2112:5: note: (near initialization for 'hdb_ldapi_interface.fini')
    hdb-ldap.c:2113:1: warning: missing initializer for field 'prefix' of 'struct hdb_method' [-Wmissing-field-initializers]
     2113 | };
          | ^
Started failing when commit 93ada1fbf ("hdb: Remove default HDB backend
footgun") added extra fields to 'struct hdb_method'.
2022-09-24 19:38:16 +10:00
Jeffrey Altman
8b0c7ec09a krb5: remove krb5-v4compat.h
Kerberos v4 compatibility definitions are no longer required
in the source tree.
2022-09-22 22:13:05 -04:00
Jeffrey Altman
97eaa6cd01 krb5: pkinit select_dh_group clarify 'bits' param is the minimum
The 'bits' parameter to select_dh_group() is the minimum acceptable
bit size.   Rename 'bits' to 'min_bits' and fix the comparision
with krb5_dh_moduli.bits to ensure that DH groups whose bit size
is the minimum acceptable are not excluded.

Fixes #1002

Reported-By: Julien Rische (GitHub: jrisc)
2022-09-16 17:00:20 -04:00
Jeffrey Altman
1e67fd6c01 krb5: rfc3526-MODP-group14 incorrect bit size
Heimdal supports the 2 mandatory MODP groups (group 2 and group 14)
according to RFC4556, however group 14 is defined with a size of
1760 bits instead of 2048.

Fixes #1001

Reported-by: Julien Rische (GitHub: jrisc)
2022-09-16 16:36:42 -04:00
Sergei Trofimovich
e7efa7783a gssapi: add dependency on gkrb5_err.h
Noticed missing target directory dependency as a build failure in
`make --shuffle` mode (added in https://savannah.gnu.org/bugs/index.php?62100):

      CC       test_common.o
    In file included from test_common.c:34:
    krb5/gsskrb5_locl.h:42:10: fatal error: gkrb5_err.h: No such file or directory
       42 | #include <gkrb5_err.h>
          |          ^~~~~~~~~~~~~
    compilation terminated.
    make[3]: *** [Makefile:2347: test_common.o] Error 1 shuffle=1656680590

The change moves gkrb5_err.h and friends to BUILT_SOURCES
to guarantee their presence when main build starts.
2022-09-16 16:13:50 -04:00
Sergei Trofimovich
254e40294e doc: add dependency on vars.texi
Noticed missing target directory dependency as a build failure in
`make --shuffle` mode (added in https://savannah.gnu.org/bugs/index.php?62100):

    Making all in doc
    make[1]: Entering directory '/build/heimdal/doc'
      MAKEINFO hx509.info
    hx509.texi:15: @include: could not find vars.texi
    hx509.texi:31: warning: undefined flag: PACKAGE_VERSION
    hx509.texi:186: warning: undefined flag: PACKAGE_VERSION
    make[1]: *** [Makefile:622: hx509.info] Error 1 shuffle=1656683556

The change moves vars.texi to BUILT_SOURCES to guarantee it's
presence when .info files start the build.
2022-09-16 16:13:50 -04:00
Sergei Trofimovich
eb8da07a7b hdb: add missing build dependency on "hdb-protos.h"
Noticed missing target directory dependency as a build failure in
`make --shuffle` mode (added in https://savannah.gnu.org/bugs/index.php?62100):

    make[2]: Leaving directory '/build/heimdal/lib/gss_preauth'
    Making all in hdb
    make[2]: Entering directory '/build/heimdal/lib/hdb'
    ../../lib/asn1/asn1_compile --option-file=./hdb.opt ./hdb.asn1 hdb_asn1
    for genfile in 'asn1_Event.c asn1_GENERATION.c asn1_HDB_EncTypeList.c asn1_HDB_Ext_Aliases.c asn1_HDB_Ext_Constrained_delegation_acl.c asn1_HDB_Ext_KeyRotation.c asn1_HDB_Ext_KeySet.c asn1_HDB_Ext_Lan_Manager_OWF.c asn1_HDB_Ext_Password.c asn1_HDB_Ext_PKINIT_acl.c asn1_HDB_Ext_PKINIT_cert.c asn1_HDB_Ext_PKINIT_hash.c asn1_HDB_EntryOrAlias.c asn1_HDB_entry_alias.c asn1_HDB_entry.c asn1_HDB_extension.c asn1_HDB_extensions.c asn1_HDB_keyset.c asn1_HDBFlags.c asn1_Key.c asn1_KeyRotation.c asn1_KeyRotationFlags.c asn1_Keys.c asn1_Salt.c'; do \
            true -style='{BasedOnStyle: Mozilla, AlwaysBreakAfterReturnType: TopLevelDefinitions, IndentWidth: 4, SortIncludes: false}' -i ${genfile}; \
    done
    ../../lib/com_err/compile_et hdb_err.et
    make  all-am
    make[3]: Entering directory '/build/heimdal/lib/hdb'
      CC       hdb-ldap.lo
    In file included from hdb_locl.h:67,
                     from hdb-ldap.c:36:
    ./hdb.h:337:10: fatal error: hdb-protos.h: No such file or directory
      337 | #include <hdb-protos.h>
          |          ^~~~~~~~~~~~~~
    compilation terminated.

The change moves hdb-protos.ha and hdb-private.h to BUILT_SOURCES
to guarantee their presence when main build starts.
2022-09-16 16:13:50 -04:00
Jeffrey Altman
88eb44fd8b ipc: mach_complete_[a]sync avoid 'ret' set but not used warning
The variable 'ret' is set but not used.   As the value is ignored
remove it.  Restructure the initialization of 'replyinCnt', 'replyout',
and 'replyoutCnt' such that a failure of vm_read() results in a
properly initialized reply structure.
2022-09-16 15:58:45 -04:00
Jeffrey Altman
de7b452dcb kuser: kinit renew_func do not update expire if no new tickets
If neither get_new_tickets() nor renew_validate() succeeded, do not
bother recomputing the 'expire' time as it is unchanged.
2022-09-16 15:58:45 -04:00
Jeffrey Altman
7b914bfb64 roken: getaddrinfo get_null return errors
get_null() can fail for two reasons.  There can be a memory allocation
issue or the hints->ai_family could be unsupported.  This change
informs the caller of the error state instead of returning success
with an invalid struct addrinfo output parameter.

Fixes #1007
Reported-by: opless
2022-09-16 15:58:45 -04:00
Daria Phoebe Brashear
76c110e1ef hx509: hx509_verify_path remove spurious fallthrough
fallthrough needs to be directly before the next case, and this duplicate
inside an else is unneeded
2022-09-16 15:58:45 -04:00
Daria Phoebe Brashear
133f517482 rewrite fallthrough to HEIM_FALLTHROUGH to deal with new Apple SDKs
Apple clang version 14.0.0 (clang-1400.0.17.3.1) fails the build
because stds.h defines `fallthrough` as a macro which is then
expanded when base.h evaluates

  # if __has_attribute(fallthrough) && __clang_major__ >= 5

The macOS SDK defines `DISPATCH_FALLTHROUGH` as the macro instead
of `fallthrough`.

This change replaces the use of `fallthrough` in the tree with
`HEIM_FALLTHROUGH` and updates the declaration in configure logic
to define `HEIM_FALLTHROUGH` based upon existing definitions
(if any) of `fallthrough` or `DISPATCH_FALLTHROUGH`.
2022-09-16 15:58:45 -04:00
Joseph Sutton
f6d26bce66 kadm5: Correctly set userAccountControl bits
We meant to clear only the UF_SMARTCARD_REQUIRED bit, but we were
instead clearing all bits excepting it.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-16 15:43:44 -04:00
Joseph Sutton
f165d1e942 lib/krb5: Avoid undefined pointer arithmetic
If the AP len is large enough, we might end up computing an address
beyond the end of the 'reply' array, which is undefined behaviour.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-09-16 15:43:44 -04:00
Nicolas Williams
f40ac787b1 hxtool: Allow ca command to generate subject key
This commit makes the hxtool ca sub-command, when invoked with
--generate-key=TYPE and --certificate-private-key=STORE, write the
private key only to the given --certificate-private-key store and not
also the --certificate=STORE.

Before this commit, invoking the hxtool ca sub-command with both,
--generate-key=TYPE and --certificate-private-key=STORE, caused the
--generate-key option to be ignored and the private key to be read from
the given store and copied to the --certificate=STORE.  That was clearly
a bug and non-sensical.
2022-08-10 19:07:54 -05:00
Nicolas Williams
9c0bc47efc Add hxtool(1) manual page 2022-08-07 18:59:28 -05:00
Nicolas Williams
4c71d1bf06 bx509: Fix typos in commentary 2022-08-07 18:59:28 -05:00
Joseph Sutton
b19633f9b9 Use constant-time memcmp when comparing sensitive buffers
This helps to avoid timing attacks.

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Joseph Sutton
20f038f4f0 hcrypto: Use memset_s() when clearing sensitive buffers
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Joseph Sutton
88ea8039e3 hcrypto: Fix typo when clearing context structure
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-04-30 13:35:52 -04:00
Nicolas Williams
c0bc8beb07 httpkadmind: Test attributes defaulting 2022-04-26 17:54:12 -05:00
Nicolas Williams
d93f0d103d httpkadmind: Clarify namespace in man page 2022-04-26 17:54:12 -05:00
Nicolas Williams
a5271cd765 httpkadmind: Enable materialization 2022-04-25 22:24:52 -05:00
Nicolas Williams
18f44e7e90 httpkadmind: Make get_keys_max_spns configurable 2022-04-25 22:24:51 -05:00
Nicolas Williams
a5273d18cd httpkadmind: Support ok-as-delegate and such
Add support for configuring the attributes of new principals created via
httpkadmind.  This can be done via virtual host-based service
namespaces, which will provide default attributes even if disabled (but
the created principals will not be disabled, naturally), or via
krb5.conf.
2022-04-25 22:24:51 -05:00
Nicolas Williams
cd2e423d10 hdb: Derive pw_end for virtual services
We derive keysets for virtual host-based service principals, and that
includes the `set_time` field of keys.  But applications using the kadm5
API lose that information.  Our httpkadmind wants to set a Cache-Control
header with an appropriate max-age so that clients know when to re-fetch
keytabs.

We could extract some of the lib/hdb/common.c functions so that
httpkadmind could re-create an HDB_entry from a kadm5 entry then compute
the desired time, but ultimately we already have an appropriate field in
the HDB_entry and kadm5_principal_ent_rec types: "password expiration".

So let's set the `pw_end` of a virtual host-based service's HDB entry to
the time when a client should next fetch the principal's keys, and we'll
use that in httpkadmind as the `pw_expiration` field of the kadm5 entry
type.
2022-04-25 22:24:51 -05:00
Nicolas Williams
a51708c356 kadmin: Fix kdb_attrs[] units order 2022-04-25 22:24:51 -05:00
Nicolas Williams
17104ea2f2 hdb: Ignore disabled namespaces
If a virtual host-based service namespace is disabled, then the virtual
services below it cease existing.

This will be useful in a later commit where we'll use virtual host-based
service namespace for providing default attributes for new concrete
host-based service principals created via httpkadmind, whether the
namespace be enabled or disabled.
2022-04-25 22:24:51 -05:00
Nicolas Williams
13611702f9 roken: Fix parse_flags() orig argument type 2022-04-25 22:24:51 -05:00
Nicolas Williams
642990620c GHA: Also build just on WIN32 windows-build 2022-04-25 22:24:51 -05:00
Nicolas Williams
b503100677 GHA: Fix Windows build (install texinfo) 2022-04-25 22:24:51 -05:00
Nicolas Williams
56b60a1a40 asn1: Fix printing of decorated types 2022-03-28 16:18:10 -05:00
Steffen Kieß
9a47ec2b02 kcm: Allow disabling automatic TGT renewal
Add --no-automatic-renewal option to disable automatic TGT renewal.
Renewal can also be disabled by setting automatic_renewal to false
in the [kcm] section of krb5.conf.
2022-03-25 23:33:02 -05:00
Nicolas Williams
6932819419 kadmind: Test other operations after LIST
Test that we can still do other things after `kadmin list` to make sure
we're not leaving -after listing- the connection in a state where other
operations can't work.

Also, no more sleeps at all in the test.
2022-03-24 17:17:22 -05:00