Remove support for dynamic METHODs.

The ENGINE code had a concept of a stable-ABI for METHODs, because that
might be a useful thing in the future when people want to have blobs
that wrap PKCS#11 or something.

However, at the moment nobody uses this feature and it didn't work very
well anyway: I hadn't updated |ENGINE_free| to free them all and
|set_method| was copying the methods, but not resetting the |is_static|
flag.

This change removes support for non-static methods. We can always put it
back later if we need.

Change-Id: Ic7401c8cb1cadd46b26a215f85bc48562efe9919
Reviewed-on: https://boringssl-review.googlesource.com/3300
Reviewed-by: Adam Langley <agl@google.com>
This commit is contained in:
Adam Langley
2015-02-06 20:56:10 +00:00
committed by Adam Langley
parent 3fd1fbd1c8
commit 4e04ee8786
2 changed files with 18 additions and 34 deletions
+12 -30
View File
@@ -15,6 +15,7 @@
#include <openssl/engine.h>
#include <string.h>
#include <assert.h>
#include <openssl/dh.h>
#include <openssl/dsa.h>
@@ -43,33 +44,23 @@ ENGINE *ENGINE_new(void) {
}
void ENGINE_free(ENGINE *engine) {
if (engine->dh_method != NULL) {
METHOD_unref(engine->dh_method);
}
/* Methods are currently required to be static so are not unref'ed. */
OPENSSL_free(engine);
}
/* set_method takes a pointer to a method and its given size and sets
* |*out_member| to point to a copy of it. The copy is |compiled_size| bytes
* long and has zero padding if needed. */
* |*out_member| to point to it. This function might want to be extended in the
* future to support making a copy of the method so that a stable ABI for
* ENGINEs can be supported. But, for the moment, all *_METHODS must be
* static. */
static int set_method(void **out_member, const void *method, size_t method_size,
size_t compiled_size) {
void *copy = OPENSSL_malloc(compiled_size);
if (copy == NULL) {
const struct openssl_method_common_st *common = method;
if (method_size != compiled_size || !common->is_static) {
return 0;
}
memset(copy, 0, compiled_size);
if (method_size > compiled_size) {
method_size = compiled_size;
}
memcpy(copy, method, method_size);
METHOD_unref(*out_member);
*out_member = copy;
*out_member = (void*) method;
return 1;
}
@@ -114,25 +105,16 @@ ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine) {
}
void METHOD_ref(void *method_in) {
struct openssl_method_common_st *method = method_in;
if (method->is_static) {
return;
}
CRYPTO_add(&method->references, 1, CRYPTO_LOCK_ENGINE);
assert(((struct openssl_method_common_st*) method_in)->is_static);
}
void METHOD_unref(void *method_in) {
struct openssl_method_common_st *method = method_in;
if (method == NULL || method->is_static) {
if (method == NULL) {
return;
}
if (CRYPTO_add(&method->references, -1, CRYPTO_LOCK_ENGINE) == 0) {
OPENSSL_free(method);
}
assert(method->is_static);
}
OPENSSL_DECLARE_ERROR_REASON(ENGINE, OPERATION_NOT_SUPPORTED);
+6 -4
View File
@@ -78,12 +78,14 @@ OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine);
* These functions take a void* type but actually operate on all method
* structures. */
/* METHOD_ref increments the reference count of |method|. */
OPENSSL_EXPORT void METHOD_ref(void *method);
/* METHOD_ref increments the reference count of |method|. This is a no-op for
* now because all methods are currently static. */
void METHOD_ref(void *method);
/* METHOD_unref decrements the reference count of |method| and frees it if the
* reference count drops to zero. */
OPENSSL_EXPORT void METHOD_unref(void *method);
* reference count drops to zero. This is a no-op for now because all methods
* are currently static. */
void METHOD_unref(void *method);
/* Private functions. */