Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OpenSSL native OCB-AES implementation #1196

Merged
merged 1 commit into from
Jun 14, 2022

Conversation

achernya
Copy link
Collaborator

@achernya achernya commented Jun 7, 2022

OpenSSL 3.0 deprecated many of the functions that ocb.cc used to
implement OCB-AES, causing a build failure when -Wdeprecated collided
with -Werror. Debian temporarily fixed this by suppressing the error
in #1191.

Since mosh 1.4 will be the next stable release of mosh, it should not
depend on deprecated functions in OpenSSL. Since version 1.1.0,
OpenSSL natively supports OCB-AES through the EVP_CIPHER API. @cgull
started early support for this in #924.

This change extends upon the previous work by @cgull in a few ways

  • EVP_EncryptInit_ex is called in ae_init to set up the
    EVP_CIPHER_CTX. It is later called in ae_encrypt and ae_decrypt
    just to load the key and nonce (IV in OpenSSL EVP parlance), which
    reduces the amount of initialization done per-packet.

  • Adds missing support for an external tag, rather than just one
    appended to the ciphertext

  • Support for non-default-sized tags

as well as some improved error handling.

Note that this change raises the minimum OpenSSL version for Mosh to
1.1.0. OpenSSL does not provide security support for versions prior to
1.1 at this time, so this is in principle reasonable dependency. If we
want to continue to support distributions (such as RHEL7) which
continue to be supported by their vendor but use an unsupported
OpenSSL, then some future work will have to restore the ocb.cc
implementation that uses the deprecated functions.

Bugs: #1174

@achernya
Copy link
Collaborator Author

achernya commented Jun 7, 2022

@bbarenblat and @davidben could you please take a look?

@achernya
Copy link
Collaborator Author

achernya commented Jun 7, 2022

Reproduced the CI failure on bionic:

Fatal assertion failure in function test_iterative at ocb-aes.cc:518
Failed test: 0 <= ae_encrypt( ctx, nonce.data(), NULL, 0, s.data(), s.len(), out.data(), NULL, AE_FINALIZE )
Aborted

@achernya
Copy link
Collaborator Author

achernya commented Jun 7, 2022

CI corrected. There was (seemingly) some UB that was only exposed on Ubuntu 18.04, but reproduced across clang and gcc. Fixed.

Copy link

@davidben davidben left a comment

Choose a reason for hiding this comment

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

I think this is right? Comments are mostly optional simplifications / optimizations.

src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
@davidben
Copy link

davidben commented Jun 9, 2022

Ugh I've no idea why GitHub decided to double up my comments... :-/

Copy link
Contributor

@bbarenblat bbarenblat left a comment

Choose a reason for hiding this comment

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

@davidben is certainly the cryptography expert here, but for what it’s worth, this LGTM from a cryptography perspective. I have a few minor comments, but substantively, this PR all looks correct.

src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Show resolved Hide resolved
src/crypto/ocb_openssl.cc Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
Copy link
Collaborator Author

@achernya achernya left a comment

Choose a reason for hiding this comment

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

@davidben PTAL

src/crypto/ocb_openssl.cc Outdated Show resolved Hide resolved
@davidben
Copy link

LGTM

OpenSSL 3.0 deprecated many of the functions that ocb.cc used to
implement OCB-AES, causing a build failure when -Wdeprecated collided
with -Werror. Debian temporarily fixed this by suppressing the error
in mobile-shell#1191.

Since mosh 1.4 will be the next stable release of mosh, it should not
depend on deprecated functions in OpenSSL. Since version 1.1.0,
OpenSSL natively supports OCB-AES through the EVP_CIPHER API. @cgull
started early support for this in mobile-shell#924.

This change extends upon the previous work by @cgull in a few ways

 * EVP_CipherInit_ex is called in ae_init to set up the
   EVP_CIPHER_CTX. It is later called in ae_encrypt and ae_decrypt
   just to load nonce (IV in OpenSSL EVP parlance), which reduces the
   amount of initialization done per-packet. However, due to OpenSSL
   API limitations, two copies of the EVP_CIPHER_CTX are kept: one for
   encryption, and one for decryption.

 * Adds missing support for an external tag, rather than just one
   appended to the ciphertext

 * Support for non-default-sized tags

as well as some improved error handling.

Note that this change raises the minimum OpenSSL version for Mosh to
1.1.0. OpenSSL does not provide security support for versions prior to
1.1 at this time, so this is in principle reasonable dependency. If we
want to continue to support distributions (such as RHEL7) which
continue to be supported by their vendor but use an unsupported
OpenSSL, then some future work will have to restore the ocb.cc
implementation that uses the deprecated functions.

Bugs: mobile-shell#1174
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.

None yet

4 participants