Commit Graph

178 Commits

Author SHA1 Message Date
Luke Howard
ef1d63a997 kinit: add --pk-anon-fast-armor option
Add the  --pk-anon-fast-armor option, which acquires a temporary anonymous
PKINIT TGT to use as a FAST armor key.
2021-08-10 15:30:45 +10:00
Isaac Boukris
a4527a28a3 Implement KERB_AP_OPTIONS_CBT (server side)
if the client asserted knowledge of channel-bindings by
passing KERB_AP_OPTIONS_CBT, and the server passed bindings,
require the bindings to match.
2021-08-06 13:15:19 +10:00
Nicolas Williams
db7763ca7b asn1: X.681/682/683 magic handling of open types
Status:

 - And it works!

 - We have an extensive test based on decoding a rich EK certficate.

   This test exercises all of:

    - decoding
    - encoding with and without decoded open types
    - copying of decoded values with decoded open types
    - freeing of decoded values with decoded open types

   Valgrind finds no memory errors.

 - Added a manual page for the compiler.

 - rfc2459.asn1 now has all three primary PKIX types that we care about
   defined as in RFC5912, with IOS constraints and parameterization:

    - `Extension`       (embeds open type in an `OCTET STRING`)
    - `OtherName`       (embeds open type in an        `ANY`-like type)
    - `SingleAttribute` (embeds open type in an        `ANY`-like type)
    - `AttributeSet`    (embeds open type in a  `SET OF ANY`-like type)

   All of these use OIDs as the open type type ID field, but integer
   open type type ID fields are also supported (and needed, for
   Kerberos).

   That will cover every typed hole pattern in all our ASN.1 modules.

   With this we'll be able to automatically and recursively decode
   through all subject DN attributes even when the subject DN is a
   directoryName SAN, and subjectDirectoryAttributes, and all
   extensions, and all SANs, and all authorization-data elements, and
   PA-data, and...

   We're not really using `SingleAttribute` and `AttributeSet` yet
   because various changes are needed in `lib/hx509` for that.

 - `asn1_compile` builds and recognizes the subset of X.681/682/683 that
   we need for, and now use in, rfc2459.asn1.  It builds the necessary
   AST, generates the correct C types, and generates templating for
   object sets and open types!

 - See READMEs for details.

 - Codegen backend not tested; I won't make it implement automatic open
   type handling, but it should at least not crash by substituting
   `heim_any` for open types not embedded in `OCTET STRING`.

 - We're _really_ starting to have problems with the ITU-T ASN.1
   grammar and our version of it...

   Type names have to start with upper-case, value names with
   lower-case, but it's not enough to disambiguate.

   The fact the we've allowed value and type names to violate their
   respective start-with case rules is causing us trouble now that we're
   adding grammar from X.681/682/683, and we're going to have to undo
   that.

   In preparation for that I'm capitalizing the `heim_any` and
   `heim_any_set` types, and doing some additional cleanup, which
   requires changes to other parts of Heimdal (all in this same commit
   for now).

   Problems we have because of this:

    - We cannot IMPORT values into modules because we have no idea if a
      symbol being imported refers to a value or a type because the only
      clue we would have is the symbol's name, so we assume IMPORTed
      symbols are for types.

      This means we can't import OIDs, for example, which is super
      annoying.

      One thing we might be able to do here is mark imported symbols as
      being of an undetermined-but-not-undefined type, then coerce the
      symbol's type the first time it's used in a context where its type
      is inferred as type, value, object, object set, or class.  (Though
      since we don't generate C symbols for objects or classes, we won't
      be able to import them, especially since we need to know them at
      compile time and cannot defer their handling to link- or
      run-time.)

    - The `NULL` type name, and the `NULL` value name now cause two
      reduce/reduce conflicts via the `FieldSetting` production.

    - Various shift/reduce conflicts involving `NULL` values in
      non-top-level contexts (in constraints, for example).

 - Currently I have a bug where to disambiguate the grammar I have a
   CLASS_IDENTIFIER token that is all caps, while TYPE_IDENTIFIER must
   start with a capital but not be all caps, but this breaks Kerberos
   since all its types are all capitalized -- oof!

   To fix this I made it so class names have to be all caps and
   start with an underscore (ick).

TBD:

 - Check all the XXX comments and address them
 - Apply this treatment to Kerberos!  Automatic handling of authz-data
   sounds useful :)
 - Apply this treatment to PKCS#10 (CSRs) and other ASN.1 modules too.
 - Replace various bits of code in `lib/hx509/` with uses of this
   feature.
 - Add JER.
 - Enhance `hxtool` and `asn1_print`.

Getting there!
2021-02-28 18:13:08 -06:00
Nicolas Williams
886cc6026c krb5: Remove uses of KRB5_USE_PATH_TOKENS 2020-05-28 00:49:55 -05:00
Nicolas Williams
e8441212d1 Move error functions from krb5 to base 2020-04-24 16:02:35 -05: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
Roland C. Dowdeswell
8ee86db261 Add enforce_ok_as_delegate setting
If this flag is set to true, then GSSAPI credential delegation will
be disabled when the "ok-as-delegate" flag is not set in the service
ticket.
2019-11-20 18:18:57 -05:00
Nicolas Williams
afaaf3d89d Add krb5_cc_configured_default_name()
Refactor krb5_cc_set_default_name() by splitting out the part that looks
for a configured default ccache name.  This will allow one to check if a
given ccache is a default ccache for a process ignoring KRB5CCNAME,
which might prove useful in the kx509 client.
2019-10-03 13:09:18 -05:00
Luke Howard
8350f34a05 krb5: don't require krbtgt otherName match for Win2K
Merged from Apple branch: when the Win2K PKINIT compatibility option is set, do
not require krbtgt otherName to match when validating KDC certificate.
2019-05-18 23:19:06 -04:00
Luke Howard
014e318d6b krb5: check KDC supports anonymous if requested
Verify the KDC recognized the request-anonymous flag by validating the returned
client principal name.
2019-05-18 20:31:52 -04:00
Luke Howard
dc791c8fcf krb5: remove duplicate KRB5_ANON_MATCH_xxx defines
Commit bdcd7d2f moved the KRB5_ANON_MATCH_xxx preprocessor symbols to krb5.h,
but did not remove the originals from krb5_locl.h. This commit removes them.
2019-05-18 13:57:43 +10:00
Luke Howard
38c797e1ae krb5: always confirm PA-PKINIT-KX for anon PKINIT
RFC8062 Section 7 requires verification of the PA-PKINIT-KX key excahnge
when anonymous PKINIT is used.  Failure to do so can permit an active
attacker to become a man-in-the-middle.

Introduced by a1ef548600.  First tagged
release Heimdal 1.4.0.

CVSS:3.0/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N (4.8)

Change-Id: I6cc1c0c24985936468af08693839ac6c3edda133
Signed-off-by: Jeffrey Altman <jaltman@auristor.com>
Approved-by: Jeffrey Altman <jaltman@auritor.com>
2019-05-14 15:52:24 -04:00
Luke Howard
bcc90f1b87 krb5: _krb5_principal_is_anonymous() helper API
Add _krb5_principal_is_anonymous() private API for checking if a principal is
anonymous or not. The third argument determines whether to match authenticated
anonymous, unauthenticated anonymous, or both types of principal.
2019-05-14 15:16:19 -04:00
Luke Howard
803efebca5 krb5, kadm5: refactor plugin API
Refactor plugin framework to use a single list of loaded plugins; add a new
plugin API where DSOs export a load function that can declare dependencies and
export multiple plugins; refactor kadm5 hook API to use krb5 plugin framework.

More information in krb5-plugin(7).
2019-01-03 20:06:27 -06:00
Luke Howard
af0d8ef677 gssapi: support for client keytab in gss_acquire_cred (#383)
For compatibility with MIT Kerberos, support automatic acquisition of initiator
credentials if a client keytab is available. The default path on non-Windows is
/var/heimdal/user/%{euid}/client.keytab, but can be overriden with the
KRB5_CLIENT_KTNAME environment variable or the default_client_keytab_name
configuration option. If a client keytab does not exist, or exists but does not
contain the principal for which initiator credentials are being acquired, the
system keytab is tried.
2018-12-31 18:20:37 +11:00
Luke Howard
fb81598d44 krb5: port MIT Linux keyring credentials cache (#166) 2018-12-24 18:17:32 +11:00
Jeffrey Altman
1d4ebc0df7 lib/krb5: restore krb5_context_data field ordering to match 7.x
The struct krb5_context_data field can be passed to plugins
which might not be aware of the new structure layout.  To
reduce the risk of data corruption, fields must never be
removed, modified or reordered.  Old unused fields are marked
deprecated and new fields are appended to the end of the structure.

This change moves two fields that were added to master which
are not present in Heimdal 7.x:

fe43be8558 added config_include_depth.

5b39bd7c1d added no_ticket_store.

Change-Id: I28b157e128732324972c99b246a93a828bc077c1
2018-06-08 12:00:38 -04:00
Viktor Dukhovni
5b39bd7c1d New KRB5_NO_TICKET_STORE env var 2017-05-26 10:53:37 -05:00
Nicolas Williams
fe43be8558 Add include/includedir directives for krb5.conf 2017-02-27 18:15:59 -06:00
Nicolas Williams
bbaae5f43c Fix 32-bit time_t regression (#220) 2016-12-06 22:44:23 -06:00
Jeffrey Altman
a013e93e95 default life/renewlife time to KDC policy
Instead of imposing a default 10 hour ticket lifetime and 1 month renew
lifetime when requesting tickets, increase the default lifetime and
renew lifetime to 2147483647 seconds.  This ensures that in the absence
of any other configuration or command line parameters that the KDC will
determine the ticket lifetime and renew lifetime.

Change-Id: I52b6eeac1ee830a9bf4d0130e8f4ec7b70bc8694
Signed-off-by: Nicolas Williams <nico@twosigma.com>
2016-11-10 16:13:10 -06:00
Uri Simchoni
a3bece16c7 lib/krb5: keep a copy of config etypes in the context
When reading configuration file, keep an extra copy of
the encryption types, and use this when resetting the
encryption types to default.

GSSAPI always resets the enctypes to default before obtaining
a TGS, because the enctypes might have previously altered,
so this prevents changing the etypes from the configured ones
to the full set of supported etypes.

Signed-off-by: Uri Simchoni <uri@samba.org>
2016-09-30 08:37:06 -07:00
Jeffrey Altman
80f8325c64 lib/krb5: krb5_locl.h do not replicate roken.h
Move roken.h to the top of the header after config.h and remove the
includes that are duplicated by roken.h.

Change-Id: I33e29736519177f17c36e5c5948d7022011ab2b2
2016-04-17 17:19:53 -05:00
Nicolas Williams
1103fb19df Fix re-definition of keyex enum 2016-04-16 16:58:08 -05:00
Nicolas Williams
490337f4f9 Make OpenSSL an hcrypto backend proper
This adds a new backend for libhcrypto: the OpenSSL backend.

Now libhcrypto has these backends:

 - hcrypto itself (i.e., the algorithms coded in lib/hcrypto)
 - Common Crypto (OS X)
 - PKCS#11 (specifically for Solaris, but not Solaris-specific)
 - Windows CNG (Windows)
 - OpenSSL (generic)

The ./configure --with-openssl=... option no longer disables the use of
hcrypto.  Instead it enables the use of OpenSSL as a (and the default)
backend in libhcrypto.  The libhcrypto framework is now always used.

OpenSSL should no longer be used directly within Heimdal, except in the
OpenSSL hcrypto backend itself, and files where elliptic curve (EC)
crypto is needed.

Because libhcrypto's EC support is incomplete, we can only use OpenSSL
for EC.  Currently that means separating all EC-using code so that it
does not use hcrypto, thus the libhx509/hxtool and PKINIT EC code has
been moved out of the files it used to be in.
2016-04-15 00:16:17 -05:00
Nicolas Williams
c80816f9c3 krb5_context: embed mutex in structure
Instead of allocating a separate mutex object on the heap,
include the HEIMDAL_MUTEX in the krb5_context structure.

Change-Id: If6db484177410487176985e43e3b43e0f2166518
2016-04-10 17:05:07 -05:00
Jeffrey Altman
e8e9cd9710 krb5: Introduce KRB5_TKT_LIFETIME_DEFAULT
Instead of hard coding 10 hours as the default ticket lifetime within
lib/krb5/init_cred_pw.c init_cred(), add a preprocessor macro,
KRB5_TKT_LIFETIME_DEFAULT, that can be overridden at build time.

The value of KRB5_TKT_LIFETIME_DEFAULT is 10 hours if not previously
defined.

Change-Id: I63e729fedee8e8c6f542e4a4665de5f40db34c03
2015-04-16 20:40:21 -04:00
Nicolas Williams
487b6820f6 Revamp name canonicalization code 2015-03-24 11:49:58 -05:00
Jeffrey Altman
31a00d6647 ISPATHSEP and ISTILDE macros; Windows portability
Windows treats '\\' and '/' equivalently but we cannot control
the form that will be used by end users.  Introduce ISPATHSEP()
macro which tests only for '/' on UNIX and both on Windows.
Introduce ISTILDE() macro to test for '~'.   When testing for
'/' with strchr() or strrchr() add conditional checks for '\\' on
Windows.

Change-Id: Ia85e698fc88f15a6a71db649db5417f02ef7e5fe
2013-09-10 22:31:38 -04:00
Love Hornquist Astrand
f396f66523 add [libdefaults]fcache_strict_checking to gate the strict checking, defaults to on 2013-07-11 21:17:49 +02:00
Love Hornquist Astrand
a7e86affd8 add basic DIR support for file caches 2013-04-29 12:30:21 -07:00
Love Hornquist Astrand
58ff480763 rewrite send to kdc to be more agressive, try kdcs in paralell and easier to configure behavior 2013-02-10 19:02:52 -08:00
Roland C. Dowdeswell
3a30f3b0d1 Windows doesn't support poll(2) or fcntl(2) so #ifdef it out in send_to_kdc.c. 2012-08-14 22:50:33 +01:00
Roland C. Dowdeswell
842ca62336 Ensure that timeouts apply to TCP socket connexions.
Currently the Heimdal code calls connect(2) on TCP connexions to
the KDC without setting O_NONBLOCK.  This code implements a
timed_connect() function which will in the case of SOCK_STREAM
sockets put the socket into non-blocking mode prior to calling
connect and use select(2) to apply the configured timeout to connect
completion.  This does not entirely solve the problem of potential
timeouts in the code as it is still possible to block while writing
to the socket.  A proper implementation would also likely start
new connexions after a short interval before timing out existing
connexions and return the results from the first KDC which successfully
responds but we did not do that yet.

This patch is from heimdal-1-5-branch patches:

	5b55e4429caed27b32aac4bc5930f2672a43f273
	6b66321b271ee4672e70ad349ec796dd755cf897
	2e12c7f3e8dca7e1696ebd92199617ce413565e7

Squashed together along with a quick shadowed variable warning fix
to allow it to compile with --enable-developer.
2012-07-12 01:00:23 +01:00
Love Hornquist Astrand
0b02f05a19 error_buf is gone 2011-09-25 17:49:06 +02:00
Nicolas Williams
a7a8a7e95c Initial patch to add as-use-strongest-session-key and same for tgs krb5.conf parameters for the KDC. These control the session key enctype selection algorithm for the AS and TGS respectively: if TRUE then they prefer the strongest enctype supported by the client, the KDC and the target principal, else they prefer the first enctype fromt he client's list that is also supported by the KDC and the target principal.
Signed-off-by: Love Hörnquist Åstrand <lha@h5l.org>
2011-06-14 20:35:19 -07:00
Love Hornquist Astrand
e4580fe4cc add glue for krb5_einval 2011-05-18 22:00:37 -07:00
Asanka C. Herath
5b91a397f8 Increase KBR5_BUFSIZ to 2048 and use it in config_file.c 2010-11-24 15:33:19 -05:00
Asanka C. Herath
d3582b56c6 Define and use a path separator string
A colon can't be used to separate paths on Windows since they are used
in drive sepecification.  Define a macro that can be used as a path
separator string.  On Windows, this is defined as ";".  It is a ":"
everywhere else.
2010-11-24 15:32:56 -05:00
Simon Wilkinson
1d9072f026 krb5: reorganise crypto.c
lib/krb5/crypto.c was a large, monolithic block of code which made
it very difficult to selectively enable and disable particular
alogrithms.

Reorganise crypto.c into individual files for each encryption and
salt time, and place the structures which tie everything together
into their own file (crypto-algs.c)

Add a non-installed library (librfc3961) and test program
(test_rfc3961) which builds a minimal rfc3961 crypto library, and
checks that it is usable.
2010-11-03 11:12:24 +00:00
Love Hornquist Astrand
edc1c3e2a1 add heimbase.h 2010-10-27 20:43:15 -07:00
Love Hornquist Astrand
d893207413 add check-rd-req-server 2010-09-01 21:56:17 -07:00
Love Hornquist Astrand
687db64c56 Patch from Secure Endpoints/Asanka Herath for windows support 2009-12-21 08:45:28 +01:00
Love Hornquist Astrand
34cbe76fdc include <com_err.h> for com_right_r 2009-11-22 07:34:59 -08:00
Love Hornquist Astrand
28c9deebf1 edd extra flags 2009-11-22 00:14:57 -08:00
Love Hornquist Astrand
23d05643e1 Include <com_err.h> 2009-11-03 23:59:46 -08:00
Love Hornquist Astrand
1e65f30a2d drop hx509_context in krb5_id 2009-09-29 13:13:51 -07:00
Love Hornquist Astrand
1ac50627e6 add forward decl for hx509_certs_data 2009-09-29 11:29:20 -07:00
Love Hornquist Astrand
61cc35b83b include hx509_context in krb5_context 2009-09-29 09:23:37 -07:00
Love Hornquist Astrand
878eb853df Add debug_dest member 2009-09-07 20:38:29 -07:00