Commit Graph

71 Commits

Author SHA1 Message Date
Nicolas Williams
64d5f86ec3 Fix warnings (some bugs, some spurious)
Many spurious VC warnings not quieted though.
2020-03-12 21:02:09 -05:00
Nicolas Williams
e515745996 hx509: private key exclusion options
Add two ways to exclude private keys when dealing with an hx509
certificate store.  One as a load option (load no private keys, never
add private keys), one as a store option (store no private keys).

This is useful for CA code so it can have a single store with the
issuer's credentials _and_ the chain for it, and copy those to a store
with the issued certificate and _not_ accidentally include the issuer's
private key.

It would be much safer still to flip the default for this flag, but that
could break out-of-tree libhx509 dependents.
2019-12-09 18:10:10 -06:00
Nicolas Williams
ddbc36d86b hx509: Store priv keys first in PEM stores
Most consumers of PEM files don't care about the order in which private
keys and certificates are stored.  However, Postfix does care when
multiple EE certs (and chains) are stored in a file, in which case it
requires that private keys come before their certificates.
2019-11-02 18:49:42 -05:00
Nicolas Williams
d31dd9e00b hx509: make file store writes atomic
Now we'll use mkostemp() and rename() into place to make
hx509_certs_store() atomic for FILE/DER-FILE/PEM-FILE stores.

This is not ideal, as it can leave temp files in place if a process
crashes in between the mkostemp() and the rename into place.

On Linux we'll eventually make use of O_TMPFILE and linkat().  The idea
will be to first create an anonymous, zero-link file in the directory
that will contain the file at the end, write the file, then linkat() the
file into place as a .new file, then rename() the .new into place.  That
will limit the amount of junk that may be left behind to just one file.
(If the linkat() fails, then unlink() the .new and try again.  If the
rename() fails that just means the caller raced with another and the
operation is complete.)

We should really make a lib/roken interface that does this.
2019-10-08 20:58:04 -05:00
Nicolas Williams
41fcafd20c hx509: add hx509_certs_destroy() 2019-10-03 13:09:18 -05:00
Nicolas Williams
e4b35ba13f hx509: create files with safe mode_t 2019-10-03 13:09:18 -05:00
Nicolas Williams
63116100a8 hx509: do not crash on missing FILE: name 2019-10-03 13:09:18 -05:00
Nicolas Williams
252487dfe4 hx509: support reading private keys from PEM files
This commit adds:

 - hx509_cert_init_private_key() for creating an hx509_cert object that
   has just a private key

 - hx509_cert_have_private_key_only() for checking whether an hx509_cert
   object has just a private key

This also generalizes the get_key() internal function in hxtool, which
is tasked with reding or generating a private key for use in signing
CSRs.  Now hxtool request-create can read/write private keys to/from PEM
files, not just DER files.

This is needed to support key types other than just RSA for CSRs and
certificates.
2019-10-03 13:09:18 -05:00
Jeffrey Altman
387684aa93 WIN32: fix calling conventions for 32-bit builds
On 32-bit Windows Intel builds the __cdecl and __stdcall calling
conventions are different so labeling the functions that are
exported or assigned to function pointers matters.

Change-Id: I03b6f34baeb9ffb2e683fd979f12f27a5078a4da
2019-01-14 06:12:36 -05:00
Jeffrey Altman
1dd38cc3de lib/hx509: declare and apply HX509_LIB_xxx macros
libhx509 is not built according to the same export and calling conventions
on Windows as the other libraries.  This change declares and applies
HX509_LIB_FUNCTION, HX509_LIB_NORETURN_FUNCTION, HX509_LIB_CALL and
HX509_LIB_VARIABLE to lib/hx509.

As a result of this change the calling convention for exported functions
will be __stdcall instead of __cdecl.

Change-Id: Ibc3f05e8088030ef7d13798f1d9c9b190bc57797
2019-01-02 10:23:39 -06:00
Jeffrey Altman
93518bfab4 use memset_s
lib roken includes support for memset_s() but it was not applied
to the Heimdal source tree.

Change-Id: I8362ec97a9be50205bb2d398e65b629b88ce1acd
2017-04-29 01:05:59 -04:00
Nicolas Williams
3ba12317a0 Misc fixes (coverity) 2016-11-28 15:09:55 -06: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
Love Hornquist Astrand
029de6cfa4 pass back an heim_error from hx509_cert_init 2012-10-07 06:33:13 -07:00
Love Hornquist Astrand
0879b9831a remove trailing whitespace 2011-05-21 11:57:31 -07:00
Love Hornquist Astrand
f5f9014c90 Warning fixes from Christos Zoulas
- shadowed variables
- signed/unsigned confusion
- const lossage
- incomplete structure initializations
- unused code
2011-04-29 20:25:05 -07:00
Love Hornquist Astrand
48ad3e1e65 add import/export type for private keys 2010-10-03 16:32:01 -07:00
Love Hornquist Astrand
ccc6175b53 use hx509_certs_iter_f 2009-11-22 13:57:48 -08:00
Love Hornquist Astrand
ce0293b994 Rename f to ksf in the global function namespace to avoid -Wshadow warning
Based on a report from Matthias Dieter Wallnöfer.
2009-10-03 11:33:41 -07:00
Love Hornquist Astrand
5373d3a869 Allow parsing of cert fail unless HX509_CERTS_UNPROTECT_ALL is set. 2009-07-30 10:20:04 +02:00
Love Hörnquist Åstrand
21ceaf518f clear error string, it makes no sense
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25224 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-05-25 23:43:57 +00:00
Love Hörnquist Åstrand
1eca860a46 Pass up error code from PEM format parser.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25220 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-05-25 23:43:11 +00:00
Love Hörnquist Åstrand
49e51e45d6 handle pkcs8 PrivateKeyInfo
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@25124 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-04-16 08:24:23 +00:00
Love Hörnquist Åstrand
ff5dab4f4a remove rcsid
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24795 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-22 23:28:18 +00:00
Love Hörnquist Åstrand
64c33e2655 remove printf
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24679 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-11 18:31:43 +00:00
Love Hörnquist Åstrand
0f2af8c10f more EC bits, now parses the private key
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24661 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-09 17:16:32 +00:00
Love Hörnquist Åstrand
82c71ee5db Make parsing of private key generic, prepare for EC private keys.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24657 ec53bebd-3082-4978-b11e-865c3cabbd6b
2009-02-07 15:13:48 +00:00
Love Hörnquist Åstrand
6937d41a02 remove trailing whitespace
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23815 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 09:21:03 +00:00
Love Hörnquist Åstrand
e172367898 switch to utf8 encoding of all files
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23814 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-09-13 08:53:55 +00:00
Love Hörnquist Åstrand
23b92e0f89 close-on-exec
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23459 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-07-27 12:13:31 +00:00
Love Hörnquist Åstrand
f3fb4ac367 close-on-exec
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23456 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-07-27 12:12:32 +00:00
Love Hörnquist Åstrand
b1f885befe use rk_undumpdata, spelling
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@23413 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-07-26 18:34:53 +00:00
Love Hörnquist Åstrand
18be53daa7 Support HX509_CERTS_UNPROTECT_ALL.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@22465 ec53bebd-3082-4978-b11e-865c3cabbd6b
2008-01-16 14:25:24 +00:00
Love Hörnquist Åstrand
6af92427cb Add writing DER certificates.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21314 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-25 18:45:07 +00:00
Love Hörnquist Åstrand
fc504fb042 Use PEM encoding/decoding functions.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21308 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-25 18:23:51 +00:00
Love Hörnquist Åstrand
b442dada5d Use hx509_pem_write.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21306 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-25 17:24:43 +00:00
Love Hörnquist Åstrand
8e9ebe14de Fail if not finding iv.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21141 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-18 21:30:11 +00:00
Love Hörnquist Åstrand
f622a16e97 Add hx509_cert_init_data and use everywhere
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@21085 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-13 06:39:53 +00:00
Love Hörnquist Åstrand
659e1cb47e Update _hx509_collector_alloc prototype.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@20776 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-06-01 22:02:01 +00:00
Love Hörnquist Åstrand
e993ff978b (store_func): use hx509_cert_binary
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19911 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-14 23:25:28 +00:00
Love Hörnquist Åstrand
80977a02f6 Factor out private key operation out of the signing, operations, support import, export, and generation of private keys. Add support for writing PEM and PKCS12 files with private keys in them.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19778 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-09 10:52:13 +00:00
Love Hörnquist Åstrand
2c45be2461 Try all formats on the binary file before giving up, this way we can
handle binary rsa keys too.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19665 ec53bebd-3082-4978-b11e-865c3cabbd6b
2007-01-04 02:01:41 +00:00
Love Hörnquist Åstrand
1f4452b34e (try_decrypt): pass down AlgorithmIdentifier that key uses to do sigatures
so there is no need to hardcode RSA into this function.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19299 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-09 12:13:21 +00:00
Love Hörnquist Åstrand
c2633ac58b Pass filename to the parse functions and use it in the error messages
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19296 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-12-08 02:35:19 +00:00
Love Hörnquist Åstrand
3d552d8a43 Return less EINVAL.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18866 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-24 14:08:32 +00:00
Love Hörnquist Åstrand
ff31485ed0 Sprinkle more hx509_context so we can return propper errors.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18863 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-24 13:48:18 +00:00
Love Hörnquist Åstrand
ec923266e2 set ret, remember to free ivdata
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18499 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-17 04:00:14 +00:00
Love Hörnquist Åstrand
1a196d0776 (parse_rsa_private_key): try all password and prompter.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18404 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-11 20:28:49 +00:00
Love Hörnquist Åstrand
00b40cc9a8 (parse_rsa_private_key): free type earlier.
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18263 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-06 13:16:07 +00:00
Love Hörnquist Åstrand
556a53109c (parse_rsa_private_key): free type after use
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18261 ec53bebd-3082-4978-b11e-865c3cabbd6b
2006-10-06 12:08:20 +00:00