Commit Graph

5568 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
Luke Howard
c953bc5e79 krb5: reintroduce deprecated krb5_addlog_func()
krb5_addlog_func() is used by Samba to obtain Kerberos log messages
and place them into the Samba logs.

Providing a hook down to the heim_addlog_func() is less disruptive
than needing to call multiple different APIs as Samba compiles
both with an included copy of Heimdal and against a system
Heimdal (when not an AD DC).

This API was deprecated and stubbed out in March 2020 by ea90ca8 and was
previously stable until 0c86917 (which looks like it should have been part of
e44c680).

Despite the need for the extra argument, which we add a test for, Samba would
prefer to keep the krb5_addlog_func() facility, so this adds it back.

Signed-off-by: Andrew Bartlett abartlet@samba.org
2021-08-09 23:27:22 +10:00
Luke Howard
f538f0e5c2 krb5: use new krb5_time_abs() function
From Apple Heimdal-597.121.1: replace calls to labs() with krb5_time_abs()
2021-08-09 21:46:39 +10:00
Luke Howard
57a1a66348 krb5: default to client realm in _krb5_get_krbtgt
If _krb5_get_krbtgt() is called with a NULL realm, use the realm of the ccache
client
2021-08-09 21:46:32 +10:00
Luke Howard
8a4ce9950f krb5: add krb5_time_abs() function
From Apple drop, add krb5_time_abs() which returns the absolute difference
between two timestamps
2021-08-09 21:46:24 +10:00
Luke Howard
65651c8106 krb5: mask should be uint64_t, not size_t
size_t is not 64 bits on all platforms
2021-08-07 19:25:22 +10:00
Luke Howard
9d16808515 krb5: mask integers to avoid unnecessary expansion
Sign-extension would expand the encoding of packed negative integers to one
greater than required.
2021-08-07 19:18:42 +10:00
Roland C. Dowdeswell
81a8b5069e krb5_storage: add a packed integer type as an endian. 2021-08-07 18:49:33 +10:00
Luke Howard
7188969371 krb5: add krb5_store_bytes()
Similar to krb5_storage_write(), but returns an error rather than the number of
bytes written.
2021-08-06 19:32:49 +10:00
Luke Howard
4e359bd5ce krb5: add krb5_store_datalen()
Store a data blob to the storage. The data is stored with an int32 as
length plus the data (not padded).  This function only differs from
krb5_store_data() insofar as it takes a void * and a length as parameters.

Patch from Roland C. Dowdeswell <elric@imrryr.org>
2021-08-06 19:22:15 +10:00
Isaac Boukris
f84a98bd5f Add client_aware_channel_bindings option
Add client support for KERB_AP_OPTIONS_CBT from MS-KILE.
2021-08-06 13:15:19 +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
00358252d3 kdc: Add synthetic PKINIT principals option 2021-06-29 14:52:07 -05:00
Luke Howard
0452d8c601 krb5: check return value in krb5_get[_cache]_next()
krb5_get_next() and krb5_get_cache_next() do not check for krb5_kcm_call()
returning non-zero before accessing the repsonse data; they only handle the
case where the return value is KRB5_CC_END.

Return immediately if the return value of krb5_kcm_call() is not KRB5_CC_END or
0. This was fixed in the Apple code.
2021-06-16 12:09:19 +10:00
Nicolas Williams
6ff3dbf297 bx509: Add addresses q-param for /get-tgt 2021-04-14 19:28:08 -05:00
Nicolas Williams
16d6bda3aa krb5: Add _krb5_parse_address_no_lookup() 2021-04-14 19:27:21 -05:00
Nicolas Williams
a5e289f4f7 kdc: Add warn_ticket_addresses config option 2021-04-13 23:22:45 -05:00
Nicolas Williams
c2bf9b9e71 kx509: Improve start_realm logic 2021-03-31 22:59:38 -05:00
Nicolas Williams
5443189b96 krb: Fix ccache resolve bug affecting ssh/kinit 2021-03-31 22:59:38 -05:00
Benjamin Kaduk
7f3445f1b7 Replace dead link in kerberos.8
While Ken Hornstein's FAQ was useful in its day, much of its content
is no longer relevant (e.g., Kerberos 4) or even actively harmful
(e.g., the latest version of MIT krb5 is not 1.2.1).  It was also
somewhat MIT-krb5-focused, especially relating to configuration file
snippets, which is not necessarily a great fit for the Heimdal
documentation.

Replace it with a tutorial hosted on kerberos.org and the classic
"dialogue" from Bill Bryant.

Fixes: #766
2021-03-26 18:47:49 -05:00
Nicolas Williams
dc74e9d00c kdc: Add Heimdal cert ext for ticket max_life
This adds support for using a Heimdal-specific PKIX extension to derive
a maximum Kerberos ticket lifetime from a client's PKINIT certificate.

KDC configuration parameters:

 - pkinit_max_life_from_cert_extension
 - pkinit_max_life_bound

If `pkinit_max_life_from_cert_extension` is set to true then the
certificate extension or EKU will be checked.

If `pkinit_max_life_bound` is set to a positive relative time, then that
will be the upper bound of maximum Kerberos ticket lifetime derived from
these extensions.

The KDC config `pkinit_ticket_max_life_from_cert` that was added earlier
has been renamed to `pkinit_max_life_from_cert`.

See lib/hx509 and lib/krb5/krb5.conf.5.
2021-03-24 19:12:00 -05:00
Nicolas Williams
cb2064d387 krb5: Make q param of DH moduli optional
MSFT makes the `q` field of `DomainParameters` OPTIONAL even though it's
actually required.  We currently validate DH groups not by validating
that p is a Sophie Germain prime but by checking the proposed group
against a compiled-in list and against a krb5.moduli file, therefore we
don't need q.  Besides, for Oakley groups, because p is a Sophie Germain
prime, we'd have q=p/j and j=2, so we can always compute q as needed
(and MIT Kerberos does).
2021-03-24 17:48:17 -05:00
Nicolas Williams
8e7c7209e8 kdc: Add param to derive max_life from client cert
This adds a KDC configuration parameter that can be used to indicate
that a PKINIT client's certificate's notAfter overrides the client
principal's HDB entry's max_life.  This parameter is a relative time
parameter, and it enables this only if set to a non-zero value (defaults
to zero).  The value of this parameter caps the max_life inferred from
the certificate.
2021-03-23 16:44:50 -05:00
Nicolas Williams
dfdc6c3a06 kdc: Document PKINIT config options 2021-03-23 16:24:25 -05:00
Nicolas Williams
fbb1a4e3ec bx509d: Allow requesting longer cert lifetimes
Add a `lifetime=NUMunit` query parameter.

Also add a krb5.conf parameter to indicate whether this is allowed.
We already have a max lifetime configuration parameter.
2021-03-07 22:20:06 -06: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
Luke Howard
fb6f89f295 lib/krb5: do not pack ccapi on Apple Silicon
macOS packs ccapi structures to 16 bits on PowerPC and Intel platforms only;
no special packing is used on ARM (Apple Silicon). Harmonize so Heimdal is ABI
compatible.
2020-11-19 11:04:19 +11:00
Jeffrey Altman
70ac849844 lib/krb5: acc_resolve_2 leak if ccErrCacheNotFound
Fix the possible leak of 's' allocated by asprintf()

When squashing the changes reference "this fixes an issue introduced by 7bf4d76 ("krb5: Improve cccol sub naming; add gss_store_cred_into2()")" in the commit message.
2020-11-06 09:09:01 -05:00
Nicolas Williams
68eba10cf1 krb5: Fix API: ccache failure 2020-11-06 09:09:01 -05:00
Nicolas Williams
2036b431dc krb5: Expose trace functions 2020-10-27 13:30:57 -05:00
Nicolas Williams
7ae2dfd853 krb5: Fix error msg when removing keytab entries
If a keytab was 0400 and one tried to delete with ktutil del then the
error message one would get prior to this commit is "entry not found".
2020-09-25 14:56:44 -05:00
Nicolas Williams
3c7d12e116 krb5: Fix FD leak in ENOMEM in stdio_from_fd 2020-09-15 11:26:52 -05:00
Nicolas Williams
b2b6599f87 krb5: Fix NULL deref on ENOMEM in fkt_add_entry(2) 2020-09-15 11:26:06 -05:00
Nicolas Williams
096888fe31 krb5: Fix NULL deref on ENOMEM in fkt_add_entry() 2020-09-14 16:38:20 -05:00
Nicolas Williams
ea83f068e9 kadm5/kadmin: Add read-only mode
Now we can have read-only kadmind instances.
2020-09-08 00:25:40 -05:00
Nicolas Williams
5447b81fb1 hdb: Move virtual principals into HDB layer
This is a large commit that adds several features:

 - Revamps and moves virtual host-based service principal functionality
   from kdc/ to lib/hdb/ so that it may be automatically visible to
   lib/kadm5/, as well as kadmin(1)/kadmind(8) and ktutil(1).

   The changes are backwards-incompatible.

 - Completes support for documenting a service principal's supported
   enctypes in its HDB entry independently of its long-term keys.  This
   will reduce HDB bloat by not requiring that service principals have
   more long-term keys than they need just to document the service's
   supported enctypes.

 - Adds support for storing krb5.conf content in principals' HDB
   entries.  This may eventually be used for causing Heimdal KDC
   services to reconfigure primary/secondary roles automatically by
   discovering the configured primary in an HDB entry for the realm.

   For now this will be used to help reduce the amount of configuration
   needed by clients of an upcoming HTTP binding of the kadmin service.
2020-09-08 00:25:36 -05:00
Nicolas Williams
0a0bf32935 krb5: Fix leak in gethostlist() 2020-09-07 22:04:59 -05:00
Nicolas Williams
fbb3bd3f8b krb5: Constify principal arg to some functions 2020-09-07 22:04:59 -05:00
Nicolas Williams
983ed75295 krb5: Add krb5_set_log_dest() 2020-09-07 22:04:59 -05:00
Nicolas Williams
7d50445d1b Generic: Fix warnings (fallthrough mosty) 2020-09-07 22:04:59 -05:00
Luke Howard
351145309d krb5: consolidate cc_ops enumeration
Consolidate the enumeration of the cc_ops table by using cc_get_prefix_ops() (a
variant of krb5_cc_get_prefix_ops that also returns the residual).
2020-08-30 13:44:19 +10:00
Luke Howard
cbcc50cd00 krb5: consolidate default ccache type logic into get_default_cc_type()
Consolidate the default credentials cache type logic into
get_default_cc_type(), so that the API: and MSLSA: types are respected on macOS
and Windows.
2020-08-29 16:13:00 +10:00
Luke Howard
7e86a27c0c krb5: update keyring ccache for new atomic load/store API 2020-07-14 09:35:14 +10:00
Nicolas Williams
73e54c4731 krb5: Export krb5_principal_is_root_krbtgt() 2020-07-09 13:27:11 -05:00
Jeffrey Altman
bbe5bf669b krb5: krb5_free_context unconditionally call hx509_context_free
Its safe to call hx509_context_free() with a NULL context.

Change-Id: I47e3aa1b57a2008dbfcd8d6de1b9c6ded84414db
2020-06-29 11:40:48 -04:00
Jeffrey Altman
07ee8fd3f4 base|krb5: struct krb5_config_binding is public
ea90ca8666
("Move some infra bits of lib/krb5/ to lib/base/ (2)") introduced
struct heim_config_binding to heimbase.h and removed the
struct krb5_config_binding definition from krb5.h.  It changed
the krb5_config_binding typedef to be based upon the heim_config_binding
typedef.

These changes broke out of tree callers of krb5_config_get_list()
and krb5_config_vget_list().  The internals of struct krb5_config_binding
are required by callers of krb5_config_get_list() and krb5_config_vget_list()
and the names must remain the same.

This change restores struct krb5_config_binding to krb5.h.  The
structure cannot be changed because it is public and leaves struct
heim_config_binding as an independent structure definition within
heimbase.h.  As a result struct heim_config_binding in heimbase.h must
remain binary compatible until such time as krb5_config_get_list() and
krb5_config_vget_list() are no longer supported.

Change-Id: I69b4fda3f656cc8daa8f5fcd0c7151cee222fc8c
2020-05-31 00:02:34 -05:00
Nicolas Williams
886cc6026c krb5: Remove uses of KRB5_USE_PATH_TOKENS 2020-05-28 00:49:55 -05:00
Nicolas Williams
16482c4a68 krb5: Default homedir access to !issuid()
Also get rid of the global static `allow_homedir` and its mutex.  We
don't need this in-tree.
2020-05-28 00:39:45 -05:00
Nicolas Williams
335d9a9f17 krb5: Fix krb5_cc_get_name() 2020-05-28 00:39:45 -05:00
Nicolas Williams
c976cbc0f0 krb5: Fix krb5_cc_get_subsidiary() harder 2020-05-28 00:21:15 -05:00