Skip to content

Move the loading of the ssl_conf module to libcrypto#5818

Closed
mattcaswell wants to merge 5 commits intoopenssl:masterfrom
mattcaswell:move-ssl-conf
Closed

Move the loading of the ssl_conf module to libcrypto#5818
mattcaswell wants to merge 5 commits intoopenssl:masterfrom
mattcaswell:move-ssl-conf

Conversation

@mattcaswell
Copy link
Member

This is an alternative more radical approach to #5813. It fixes the same problems but additionally fixes the root issue about what happens if libcrypto gets initialised before libssl.

The GOST engine needs to be loaded before we initialise libssl. Otherwise
the GOST ciphersuites are not enabled. However the SSL conf module must
be loaded before we initialise libcrypto. Otherwise we will fail to read
the SSL config from a config file properly.

Another problem is that an application may make use of both libcrypto and
libssl. If it performs libcrypto stuff first and OPENSSL_init_crypto()
is called and loads a config file it will fail if that config file has
any libssl stuff in it.

This commit separates out the loading of the SSL conf module from the
interpretation of its contents. The loading piece doesn't know anything
about SSL so this can be moved to libcrypto. The interpretation of what it
means remains in libssl. This means we can load the SSL conf data before
libssl is there and interpret it when it later becomes available.

Fixes #5809

The GOST engine needs to be loaded before we initialise libssl. Otherwise
the GOST ciphersuites are not enabled. However the SSL conf module must
be loaded before we initialise libcrypto. Otherwise we will fail to read
the SSL config from a config file properly.

Another problem is that an application may make use of both libcrypto and
libssl. If it performs libcrypto stuff first and OPENSSL_init_crypto()
is called and loads a config file it will fail if that config file has
any libssl stuff in it.

This commit separates out the loading of the SSL conf module from the
interpretation of its contents. The loading piece doesn't know anything
about SSL so this can be moved to libcrypto. The interpretation of what it
means remains in libssl. This means we can load the SSL conf data before
libssl is there and interpret it when it later becomes available.

Fixes openssl#5809
@mattcaswell mattcaswell added this to the 1.1.1 milestone Mar 30, 2018
@mattcaswell mattcaswell requested a review from levitte March 30, 2018 18:27

if (!RUN_ONCE(&ssl_base, ossl_init_ssl_base))
if (!OPENSSL_init_crypto(opts
| OPENSSL_INIT_LOAD_CONFIG
Copy link
Member

@kroeckx kroeckx Mar 30, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Loading the default config by default is at least not consistent with the documentation as far as I understand. So maybe the documentation should get updated?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I updated the pod documentation and also added a CHANGES entry.

SM2_plaintext_size 4468 1_1_1 EXIST::FUNCTION:SM2
CONF_ssl_name_find 4469 1_1_1 EXIST::FUNCTION:
CONF_ssl_get_cmd 4470 1_1_1 EXIST::FUNCTION:
CONF_ssl_get 4471 1_1_1 EXIST::FUNCTION:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exporting functions from libcrypto so libssl can use them just feels so wrong.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It solves a probllem that's otherwise a catch 22, so I think it should be allowed.

However, since these are internal by design from the start, they should probably be all lowercase.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is quite a lot of precedent for this. I changed the names to all lowercase.

@kroeckx
Copy link
Member

kroeckx commented Mar 30, 2018

Please add some minimal documentation to the functions.

@richsalz
Copy link
Contributor

The CONF_ssl functions should not be documented, and they should only be declared in an internal header file; they are not for general use, right?

#include <openssl/x509.h>
#include <openssl/asn1.h>
#include <openssl/engine.h>
#include "conflcl.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, we usually have a _ before lcl...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed.

SM2_plaintext_size 4468 1_1_1 EXIST::FUNCTION:SM2
CONF_ssl_name_find 4469 1_1_1 EXIST::FUNCTION:
CONF_ssl_get_cmd 4470 1_1_1 EXIST::FUNCTION:
CONF_ssl_get 4471 1_1_1 EXIST::FUNCTION:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It solves a probllem that's otherwise a catch 22, so I think it should be allowed.

However, since these are internal by design from the start, they should probably be all lowercase.

@levitte
Copy link
Member

levitte commented Mar 31, 2018

The CONF_ssl functions should not be documented, and they should only be declared in an internal header file; they are not for general use, right?

I think like @kroeckx (even though I often forget it myself), that they should at least get documented intenally, for example as comments before the functions themselves. (@kroeckx keeps reminding me to do this a little now and then, and rightfully so)

@levitte
Copy link
Member

levitte commented Mar 31, 2018

I'm all for this solution, pending fixups.

@mattcaswell
Copy link
Member Author

I added some internal documentation (as comments before the functions).

New commits pushed addressing all outstanding comments.

@mattcaswell
Copy link
Member Author

Ping @levitte. Are you ok with this now?

There is a question as to which branches this should go to. Perhaps this is too radical for 1.1.0? In which case I'd suggest we push this one to master, and #5813 to 1.1.0. What do you think?

@levitte
Copy link
Member

levitte commented Apr 4, 2018

Re 1.1.0, if I'm getting it right, #5813 has some corner case issue that this more radical way fixes, right? Are there any user visible drawbacks with this PR? If not, I see about zero problems going with the more radical change in 1.1.0 as well. It is, after all, not a new feature, but a bug fix, although a bit more involved one than what you'd usually expect.

The way I understand it, this one is more robust than #5813, is that correct? That makes the choice even easier.

However, make sure to correct the version numbers on the added functions in util/libcrypto.num

@mattcaswell
Copy link
Member Author

Re 1.1.0, if I'm getting it right, #5813 has some corner case issue that this more radical way fixes, right?

Right

Are there any user visible drawbacks with this PR? If not, I see about zero problems going with the more radical change in 1.1.0 as well. It is, after all, not a new feature, but a bug fix, although a bit more involved one than what you'd usually expect.

No, there shouldn't be. Although it will need a slight tweak for 1.1.0 because this PR makes loading the config file a default for libssl. Although this is a behaviour change I think it was accepted for 1.1.1 and most people seemed to have been expecting it as a result of #4848 (but that PR didn't actually make that change). For 1.1.0 though we probably shouldn't be doing that.

The way I understand it, this one is more robust than #5813, is that correct? That makes the choice even easier.

Yes

However, make sure to correct the version numbers on the added functions in util/libcrypto.num

Done. New fixup commit pushed.

I'll go create a 1.1.0 version in a different PR.

@levitte
Copy link
Member

levitte commented Apr 4, 2018

(let's see that the CIs agree as well before merging, yeah?)

@mattcaswell
Copy link
Member Author

Pushed. Thanks.

@mattcaswell mattcaswell closed this Apr 5, 2018
levitte pushed a commit that referenced this pull request Apr 5, 2018
The GOST engine needs to be loaded before we initialise libssl. Otherwise
the GOST ciphersuites are not enabled. However the SSL conf module must
be loaded before we initialise libcrypto. Otherwise we will fail to read
the SSL config from a config file properly.

Another problem is that an application may make use of both libcrypto and
libssl. If it performs libcrypto stuff first and OPENSSL_init_crypto()
is called and loads a config file it will fail if that config file has
any libssl stuff in it.

This commit separates out the loading of the SSL conf module from the
interpretation of its contents. The loading piece doesn't know anything
about SSL so this can be moved to libcrypto. The interpretation of what it
means remains in libssl. This means we can load the SSL conf data before
libssl is there and interpret it when it later becomes available.

Fixes #5809

Reviewed-by: Richard Levitte <[email protected]>
(Merged from #5818)
levitte pushed a commit that referenced this pull request Apr 5, 2018
When libssl is initialised it will attempt to load any config file. This
ensures any system_default configuration (as per
#4848) is used.

Reviewed-by: Richard Levitte <[email protected]>
(Merged from #5818)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot use the GOST engine in s_client/s_server

4 participants