summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2016-04-05 10:06:18 -0400
committerNick Mathewson <nickm@torproject.org>2016-04-05 10:06:18 -0400
commit6720628c9767e0337baabc346fd9fc0f6deac96d (patch)
tree6162b9ab55d40628a8aa90a0c91d64a6ddf3a322 /src/common
parent705d3b221e4011b4d041dd486c98f42201322193 (diff)
parent92ae6b95243054644dd8515a9cfa11679440a579 (diff)
downloadtor-6720628c9767e0337baabc346fd9fc0f6deac96d.tar.gz
tor-6720628c9767e0337baabc346fd9fc0f6deac96d.zip
Merge branch 'maint-0.2.8'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/crypto.c38
-rw-r--r--src/common/tortls.c10
2 files changed, 42 insertions, 6 deletions
diff --git a/src/common/crypto.c b/src/common/crypto.c
index 11f8e1db19..2da579119b 100644
--- a/src/common/crypto.c
+++ b/src/common/crypto.c
@@ -72,6 +72,16 @@
#define DISABLE_ENGINES
#endif
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,4)
+/* OpenSSL as of 1.1.0-pre4 has an "new" thread API, which doesn't require
+ * seting up various callbacks.
+ *
+ * Note: Yes, using OPENSSL_VER is naughty, but theis was introduced in the
+ * pre-release series.
+ */
+#define NEW_THREAD_API
+#endif
+
/** Longest recognized */
#define MAX_DNS_LABEL_SIZE 63
@@ -83,10 +93,12 @@
/** Macro: is k a valid RSA private key? */
#define PRIVATE_KEY_OK(k) ((k) && (k)->key && (k)->key->p)
+#ifndef NEW_THREAD_API
/** A number of preallocated mutexes for use by OpenSSL. */
static tor_mutex_t **openssl_mutexes_ = NULL;
/** How many mutexes have we allocated for use by OpenSSL? */
static int n_openssl_mutexes_ = 0;
+#endif
/** A public key, or a public/private key-pair. */
struct crypto_pk_t
@@ -417,7 +429,11 @@ crypto_global_init(int useAccel, const char *accelName, const char *accelDir)
void
crypto_thread_cleanup(void)
{
+#ifdef NEW_THREAD_API
+ ERR_remove_thread_state();
+#else
ERR_remove_thread_state(NULL);
+#endif
}
/** used by tortls.c: wrap an RSA* in a crypto_pk_t. */
@@ -3068,6 +3084,7 @@ memwipe(void *mem, uint8_t byte, size_t sz)
OpenSSL library with thread support enabled.
#endif
+#ifndef NEW_THREAD_API
/** Helper: OpenSSL uses this callback to manipulate mutexes. */
static void
openssl_locking_cb_(int mode, int n, const char *file, int line)
@@ -3085,6 +3102,13 @@ openssl_locking_cb_(int mode, int n, const char *file, int line)
tor_mutex_release(openssl_mutexes_[n]);
}
+static void
+tor_set_openssl_thread_id(CRYPTO_THREADID *threadid)
+{
+ CRYPTO_THREADID_set_numeric(threadid, tor_get_thread_id());
+}
+#endif
+
#if 0
/* This code is disabled, because OpenSSL never actually uses these callbacks.
*/
@@ -3135,18 +3159,13 @@ openssl_dynlock_destroy_cb_(struct CRYPTO_dynlock_value *v,
}
#endif
-static void
-tor_set_openssl_thread_id(CRYPTO_THREADID *threadid)
-{
- CRYPTO_THREADID_set_numeric(threadid, tor_get_thread_id());
-}
-
/** @{ */
/** Helper: Construct mutexes, and set callbacks to help OpenSSL handle being
* multithreaded. Returns 0. */
static int
setup_openssl_threading(void)
{
+#ifndef NEW_THREAD_API
int i;
int n = CRYPTO_num_locks();
n_openssl_mutexes_ = n;
@@ -3155,6 +3174,7 @@ setup_openssl_threading(void)
openssl_mutexes_[i] = tor_mutex_new();
CRYPTO_set_locking_callback(openssl_locking_cb_);
CRYPTO_THREADID_set_callback(tor_set_openssl_thread_id);
+#endif
#if 0
CRYPTO_set_dynlock_create_callback(openssl_dynlock_create_cb_);
CRYPTO_set_dynlock_lock_callback(openssl_dynlock_lock_cb_);
@@ -3170,7 +3190,11 @@ int
crypto_global_cleanup(void)
{
EVP_cleanup();
+#ifdef NEW_THREAD_API
+ ERR_remove_thread_state();
+#else
ERR_remove_thread_state(NULL);
+#endif
ERR_free_strings();
if (dh_param_p)
@@ -3187,6 +3211,7 @@ crypto_global_cleanup(void)
CONF_modules_unload(1);
CRYPTO_cleanup_all_ex_data();
+#ifndef NEW_THREAD_API
if (n_openssl_mutexes_) {
int n = n_openssl_mutexes_;
tor_mutex_t **ms = openssl_mutexes_;
@@ -3198,6 +3223,7 @@ crypto_global_cleanup(void)
}
tor_free(ms);
}
+#endif
tor_free(crypto_openssl_version_str);
tor_free(crypto_openssl_header_version_str);
diff --git a/src/common/tortls.c b/src/common/tortls.c
index fe21875f91..4ffc672546 100644
--- a/src/common/tortls.c
+++ b/src/common/tortls.c
@@ -2274,8 +2274,18 @@ tor_tls_get_n_raw_bytes(tor_tls_t *tls, size_t *n_read, size_t *n_written)
* save the original BIO for tls->ssl in the tor_tls_t structure, but
* that would be tempting fate. */
wbio = SSL_get_wbio(tls->ssl);
+#if OPENSSL_VERSION_NUMBER >= OPENSSL_VER(1,1,0,0,5)
+ /* BIO structure is opaque as of OpenSSL 1.1.0-pre5-dev. Again, not
+ * supposed to use this form of the version macro, but the OpenSSL developers
+ * introduced major API changes in the pre-release stage.
+ */
+ if (BIO_method_type(wbio) == BIO_TYPE_BUFFER &&
+ (tmpbio = BIO_next(wbio)) != NULL)
+ wbio = tmpbio;
+#else
if (wbio->method == BIO_f_buffer() && (tmpbio = BIO_next(wbio)) != NULL)
wbio = tmpbio;
+#endif
w = BIO_number_written(wbio);
/* We are ok with letting these unsigned ints go "negative" here: