summaryrefslogtreecommitdiff
path: root/src/common/crypto.c
AgeCommit message (Collapse)Author
2016-11-03Merge branch 'maint-0.2.8' into maint-0.2.9Nick Mathewson
2016-11-03Work around a behavior change in openssl's BUF_MEM codeNick Mathewson
In our code to write public keys to a string, for some unfathomable reason since 253f0f160e1185c, we would allocate a memory BIO, then set the NOCLOSE flag on it, extract its memory buffer, and free it. Then a little while later we'd free the memory buffer with BUF_MEM_free(). As of openssl 1.1 this doesn't work any more, since there is now a BIO_BUF_MEM structure that wraps the BUF_MEM structure. This BIO_BUF_MEM doesn't get freed in our code. So, we had a memory leak! Is this an openssl bug? Maybe. But our code was already pretty silly. Why mess around with the NOCLOSE flag here when we can just keep the BIO object around until we don't need the buffer any more? Fixes bug 20553; bugfix on 0.0.2pre8
2016-09-24Merge branch 'osx_sierra_028'Nick Mathewson
2016-09-24Fix compilation on OSX Sierra (10.12)Nick Mathewson
2016-09-16Add support for AES256 and AES192Nick Mathewson
(This will be used by prop224)
2016-09-16Remove a needless level of indirection from crypto_cipher_tNick Mathewson
Now that crypto_cipher_t only contains a pointer, it no longer has any reason for an independent existence.
2016-09-16Simplify the crypto_cipher_t interface and structureNick Mathewson
Previously, the IV and key were stored in the structure, even though they mostly weren't needed. The only purpose they had was to support a seldom-used API where you could pass NULL when creating a cipher in order to get a random key/IV, and then pull that key/IV back out. This saves 32 bytes per AES instance, and makes it easier to support different key lengths.
2016-09-16In aes.c, support 192-bit and 256-bit keys.Nick Mathewson
Also, change the input types for aes_new_cipher to be unsigned, as they should have been all along.
2016-09-09Chop another ~93 RSA key generations out of the unit testsNick Mathewson
We have a mock for our RSA key generation function, so we now wire it to pk_generate(). This covers all the cases that were not using pk_generate() before -- all ~93 of them.
2016-07-28Fix a huge pile of -Wshadow warnings.Nick Mathewson
These appeared on some of the Jenkins platforms. Apparently some GCCs care when you shadow globals, and some don't.
2016-06-27Merge branch 'maint-0.2.8'Nick Mathewson
2016-06-24Bug19499: Fix GCC warnings when building against bleeding edge OpenSSL.Yawning Angel
The previous version of the new accessors didn't specify const but it was changed in master.
2016-06-17Use the Autoconf macro AC_USE_SYSTEM_EXTENSIONScypherpunks
The Autoconf macro AC_USE_SYSTEM_EXTENSIONS defines preprocessor macros which turn on extensions to C and POSIX. The macro also makes it easier for developers to use the extensions without needing (or forgetting) to define them manually. The macro can be safely used because it was introduced in Autoconf 2.60 and Tor requires Autoconf 2.63 and above.
2016-06-14Use ENABLE/DISABLE_GCC_WARNING in masater.Nick Mathewson
2016-06-14Merge branch 'maint-0.2.8'Nick Mathewson
2016-06-14Resolve the remaining openssl "-Wredundant-decls" warnings.Nick Mathewson
Another part of 19406
2016-06-14Merge branch 'maint-0.2.8'Nick Mathewson
2016-06-14Bug 19406: OpenSSL made RSA and DH opaque in 1.1.0.Yawning Angel
There's accessors to get at things, but it ends up being rather cumbersome. The only place where behavior should change is that the code will fail instead of attempting to generate a new DH key if our internal sanity check fails. Like the previous commit, this probably breaks snapshots prior to pre5.
2016-06-14Bug 19406: OpenSSL changed the Thread API in 1.1.0 again.Yawning Angel
Instead of `ERR_remove_thread_state()` having a modified prototype, it now has the old prototype and a deprecation annotation. Since it's pointless to add extra complexity just to remain compatible with an old OpenSSL development snapshot, update the code to work with 1.1.0pre5 and later.
2016-05-25Merge branch 'maint-0.2.8'Nick Mathewson
2016-05-25Merge branch 'bug19152_024_v2' into maint-0.2.8Nick Mathewson
2016-05-25Fix a dangling pointer issue in our RSA keygen codeNick Mathewson
If OpenSSL fails to generate an RSA key, do not retain a dangling pointer to the previous (uninitialized) key value. The impact here should be limited to a difficult-to-trigger crash, if OpenSSL is running an engine that makes key generation failures possible, or if OpenSSL runs out of memory. Fixes bug 19152; bugfix on 0.2.1.10-alpha. Found by Yuan Jochen Kang, Suman Jana, and Baishakhi Ray. This is potentially scary stuff, so let me walk through my analysis. I think this is a bug, and a backport candidate, but not remotely triggerable in any useful way. Observation 1a: Looking over the OpenSSL code here, the only way we can really fail in the non-engine case is if malloc() fails. But if malloc() is failing, then tor_malloc() calls should be tor_asserting -- the only way that an attacker could do an exploit here would be to figure out some way to make malloc() fail when openssl does it, but work whenever Tor does it. (Also ordinary malloc() doesn't fail on platforms like Linux that overcommit.) Observation 1b: Although engines are _allowed_ to fail in extra ways, I can't find much evidence online that they actually _do_ fail in practice. More evidence would be nice, though. Observation 2: We don't call crypto_pk_generate*() all that often, and we don't do it in response to external inputs. The only way to get it to happen remotely would be by causing a hidden service to build new introduction points. Observation 3a: So, let's assume that both of the above observations are wrong, and the attacker can make us generate a crypto_pk_env_t with a dangling pointer in its 'key' field, and not immediately crash. This dangling pointer will point to what used to be an RSA structure, with the fields all set to NULL. Actually using this RSA structure, before the memory is reused for anything else, will cause a crash. In nearly every function where we call crypto_pk_generate*(), we quickly use the RSA key pointer -- either to sign something, or to encode the key, or to free the key. The only exception is when we generate an intro key in rend_consider_services_intro_points(). In that case, we don't actually use the key until the intro circuit is opened -- at which point we encode it, and use it to sign an introduction request. So in order to exploit this bug to do anything besides crash Tor, the attacker needs to make sure that by the time the introduction circuit completes, either: * the e, d, and n BNs look valid, and at least one of the other BNs is still NULL. OR * all 8 of the BNs must look valid. To look like a valid BN, *they* all need to have their 'top' index plus their 'd' pointer indicate an addressable region in memory. So actually getting useful data of of this, rather than a crash, is going to be pretty damn hard. You'd have to force an introduction point to be created (or wait for one to be created), and force that particular crypto_pk_generate*() to fail, and then arrange for the memory that the RSA points to to in turn point to 3...8 valid BNs, all by the time the introduction circuit completes. Naturally, the signature won't check as valid [*], so the intro point will reject the ESTABLISH_INTRO cell. So you need to _be_ the introduction point, or you don't actually see this information. [*] Okay, so if you could somehow make the 'rsa' pointer point to a different valid RSA key, then you'd get a valid signature of an ESTABLISH_INTRO cell using a key that was supposed to be used for something else ... but nothing else looks like that, so you can't use that signature elsewhere. Observation 3b: Your best bet as an attacker would be to make the dangling RSA pointer actually contain a fake method, with a fake RSA_private_encrypt function that actually pointed to code you wanted to execute. You'd still need to transit 3 or 4 pointers deep though in order to make that work. Conclusion: By 1, you probably can't trigger this without Tor crashing from OOM. By 2, you probably can't trigger this reliably. By 3, even if I'm wrong about 1 and 2, you have to jump through a pretty big array of hoops in order to get any kind of data leak or code execution. So I'm calling it a bug, but not a security hole. Still worth patching.
2016-05-23Expose crypto_digest_algorithm_get_length from crypto.cNick Mathewson
Also, use it in routerparse.c
2016-05-16Mark even more crypto lines (the fragile_assert ones) as unreachableNick Mathewson
2016-05-16Refactor digest allocation backend codeNick Mathewson
I'm doing this to simplify crypto_digest_smartlist_prefix, and make it better covered by our tests.
2016-05-16Cover all our DH code, and/or mark it unreachable.Nick Mathewson
2016-05-16Treat absent argument to crypto_log_errors as a bug.Nick Mathewson
2016-05-16Slight improvements to DH coverage.Nick Mathewson
2016-05-16Mark some unreachable lines in crypto.cNick Mathewson
2016-05-16Improve test coverage of our strongest-rng code.Nick Mathewson
2016-04-25Remove redundant declarations of MINNick Mathewson
Apparently somewhere along the line we decided that MIN might be missing. But we already defined it (if it was missing) in compat.h, which everybody includes. Closes ticket 18889.
2016-04-12Add LCOV_EXCL* markers to crypto.c and crypto_s2k.cNick Mathewson
This marks some lines as unreachable by the unit tests, and as therefore excluded from test coverage. (Note: This convention is only for lines that are absolutely unreachable. Don't use it anywhere you wouldn't add a tor_fragile_assert().)
2016-04-05Only define NEW_THREAD_API when not building with LibreSSL.Nick Mathewson
2016-04-05OpenSSL 1.1.0-pre4 and later(?) have a new "thread API".Yawning Angel
It appears that setting the various callbacks is no longer required, so don't.
2016-02-28clean/extend some module docs, including fix from #18403Nick Mathewson
2016-02-27Update the copyright year.Nick Mathewson
2016-02-23Merge branch 'bug17795'Nick Mathewson
2016-02-23Fix an erroneous renamingNick Mathewson
Did you know that crypto_digest_all is a substring of crypto_digest_alloc_bytes()? Hence the mysterious emergence of "crypto_common_digestsoc_bytes". Next time I should use the \b assertion in my regexen. Spotted by Mike.
2016-02-10Another automated rename.Nick Mathewson
Also simplify crypto_common_digests() to have no loop.
2016-02-10Rename crypto_digest_all, and digests_t.Nick Mathewson
They are no longer "all" digests, but only the "common" digests. Part of 17795. This is an automated patch I made with a couple of perl one-liners: perl -i -pe 's/crypto_digest_all/crypto_common_digests/g;' src/*/*.[ch] perl -i -pe 's/\bdigests_t\b/common_digests_t/g;' src/*/*.[ch]
2016-02-06Merge remote-tracking branch 'yawning/bug18221'Nick Mathewson
2016-02-06Fix spaces.Nick Mathewson
2016-02-06Merge branch 'cleaned_aes_crypt'Nick Mathewson
2016-02-06Removed aes_crypt, left only aes_crypt_inplace. Removed ↵Malek
should_use_openssl_CTR, was used for openssl 1.0.0 bug.
2016-02-06changing output of crypto_cipher_crypt_inplace from int to voidHassan Alsibyani
2016-02-03Make Tor build happily with OpenSSL master and libressl.Nick Mathewson
Also tested with 1.0.0t and 1.0.2f. Closes ticket 19784. Closes most of 17921. (Still need to make some tests pass.)
2016-02-02Validate the DH parameters for correctness.Yawning Angel
We use sensible parameters taken from common sources, and no longer have dynamic DH groups as an option, but it feels prudent to have OpenSSL validate p and g at initialization time.
2016-01-27Restrict the meaning of digests_t to sha1+sha256.Nick Mathewson
This saves CPU and RAM when handling consensuses and x509 certs. Closes ticket 17795; bug not in any released tor.
2016-01-19Merge branch 'maint-0.2.7'Nick Mathewson
2016-01-19Merge branch 'maint-0.2.6' into maint-0.2.7Nick Mathewson