Skip to content

Conversation

jliang1010
Copy link

OpenSSL v1.1 issue has been mentioned in both #361

Jian Liang added 2 commits December 5, 2016 14:00
OpenSSL v1.1 doesn't expose structures directly, instead pointers
are used. Change the existing code to prepare for that to make it
clearer what the actual OpenSSL v1.1 changes entail.
- Insert conditions to prevent incompatibility with OpenSSL v1.0.x
- Align function calls and access to variables
@bretambrose
Copy link
Contributor

I've pulled this into an internal repo where we can have our security team review it. Thanks for doing this work.

{
namespace OpenSSL
{
#if OPENSSL_VERSION_NUMBER < 0x10100003L
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe the version numbers should have a 1 (or a zero, doesn't really matter) as the last digit, so that people on 1.1b and 1.1a work as well.

Copy link
Contributor

@andred andred Dec 12, 2016

Choose a reason for hiding this comment

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

From https://wiki.openssl.org/index.php/Manual:OPENSSL_VERSION_NUMBER(3)

MNNFFPPS: Major miNor miNor Fix Fix Patch Patch Status

The last nibble is for the release candidates. The api changes were introduced in 1.1 rc 3, which is not the same as 1.1c

ERR_load_CRYPTO_strings();
OPENSSL_add_all_algorithms_noconf();

#if OPENSSL_VERSION_NUMBER < 0x10100003L
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the locking setup removed here? Is there some documentation somewhere on why it's no longer necessary. I can't find anything about it being deprecated.

Copy link
Author

@jliang1010 jliang1010 Dec 8, 2016

Choose a reason for hiding this comment

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

Check the source code of openssl-1.1.0, include/openssl/crypto.h, from line 208

/*

  • The old locking functions have been removed completely without compatibility
  • macros. This is because the old functions either could not properly report
  • errors, or the returned error values were not clearly documented.
  • Replacing the locking functions with with no-ops would cause race condition
  • issues in the affected applications. It is far better for them to fail at
  • compile time.
  • On the other hand, the locking callbacks are no longer used. Consequently,
  • the callback management functions can be safely replaced with no-op macros.
    */

@andred
Copy link
Contributor

andred commented Feb 2, 2017

Any update on this? Is anything wrong with the patches? Also, without OpenSSL 1.1 support, TLSv1.3 won't be possible either...

@bretambrose
Copy link
Contributor

We've got a lot on our plate at the moment so no one's had a chance to go through and test it thoroughly yet.

@andred
Copy link
Contributor

andred commented Feb 9, 2017

Thanks for the update Bret.

@janekolszak
Copy link
Contributor

What's up with this PR?

Copy link
Contributor

@JonathanHenson JonathanHenson left a comment

Choose a reason for hiding this comment

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

In general, I'm not delighted about the new heap alloc stuff. Is there another way. Also, there's some duplication between the #ifdef blocks that we can probably get rid of.

ctx = &_ctx;
HMAC_CTX_init(ctx);
#else
ctx=HMAC_CTX_new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we now allocating things on the heap? Is this required for the latest OpenSSL?

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe so. Several structures have been made opaque in OpenSSL 1.1, so the OpenSSL allocators have to be used, see https://www.openssl.org/docs/man1.1.0/crypto/HMAC_CTX_free.html unless there is something I missed.

toMove.m_ctx.cipher = nullptr;
toMove.m_ctx.cipher_data = nullptr;
toMove.m_ctx.engine = nullptr;
EVP_CIPHER_CTX_copy(m_ctx, toMove.m_ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this change!

Copy link
Contributor

Choose a reason for hiding this comment

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

This actually needs updating, as m_ctx hasn't been assigned yet. I believe a call to init() should be sufficient.

EVP_CIPHER_CTX_init(&m_ctx);
#if OPENSSL_VERSION_NUMBER < 0x10100003L
m_ctx = &_m_ctx;
EVP_CIPHER_CTX_init(m_ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure why this is inside the compiletime ifdefs, isn't it the same between versions?

Copy link
Contributor

@andred andred Apr 3, 2017

Choose a reason for hiding this comment

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

Thanks, well spotted. EVP_CIPHER_CTX_init() is obsolete in OpenSSL 1.1, and they
# define EVP_CIPHER_CTX_init(c) EVP_CIPHER_CTX_reset(c) in evp.h
So the call should really be to EVP_CIPHER_CTX_reset() instead. Can you apply that change before merging, or do you want me to update the commit?

m_ctx = &_m_ctx;
EVP_CIPHER_CTX_init(m_ctx);
#else
m_ctx = EVP_CIPHER_CTX_new();
Copy link
Contributor

Choose a reason for hiding this comment

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

Uggh, I just tried to make this not need all the #ifdef checks until I realized the *new and *free functions where not part of the 1.0 interface. I'll be merging this.

In the meantime the new and free needs to be moved to constructor and destructors, then I'll merge it over.

@andred andred mentioned this pull request Apr 20, 2017
@singku singku self-requested a review April 27, 2017 00:08
@singku singku self-assigned this Apr 27, 2017
@singku
Copy link
Contributor

singku commented Apr 27, 2017

I am closing this PR because it's similar with #507

@singku singku closed this Apr 27, 2017
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.

6 participants