Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NSS TLS #306

Closed
wants to merge 63 commits into from
Closed

NSS TLS #306

wants to merge 63 commits into from

Conversation

Labels
None yet
Projects
None yet
2 participants
@ahf
Copy link
Member

@ahf ahf commented Sep 4, 2018

This PR tracks review for https://trac.torproject.org/projects/tor/ticket/26819

nmathewson added 30 commits Jul 11, 2018
When it is set, include the NSS headers and libraries as
appropriate.  Doesn't actually use them yet, though.
These are now part of crypto_init.c.  The openssl-only parts now
live in crypto_openssl_mgt.c.

I recommend reviewing this patch with -b and --color-moved.
This is largely conjectural, based on online documentation for NSS
and NSPR.
We need this in our unit tests, since otherwise NSS will notice
we've forked and start cussing us out.

I suspect we'll need a different hack for daemonizing, but this
should be enough for tinytest to work.
This was a fairly straightforward port, once I realized which layer
I should be calling into.
This is comparatively straightforward too, except for a couple of
twists:

   * For as long as we're building with two crypto libraries, we
     want to seed _both_ their RNGs, and use _both_ their RNGs to
     improve the output of crypto_strongest_rand()

   * The NSS prng will sometimes refuse to generate huge outputs.
     When it does, we stretch the output with SHAKE.  We only need
     this for the tests.
We only ever need this to get us a DH ephemeral key object,
so make a function that does just that.
Notably, there's a test to make sure that it round-trips with
OpenSSL, if OpenSSL is enabled.
(We do this unconditionally, since we still need it for tortls.c)
nmathewson added 27 commits Aug 21, 2018
This cleans up a lot of junk from crypto_rsa_openssl, and will
save us duplicated code in crypto_rsa_nss (when it exists).

(Actually, it already exists, but I am going to use git rebase so
that this commit precedes the creation of crypto_rsa_nss.)
Also, add a stubbed-out nss version of the modules.  The tests won't
pass with NSS yet since the NSS modules don't do anything.

This is a good patch to read with --color-moved.
We used to link both libraries at once, but now that I'm working on
TLS, there's nothing left to keep OpenSSL around for when NSS is
enabled.

Note that this patch causes a couple of places that still assumed
OpenSSL to be disabled when NSS is enabled
   - tor-gencert
   - pbkdf2
This was a gap that we left in the last commit.
This ensures that our test failure messages actually tell us what
strings Tor was expecting.  I will need this to debug some test
failures.
I'll need this for debugging.
7 unit tests are failing at this point, but they're all TLS-related.
This is enough to get a chutney network to bootstrap, though a bunch
of work remains.
This function was supposed to implement a half-duplex mode for our
TLS connections.  However, nothing in Tor actually uses it (besides
some unit tests), and the implementation looks really questionable
to me.  It's probably best to remove it.  We can add a tested one
later if we need one in the future.
The tls_log_errors() function now behaves differently for NSS than
it did for OpenSSL, so we need to tweak it a bit.
Fix some compiler warnings from clang.
Copy link
Member Author

@ahf ahf left a comment

I love these changes. I think the refactoring of all this crypto code looks very nice. I have left some small comments that I'd like to see changed. I'm gonna go over the code base once more now that I have a good feeling of how it work to see if I can spot any deeper issues.


if test "x$enable_nss" = "xyes"; then
AC_DEFINE(ENABLE_NSS, 1,
[Defined if we're building with NSS in addition to OpenSSL.])
Copy link
Member Author

@ahf ahf Sep 4, 2018

The wording here is misleading: you can build Tor with NSS only.

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

Fixed in 2f0eaaf

if (connection_speaks_cells(conn)) {
or_connection_t *or_conn = TO_OR_CONN(conn);
tor_tls_free(or_conn->tls);
or_conn->tls = NULL;
Copy link
Member Author

@ahf ahf Sep 4, 2018

tor_tls_free() should set or_conn->tls to NULL.

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

Right; the compiler should remove this redundancy for us.


#include "siphash.h"

/** Boolean: has OpenSSL's crypto been initialized? */
Copy link
Member Author

@ahf ahf Sep 4, 2018

We should probably remove the mentioning of OpenSSL here.

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

done in 3730b9b

/** Boolean: has OpenSSL's crypto been initialized? */
static int crypto_early_initialized_ = 0;

/** Boolean: has OpenSSL's crypto been initialized? */
Copy link
Member Author

@ahf ahf Sep 4, 2018

Same here. Remove OpenSSL from this comment.

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

done in 3730b9b

SSL_set_tlsext_host_name(tls->ssl, NULL);
#endif
SSL_free(tls->ssl);
tor_tls_impl_free_(tls->ssl);
Copy link
Member Author

@ahf ahf Sep 4, 2018

Why not have a FREE_AND_NULL() variant of this?

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

tls_impl_free_ and tls_x509_impl_free_ are tiny wrappers around the underlying types.

#define TORTLS_PRIVATE
#define TOR_X509_PRIVATE

#ifdef _WIN32 /*wrkard for dtls1.h >= 0.9.8m of "#include <winsock.h>"*/
Copy link
Member Author

@ahf ahf Sep 4, 2018

I know this comes from a code movement, but this comment makes no sense to me at all. Maybe we should fix that afterwards.

Copy link
Contributor

@nmathewson nmathewson Sep 4, 2018

aa554cf revises this for the openssl case, and removes the comment for the nss case.

@ahf
Copy link
Member Author

@ahf ahf commented Sep 21, 2018

This has already been merged. Closing.

@ahf ahf closed this Sep 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment