Commit Graph

2092 Commits

Author SHA1 Message Date
Nicolas Williams
485b5d575a hxtool: Check hx509_request_init() return 2023-01-04 16:17:57 -06:00
Nicolas Williams
8b44896bc1 hx509: Fix harmless TOCTOU in load_crl() 2023-01-04 00:43:35 -06:00
Nicolas Williams
64254d64dd hx509: Fix ENOMEM free of garbage encoding PKCS#10 2023-01-04 00:43:35 -06:00
Nicolas Williams
1473b96d1c hx509: Fix leak in templated certificates 2023-01-04 00:43:35 -06:00
Nicolas Williams
06fdd14d4d hx509: Quiet static analyzer false positives 2023-01-04 00:43:35 -06:00
Nicolas Williams
42fff5ec5f hx509: Add content and some EXAMPLES to hxtool(1)
hxtool is a very useful command, with a very user-friendly interface, at
least compared to OpenSSL's openssl(1).  We should document it better.

Currently there are no manual pages for hxtool(1)'s subcommands, though
their --help message is pretty self-explanatory.  Now the hxtool(1) page
provides better clues to the user, including examples.
2022-12-19 17:03:38 -06:00
Nicolas Williams
d24b7fd8b2 hx509: Add hxtool cc --no-root-certs, --no-private-keys, and --append options 2022-12-19 16:26:03 -06:00
Nicolas Williams
6def4750bc hx509: Add HX509_CERTS_STORE_NO_ROOTS flag
This will allow us to add a --no-roots option to

    hxtool copy-certificate

which is convenient when copying certificate chains from stores that may
include root CA certificates.
2022-12-19 16:24:23 -06:00
Nicolas Williams
49c00512a7 hx509: Don't check if non-self-signed certs have a self-signing capable signature alg
We don't need the _hx509_self_signed_valid() check if the certificate is
not self-signed.
2022-12-19 16:23:03 -06:00
Nicolas Williams
168124cd09 hx509: Add hx509_cert_is_{ca,root,self_signed}()
These are convenient utility functions.
2022-12-19 16:21:42 -06:00
Nicolas Williams
4da64d119e hx509: Return better error in CSR authorization functions 2022-12-05 23:01:52 -06:00
Nicolas Williams
ce1dd5fc76 hx509: Export missing CSR authz symbols 2022-12-05 23:01:52 -06:00
Nicolas Williams
5dd018b7ed hx509: Get i2d_PUBKEY() prototype from correct header 2022-11-22 15:33:03 -06:00
Nicolas Williams
264f0bd1a2 hx509: OpenSSL 3.0 support 2022-11-22 11:34:54 -05:00
Nicolas Williams
0d5b238186 hx509: PKCS#12 missing error check 2022-11-22 11:34:54 -05:00
Nicolas Williams
cce8ae9927 hx509: Pass PKCS#8 keys to lower layers
OpenSSL's d2i_ECPrivateKey() is deprecated, so we have to use
d2i_PrivateKey(), but d2i_PrivateKey() wants the whole PKCS#8 blob so it
can know what kind of key it is.  So we need to let the hx509 EC layer
get that blob.  The internal APIs need some refactoring, so for now we
use a hack where we try to parse the private key with and without the
PKCS#8 wrapper.
2022-11-22 11:34:54 -05:00
Daria Phoebe Brashear
76c110e1ef hx509: hx509_verify_path remove spurious fallthrough
fallthrough needs to be directly before the next case, and this duplicate
inside an else is unneeded
2022-09-16 15:58:45 -04:00
Daria Phoebe Brashear
133f517482 rewrite fallthrough to HEIM_FALLTHROUGH to deal with new Apple SDKs
Apple clang version 14.0.0 (clang-1400.0.17.3.1) fails the build
because stds.h defines `fallthrough` as a macro which is then
expanded when base.h evaluates

  # if __has_attribute(fallthrough) && __clang_major__ >= 5

The macOS SDK defines `DISPATCH_FALLTHROUGH` as the macro instead
of `fallthrough`.

This change replaces the use of `fallthrough` in the tree with
`HEIM_FALLTHROUGH` and updates the declaration in configure logic
to define `HEIM_FALLTHROUGH` based upon existing definitions
(if any) of `fallthrough` or `DISPATCH_FALLTHROUGH`.
2022-09-16 15:58:45 -04:00
Nicolas Williams
f40ac787b1 hxtool: Allow ca command to generate subject key
This commit makes the hxtool ca sub-command, when invoked with
--generate-key=TYPE and --certificate-private-key=STORE, write the
private key only to the given --certificate-private-key store and not
also the --certificate=STORE.

Before this commit, invoking the hxtool ca sub-command with both,
--generate-key=TYPE and --certificate-private-key=STORE, caused the
--generate-key option to be ignored and the private key to be read from
the given store and copied to the --certificate=STORE.  That was clearly
a bug and non-sensical.
2022-08-10 19:07:54 -05:00
Nicolas Williams
9c0bc47efc Add hxtool(1) manual page 2022-08-07 18:59:28 -05:00
Nicolas Williams
563964ce96 hx509: Use %left for ! instead of %precedence 2022-01-21 23:34:40 -06:00
Nicolas Williams
88e31d2da8 sl: Add missing sel-gram.h target 2022-01-21 23:15:21 -06:00
Nicolas Williams
664b749399 hx509: Fix sel-gram.y shift/reduce conflicts
AND and OR are now binary operators, left-associative, with AND having
higher precedence than OR.

The not operator is now higher-precedence than the AND and OR operators.
2022-01-21 22:58:22 -06:00
Jeffrey Altman
04527412e3 Follow the Linux kernel's lead on "fallthrough"
The pseudo keyword 'fallthrough' is defined such that case statement
blocks must end with any of these keywords:
 * break;
 * fallthrough;
 * continue;
 * goto <label>;
 * return [expression];
 *
 *  gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes

The macro is defined either as

  __attribute__((__fallthrough__))

or as

  do {} while (0)  /* fallthrough */

not including the semicolon.

This change implements the Linux kernel style and updates several locations
where "/*fallthrough*/ and /* FALLTHROUGH */ were not previously replaced.

Externally imported code such as libedit, libtommath and sqlite are
restored to their unaltered state.

Change-Id: I69db8167b0d5884f55d96d72de3059a0235a1ba3
2022-01-21 10:39:47 -05:00
Nicolas Williams
dd71303a2f hx509: Fix coverity warnings 2022-01-17 17:36:48 -06:00
Nicolas Williams
4b7ad8ee43 hx509: Fix strerror(negative); streamline code
Calling strerror() with a negative value is an error.

Besides fixing that, we streamline hx509_get_error_string(), making it much
simpler and easier to read.
2022-01-17 15:17:33 -06:00
Jeffrey Altman
401bdd8bf3 lib/hx509: hx509_request_get_san SAN_TYPE_PKINIT return failure
if _hx509_unparse_KRB5PrincipalName() fails return the error code
to the hx509_request_get_san() caller.

Change-Id: I3ad8ceda23f00263890115f292ca7e4c8ce9317b
2022-01-16 22:43:02 -05:00
Jeffrey Altman
a73c45bef1 lib/hx509: hxtool test_crypto destroy 'vctx'
call hx509_verify_destroy_ctx to free 'vctx'

Change-Id: I4125a46760b8b988a63fb8d96d91a4a8b948b606
2022-01-16 22:11:28 -05:00
Jeffrey Altman
53e0b5448e lib/hx509: revoke_print addrof to hx509_revoke_free
1a793c04fa
("lib/hx509: revoke_print free revoke_context") forgot to pass
the address of 'revoke_ctx' to hx509_revoke_free().

Change-Id: I430a72a4dc7bce7099fc02bbe1feae625304a53a
2022-01-16 22:07:52 -05:00
Jeffrey Altman
603ee4d65d lib/hx509: _hx509_cert_to_env free 'buf'
The output buffer returned from hx509_name_to_string() must be
freed before it is overwritten by another call to
hx509_name_to_string().

Change-Id: Iaf28b14a2712cd28085ac5452819818e739d43ed
2022-01-16 21:59:49 -05:00
Jeffrey Altman
1a793c04fa lib/hx509: revoke_print free revoke_context
call hx509_revoke_free() to free the context.

Change-Id: I2f4439a848011cc0ab46f2802f5e4871baba348f
2022-01-16 21:53:06 -05:00
Jeffrey Altman
c59dd0b36c lib/hx509: hx509_request_get_san handle strpool on error
_hx509_unparse_utf8_string_name() and
_hx509_unparse_KRB5PrincipalName() can return a strpool even if
they fail.  The strpool must be passed through rk_strpoolcollect()
in order to return the contents to the caller of
hx509_request_get_san().

Change-Id: Ifda5620f4e9e00ca188aa138f692fccc12621ae8
2022-01-16 21:49:34 -05:00
Jeffrey Altman
708d9b4042 hx509_request_get_san can return an output string on failure
Tighten up all of the call sites of hx509_request_get_san()
to free the output string returned upon failure.

Use frees(&s) instead of free(s); s = NULL;.

Change-Id: I71035d7c1d2330a1a3a1b3b730cdd6ba1e6b7da3
2022-01-16 21:49:10 -05:00
Jeffrey Altman
363bc7d983 handle negative return values
do not pass negative values to malloc

do not pass negative values to strerror

do not pass negative values to ftruncate

do not pass negative values to fclose

Change-Id: I79ebef4e22edd14343ebeebb2ef8308785064fe8
2022-01-16 00:48:09 -05:00
Nicolas Williams
aea18c3006 Use fallthrough statement attribute (moar)
GCC is very finicky.
2022-01-14 16:58:59 -06:00
Nicolas Williams
c607135a03 Use fallthrough statement attribute (moar) 2022-01-14 16:53:34 -06:00
Nicolas Williams
ddc6113610 Use fallthrough statement attribute 2022-01-14 16:32:58 -06:00
Nicolas Williams
ea61f68d55 hx509: Fix name expansion bug 2022-01-14 12:44:00 -06:00
Nicolas Williams
e23bc7d53d hx509: Fix warnings and leaks 2022-01-14 12:42:52 -06:00
Nicolas Williams
f91b171f04 hxtool: parse_bytes() now returns ssize_t 2021-12-18 11:34:12 +11:00
Nicolas Williams
e84bcc29d3 hx509: Flags are unsigned 2021-12-18 11:34:12 +11:00
Luke Howard
8a54096266 hx509: revert UTF-8 change to hx509 test data
76860287 changed all KTH copyrights to use UTF-8, but that broke test_cms.
Revert that commit as applied to the test data.
2021-11-30 12:12:47 +11:00
Andrew Bartlett
7686028718 Use UTF-8 in KTH copyright notice
Samba is starting to protect against bi-di attacks and the starting point
is to require that input files be fully UTF-8.  In 2021 this is a reasonable
starting point anyway.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
2021-11-29 12:50:26 +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
Robert Crowston
6d1e3c3d5b Fix spelling/grammar in various PKINIT messages
Only error messages and code comments touched.
2021-10-16 12:32:04 +11:00
Nicolas Williams
e6283e2d3f hx509: For times before 2050 use UTCTime (fix pasto) 2021-08-25 22:54:25 -05:00
Nicolas Williams
3f7972e6be hx509: Use preferred attribute string types
The DC (domainComponent) attribute wants to be an IA5String.

This really doesn't matter, but if we want to conform to the spec (RFC 4519,
referenced by RFC 5280), then we have to do this.
2021-08-25 17:00:12 -05:00
Nicolas Williams
f425e116b5 hx509: For times before 2050 use UTCTime 2021-08-25 16:48:10 -05:00
Nicolas Williams
b8112ac562 hx509: Build libhx509template and hxtool with it 2021-08-12 17:31:35 -05:00
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