Instead of global data store it in an OPENSSL_CTX#8857
Instead of global data store it in an OPENSSL_CTX#8857mattcaswell wants to merge 11 commits intoopenssl:masterfrom
Conversation
|
Just wondering (having not thought this properly through): would it be reasonable to register the "openssl_ctx_run_once" calls like the "openssl_ctx_onfree" ones and make them automatic? |
Where would you register them? As a hard coded list perhaps? There are pros and cons: pro: you don't have to check all the time whether you've done the initialisation yet |
|
fixup up pushed to address "make update" issues. |
|
Another fixup to address a mem leak. |
Even if registered before time (a fixed list is a good place), they'd only be called on context creation. Does that necesarily imply a cascade of other initialisers being called independent of what gets used by the applications?? |
|
Question: did you have to put ex_data class data in the global context for some reason, or did you just take "everything" in #8760 more literally than I meant it? My thoughts, that I may or may not have shared, is that the ex_data class data would remain global (note: global to the module that includes the ex_data object file) |
I think this should be an entirely separate PR. There's nothing in this PR that should be inherently dependant on #8728, and having the two mixed in one PR makes it harder to review this one. |
Yes. This solves the problem of the ex_data_lock. By tying it to the lifetime of the OPENSSL_CTX we avoid all the issues we were having with freeing it on the provider side. I see no reason to treat that global data differently to any other global data. In fact its kind of weird not to. This makes things conceptually much simpler. |
I disagree, especially on a conceptual level. See it like this, the |
I think you are overcomplicating it. Think of OPENSSL_CTX as a scope. The OSSL_EX_DATA_GLOBAL is class data for all classes within that scope. The OPENSSL_CTX class of objects is slightly different to other classes in that there is only ever one instance within a given scope. I don't think this is a problem. |
include/openssl/crypto.h
Outdated
There was a problem hiding this comment.
Will people be very upset of we make CRYPTO_EX_DATA opaque?
There was a problem hiding this comment.
We're supposed to be trying not to break stuff wherever possible. I think this could be a case where we could break things so I think it is best to avoid it.
Various core and property related code files used global data. We should store all of that in an OPENSSL_CTX instead.
|
I updated this to remove the dependency on #8728. |
Thank you! |
|
The reason you're getting build errors on Windows is the new inclusion of : ; git diff
diff --git a/test/build.info b/test/build.info
index ded3bd770a..2800c71d3e 100644
--- a/test/build.info
+++ b/test/build.info
@@ -503,7 +503,7 @@ IF[{- !$disabled{tests} -}]
DEPEND[wpackettest]=../libcrypto ../libssl.a libtestutil.a
SOURCE[property_test]=property_test.c
- INCLUDE[property_test]=../include ../apps/include
+ INCLUDE[property_test]=.. ../include ../apps/include
DEPEND[property_test]=../libcrypto.a libtestutil.a
SOURCE[ctype_internal_test]=ctype_internal_test.c |
|
These manuals need an update:
|
We should be seeking to move the OPENSSL_init_crypto and OPENSSL_cleanup processing into OPENSSL_CTX instead.
After a bit of "Doh!" moment I realised that we could do this with all of the openssl_ctx_init_index calls - and suddenly you don't need some of the run_once calls at all because a number of them were only there to initialise the index. Furthermore, I realised I wasn't using OPENSSL_CTX quite right and I could move even more initialisation code into the OPENSSL_CTX_METHOD "new" functions. This significantly simplifies things. Most code can just set up an OPENSSL_CTX_METHOD and it all just initialises itself when needed and frees itself when the OPENSSL_CTX_METHOD is freed. No need to call openssl_ctx_run_once or openssl_ctx_onfree at all. There is still one spot where openssl_ctx_run_once is required. There are no places where openssl_ctx_onfree is now needed, although I have left the implementation there since I suspect it will be needed as we roll this out to more places in the code. New commits pushed addressing the feedback and making the changes described above. Taking this out of WIP. |
Thanks for the hint. Should be sorted now. Also I updated the internal manuals as requested. |
|
Updated to address @levitte's feedback. |
|
So, what about #8857 (comment)? |
|
(other than that, I'm not reasonably happy with this PR) |
Responded to |
|
Pusehd! Thanks. |
Reviewed-by: Richard Levitte <[email protected]> (Merged from #8857)
Various core and property related code files used global data. We should store all of that in an OPENSSL_CTX instead. Reviewed-by: Richard Levitte <[email protected]> (Merged from #8857)
We should be seeking to move the OPENSSL_init_crypto and OPENSSL_cleanup processing into OPENSSL_CTX instead. Reviewed-by: Richard Levitte <[email protected]> (Merged from #8857)
Reviewed-by: Richard Levitte <[email protected]> (Merged from #8857)
I suppose you meant now instead of not :) |
Uhmmmm... yes! |
This is built on top of the commits in #8728 (Make the EVP API available from within the FIPS module) and addresses the current issues in that PR. Not sure whether to replace that PR with this one or keep it separate.
The new stuff is in the last two commits. Essentially all global data in the core and evp code is moved into the OPENSSL_CTX instead. This was always the intention anyway (see #8760).
A new function "openssl_ctx_run_once" is introduced which is similar to RUN_ONCE except initialisation code is run once per OPENSSL_CTX. We also add a new function "openssl_ctx_onfree" which is similar to OPENSSL_atexit() except it runs when the OPENSSL_CTX is freed.
The ex_data global data is a bit of a special case and needs some separate handling since we can't store that in the normal way in the OPENSSL_CTX (because ex_data is used in the implementation of OPENSSL_CTX).
Having made all these changes it is then possible to share all the same initialisation and de-initialisation code between the FIPS provider and the default provider. We don't need to treat FIPS any differently. Everything is initialised "on demand" as it is normally.
WIP because of the dependency on #8728 and because there are various updates required to the internal documentation that I haven't looked at yet.