Commit Graph

55 Commits

Author SHA1 Message Date
Jeffrey Altman
2d89b4c27c kdc: -Wcalloc-transposed args
warning: 'calloc' sizes specified with 'sizeof' in the earlier argument
and not in the later argument [-Wcalloc-transposed-args].

Swap the args.
2024-06-04 06:22:37 -04:00
Nicolas Williams
dcef1341d3 kdc: Add error symbols for error logging
Having "KRB5KRB_AP_ERR_ILL_CR_TKT" in log messages is much better than
"UNKNOWN--1765328341".
2022-03-16 15:04:10 -05:00
Luke Howard
144caf67fa kdc: add wrappers for heimbase object accessors
Add libkdc wrappers for heimbase object accessors so plugins can use audit and
request attribute APIs without consuming libheimbase. Exposed API surface is
minimal and is limited to reading array collections, and reading/creating base
and custom types.
2022-01-28 17:24:57 -06:00
Luke Howard
ed4fe65794 base: change ret fieldname to error_code in request struct 2022-01-20 17:23:24 +11:00
Nicolas Williams
1a08b3b47f kdc: Make --kdc-request-log-file concrrency-safe
Build the entry to write to the log file in memory, the write it with
O_APPEND.  This should make writes to the request log file safer in
multi-process KDC configurations.

Also, check results of krb5_store_*() functions (coverity alerted to
this).
2022-01-18 00:19:15 -06:00
Luke Howard
94ed961d02 kdc: make auditing API public
Samba plugins will need to use auditing API without including krb5-private.h,
so make the auditing APIs public.
2022-01-18 16:09:50 +11:00
Luke Howard
4befd3e355 kdc: remove krb5_ prefix for KDC attribute functions
We will use the kdc_ rather than krb5_kdc_ prefix for new public APIs exported
from libkdc. Amend the recently introduced
request_{get,set,copy,delete}_attribute APIs to conform.
2022-01-17 23:50:04 -05:00
Luke Howard
d77e9988ec kdc: add _kdc_audit_addkv_{number,object}
Wrappers for new auditing functions in libheimbase.
2022-01-04 12:37:39 +11:00
Luke Howard
ce58eb9081 kdc: annotate libkdc Windows function annotations
Annotate libkdc APIs with KDC_LIB_{CALL,FUNCTION} to ensure correct calling
convention and optimized DLL importing on Windows.

Ensure Windows and libtool export tables are consistent.
2022-01-04 12:27:43 +11:00
Luke Howard
a8ff420b16 kdc: add attribute dictionary to kdc_request_t
Add a heim_dict_t to the KDC request structure for use by pre-authentication
mechanisms and plugins.
2022-01-04 12:27:43 +11:00
Luke Howard
b27026996a base: s/addkv_{bool,number,object}/setkv
Now heim_audit_addkv() correctly supports multiple values, the other functions
that (by design) replace existing values with a single value should use the
heim_audit_setkv prefix.

A subsequent commit could add variants that support multiple values for
non-string types.
2022-01-04 09:07:10 +11:00
Luke Howard
24c606719e kdc: fix _kdc_audit_addkv_bool wrapper copy paste
_kdc_audit_addkv_bool() should call heim_audit_addkv_bool() not
heim_audit_addkv_number(). Copy/paste error.
2022-01-03 09:36:50 +11:00
Luke Howard
e15e711b13 kdc: remove auth_event_details audit key
The auth event details audit key (formerly, parameter to auth_status)
contained, variously, an encryption type name; a PKINIT client certificate
name; or, a GSS initiator name. Audit these instead using individual keys that
reflect the values' contents.
2022-01-02 15:25:52 +11:00
Luke Howard
cc0874d410 kdc: preserve value types in auditing
Preserve integer/boolean audit values as their native types; convert to strings
when logging only. This commit goes some way towards unifying the two auditing
APIs.
2022-01-02 15:25:52 +11:00
Luke Howard
b1dcc1a474 kdc: refactor Samba-specific auditing API in terms of existing API
Make Samba-specific HDB auth status API a wrapper on the existing auditing API,
with a view towards unifying the two APIs in a future commit.

The term "auth status" is replaced with "auth event", and the HDB auth_status
method is replaced with a more general purpose audit method which has access to
the entire request structure.
2022-01-02 15:25:52 +11:00
Nicolas Williams
fb3ea5b943 kdc: Add ret to common svc req elements
We're logging SUCCESS even when the KDC sends error replies.  That's
because we're returning success to process_request() even when we send
errors to clients.  The error we want to send to the client, and that we
succeed or fail to send it, are different statuses.

Also, further move things into `r` and out of function arguments.
2021-12-27 10:16:58 +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
Nicolas Williams
1870584d22 kdc: Fix _kdc_audit_addaddrs() buglet 2021-06-21 23:38:16 -05:00
Nicolas Williams
9ce3cbbf2a kdc: Improve warn_ticket_addresses feature
- Don't log "Request from wrong address (ignoring)".
 - Add "wrongaddr=yes" kv to final log message.
 - Add request and ticket addresses (up to 3) to final log message.
2021-05-12 17:56:26 -05:00
Nicolas Williams
2d1fee6d11 kdc: Set r->addr
Fixes a NULL-dereference.
2021-04-14 19:27:21 -05:00
Nicolas Williams
01509f553d Move KDC audit functionality to lib/base/ 2020-04-24 16:02:35 -05:00
Nicolas Williams
1d5062b167 kdc: Modernize kx509 logging too 2019-12-11 19:34:36 -06:00
Nicolas Williams
608c2876d4 kdc: Fix audit_addkv() typos and reason handling
Now we'll put the "reason=..." last in the log lines and we won't escape
spaces -- just newlines and other control characters.  This makes
reading log lines much easier without complicating parsing of log lines
because interior key=value pairs do get whitespace escaped or removed.
2019-12-10 22:14:38 -06:00
Nicolas Williams
18df68d6e9 bx509: Add proper logging 2019-12-10 21:26:47 -06:00
Nicolas Williams
733140553a kdc: Fix leaks 2019-12-09 21:39:30 -06:00
Nicolas Williams
bdff7835a2 kdc: Fix warnings: fix _kdc_audit_addkv() usage 2019-12-05 11:26:44 -06:00
Roland C. Dowdeswell
430e18c074 kdc/process.c: add tracing messages. 2019-12-05 00:05:56 -05:00
Roland C. Dowdeswell
7d353d0557 Generate a single summary audit line for AS/TGS.
We refactor the code a bit to extend kdc_request_t which until now
was only used for the AS.  We make the structure extensible and
start using it for the TGS as well.  We leave digest and kx509
alone for the time being.

We also define the concept of kv-pairs in our audit trail which
allows us to define a rigorous but extensible format:

type error from-addr client server key1=val1 key2=val2 ...
2019-12-05 00:05:56 -05:00
Nicolas Williams
6a7e7eace6 Add kx509 client and revamp kx509 service
This commit adds support for kx509 in libkrb5, and revamps the KDC's
kx509 service (fixing bugs, adding features).

Of note is that kx509 is attempted optimistically by the client, with
the certificate and private key stored in the ccache, and optionally in
an external PEM or DER file.

NOTE: We do not optimistically use kx509 in krb5_cc_store_cred() if the
      ccache is a MEMORY ccache so we don't generate a key when
      accepting a GSS context with a delegated credential.

kx509 protocol issues to be fixed in an upcoming commit:

 - no proof of possession (this is mostly not too bad, but we'll want to
   fix it by using CSRs)
 - no algorithm agility (only plain RSA is supported)
 - very limited (no way to request any options in regards to the
   requested cert)
 - error codes are not very useful

Things we're adding in this commit:

 - libkrb5 kx509 client
 - automatic kx509 usage hooked in via krb5_cc_store_cred() of start TGT
 - per-realm templates on the KDC side
 - per-realm issuer certificates
 - send error messages on the KDC side
   (this is essential to avoid client-side timeouts on error)
 - authenticate as many error messages
 - add a protocol probe feature so we can avoid generating a
   keypair if the service is not enabled
   (once we add support for ECC algorithms we won't need this
    anymore; the issue is that RSA keygen is slow)
 - support for different types of client principals, not just username:

    - host-based service and domain-based service, each with its own
      template set per-{realm, service} or per-service

   (the idea is to support issuance of server certificates too, not
    just client/user certs)
 - more complete support for SAN types
 - tests (including that PKINIT->kx509->PKINIT works, which makes it
   possible to have "delegation" of PKIX credentials by just delegating
   Kerberos credentials)
 - document the protocol in lib/krb5/kx509.c

Future work:

 - add option for longer-ticket-lifetime service certs
 - add support for ECDSA, and some day for ed25519 and ed448
 - reuse private key when running kinit
   (this will require rethinking how we trigger optimistic kx509
    usage)
 - HDB lookup for:
    - optional revocation check (not strictly necessary)
    - adding to certificates those SANs listed in HDB
       - hostname aliases (dNSName SANs)
       - rfc822Name (email)
       - XMPP SANs
       - id-pkinit-san (a user could have aliases too)
 - support username wild-card A RRs, ala OSKT/krb5_admin
    i.e., if a host/f.q.d.n principal asks for a certificate for
    some service at some-label.f.q.d.n, then issue it
   (this is not needed at OSKT sites because OSKT already
    supports keying such service principals, which means kx509
    will issue certificates for them, however, it would be nice
    to be able to have this independent of OSKT)
   (a better way to do this would be to integrate more of OSKT
    into Heimdal proper)
 - a kx509 command, or heimtools kx509 subcommand for explicitly
   attempting use of the kx509 protocol (as opposed to implicit, as is
   done in kinit via krb5_cc_store_cred() magic right now)

Issues:

 - optimistically trying kx509 on start realm TGT store -> timeout issues!
    - newer KDCs will return errors because of this commit; older ones
      will not, which causes timouts
    - need a separate timeout setting for kx509 for optimistic case
    - need a [realm] config item and DNS SRV RR lookup for whether a
      realm is expected to support kx509 service
2019-10-08 21:26:50 -05:00
Love Hörnquist Åstrand
4b0121f545 release pool when done 2014-08-23 18:54:05 -07:00
Love Hörnquist Åstrand
ec152cdf1a drain pool for each request 2012-04-05 22:55:01 -07:00
Love Hornquist Astrand
13eeb30a1d Create a request structure 2011-07-24 20:24:37 -07:00
Love Hornquist Astrand
0879b9831a remove trailing whitespace 2011-05-21 11:57:31 -07:00
Love Hornquist Astrand
cc42e85e7f Remove deprecated krb4 kdc components 2010-11-20 14:11:35 -08:00
Love Hörnquist Åstrand
2ba9e9214c force submodules to claim the package
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24530 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-26 01:30:42 +00:00
Love Hörnquist Åstrand
ab94b8cc72 drop name
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24528 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-26 01:30:02 +00:00
Love Hörnquist Åstrand
8d3b69871c fix length bits
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24527 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-26 01:19:48 +00:00
Love Hörnquist Åstrand
0c7bd19591 split into probe functions
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24489 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-26 01:07:52 +00:00
Love Hörnquist Åstrand
89edf1be0e make digest, kx509 and krb4
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24484 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-25 20:50:15 +00:00
Love Hörnquist Åstrand
415e779f94 make digest and kx509 optional
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24420 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-01-25 00:41:09 +00:00
Love Hörnquist Åstrand
6937d41a02 remove trailing whitespace
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23815 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 09:21:03 +00:00
Love Hörnquist Åstrand
e172367898 switch to utf8 encoding of all files
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23814 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 08:53:55 +00:00
Love Hörnquist Åstrand
e9fe84bf9c catch errors from _kdc_do_version4
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23498 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-08-11 09:59:43 +00:00
Love Hörnquist Åstrand
7fcd266fdd use krb5_set_error_message
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23316 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-06-23 04:32:32 +00:00
Love Hörnquist Åstrand
8b91b80a1e Remove out2, no longer used.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20959 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-07 04:46:06 +00:00
Love Hörnquist Åstrand
43a028c82a Save asn1 class, type and tag of the reply if there is one. Used to
verify the reply in kdc-replay.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20956 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-07 04:32:53 +00:00
Love Hörnquist Åstrand
7e2f36b1d6 (krb5_kdc_save_request): save request to file.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20949 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-07 03:07:04 +00:00
Love Hörnquist Åstrand
c42a34c36d (krb5_kdc_process*): dont update _kdc_time automagicly.
(krb5_kdc_update_time): set or get current kdc-time.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20947 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-07 02:20:10 +00:00
Love Hörnquist Åstrand
f74250eb28 Handle kx509 requests.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19553 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-28 21:09:35 +00:00
Love Hörnquist Åstrand
6ff3e7477d Pass down datagram_reply to _kdc_tgs_rep.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19162 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-11-27 14:16:09 +00:00