Greg Hudson [Sun, 27 Nov 2016 23:37:12 +0000 (18:37 -0500)]
Allow slapd path configuration in t_kdb.py
The upstream OpenLDAP installs slapd in libexec, which is not
typically in the path. Also, copying the binary can sometimes cause
it to fail; for instance, in the OpenCSW package,
/opt/csw/libexec/slapd is a script which chooses a binary based on the
system architecture and the path to the script. Allow the test runner
to set the SLAPD environment variable to specify the slapd location
and avoid the copy.
Greg Hudson [Tue, 22 Nov 2016 07:17:38 +0000 (02:17 -0500)]
Simplify LDAP module by relying on OpenLDAP 2.1
Solaris 11 provides an OpenLDAP library (which we don't auto-detect,
but should) in addition to the old Mozilla LDAP library; this will
become the default LDAP library in the next release. As there is no
longer a need to build against the Mozilla LDAP library, and as we
have unwittingly relied on some OpenLDAP-specific features since 1.13,
remove the compatibility code for the Mozilla LDAP library and just
require OpenLDAP 2.1 (which added ldap_str2dn).
Greg Hudson [Mon, 31 Oct 2016 15:48:54 +0000 (11:48 -0400)]
Make zap() more reliable
The gcc assembly version of zap() could still be optimized out under
gcc 5.1 or later, and the krb5int_zap() function could be optimized
out with link-time optimization. Based on work by Zhaomo Yang and
Brian Johannesmeyer, use the C11 memset_s() when available, then fall
back to a memory barrier with gcc or clang, and finally fall back to
using krb5int_zap(). Modify krb5int_zap() to use a volatile pointer
in case link-time optimization is used.
Greg Hudson [Fri, 28 Oct 2016 14:26:04 +0000 (10:26 -0400)]
Add doxygen comments for RFC 8009, RFC 4757
The aes-sha2 specification has been published as RFC 8009. Add
Doxygen comments to the #defines for its enctype and checksum type
comments. Also add comments for the RC4 enctype and checksum type
constants referring to RFC 4757.
Greg Hudson [Fri, 7 Oct 2016 15:23:02 +0000 (11:23 -0400)]
Clarify krb5_kt_resolve() API documentation
Explicitly say to use krb5_kt_close() like we do for most other
allocating API calls. Note the default type. Instead of saying "The
key table is not opened," say that the keytab file for FILE keytabs is
not opened by this call.
Greg Hudson [Thu, 6 Oct 2016 15:28:33 +0000 (11:28 -0400)]
Suggest unlocked iteration for mkey rollover
In database.rst when discussing the procedure for master key rollover,
suggest using unlocked iteration for large databases. Also make it
clear that unavailability due to locking during iteration is specific
to DB2.
Greg Hudson [Wed, 5 Oct 2016 14:51:52 +0000 (10:51 -0400)]
Fix "make depend" when cmocka.h not present
Add an intermediary header file k5-cmocka.h, which only includes
cmocka.h if we detected an appropriate version of cmocka at configure
time. This allows "make depend" to successfully run over cmocka test
programs when cmocka.h isn't present on the build platform.
For convenience, k5-cmocka.h also includes stdarg.h, stddef.h, and
setjmp.h, which are required to include cmocka.h.
Greg Hudson [Tue, 4 Oct 2016 16:36:30 +0000 (12:36 -0400)]
Error on discarded qualifiers in gcc
If a function call passes a const pointer to a function accepting the
same pointer type without the const qualifier, that should be treated
as an erorr if possible. In sufficiently recent gcc, pass
-Werror=discarded-qualifiers. (In clang, this is already covered by
-Werror=incompatible-pointer-types which we recently added.)
Greg Hudson [Tue, 4 Oct 2016 15:35:29 +0000 (11:35 -0400)]
Improve builtin PBKDF2 code hygiene
In F() in the builtin implementation of PBKDF2, use make_data() to
fully initialize sdata and out; otherwise we (harmlessly) copy an
uninitialized magic field in hmac(). Also simplify out the local
variable tlen.
Tom Yu [Tue, 4 Oct 2016 22:14:51 +0000 (18:14 -0400)]
Set alg param correctly for PKCS1
When using a smart card and constructing a DigestInfo to pass to the
CKM_RSA_PKCS mechanism, make sure to set the AlgorithmIdentifier
parameters correctly. This is typically an ASN.1 NULL value.
Greg Hudson [Tue, 8 Dec 2015 04:32:18 +0000 (23:32 -0500)]
Add aes-sha2 test cases
Add test cases for all of the test vectors in the aes-sha2 draft. In
t_cksums.c and t_decrypt.c, modify the test structure to allow for
binary plaintexts. In t_str2key.c, modify the test structure to allow
for binary salts. In t_derive.c, allow tests to have outputs which
don't match the key size, using krb5int_derive_random() instead of
krb5int_derive_key().
Add test cases for KRB-FX-CF2 and for gss_pseudo_random() using test
vectors generated ourselves.
Add k5test and dejagnu test passes for aes-sha2 enctypes.
Greg Hudson [Tue, 8 Dec 2015 03:16:24 +0000 (22:16 -0500)]
Rewrite t_prf crypto test program
Rewrite the pseudo-random test program to use hardcoded test cases
instead of input and expected output files. The test cases are the
same, using hardcoded keys instead of running string-to-key over
"key1" or "key2".
Greg Hudson [Sun, 6 Dec 2015 00:36:57 +0000 (19:36 -0500)]
Add aes-sha2 enctype support
Add support to libk5crypto for the aes128-cts-hmac-sha256-128 and
aes256-cts-hmac-sha384-192 encryption types, and the
hmac-sha256-128-aes128 and hmac-sha384-192-aes256 checksum types.
Key derivation for the new encryption types uses a hash, so we need to
add a hash parameter to the krb5int_derive_ functions, which can be
null except when DERIVE_SP800_108_HMAC is given. Rename the helper
function derive_random_sp800_108_cmac() to
derive_random_sp800_108_feedback_cmac() to make it clear that feedback
mode is used, since the new enctype uses counter mode.
Greg Hudson [Mon, 7 Dec 2015 16:16:06 +0000 (11:16 -0500)]
Enable PBKDF2 with SHA-256 and SHA-384
Rename krb5int_pbkdf2_hmac_sha1() to krb5int_pbkdf2_hmac() and add a
hash parameter. In the OpenSSL implementation, look up the
corresponding PBKDF2 parameter based on the hash pointer. In
pbkdf2_string_to_key(), pass the hash function for the key type if one
is present, and use SHA-1 if it does not (as for the Camellia
enctypes).
In the builtin implementation, use the hash provider instead of
assuming SHA-1. Remove the functional parameterization of the PRF and
turn it into an hmac() helper function. Use krb5int_hmac_keyblock()
to remove the need for a krb5_key object containing the password.
Rename the internal function from krb5int_pbkdf2() to pbkdf2().
Greg Hudson [Sun, 6 Dec 2015 00:36:41 +0000 (19:36 -0500)]
Add libk5crypto SHA-256 and SHA-384 hash providers
Add SHA-256 and SHA-384 hash providers to each of the libk5crypto back
ends, in preparation for AES-SHA2 support. For the builtin back end,
adapt SHA-512 code from Heimdal (SHA-384 is just truncated SHA-512
with different initial values). Replace builtin/sha2/t_sha256.c with
a program under crypto_tests which tests SHA-256 and SHA-384 in all
back ends.
Greg Hudson [Sat, 5 Dec 2015 22:20:26 +0000 (17:20 -0500)]
Consolidate libk5crypto OpenSSL hash providers
In the libk5crypto OpenSSL back end, combine all of the hash providers
which use the OpenSSL EVP interface into a single file to reduce code
duplication.
In the previous code, when the remote peer performed an orderly shutdown
on the socket, libkrad would enter a state in which all future requests
timed out. Instead, if the peer shuts down its socket, we need to
attempt to reopen it.
Ben Kaduk [Mon, 26 Jan 2015 16:15:42 +0000 (11:15 -0500)]
Improve keytab documentation
In the k5srvutil man page, do not give the impression that arbitrary
new keys can be added to the keytab (requested by Dan Gillmor), since
only the new keys randomly generated by the KDC via 'k5srvutil change'
can be added to the keytab. Reiterate the importance of running
k5srvutil delold after running k5srvutil change in the description of
k5srvutil change, as well as in the description of k5srvutil delold
itself.
In install_kdc.rst, mention using a separate keytab file when
generating a keytab on a KDC for use on another host.
[ghudson@mit.edu: squashed two commits, condensed commit message]
Ben Kaduk [Wed, 11 Jun 2014 20:38:57 +0000 (16:38 -0400)]
Document krb5_kt_next_entry() requirement
Successful calls to krb5_kt_next_entry() return a krb5_keytab_entry
that the caller is responsible for freeing. Note this, and the
proper function to do so, in the doxygen comments.
In prepare_error_as(), if krb5_us_timeofday() fails and error pa-data
was supplied, the FAST cookie and a shallow copy of the error padata
can be leaked. Reported by Will Fiveash.
Greg Hudson [Tue, 3 May 2016 17:22:46 +0000 (13:22 -0400)]
Add PKINIT support for OpenSSL 1.1.0
OpenSSL 1.1 makes the DH, EVP_MD_CTX, X509, and X509_STORE_CTX types
opaque, removes asn1_mac.h, removes the M_ASN1_* macros, and removes
CRYPTO_malloc_init(). Change the PKINIT code to work with OpenSSL 1.1
while retaining compatibility with OpenSSL 1.0. The new code uses
X509_STORE_set_verify_cb(), which is not present in OpenSSL 0.9, so
require OpenSSL 1.0 for PKINIT support.
Greg Hudson [Fri, 17 Jun 2016 16:00:21 +0000 (12:00 -0400)]
Add libk5crypto support for OpenSSL 1.1.0
OpenSSL 1.1.0 makes the EVP_MD_CTX, EVP_CIPH_CTX, and EVP_HMAC_CTX
types opaque. Change the libk5crypto OpenSSL code to work with
OpenSSL 1.1 while retaining compatibility with previous versions.
Add the prng_os.c module, using the name previously occupied by what
is now prng_device.c. Unlike prng_device.c, this PRNG module
maintains no file descriptor and just uses k5_os_random(), which is
most efficient on platforms which have a getrandom() system call.
Sarah Day [Fri, 19 Aug 2016 17:47:22 +0000 (13:47 -0400)]
Fix KDC lookaside cache entry count tracking
The KDC lookaside cache was incrementing num_entries when an entry was
added, but it did not decrement num_entries when an entry was removed.
Decrement num_entries in discard_entry(). Also fix some function
comments to correctly explain what the function is doing, and refactor
kdc_insert_lookaside by moving the code that inserts an entry into a
new static function called insert_entry().
Tom Yu [Tue, 20 Sep 2016 19:58:50 +0000 (15:58 -0400)]
Silence warnings in lib/rpc
Cast through (void *) in xdr.c to silence pointer target width
warnings. In xdr_sizeof.c, use x_private and x_base as proper
pointers as in xdr_mem.c instead of trying to store an integer in a
pointer.
Matt Rogers [Wed, 24 Aug 2016 04:42:16 +0000 (00:42 -0400)]
Add configuration option for URI lookups
Add the boolean option 'dns_uri_lookup' to krb5.conf's libdefaults
section, to allow disabling URI lookups seperately from SRV lookups.
The default value is 'true'.
Matt Rogers [Mon, 18 Jul 2016 16:13:55 +0000 (12:13 -0400)]
Enable KDC discovery through DNS URI records
Add the dns_locate_server_uri(), locate_uri(), and parse_uri_fields()
functions to find and process KDC service information from specially
formatted URI records detailed at
http://k5wiki.kerberos.org/wiki/Projects/KDC_Discovery
Search for URI records before searching for SRV records. Rename
dns_locate_server() to dns_locate_server_srv() for consistency. Add
URI-specific information to the t_locate_kdc host entry output.
Matt Rogers [Mon, 18 Jul 2016 14:18:45 +0000 (10:18 -0400)]
Add DNS URI query function
Add the k5_make_uri_query() function for finding URI records of a
given realm and service tag. Turn some common code shared with
krb5int_make_srv_query_realm() into helper functions.
Matt Rogers [Wed, 13 Jul 2016 20:27:57 +0000 (16:27 -0400)]
Add a master flag to struct server_entry
URI lookups will contain a flag to indicate if the KDC is a master or
normal KDC, so add a master variable to server_entry. The default
value is -1 and means that the status has not been determined by the
information source. If the flag is set, use it to avoid a seperate
lookup in k5_kdc_is_master().
Also add a "master" argument to add_host_to_list(). Adjust the
existing calls of add_host_to_list() for the new argument (set to -1
as they are from non-URI lookups).
Tom Yu [Fri, 16 Sep 2016 23:02:45 +0000 (19:02 -0400)]
Remove more non-DFSG documentation
Delete an Internet-Draft that we missed on an earlier pass. Also
remove ISOC/BCP 78 copyright language because the remaining extracts
from RFCs are small enough to be fair use.
Tom Yu [Wed, 31 Aug 2016 17:40:22 +0000 (13:40 -0400)]
Stop generating doc/CHANGES
Shipping a 10MB+ doc/CHANGES file in the release tarball doesn't make
much sense in a modern context where historical information is readily
available in a distributed version control system.
Tom Yu [Wed, 7 Sep 2016 21:28:34 +0000 (17:28 -0400)]
Fix unaligned accesses in bt_split.c
In the libdb2 btree back end, splitting a page at an overflow key
could result in an unaligned access, causing a crash (and data
corruption) on platforms with strict alignment. This probably occurs
only rarely in practice.
Add a public libkdb5 function to register the KDB keytab type. This
functionality is needed for out-of-tree KDC servers such as the Samba
kpasswd service.
Ben Kaduk [Thu, 11 Aug 2016 04:25:47 +0000 (23:25 -0500)]
Fix build with -O3 on ppc64el
Ubuntu runs ppc64el builds with -O3, which elicited a few warnings
from gcc that were not generated elsewhere, as documented at
https://bugs.launchpad.net/ubuntu/+source/krb5/+bug/1592841 .
Initialize the output variable at the top of a couple of helper functions
to silence the uninitialized-variable warnings.
Commit e3d9f03a658e247dbb43cb345aa93a28782fd995 (ticket 8481) added
several checks for negative length values when decoding DB2 principal
entries, including two unnecessary checks on unsigned values. Remove
those checks as they can generate warnings.
Greg Hudson [Thu, 25 Aug 2016 19:37:23 +0000 (15:37 -0400)]
Consolidate sn2princ_realm() in kprop and kpropd
In kprop and kpropd, factor out the duplicated implementation of
sn2princ_with_realm() into kprop_util.c. Rename it to
sn2princ_realm(), remove the type parameter, and require the sname
parameter to be specified. Rewrite the function to use
krb5_expand_hostname(), avoiding an unnecessary hostrealm lookup.
We depend on the behavior of having a separate subshell for each line in
our Makefiles, so force it where make (observed FreeBSD 10.3) does not
create one.
[ghudson@mit.edu: also changed rules in config/post.in]
Tom Yu [Thu, 25 Aug 2016 22:02:56 +0000 (18:02 -0400)]
Avoid byte-swap cache corruption in libdb2
Apply a patch from NetBSD to restore the cached copy of a page to the
machine byte order after a write operation swapped it to the file byte
order. As a regression test, modify test13 to sync the database file
after each put to exercise this bug.
Tom Yu [Fri, 26 Aug 2016 22:40:49 +0000 (18:40 -0400)]
Add known file test case for btree byte swap
Add a regression test for the preceding bugfix. This test uses btree
database files with known contents and byte orders with short keys and
overflow data items.
Tom Yu [Fri, 26 Aug 2016 19:24:52 +0000 (15:24 -0400)]
Fix btree byte swapping for overflow data
When operating on a btree database file of the opposite endianness,
libdb2 was swapping the wrong bytes if a record had a short key but
overflow data. Fix this bug by not incrementing p when swapping a
P_BIGKEY overflow pointer, and by always skipping the full key size
before swapping a P_BIGDATA overflow pointer (instead of assuming that
a P_BIGKEY pointer always precedes a P_BIGDATA pointer).
Greg Hudson [Fri, 26 Aug 2016 16:55:40 +0000 (12:55 -0400)]
Fix thread support for Solaris and simplify
threads.c failed to build on Solaris afer commit 17932091cc0d5981c5a78d389ffa4a5c7b532bd6 because k5-thread.h did not
define the conditional k5_once_t structure (because NO_WEAK_PTHREADS
is defined) but threads.c tried to build the conditional k5_once()
function.
Use a single preprocessor symbol, USE_CONDITIONAL_PTHREADS, to
determine whether to use and define pthreads functions which
conditionalize on whether pthreads is loaded. In threads.c, move the
new k5_once() definitions into the USE_CONDITIONAL_PTHREADS block,
defining a stub function if other code will not refer to it.
Also move #pragma weak declarations from k5-threads.h into threads.c,
as we should no longer be conditionally referring to those symbols
outside of threads.c.
Also eliminate some missing-prototype warnings where we define
functions for linker-visibility but don't have corresponding
prototypes in k5-threads.h.
Greg Hudson [Tue, 23 Aug 2016 17:41:00 +0000 (13:41 -0400)]
Improve checking of decoded DB2 principal values
In krb5_decode_princ_entry(), verify the length of the principal name
before calling krb5_parse_name() or strlen(), to avoid a possible
buffer read overrun. Check all length fields for negative values.
Avoid performing arithmetic as part of bounds checks. If the value of
key_data_ver is unexpected, return KRB5_KDB_BAD_VERSION instead of
aborting.
Tom Yu [Sat, 27 Aug 2016 21:04:11 +0000 (17:04 -0400)]
Fix check-pytests-no
Commit 0db097ba8b605ea7a6e0364ad786da6528868179 accidentally removed
the $(SKIPTESTS) line from check-pytests-no, causing a syntax error
when running "make check" when python is missing or not sufficiently
new.
To work correctly with older Samba clients, we should guess the mutual
flag based on the ap_options from the AP-REQ and not set it
unconditionally. Found by the Samba torture testsuite.
[ghudson@mit.edu: edited comments and commit message]
Greg Hudson [Tue, 23 Aug 2016 16:38:54 +0000 (12:38 -0400)]
Remove svcauth_gss_creds
svcauth_gss_creds was in the libgssrpc library export list (as
gssrpc_svc_auth_gss_creds) but was not declared in a public header and
has no value to applications. Remove it.
Greg Hudson [Tue, 23 Aug 2016 16:35:50 +0000 (12:35 -0400)]
Fix GSSRPC server credential memory leak
In svc_auth_gss.c, stop using the global svcauth_gss_creds, and
instead keep a credential in struct svc_rpc_gss_data. This change
ensures that the same credential is used for each accept_sec_context
call for a particular context, and ensures that the credential is
freed when the authentication data is destroyed. Also, do not acquire
a credential when the default name is used (as it is in kadmind) as it
is not needed.
Leave the svcauth_gss_creds around for the backportable fix as it is
in the library export list. It will be removed in a subsequent
commit.
Sarah Day [Mon, 8 Aug 2016 20:40:17 +0000 (16:40 -0400)]
Convert k5-thread macros to functions
k5-thread.h has several pthread support calls defined as macros which
conditionally call pthread functions. If a program is linked with
libkrb5support and uses these macros, and the program isn't compiled
with -fPIC, then it can crash if the pthread functions are linked at
runtime (via LD_PRELOAD, for instance) but not at compile time.
Convert the conditional macros to functions, so that libkrb5support is
responsible for determining whether pthreads is loaded and for calling
the pthreads functions if it is.
Greg Hudson [Fri, 20 Nov 2015 00:32:11 +0000 (19:32 -0500)]
Use krb5_expand_hostname() to get admin service
In libkadm5's kadm5_get_admin_service_name(), use
krb5_expand_hostname() instead of custom canonicalization code to
canonicalize the hostname. There are some minor behavior differences;
in addition to the changes listed in the previous commit, the old code
did not downcase the result of the getaddrinfo() lookup, while the new
code does.
Greg Hudson [Tue, 17 Nov 2015 18:33:21 +0000 (13:33 -0500)]
Use krb5_expand_hostname() when creating KDB
In kdb5_util's add_admin_princs(), use krb5_expand_hostname() instead
of custom canonicalization code to canonicalize the hostname. There
are some minor behavior differences:
* Canonicalization will no longer use AI_ADDRCONFIG.
* Canonicalization will use reverse DNS if configuration permits.
* Canonicalization will be affected by the dns_canonicalize_hostname
and rdns profile variables.
* If name lookup fails, the original hostname will be used.
* A trailing dot will be removed from the name lookup result, if
present.
Greg Hudson [Tue, 17 Nov 2015 18:06:31 +0000 (13:06 -0500)]
Add krb5_expand_hostname() API
Add a new public libkrb5 function expand_hostname(). It follows the
same contract as the Heimdal function, except that the caller should
use krb5_free_string() instead of krb5_xfree() to free the result.
As a small side effect, we no longer remove trailing dots from the
hostname in krb5_sname_to_principal() when invoked with type
KRB5_NT_UNKNOWN. Adjust a test case in t_sn2princ.py accordingly.
In spnego_gss_import_cred(), use create_spnego_cred() to create the
SPNEGO credential structure. Prior to this change, an imported SPNEGO
cred did not initialize the no_ask_integ field (added by commit cf39ed349976908626cad3e05e17788f8334bce9, ticket #6938).
Greg Hudson [Mon, 8 Aug 2016 18:39:24 +0000 (14:39 -0400)]
Add another AD-SIGNTICKET corner case test
Prior to the fix for #8139, forwarded TGTs obtained across a krbtgt
re-key could fail if the preferred krbtgt enctype changed, because
krb5_c_verify_checksum() returns an bad-enctype error due to the
mismatched checksum. Add a test case for this scenario, using a new
test harness program which obtains a forwarded TGT.
Greg Hudson [Wed, 17 Aug 2016 15:50:31 +0000 (11:50 -0400)]
Output last command info on k5test failures
When a k5test failure occurs, display the last executed command, its
command index, and its output. This will make it easier to understand
"make check" failures when it is not easy to run subsequent commands
or investigate the filesystem of the build host.
Greg Hudson [Fri, 5 Aug 2016 16:28:03 +0000 (12:28 -0400)]
Use responder for non-preauth AS requests
If no AS reply key is computed during pre-authentication (typically
because no pre-authentication was required by the KDC), ask for the
password using the responder before calling gak_fct for the key, and
supply any resulting responder items to gak_fct.