Fix auto-discovery of ENGINEs, ported from HEAD.
authorGeoff Thorpe <geoff@openssl.org>
Mon, 28 Apr 2008 21:45:43 +0000 (21:45 +0000)
committerGeoff Thorpe <geoff@openssl.org>
Mon, 28 Apr 2008 21:45:43 +0000 (21:45 +0000)
NB, this fixes a regression relative to 0.9.7 and the documented behaviour,
but it would make sense for distro maintainers and others with an interest
in system behaviour to test with this change. The fix re-enables behaviour
that was broken and thus inherently disabled. In particular, if you
register an ENGINE implementation, and that ENGINE is able to successfully
self-initialise on the host, it will get used automatically (as claimed in
the documentation and as was the case for 0.9.7) - this was not the case
with 0.9.8 until now because of a bug.

PR: 1668
Submitted by: Ian Lister
Reviewed by: Geoff Thorpe

CHANGES
crypto/engine/eng_table.c

diff --git a/CHANGES b/CHANGES
index 665c56a150a0e2a4dc4dbbb9389e7e1a4de05648..13d62bcf2f25fc95f35cf273d09624a84e3e8f0e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,18 @@
 
  Changes between 0.9.8g and 0.9.8h  [xx XXX xxxx]
 
+  *) Reverse ENGINE-internal logic for caching default ENGINE handles.
+     This was broken until now in 0.9.8 releases, such that the only way
+     a registered ENGINE could be used (assuming it initialises
+     successfully on the host) was to explicitly set it as the default
+     for the relevant algorithms. This is in contradiction with 0.9.7
+     behaviour and the documentation. With this fix, when an ENGINE is
+     registered into a given algorithm's table of implementations, the
+     'uptodate' flag is reset so that auto-discovery will be used next
+     time a new context for that algorithm attempts to select an
+     implementation.
+     [Ian Lister (tweaked by Geoff Thorpe)]
+
   *) Backport of CMS code to OpenSSL 0.9.8. This differs from the 0.9.9
      implemention in the following ways:
 
index 0c1656168d50d60ed45a8bfdd6889eb4e089f6f4..8879a267d1432f8d1008c01e310bea9d8fc1c976 100644 (file)
@@ -135,7 +135,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
                        {
                        fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
                        if(!fnd) goto end;
-                       fnd->uptodate = 0;
+                       fnd->uptodate = 1;
                        fnd->nid = *nids;
                        fnd->sk = sk_ENGINE_new_null();
                        if(!fnd->sk)
@@ -152,7 +152,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
                if(!sk_ENGINE_push(fnd->sk, e))
                        goto end;
                /* "touch" this ENGINE_PILE */
-               fnd->uptodate = 1;
+               fnd->uptodate = 0;
                if(setdefault)
                        {
                        if(!engine_unlocked_init(e))
@@ -164,6 +164,7 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
                        if(fnd->funct)
                                engine_unlocked_finish(fnd->funct, 0);
                        fnd->funct = e;
+                       fnd->uptodate = 1;
                        }
                nids++;
                }
@@ -179,8 +180,7 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
        while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
                {
                (void)sk_ENGINE_delete(pile->sk, n);
-               /* "touch" this ENGINE_CIPHER */
-               pile->uptodate = 1;
+               pile->uptodate = 0;
                }
        if(pile->funct == e)
                {