Commit Graph

30776 Commits

Author SHA1 Message Date
Nicolas Williams
20c4c0dea9 asn1: Fix ENOMEM leak in der_print_bit_string() 2023-01-04 00:43:35 -06:00
Nicolas Williams
26b1acf3b8 asn1: Remove unused variable assignment in main.c 2023-01-04 00:43:35 -06:00
Nicolas Williams
9fc2e943ca base: Fix use-after-free in heim_path_vcreate() 2023-01-04 00:43:35 -06:00
Nicolas Williams
23a9ca27a5 base: Fix use-after-free db.c (mostly unused in prod)
We only use `db` for an2ln testing.
2023-01-04 00:43:35 -06:00
Nicolas Williams
c05294e2c5 base: Remove unused variable assignment in JSON string parsing 2023-01-04 00:43:35 -06:00
Nicolas Williams
a331a7a04f wind: Check for integer overflow in idn-lookup utility 2023-01-04 00:43:35 -06:00
Nicolas Williams
0ffb00275a sl: Fix leak 2023-01-04 00:43:35 -06:00
Nicolas Williams
b93129f83d roken: Fix FD and memory leaks in rk_undumptext() 2023-01-04 00:43:35 -06:00
Nicolas Williams
11c0cbe9c2 roken: Fix base32/64 decode slowness 2023-01-04 00:43:35 -06:00
Nicolas Williams
7c3a064764 roken: Quiet warnings at mergesort callers
Some static analyzers can't tell that mergesort_r() isn't outputting
freed memory.
2023-01-04 00:43:35 -06:00
Nicolas Williams
aee72d61bf roken: Move an #endif in issuid() to avoid dead code 2023-01-04 00:43:35 -06:00
Nicolas Williams
319793b30b roken: Fix leak in new undump_not_file() 2023-01-04 00:43:35 -06:00
Brian May
73b42d3238 Build rk_closefrom even if including in libc 2023-01-04 00:43:35 -06:00
Nicolas Williams
77a452f4fd kdc: Make path to MIT Kerberos for testing configurable 2023-01-04 00:43:35 -06:00
Nicolas Williams
0f769dde17 cf: Make path to MIT Kerberos for testing configurable 2023-01-04 00:43:35 -06:00
Nicolas Williams
594c478482 GHA: Fix Coverity build 2023-01-04 00:43:35 -06:00
Nicolas Williams
58e07f8882 krb5: Fix(?) st_nlink check in fcache.c
We have a check for symlinks and hardlinks so that we refuse to open
ccaches through symlinks or which have hardlinks.  This check is too
strict, checking for `st_nlink != 1`, which runs into trouble when a
ccache is mounted as a file into a container, in which case `stat(2)`
reports it as having zero links.

The fix is to check for `st_nlink > 1`:

    -    if (sb2.st_nlink != 1) {
    +    if (sb2.st_nlink > 1) {
            krb5_set_error_message(context, EPERM, N_("Refuses to open hardlinks for caches FILE:%s", ""), filename);

Though I question the utility of the hardlink check.  MIT Kerberos
doesn't have it.
2022-12-29 22:27:42 -06:00
Brian May
f4fd02b810 Increment hcrypto library version 2022-12-29 21:43:02 -06:00
Nicolas Williams
5c74a82e98 kadm5: Fix #1055 2022-12-29 12:20:19 -06:00
Nicolas Williams
1d9ea9b73c kadm5: Add better fuzz inputs 2022-12-22 18:14:07 -06:00
Nicolas Williams
42b0702601 krb5: Better checking for storage EOF 2022-12-22 17:55:13 -06:00
Nicolas Williams
662fda9608 kadm5: Add a fuzzer input for test_marshall
TODO:

 - Add more inputs.
2022-12-22 10:27:23 -06:00
Nicolas Williams
66b16d12d8 roken: Use calloc() for overflow det. in hex_encode
Using calloc() means setting errno on overflow instead of not.
2022-12-22 10:27:23 -06:00
Stefan Metzmacher
dc3ac8592b heimbase-atomics: let heim_base_atomic_* use 'long' instead of 'int' on AIX
As the atomics are signed on AIX, we better try to use the largest
possible max value.

The 'int' API uses 32-bit values for both 32-bit and 64-bit binaries:

  typedef int *atomic_p;

  int fetch_and_add(atomic_p addr, int value);

The 'long' API uses 32-bit values for 32-bit binaries and 64-bit values
for 64-bit binaries:

  typedef long *atomic_l;

  long fetch_and_addlp(atomic_l addr, long value);

So we better use the 'long' API in order to avoid any potential
problems with the heim_base_atomic_integer_max magic value, where
INT[32]_MAX would be a little bit low compared to 64-bit pointer space.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-12-22 22:12:52 +11:00
Stefan Metzmacher
1e5cb64569 heimbase-atomics: fix heim_base_atomic_* on AIX
The API looks like this on AIX:

  typedef int *atomic_p;

  int fetch_and_add(atomic_p addr, int value);

The strange thing is that the xlc compiler ignores missing arguments by
default. (It warns but doesn't fail to compile)
As a result the value argument was just uninitialized memory,
which means that the ref_cnt variable of struct heim_base,
gets unpredictable values during heim_retain() and heim_release(),
resulting in memory leaks.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-12-22 22:12:52 +11:00
Nicolas Williams
131d90c414 bx509d: Fix tests skipping on OS X 2022-12-21 22:14:03 -06:00
Nicolas Williams
07ce06e7b2 kadm5: Add test_marshall program
The lib/kadm5/test_marshall program allows one to construct and check
encodings for various struct types for which we have
{kadm5,krb5}_{ret,store}_<type>() functions.

Currently supported are:

 - krb5_keyblock
 - krb5_principal
 - krb5_times
 - krb5_address
 - krb5_addresses
 - krb5_authdata
 - krb5_creds
 - krb5_key_data
 - krb5_tl_data
 - kadm5_principal_ent_rec

With this we'll be able to a) construct test vectors, b) use those to
drive fuzzing with AFL or other fuzzers.
2022-12-21 22:14:03 -06:00
Nicolas Williams
8b6926f4c0 roken: Add rk_undumptext() and support ttys and such
Add rk_undumptext(), which NUL-terminates the contents it reads.

rk_undumptext(), and now also rk_undumpdata(), can read from regular and
non-regular files (e.g., ttys, pipes, devices, but -on Windows- not
sockets).

This means that `asn1_print` can now read from `/dev/stdin`, which can
be a pipe.

There's a way to set a limit on how much to read from non-regular files,
and that limit defaults to 10MB.

At any rate, the rk_dumpdata(), rk_undumpdata(), and rk_undumptext() functions
really do not belong in lib/roken but in lib/base.  There are other utility
functions in lib/roken that don't belong there too.  A rationalization of the
split between lib/roken and lib/base is overdue.  And while we're at it -lest I
forget- it'd be nice to move all the krb5_storage functions out of lib/krb5 and
into lib/base, as those could come in handy for, e.g., implementing OpenSSH
style certificates and other things outside the krb5 universe.
2022-12-21 22:06:15 -06:00
Nicolas Williams
ca2467a4c4 roken: Do not use net_read() for regular files!
The bug fixed herein almost certainly means that PKINIT was never
working on Windows, since lib/hx509 uses rk_undumpdata() to read regular
files containing certificates and keys, but then since rk_undumpdata()
was using net_read(), that can't have worked.  On Windows net_read()
insists on the FD being a socket, and because of winsock, the namespaces
of socket and file descriptors on Windows are distinct.
2022-12-20 22:19:39 -06:00
Nicolas Williams
8f71755d2b kadmind: Fix uninitialized heap pointer use (#1051) 2022-12-19 20:23:51 -06:00
Nicolas Williams
8423016920 doc: Fix dvi/pdf/ps build 2022-12-19 17:54:11 -06:00
Nicolas Williams
42fff5ec5f hx509: Add content and some EXAMPLES to hxtool(1)
hxtool is a very useful command, with a very user-friendly interface, at
least compared to OpenSSL's openssl(1).  We should document it better.

Currently there are no manual pages for hxtool(1)'s subcommands, though
their --help message is pretty self-explanatory.  Now the hxtool(1) page
provides better clues to the user, including examples.
2022-12-19 17:03:38 -06:00
Nicolas Williams
d24b7fd8b2 hx509: Add hxtool cc --no-root-certs, --no-private-keys, and --append options 2022-12-19 16:26:03 -06:00
Nicolas Williams
6def4750bc hx509: Add HX509_CERTS_STORE_NO_ROOTS flag
This will allow us to add a --no-roots option to

    hxtool copy-certificate

which is convenient when copying certificate chains from stores that may
include root CA certificates.
2022-12-19 16:24:23 -06:00
Nicolas Williams
49c00512a7 hx509: Don't check if non-self-signed certs have a self-signing capable signature alg
We don't need the _hx509_self_signed_valid() check if the certificate is
not self-signed.
2022-12-19 16:23:03 -06:00
Nicolas Williams
168124cd09 hx509: Add hx509_cert_is_{ca,root,self_signed}()
These are convenient utility functions.
2022-12-19 16:21:42 -06:00
Nicolas Williams
e2e7eacb6f base: Do not include config.h twice 2022-12-15 17:44:41 -06:00
Nicolas Williams
fd6597614e bx509d: Add test of IPC CSR authorizer
We have a CSR authorizer plugin for calling to an IPC service.

In this commit we add test implementation of such a service.

We also remove the simple_csr_authorizer plugin and fold its
functionality into the new test_csr_authorizer functionality.
2022-12-15 17:44:41 -06:00
Nicolas Williams
f47f15d5b9 bx509d: /get-tgts: Allow piecemeal authorization
We use the CSR authorizer system for /get-tgt and /get-tgts because,
well, the CSR authorizer system knows how to deal with principal names
("PKINIT SANs").

The caller of the /get-tgts end-point is a batch API that is meant for
super-user clients that implement orchestration for automation.  For
this end-point it's important to be able to return TGTs for just the
requested principals that are authorized rather than fail the whole
request because one principal isn't.  A principal might be rejected by
the authorizer if, for example, it's not meant to exist, and that might
be desirable because "synthetic" HDB entries might be configured, and we
might not want principals that don't exist to appear to exist for such
an orchestration service.

The hx509 CSR related functions allow one to mark specific requested
EKUs and SANs as authorized or not.  Until now we have simply rejected
all requests that don't have all attributes approved, but for /get-tgts
we need partial request approval.  This commit implements partial
request approval for the /get-tgts end-point.
2022-12-15 17:44:41 -06:00
Nicolas Williams
ba93778682 bx509d: Set log destination 2022-12-15 17:44:41 -06:00
Nicolas Williams
cf020532c2 bx509d: Fix leak of error messages 2022-12-15 17:44:41 -06:00
Nicolas Williams
d5a87e5906 roken: Add easprintf() and evasprintf() utils
Like emalloc() and ecalloc(): errx on ENOMEM.
2022-12-08 20:49:28 -06:00
Nicolas Williams
aaff3aa5c5 Do not include config.h in heimbase.h (fix #447)
We can't include config.h in public headers, as config.h is not public.

This reverts part of commit a8f0905b71.
2022-12-08 14:06:03 -06:00
Nicolas Williams
4303e7b2a3 base: Make heim_log_ref() thread-safe (fix build) 2022-12-07 21:39:26 -06:00
Nicolas Williams
9fb46adf97 kadmin: Support heredocs better to speed up tests
Now we can use heredocs to execute multiple kadmin commands with just
one `execve()`:

```
${kadmin} <<EOF || exit 1
init ...
add ...
...
EOF
```

This will allow tests to use heredocs in setting up an HDB so as to go a
bit faster.
2022-12-07 21:28:54 -06:00
Nicolas Williams
1c4902378f base: Make heim_log_ref() thread-safe
This is necessary to making multiple `krb5_context`s be able to share a
log facility.
2022-12-07 21:28:19 -06:00
Nicolas Williams
9152d38d27 sl: Unknown commands -> error
This will allow typos in kadmin heredocs in scripts to cause kadmin to
exit with a non-zero status code.
2022-12-07 21:27:50 -06:00
Nicolas Williams
0a15a9eea6 sl: Support continued line inputs for heredocs
This will allow kadmin to support heredocs, which will speed up testing.
2022-12-07 21:27:06 -06:00
Nicolas Williams
4da64d119e hx509: Return better error in CSR authorization functions 2022-12-05 23:01:52 -06:00
Nicolas Williams
ce1dd5fc76 hx509: Export missing CSR authz symbols 2022-12-05 23:01:52 -06:00