Commit Graph

1779 Commits

Author SHA1 Message Date
Jeffrey Altman
713aa7961a kdc: kx509.c fix build failures
bcb5ed28fb ("kdc/kx509.c: clean up
krb5_get_error_message strings used for mk_error_resp") introduced a
build failure.  'context' is not a local variable but a field in the
kx509_req_context.

Change-Id: I38a8a9b1a19c3370dfc039d6e09445425936c32b
2020-03-08 12:01:35 -04:00
Daria Phoebe Brashear
bcb5ed28fb kdc/kx509.c: clean up krb5_get_error_message strings used for mk_error_resp
mk_error_response expects the strings it builds will need to be freed but
not those passed in; krb5_get_error_message generates a string which needs to
be freed. keep track of and free those strings.
2020-03-06 11:56:03 -06:00
Daria Phoebe Brashear
bfcc7a90ed kdc kx509: avoid double free of cprinc and s in check_authz
on error from der_parse_heim_old we early exit via out, which frees
s and cprinc; we should not do so a second time unless we explicitly
NULL the pointers but there is no value in doing so.
2020-03-06 11:56:03 -06:00
Nicolas Williams
ea90ca8666 Move some infra bits of lib/krb5/ to lib/base/ (2)
This is the second of two commits in a series that must be picked together.

This series of two commits moves parts of lib/krb5/ infrastructure
functionality to lib/base/, leaving behind wrappers.

Some parts of libkrb5 are entirely generic or easily made so, and could
be useful in various parts of Heimdal that are not specific to the krb5
API, such as:

 - lib/gssapi/  (especially since the integration of NegoEx)
 - lib/hx509/
 - bx509d       (which should really move out of kdc/)

For the above we need to move these bits of lib/krb5/:

 - lib/krb5/config_file.c   (all of it, leaving forwardings behind)
 - lib/krb5/config_reg.c    (all of it)
 - lib/krb5/plugin.c        (all of it, leaving forwardings behind)
 - lib/krb5/log.c           (all of it, ditto)
 - lib/krb5/heim_err.et     (all of it)

And because of those two, these too must also move:

 - lib/krb5/expand_path.c   (all of it, leaving forwardings behind)
 - lib/krb5/warn.c          (just the warning functions, ditto)

The changes to the moved files are mostly quite straightforward and are
best reviewed with --word-diff=color.

We're also creating a heim_context and a heim API to go with it.  But
it's as thin as possible, with as little state as necessary to enable
this move.  Functions for dealing with error messages use callbacks.

Moving plugin.c does have one knock-on effect on all users of the old
krb5 plugin API (which remains), which is that a global search and
replace of struct krb5_plugin_data to struct heim_plugin_data was
needed, though the layout and size of that structure doesn't change, so
the ABI doesn't either.

As well, we now build lib/vers/ and lib/com_err/ before lib/base/ so as
to be able to move lib/krb5/heim_err.et to lib/base/ so that we can make
use of HEIM_ERR_* in lib/base/, specifically in the files that moved.

Once this is all done we'll be able to use config files and plugins in
lib/hx509/, we'll be able to move bx509d out of kdc/, and so on.

Most if not all of the new functions in lib/base/ are Heimdal-private,
thus calling conventions for them are not declared.

Status:

 - builds and passes CIs (Travis, Appveyor)
 - ran make check-valgrind and no new leaks or other memory errors
 - ready for review

HOW TO REVIEW:

     $ # Review file moves:
     $ git log --stat -n1 HEAD^
     $
     $ # Review changes to moved files using --word-diff=color
     $ git log -p -b -w --word-diff=color HEAD^..HEAD   \
               lib/base/config_file.c                   \
               lib/base/config_reg.c                    \
               lib/base/expand_path.c                   \
               lib/base/warn.c                          \
               lib/krb5/config_file.c                   \
               lib/krb5/config_reg.c                    \
               lib/krb5/expand_path.c                   \
               lib/krb5/warn.c
     $
     $ # Review the whole thing, possibly adding -b and/or -w, and
     $ # maybe --word-diff=color:
     $ git log -p origin/master..HEAD
     $ git log -p -b -w origin/master..HEAD
     $ git log -p -b -w --word-diff=color origin/master..HEAD

TBD (future commits):

 - make lib/gssapi use the new heimbase functions
 - move kx509/bx509d common code to lib/hx509/ or other approp. location
 - move bx509d out of kdc/
2020-03-02 10:56:13 -06:00
Isaac Boukris
839b073fac tgs-req: strip forwardable and proxiable if the server is disallowed 2020-02-11 02:49:36 -05:00
Nicolas Williams
1cbbca8dcf bx509: Add /, /health for load balancer checking
A HEAD or GET of / or /health will now produce a 200 instead of a 404.

Ideally we should add configuration arguments that would allow /health
to get a token, make a CSR, and test the /bx509 (and/or /bnegotiate)
functionality, that way we'd have a real health check.  For now we defer
that work, as external health monitoring can be done using a simple
script anyways.
2020-01-10 11:43:00 -06:00
Nicolas Williams
e7ad9da3cc bx509: Do not clobber library error info 2020-01-10 11:34:33 -06:00
Nicolas Williams
62c0261cff kdc: add test_token_validator -a option 2020-01-10 11:32:59 -06:00
Nicolas Williams
8430acfe95 kdc: implement test_kdc_ca -a option 2020-01-10 11:30:56 -06:00
Nicolas Williams
8ef971786b bx509: Fix CSR authorizer IPC plugin bug
When marking SANs authorized, mark the SAN, not some EKU, authorized!
2020-01-10 11:29:21 -06:00
Nicolas Williams
2b92d938ae Add bx509d.8 man page 2020-01-03 00:12:43 -06:00
Luke Howard
8fd3cc84eb kdc: link test_token_validator against libgssapi
The Negotiate token validation plugin links against libgssapi, but on macOS the
dynamic linker cannot find it before Heimdal is installed. This causes tests to
fail. Although test_token_validator itself does not require libgsaspi, link
against it so that the test can proceed.
2020-01-01 19:15:59 +11:00
Nicolas Williams
a79714da93 kdc: Fix build race 2019-12-20 16:05:03 -06:00
Nicolas Williams
9a41785682 bx509: Fix cjwt_token_validator build 2019-12-20 15:58:44 -06:00
Nicolas Williams
ee0a288f92 bx509: Work around microhttpd bug 2019-12-20 15:54:27 -06: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
58848fce7b kdc: Add missing exports 2019-12-10 17:23:46 -06:00
Isaac Boukris
77b480d2a0 CVE-2019-14870: Validate client attributes in protocol-transition
Signed-off-by: Isaac Boukris <iboukris@gmail.com>
2019-12-10 05:24:02 -05:00
Isaac Boukris
013210d1eb CVE-2019-14870: Apply forwardable policy in protocol-transition
Signed-off-by: Isaac Boukris <iboukris@gmail.com>
2019-12-10 05:24:02 -05:00
Isaac Boukris
51415eaaae CVE-2019-14870: Always lookup impersonate client in DB
Signed-off-by: Isaac Boukris <iboukris@gmail.com>
2019-12-10 05:24:02 -05:00
Nicolas Williams
733140553a kdc: Fix leaks 2019-12-09 21:39:30 -06:00
Nicolas Williams
d1a2652090 bx509: CSRF protection for /bnegotiate 2019-12-09 20:13:33 -06:00
Nicolas Williams
0a0a27ccec kdc: bx509: Do not vend issuer private keys 2019-12-09 18:10:10 -06:00
Nicolas Williams
b5c158d9f7 Fix tests/can and tests/kdc
krb5_kdc_process_request() must return 0 when it produces a reply, and only
return non-zero when it could not construct any kind of reply (e.g., ENOMEM, or
-1 if no handler claimed responsibility for the request).
2019-12-05 17:22:47 -06:00
Nicolas Williams
52b8fae5e0 Fix Travis build moar 2019-12-05 15:34:09 -06:00
Nicolas Williams
6acb2e3f36 kdc: Fix JWK key rotation danger 2019-12-05 11:26:56 -06:00
Nicolas Williams
bdff7835a2 kdc: Fix warnings: fix _kdc_audit_addkv() usage 2019-12-05 11:26:44 -06:00
Nicolas Williams
2d1454c686 Fix Travis build 2019-12-04 23:12:04 -06:00
Roland C. Dowdeswell
05e8517542 kdc/fast.c: fix leak in unusual error path. 2019-12-05 00:05:56 -05:00
Roland C. Dowdeswell
430e18c074 kdc/process.c: add tracing messages. 2019-12-05 00:05:56 -05:00
Roland C. Dowdeswell
6db323157f Reduce older log messages to level 4 and collect some errors.
We take all of the kdc_log() and _kdc_r_log() calls in AS and TGS
and move their log levels down to debugging on the assumption that
our new log line subsumes the "informational" requirements.  We
collect some additional information in the kv-pair "pe-text" which
is like e-text except it is not returned to the client.
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
575c67806b Add bx509d 2019-12-04 21:34:44 -06:00
Roland C. Dowdeswell
3c7da79838 derived keys: ensure that princ is correct
We copy the princ in the hdb_entry so that if it is later used, it
will reflect what we want.
2019-11-07 20:11:55 -05:00
Roland C. Dowdeswell
c7d4682aed Define log levels in docs and change default to 0-3.
We define the meaning of the various log levels in the man page
for krb5_openlog(3).  If logging configured and levels are not
specified, we change the default levels to 0-3 which should exclude
debugging messages which are generally only desired in exceptional
circumstances.

We also go through the KDC and adjust the levels to be appropriate.
2019-10-21 13:43:01 +01:00
Roland C. Dowdeswell
aa5c525e71 Implement [kdc] derived_keys_maxdots 2019-10-18 14:47:33 -04:00
Nicolas Williams
dfada0ccad kx509: Add CSR support
This commit adds support for proof of posession to the kx509 protocol by
using PKCS#10 CSRs.

This allows conveyance of extReq CSR attributes requesting desired
Certificate Extensions.
2019-10-09 20:53:30 -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
Nicolas Williams
6deb2a6bae kdc: improve HTTP parsing 2019-10-03 13:09:18 -05:00
Nicolas Williams
d3ef0ee743 kdc: fix leaks 2019-10-03 13:09:18 -05:00
Nicolas Williams
75b5c94a62 kdc: fix invalid free at exit time 2019-10-03 13:09:18 -05:00
Nicolas Williams
1ae941af9b roken_detach_prep() should return fd 2019-10-03 13:09:18 -05:00
Roland C. Dowdeswell
366b787917 We provide a "derived key" mechanism to allow wildcard princs
In order to support certain use cases, we implement a mechanism to
allow wildcard principals to be defined and for the KDC to issue
tickets for said principals by deriving a key for them from a
cluster master entry in the HDB.

The way that this works is we defined an entry of the form:

	WELLKNOWN/DERIVED-KEY/KRB5-CRYPTO-PRFPLUS/<hostname>@REALM

When reading from the Kerberos DB, if we can't find an entry for
what looks like a hostbased principal, then we will attempt to
search for a principal of the above form chopping name components
off the front as we search.

If we find an entry, then we derive keys for it by using
krb5_crypto_prfplus() with the entry's key and the principal name
of the request.
2019-09-18 21:20:47 +01:00
Viktor Dukhovni
fae8df3839 Optional backwards-compatible anon-pkinit behaviour
* Anonymous pkinit responses from the KDC where the name
  type is not well-known (as issued by 7.5 KDCs and earlier)
  are accepted by the client.  There is no need for the client
  to strictly enforce the name type.

* With historical_anon_pkinit = true, the kinit(1) client's
  "--anonymous" option only performs anon pkinit, and does
  not require an '@' prefix for the realm argument.

* With historical_anon_realm = true, the KDC issues anon
  pkinit tickets with the legacy pre-7.0 "real" realm.
2019-09-04 18:00:15 -04:00
Nicolas Williams
9c51900238 Declare kdc log functions to be printf-like
And add a kdc_vlog() function.
2019-07-09 13:17:06 -05:00
Nicolas Williams
7fc90ce1c8 Remove references to Kerberos v4 from kdc/kdc.8 2019-07-09 12:38:08 -05:00
Roland C. Dowdeswell
9aa573c9ce kdc: no error if req is fwdable on non-fwdable princ
Instead of returning an error if the client asks for
a forwardable ticket where it isn't allowed, we simply
return one that isn't forwardable.
2019-06-21 10:11:58 -04:00
Jeffrey Altman
4331f4c7d4 kdc: history of request_anonymous vs cname-in-addl-tkt confusion
Drafts 0 through 10 of the Kerberos anonymity internet draft,
https://tools.ietf.org/html/draft-ietf-krb-wg-anon, specified the
TicketFlags.anonymous flag as bit 14 and the KDCOptions.anonymous
flag as bit 14.  These were changed to bit 16 by MIT after it was
discovered that Microsoft used KDCOptions bit 14 for S4U2Proxy
cname-in-addl-tkt.

(Feb 2007) Heimdal added constrained delegation support prior to
1.0 but named the KDCOptions flag constrained_delegation instead of
cname-in-addl-tkt as per MS-SFU.  It also assigned bit 16 instead
of bit 14.  Perhaps this was done in the hope that the conflict
with Microsoft would be resolved in favor of the IETF internet
draft instead of the proprietary protocol extension.

adf9121822 ("Add PA-ClientCanonicalized
and friends.") introduced the KDCOptions.constrained_delegation flag
as bit 16.

(June 2007) In order to make Heimdal's constrained delegation work
with Microsoft's implementation Heimdal began to set both KDCOptions
bits 14 and 16 when requesting constrained delegation.

d5bb7a7c56 ("(krb5_get_creds): if
KRB5_GC_CONSTRAINED_DELEGATION is set, set both") set both the
anonymous and constrained_delegation TicketFlags when issuing a
S4U2Proxy request.

(June 2010) MIT reassigned the KDCOption.anonymous and
TicketFlags.anonymous flags to bit 16.  draft-ietf-krb-anon-11
was published with this change.

(July 2014) After the release of Heimdal 1.5.0 and prior to 1.5.1
it was noticed that Heimdal's anonymous TGT support did not
interoperate with MIT.

86554f5a7f ("Use correct value for
anonymous flags") swapped the bit assignments for request_anonymous
and constrained_delegation but failed to remove the setting of
KDCOptions bit 16 ("anonymous") when requesting constrained
delegation.

(May 2019) Prior to the 7.6 release many corrections to Heimdal's
anonymity support were introduced to bring it into compliance
with RFC8062.  This included support for requesting anonymous
tickets via the TGS service.  Because not all KDC can satisfy
anonymous requests the client must verify if the response was
anonymized.  This check wasn't added until after 7.6 was
released.

014e318d6b ("krb5: check KDC
supports anonymous if requested").

The combination of setting KDCOption.anonymous when requesting
constrained delegation and the anonymized ticket validation
broke S4U2Proxy requests to Windows KDCs.  Windows KDCs ignore
the KDCOption.anonymous flag when processing a TGS request
with KDCOption.cname-in-addl-tkt set.

ea7615ade3 ("Do not set
anonymous flag in S4U2Proxy request") removed the behavior
of setting the KDCOption.anonymous flag that should have
been removed in July 2014.

(June 2019) The Heimdal KDC includes fallback logic to handle
Heimdal clients from 1.0 to 1.5.0, inclusive, that set the
KDCOptions.anonymous flag as bit 14.  Prior to the 7.7 release
this logic only handled AS request but failed to handle the
constrained delegation request case where both bits 14 and 16
were set in the TGS request.

cdd0b70d37 ("kdc: don't misidentify
constrained delegation requests as anonymous") added the TGS
request validation to distinguish anonymous requests from
constrained delegation requests.

This change documents the history in the commit message and
updates some in-tree comments.

Change-Id: I625cd012e2e6c263c71948c6021cc2fad4d2e53a
2019-06-04 09:35:17 +10:00