libsrtp icon indicating copy to clipboard operation
libsrtp copied to clipboard

Support for OpenSSL 3.0

Open nazar-pc opened this issue 3 years ago • 8 comments

In 3.0 some APIs were deprecated that results in this warnings:

[1025/1321] Compiling C object subprojects/libsrtp-2.4.2/libsrtp2.a.p/crypto_hash_hmac_ossl.c.o
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_alloc’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:106:5: warning: ‘HMAC_CTX_new’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  106 |     (*a)->state = HMAC_CTX_new();
      |     ^
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:33:33: note: declared here
   33 | OSSL_DEPRECATEDIN_3_0 HMAC_CTX *HMAC_CTX_new(void);
      |                                 ^~~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_dealloc’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:136:5: warning: ‘HMAC_CTX_free’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  136 |     HMAC_CTX_free(hmac_ctx);
      |     ^~~~~~~~~~~~~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:35:28: note: declared here
   35 | OSSL_DEPRECATEDIN_3_0 void HMAC_CTX_free(HMAC_CTX *ctx);
      |                            ^~~~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_start’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:152:5: warning: ‘HMAC_Init_ex’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  152 |     if (HMAC_Init_ex(state, NULL, 0, NULL, NULL) == 0)
      |     ^~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:43:27: note: declared here
   43 | OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
      |                           ^~~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_init’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:164:5: warning: ‘HMAC_Init_ex’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  164 |     if (HMAC_Init_ex(state, key, key_len, EVP_sha1(), NULL) == 0)
      |     ^~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:43:27: note: declared here
   43 | OSSL_DEPRECATEDIN_3_0 int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
      |                           ^~~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_update’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:179:5: warning: ‘HMAC_Update’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  179 |     if (HMAC_Update(state, message, msg_octets) == 0)
      |     ^~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:45:27: note: declared here
   45 | OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
      |                           ^~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c: In function ‘srtp_hmac_compute’:
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:205:5: warning: ‘HMAC_Update’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  205 |     if (HMAC_Update(state, message, msg_octets) == 0)
      |     ^~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:45:27: note: declared here
   45 | OSSL_DEPRECATEDIN_3_0 int HMAC_Update(HMAC_CTX *ctx, const unsigned char *data,
      |                           ^~~~~~~~~~~
../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:208:5: warning: ‘HMAC_Final’ is deprecated: Since OpenSSL 3.0 [-Wdeprecated-declarations]
  208 |     if (HMAC_Final(state, hash_value, &len) == 0)
      |     ^~
In file included from ../../../subprojects/libsrtp-2.4.2/crypto/hash/hmac_ossl.c:54:
../../../subprojects/openssl-3.0.2/include/openssl/hmac.h:47:27: note: declared here
   47 | OSSL_DEPRECATEDIN_3_0 int HMAC_Final(HMAC_CTX *ctx, unsigned char *md,
      |                           ^~~~~~~~~~

Would be nice to get them fixes in upcoming releases.

nazar-pc avatar Apr 03 '22 08:04 nazar-pc

Related to this: https://github.com/openssl/openssl/blob/master/doc/man7/migration_guide.pod#deprecated-low-level-mac-functions

paulej avatar Apr 13 '22 16:04 paulej

Yes, it is not a very difficult process to refactor the code, but some needs to spend time on it

nazar-pc avatar Apr 13 '22 17:04 nazar-pc

Note that even though these functions are deprecated, they're still fully available in OpenSSL 3.x, and the high-level APIs just call these low-level functions directly. So this change wouldn't (as far as I know) gain anything other than preventing compile-time warnings.

The old OpenSSL 1.1 APIs are also, as far as I know, still the APIs used by libressl and BoringSSL, so the old code couldn't be removed even if we wanted to drop OpenSSL 1.1 support. (The new APIs were only introduced in OpenSSL 3.x.)

JonathanLennox avatar Apr 19 '22 21:04 JonathanLennox

  1. Having compile-time warnings is a bad practice in general, so not generating them would be nice
  2. It is possible to disable 1.1 APIs in OpenSSL 3.0 if desired; some might do that, then libsrtp will become incompatible
  3. I don't suggest to drop OpenSSL 1.1 at this point, just add OpenSSL 3.0 support explicitly to avoid build warnings

nazar-pc avatar Apr 19 '22 21:04 nazar-pc

We will add support for compiling cleanly against OpenSSL 3.0 either by using the OpenSSL version define or a explicit compile flag (or both). Should be ready for next release.

pabuhler avatar Apr 26 '22 20:04 pabuhler

#602 fails with OpenSSL 3.0.2. but passes with OpenSSL 3.0.3-dev, I will investigate why when I get time but does anyone know if EVP_MAC reuse has issues?

pabuhler avatar May 02 '22 16:05 pabuhler

https://github.com/openssl/openssl/issues/17811 :(

pabuhler avatar May 02 '22 16:05 pabuhler

#605 is an alternative solution that simply disables the warning for now.

pabuhler avatar May 06 '22 09:05 pabuhler

Looks like autoconf fails on detecting openssl 3.x

checking for library containing EVP_EncryptInit... no
configure: error: in `/home/tkloczko/rpmbuild/BUILD/libsrtp-2.4.2':
configure: error: can't find openssl >= 1.0.1 crypto lib
See `config.log' for more details

I see some openssl 3.x fixes above last tag. Is it possible to make new release to fix build of the libsrtp with openssl 3.x?

kloczek avatar Dec 03 '22 14:12 kloczek

Hi @kloczek am planning on a new release in next few weeks, will be sure sure to address this issue

pabuhler avatar Dec 04 '22 20:12 pabuhler

In this case |I found that it was mileading mesage. If you will look closet on the bottom openssl detection https://github.com/cisco/libsrtp/blob/cc362ae5b3d30c89d8dc00c22f84f615fb02d956/configure.ac#L208-L256 you can fiund libdl and libz detections. I had no installed libz devel resources and that message was printed by incorrecvt logic in tjhat section Looks like libz detection can be removed because nothing in source tree is usimg libz.

[tkloczko@devel-g2v libsrtp-2.4.2]$ grep zlib.h -r
[tkloczko@devel-g2v libsrtp-2.4.2]$

Whole section could be dramatically reduced if PKG_CHECK_MODULES() aclocal macro would be used.

kloczek avatar Dec 05 '22 22:12 kloczek

BTW looks like actual C code is not using libdl as well.

kloczek avatar Dec 05 '22 22:12 kloczek

Here is minimal version of the fix

--- a/configure.ac
+++ b/configure.ac
@@ -250,9 +250,6 @@
          [CFLAGS="$CFLAGS $crypto_CFLAGS"
           LIBS="$crypto_LIBS $LIBS"
           openssl_cleanse_broken=maybe])])
-   else
-     AC_CHECK_LIB([dl], [dlopen], [], [AC_MSG_WARN([can't find libdl])])
-     AC_CHECK_LIB([z], [inflate], [], [AC_MSG_WARN([can't find libz])])
    fi

    AC_SEARCH_LIBS([EVP_EncryptInit], [crypto],

kloczek avatar Dec 05 '22 22:12 kloczek

closing this as #602 is merged and there are now active work flows that test openssl 1.1.1 & 3.0.2 & 3.0.7

pabuhler avatar Dec 16 '22 09:12 pabuhler