Commit Graph

30539 Commits

Author SHA1 Message Date
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
Nicolas Williams
674696151a gss-token: Fix acceptor context leak 2022-12-05 23:01:52 -06:00
Nicolas Williams
f0feaab938 asn1: Template CHOICE element 0 bug
While we no longer have a decoder CHOICE element 0 bug, we did still
have one encode and copy and free that was leading to a memory leak (and
_save trashing) prior to the fix for

    asn1: Fix 1-byte leaks in der_copy_octet_string()

This commit fixes that.
2022-11-30 11:59:45 -06:00
Nicolas Williams
50eb3bc245 asn1: Fix 1-byte leaks in der_copy_octet_string()
We sometimes do things like `memset(&cert, 0, sizeof(cert))` then
`copy_Certificate(&cert, &cert_copy)`, and then we end up leaking a
byte in `der_copy_octet_string()` due to it having this code:

```C
der_copy_octet_string (const heim_octet_string *from, heim_octet_string *to)
{
    assert(from->length == 0 || (from->length > 0 && from->data != NULL));
    if (from->length == 0)
	to->data = calloc(1, 1);
    else
	to->data = malloc(from->length);
    ...
}
```

The traces where this happens always involve the `_save` field of
`Name` or `TBSCertificate`.

This code was assuming that length 0 octet strings are expected to have
a non-NULL `data`, probably in case the C library's allocator returns
non-NULL pointers for `malloc(0)`, but then, why not just call
`malloc(0)`?  But calling `malloc(0)` would then still lead to this leak
in on such systems.

Now, `der_free_octet_string()` does unconditionally `free()` the
string's `data`, so the leak really is not there but elsewhere, probably
in `lib/asn1/template.c:_asn1_free()`, but it clearly does
`der_free_octet_string()` the `_save` field of types that have it.
2022-11-30 11:59:45 -06:00
Nicolas Williams
0c08fb9e3a ipc: Exclude UNIX: prefix in socket name
Otherwise we don't format the same socket name as the client.
2022-11-30 00:29:25 -06:00
Nicolas Williams
badbef825d roken: Add trailing / to PID file DIR path
Otherwise if $HEIM_PIDFILE_DIR doesn't end in / then the pidfile gets
created in the parent.
2022-11-30 00:28:41 -06:00
Luke Howard
b4c0ef9970 asn1: ensure quoting of default string values
5398425c introduced support for propagating ASN.1 default values to the emitted
JSON, but it neglected to quote string values, which caused ASN.1 parsing
errors. Correct this.
2022-11-26 22:39:37 +11:00
Nicolas Williams
5dd018b7ed hx509: Get i2d_PUBKEY() prototype from correct header 2022-11-22 15:33:03 -06:00
Nicolas Williams
cd02c50be5 kdc: OpenSSL 3.0 support 2022-11-22 11:34:54 -05:00
Nicolas Williams
6336cf69d4 krb5: OpenSSL 3.0 support 2022-11-22 11:34:54 -05:00
Nicolas Williams
264f0bd1a2 hx509: OpenSSL 3.0 support 2022-11-22 11:34:54 -05:00
Nicolas Williams
0d5b238186 hx509: PKCS#12 missing error check 2022-11-22 11:34:54 -05:00
Nicolas Williams
cce8ae9927 hx509: Pass PKCS#8 keys to lower layers
OpenSSL's d2i_ECPrivateKey() is deprecated, so we have to use
d2i_PrivateKey(), but d2i_PrivateKey() wants the whole PKCS#8 blob so it
can know what kind of key it is.  So we need to let the hx509 EC layer
get that blob.  The internal APIs need some refactoring, so for now we
use a hack where we try to parse the private key with and without the
PKCS#8 wrapper.
2022-11-22 11:34:54 -05:00
Nicolas Williams
2ddea96ba2 hcrypto: Use builtin 1DES/RC2/RC4 (OpenSSL 3)
At some point before we make an 8.0 release we'll probably just remove
all the legacy, weak ciphers and hashes (except MD5, most likely).

To drop these we'll have to re-generate PKCS#12 test samples using
stronger PBEs, and possible add new PBE types.
2022-11-22 11:34:54 -05:00
Nicolas Williams
11846fcabb hcrypto: Fix EVP_CipherUpdate() bugs 2022-11-22 11:34:54 -05:00
Nicolas Williams
47e6c68de8 hcrypto: OpenSSL's EVP_Cipher() returns a length 2022-11-22 11:34:54 -05:00
Nicolas Williams
83cd1255f6 cf: Check for OpenSSL FIPS 2022-11-22 11:34:54 -05:00
Nicolas Williams
ac8c1341fb cf: Check for OpenSSL 3.0
This check is admittedly lame.  But it's all I have time for at the
moment.  A better check would be a program that includes the correct
headers and succeeds if the OpenSSL version macro indicates it's at
3.0 or higher.  Or perhaps we could run the openssl(1) version command-
line and parse its output.  But checking for functions that are in 3.0
and not 1.1 will do for the time being.
2022-11-22 11:34:54 -05:00
Nicolas Williams
aa3355e3bf hcrypto: Remove dead MD2 code 2022-11-17 19:20:08 -06:00
Stefan Metzmacher
8f9c2d115e lib/krb5: remove dead code from pk_verify_host()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
4baf76220c lib/krb5: remove unused krb5_krbhst_info argument of pk_verify_host()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
7b3b67be37 lib/krb5: remove unused krb5_krbhst_info argument of pk_rd_pa_reply_enckey()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
94443d4768 lib/krb5: remove unused krb5_krbhst_info argument of pk_rd_pa_reply_dh()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
600e126135 lib/krb5: remove unused krb5_krbhst_info argument from _krb5_pk_rd_pa_reply()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
c5feb63c55 lib/krb5: remove unused krb5_krbhst_info argument of pa_step_f
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
893522a79f lib/krb5: remove unused krb5_krbhst_info argument to pa_step()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
315592f018 lib/krb5: remove unused krb5_krbhst_info argument of process_pa_data_to_key()
Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
a4fc4dcb6a lib/krb5: mark in argument of krb5_init_creds_step() as const
This has no real effect, but make things more clear
and matches the pattern for krb5_sendto_context().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
fd75c3e23c lib/krb5: let krb5_init_creds_step() return an out_realm
This matches krb5_init_creds_step() from MIT. The only
difference is the type 'krb5_realm' (Heimdal) vs. 'krb5_data' (MIT).

    krb5_error_code KRB5_CALLCONV
    krb5_init_creds_step(krb5_context context,
                         krb5_init_creds_context ctx,
                         krb5_data *in,
                         krb5_data *out,
                         krb5_data *realm,
                         unsigned int *flags);

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to fix up the prototype in order to make the
function actually useful for external callers.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
b0bc54c921 lib/krb5: let krb5_init_creds_step() return an allocated out buffer
It should not return pointers to the internal state,
this matches the way the krb5_init_creds_step() works in MIT.

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to change the behavior as there can't be any
external users of the function.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
30c978f013 lib/krb5: fix krb5_init_creds_step() interaction with krb5_fast_anon_pkinit_step()
_krb5_fast_anon_pkinit_step() should not set
KRB5_INIT_CREDS_STEP_FLAG_CONTINUE if it doesn't generate any output.

And krb5_init_creds_step() needs to return if
_krb5_fast_anon_pkinit_step() returned with
KRB5_INIT_CREDS_STEP_FLAG_CONTINUE set.
As that means the recursive call to krb5_init_creds_step()
generated output that should be send to a KDC and the
KDC response if needed as input for the next step.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Stefan Metzmacher
acaa62636f lib/krb5: krb5_init_creds_get() passes hostinfo=NULL to krb5_init_creds_step()
The current prototype of krb5_init_creds_step() is completely
useless as the caller has no way to know the destination
realm for the out blob.

The only internal caller of krb5_init_creds_step()
passes hostinfo=NULL and this commit makes it more obvious that hostinfo
is always NULL.

NOTE: commit 1cdc9d5f3c
"krb5: export krb5_init_creds_step()" exported
krb5_init_creds_step() the first time, but that's
not in any released version, so it should be fine
to fix up the prototype.

The aim is to remove hostinfo from the krb5_init_creds_step() internals
completely and move krb5_init_creds_step() to a useful prototype
where it returns the destination realm for the out packet.

Which means the prototype will mostly match the one MIT is using:

   krb5_error_code KRB5_CALLCONV
   krb5_init_creds_step(krb5_context context,
                        krb5_init_creds_context ctx,
                        krb5_data *in,
                        krb5_data *out,
                        krb5_data *realm,
                        unsigned int *flags);

Follow up patches demonstrate that the hostinfo related code
in pk_verify_host() is actually dead code as all layers
just passed down the NULL value from krb5_init_creds_get().

Signed-off-by: Stefan Metzmacher <metze@samba.org>
2022-11-17 19:55:32 -05:00
Joseph Sutton
cfb32a638e Introduce macro for common plugin structure elements
Heimdal's HDB plugin interface, and hence Samba's KDC that depends upon
it, doesn't work on 32-bit builds due to structure fields being arranged
in the wrong order. This problem presents itself in the form of
segmentation faults on 32-bit systems, but goes unnoticed on 64-bit
builds thanks to extra structure padding absorbing the errant fields.

This commit reorders the HDB plugin structure fields to prevent crashes
and introduces a common macro to ensure every plugin presents a
consistent interface.

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

Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2022-11-17 17:15:21 -06:00
Luke Howard
16179383fb asn1: note IMPLICIT CHOICE promoted to EXPLICIT
Record when a CHOICE field is promoted from IMPLICIT to EXPLICIT and convey
this in the ASN.1 compiler's JSON output, so that other tools (e.g. which have
a representation isomorphic to the original ASN.1) may use it.
2022-11-17 17:03:19 -06:00
Luke Howard
5398425cd2 asn1: propagate default values to JSON
Propagate ASN.1 DEFAULT values to ASN.1 compiler JSON output, with the defval
key.
2022-11-17 17:03:19 -06:00
Luke Howard
bc3d9c0115 asn1: JSON output open type IDs
Include open type IDs in JSON output of ASN.1 compiler.
2022-11-17 17:03:19 -06:00
Luke Howard
6a3604caf1 asn1: fix incorrect tag value for UT_UniversalString 2022-11-17 17:03:19 -06:00
Andrew Bartlett
c132e6ff49 lib/base: Avoid compiler warning about use-after-free on Fedora 36
While the local stack pointers could be thought of as "only"
numbers that are not invalidated by the memory they point at
being freed, any use of the pointer after the free is undefined
and so warned about (at best).

gcc version 12.2.1 20220819 (Red Hat 12.2.1-1) (GCC)

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2022-11-17 09:42:48 -05:00