summaryrefslogtreecommitdiff
path: root/lib/libcrypto/pem
AgeCommit message (Collapse)Author
2020-07-25remove half a dozen "goto" statements and a labelIngo Schwarze
that change nothing whatsoever, except making the code harder to read; OK tb@
2020-07-23Fix a bug in PEM_X509_INFO_read_bio(3) that is very likely to causeIngo Schwarze
use-after-free and double-free issues in calling programs. The bug was introduced in SSLeay-0.6.0 released on June 21, 1996 and has been present since OpenBSD 2.4. I found the bug while documenting the function. The bug could bite in two ways that looked quite different from the perspective of the calling code: * If a stack was passed in that already contained some X509_INFO objects and an error occurred, all the objects passed in would be freed, but without removing the freed pointers from the stack, so the calling code would probable continue to access the freed pointers and eventually free them a second time. * If the input BIO contained at least two valid PEM objects followed by at least one PEM object causing an error, at least one freed pointer would be put onto the stack, even though the function would return NULL rather than the stack. But the calling code would still have a pointer to the stack, so it would be likely to access the new bogus pointers sooner or later. Fix all this by remembering the size of the input stack on entry and cutting it back to exactly that size when exiting due to an error, but no further. While here, do some related cleanup: * Garbage collect the automatic variables "error" and "i" which were only used at one single place each. * Use NULL rather than 0 for pointers. I like bugfixes that make the code four lines shorter, reduce the number of variables by one, reduce the number of brace-blocks by one, reduce the number if if-statements by one, and reduce the number of else-clauses by one. Tweaks and OK tb@.
2019-09-06Handle CMS PEM headers.Joel Sing
ok inoguchi@ tb@
2019-07-08Clean up pvkfmt.cKinichiro Inoguchi
- Replace EVP_CIPHER_CTX_init with EVP_CIPHER_CTX_new and handle return value - Replace EVP_CIPHER_CTX_cleanup with EVP_CIPHER_CTX_free - Change two 'return -1;' to 'goto err;' for avoiding leak - Remove the case if enclevel == 0 - Change enclevel checking to make more consistent - Change all goto label to 'err' and insert space before goto label ok and advise from tb@
2019-07-07Fix pvk format processing in libcryptoKinichiro Inoguchi
- Return the valid pointer in i2b_PVK() - Use EVP_Decrypt* instead of EVP_Encrypt* - Fix error handling after BIO_write() in i2b_PVK_bio() ok tb@
2018-08-24Change PEM_Sign{Init,Update}() to return an int.Theo Buehler
tested in a bulk by sthen ok jsing
2018-08-24Check return value of EVP_EncodeUpdate() in PEM_write_bio().Theo Buehler
ok jsing
2018-08-05Fix memory leak in i2b_PVK in error handling.Brent Cook
Simplify parameter checks since this is only called from one place. Found by Coverity, CID 183502. ok beck@
2018-05-13Add const qualifier to the 'name', 'header', and 'data' arguments ofTheo Buehler
PEM_write(3) and PEM_write_bio(3). tested in a bulk build by sthen ok jsing
2018-04-14make ENGINE_finish() succeed on NULL and simplify callers as inTheo Buehler
OpenSSL commit 7c96dbcdab9 by Rich Salz. This cleans up the caller side quite a bit and reduces the number of lines enclosed in #ifndef OPENSSL_NO_ENGINE. codesearch.debian.net shows that almost nothing checks the return value of ENGINE_finish(). While there, replace a few nearby 'if (!ptr)' with 'if (ptr == NULL)'. ok jsing, tested by & ok inoguchi
2017-05-02use freezero() instead of memset/explicit_bzero + free. SubstantiallyTheo de Raadt
reduces conditional logic (-218, +82). MOD_EXP_CTIME_MIN_CACHE_LINE_WIDTH cache alignment calculation bn/bn_exp.c wasn'tt quite right. Two other tricky bits with ASN1_STRING_FLAG_NDEF and BN_FLG_STATIC_DATA where the condition cannot be collapsed completely. Passes regress. ok beck
2017-01-29Send the function codes from the error functions to the bit bucket,Bob Beck
as was done earlier in libssl. Thanks inoguchi@ for noticing libssl had more reacharounds into this. ok jsing@ inoguchi@
2017-01-21Make explicit _ct and _nonct versions of bn_mod_exp funcitons thatBob Beck
matter for constant time, and make the public interface only used external to the library. This moves us to a model where the important things are constant time versions unless you ask for them not to be, rather than the opposite. I'll continue with this method by method. Add regress tests for same. ok jsing@
2016-11-05Make sure PEM_SealInit() will correctly destroy the PEM_ENCODE_SEAL_CTXMiod Vallat
upon error, as there is no way to do this outside of PEM_SealFinal(), which can only work if PEM_SealInit() succeeded... ok beck@ jsing@
2016-10-19unifdef OPENSSL_NO_CMSJoel Sing
2016-09-04Place IMPLEMENT_PEM macros under #ifndef LIBRESSL_INTERNAL.Joel Sing
2016-09-04Sort and group functions.Joel Sing
2016-09-04Expand IMPLEMENT_PEM macros.Joel Sing
No change in generated assembly.
2016-03-02fix the rest of the read_ledword() calls used as lengths to be bounded.Bob Beck
inspired by guido vranken https://guidovranken.wordpress.com/2016/03/01/public-disclosure-malformed-private-keys-lead-to-heap-corruption-in-b2i_pvk_bio/ ok doug@
2016-03-02bound lengths coming out of a pem file to something like realityBob Beck
ok deraadt@
2015-09-10Correct spelling of OPENSSL_cleanse.Joel Sing
ok miod@
2015-07-19Drop stupid (int) casts for the arguments of malloc() and friends. This isMiod Vallat
not 16-bit MS-DOS anymore. ok bcook@ tedu@
2015-07-16Make sure the `reject negative sizes' logic introduced in 1.34 is actuallyMiod Vallat
applied to all code paths. ok beck@ bcook@ doug@ guenther@
2015-05-15Fix return paths with missing EVP_CIPHER_CTX_cleanup() calls.Jonathan Gray
ok doug@
2015-02-11Guenther has plans for OPENSSL_NO_CMS, so revert this for the moment.Bob Beck
2015-02-11get rid of OPENSSL_NO_CMS code we do not use.Bob Beck
ok miod@
2015-02-11Enable building with -DOPENSSL_NO_DEPRECATED.Doug Hogan
If you didn't enable deprecated code, there were missing err.h and bn.h includes. This commit allows building with or without deprecated code. This was not derived from an OpenSSL commit. However, they recently enabled OPENSSL_NO_DEPRECATED in git and fixed these header problems in a different way. Verified with clang that this only changes line numbers in the generated asm. ok miod@
2015-02-10Replace assert() and OPENSSL_assert() calls with proper error return paths.Miod Vallat
Careful review, feedback & ok doug@ jsing@
2014-10-22Use arc4random_buf() instead of RAND_bytes() or RAND_pseudo_bytes().Joel Sing
arc4random_buf() is guaranteed to always succeed - it is worth noting that a number of the replaced function calls were already missing return value checks. ok deraadt@
2014-10-18None of these need to include <openssl/rand.h>Joel Sing
2014-07-23Make sure PEM_def_callback() correctly handles negative buffer sizes; all usesMiod Vallat
within libcrypto are safe, but until we can change this function prototype to use size_t instead of int, better be safe than sorry. tweaks and ok guenther@
2014-07-12if (x) FOO_free(x) -> FOO_free(x).Miod Vallat
Improves readability, keeps the code smaller so that it is warmer in your cache. review & ok deraadt@
2014-07-11Missing bounds check in do_PVK_body(); OpenSSL RT #2277, from OpenSSL trunk,Miod Vallat
but without a memory leak.
2014-07-11Only import cryptlib.h in the four source files that actually need it.Joel Sing
Remove the openssl public includes from cryptlib.h and add a small number of includes into the source files that actually need them. While here, also sort/group/tidy the includes. ok beck@ miod@
2014-07-10Explicitly include <openssl/opensslconf.h> in every file that referencesJoel Sing
an OPENSSL_NO_* define. This avoids relying on something else pulling it in for us, plus it fixes several cases where the #ifndef OPENSSL_NO_XYZ is never going to do anything, since OPENSSL_NO_XYZ will never defined, due to the fact that opensslconf.h has not been included. This also includes some miscellaneous sorting/tidying of headers.
2014-07-10Stop including standard headers via cryptlib.h - pull in the headers thatJoel Sing
are needed in the source files that actually require them. ok beck@ miod@
2014-07-10delete some casts. ok miodTed Unangst
2014-07-10Missing allocation checks and potential NULL pointer dereference in theMiod Vallat
error path in PEM_X509_INFO_read_bio(); ok guenther@ jsing@
2014-07-09remove unused, private version strings except SSL_version_strBrent Cook
Also remove unused des_ver.h, which exports some of these strings, but is not installed. ok miod@ tedu@
2014-06-12tags as requested by miod and teduTheo de Raadt
2014-06-07malloc() result does not need a cast.Theo de Raadt
ok miod
2014-06-01Avoid the use of an uninitialised variable. In reality, this is a non-issueJoel Sing
since the calculated value is not actually used in the uninitialised case. Change the code so that we only do the calculation if we actually need it. Issue detected by clang and reported by both brad@ and Brent Cook.
2014-05-30more: no need for null check before freeTheo de Raadt
ok tedu guenther
2014-05-29convert 53 malloc(a*b) to reallocarray(NULL, a, b). that is 53Theo de Raadt
potential integer overflows easily changed into an allocation return of NULL, with errno nicely set if need be. checks for an allocations returning NULL are commonplace, or if the object is dereferenced (quite normal) will result in a nice fault which can be detected & repaired properly. ok tedu
2014-05-29Everything sane has stdio, and FILE *. we don't need ifdefs for this.Bob Beck
ok to firebomb from tedu@
2014-05-26We don't really to keep history in constructs such as:Miod Vallat
#if 1 /* new with openssl 0.9.4 */ current code; #else obsolete code; #endif
2014-05-24Almost nothing actually needs to include <openssl/e_os2.h>, however byJoel Sing
including it they get <openssl/opensslconf.h>. So instead of pulling in <openssl/e_os2.h>, just pull in <openssl/opensslconf.h>. "go ahead" miod@
2014-05-22if (x) free(x) -> free(x); semantic patch generated with coccinelle, carefullyMiod Vallat
eyeballed before applying. Contributed by Cyril Roelandt on tech@
2014-04-26Replace all use of ERR_add_error_data with ERR_asprintf_error_data.Bob Beck
This avoids a lot of ugly gymnastics to do snprintfs before sending the bag of strings to ERR, and eliminates at least one place in dso_dlfctn.c where it was being called with the incorrect number of arguments and using random things off the stack as addresses of strings. ok krw@, jsing@
2014-04-23Unifdef -UPEDANTIC. ok beck@ tedu@Miod Vallat