From 7e40442766e90d36fcba8d253917f5379b0faf63 Mon Sep 17 00:00:00 2001 From: paperchalice Date: Fri, 10 Jan 2025 19:10:05 +0800 Subject: [PATCH] [librtmp] 2024-03-01 --- ports/librtmp/CMakeLists.txt | 25 +++++-- ports/librtmp/dh.patch | 136 ---------------------------------- ports/librtmp/handshake.patch | 35 --------- ports/librtmp/hashswf.patch | 28 ------- ports/librtmp/pkgconfig.patch | 15 ++++ ports/librtmp/portfile.cmake | 9 +-- ports/librtmp/vcpkg.json | 3 +- 7 files changed, 39 insertions(+), 212 deletions(-) delete mode 100644 ports/librtmp/dh.patch delete mode 100644 ports/librtmp/handshake.patch delete mode 100644 ports/librtmp/hashswf.patch create mode 100644 ports/librtmp/pkgconfig.patch diff --git a/ports/librtmp/CMakeLists.txt b/ports/librtmp/CMakeLists.txt index c9f77f16bbf63d..c4c12d7f030600 100644 --- a/ports/librtmp/CMakeLists.txt +++ b/ports/librtmp/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.8) +cmake_minimum_required(VERSION 3.10) project(librtmp C) @@ -43,13 +43,26 @@ if(MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /wd4996") endif() -add_library(librtmp ${SRCS} ${HEADERS} ${SRCS_MSVC}) +add_library(rtmp ${SRCS} ${HEADERS} ${SRCS_MSVC}) -target_include_directories(librtmp PRIVATE ./librtmp) -target_link_libraries(librtmp PRIVATE ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES}) -target_link_libraries(librtmp PRIVATE Ws2_32.lib Winmm.lib) +target_include_directories(rtmp PRIVATE ./librtmp) +target_link_libraries(rtmp PRIVATE ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES}) +if(MSVC OR MINGW) + target_link_libraries(rtmp PRIVATE Ws2_32.lib Winmm.lib) +endif() + +set(libdir [[${prefix}/lib]]) +set(VERSION 2.6) # from ChangeLog +set(CRYPTO_REQ "libssl,libcrypto") +if(MSVC OR MINGW) + set(PRIVATE_LIBS "-lWS2_32 -lWinMM") +endif() +configure_file(librtmp/librtmp.pc.in librtmp.pc @ONLY) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/librtmp.pc + DESTINATION lib/pkgconfig +) -install(TARGETS librtmp +install(TARGETS rtmp RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) diff --git a/ports/librtmp/dh.patch b/ports/librtmp/dh.patch deleted file mode 100644 index 4b03453547ed39..00000000000000 --- a/ports/librtmp/dh.patch +++ /dev/null @@ -1,136 +0,0 @@ -diff --git a/librtmp/dh.h b/librtmp/dh.h -index 8e285a60c..ea562d200 100644 ---- a/librtmp/dh.h -+++ b/librtmp/dh.h -@@ -139,11 +139,14 @@ typedef BIGNUM * MP_t; - #define MP_setbin(u,buf,len) BN_bn2bin(u,buf) - #define MP_getbin(u,buf,len) u = BN_bin2bn(buf,len,0) - -+ - #define MDH DH - #define MDH_new() DH_new() - #define MDH_free(dh) DH_free(dh) - #define MDH_generate_key(dh) DH_generate_key(dh) - #define MDH_compute_key(secret, seclen, pub, dh) DH_compute_key(secret, pub, dh) -+#define MPH_set_pqg(dh, p, q, g, res) res = DH_set0_pqg(dh, p, q, g) -+#define MPH_set_length(dh, len, res) res = DH_set_length(dh,len) - - #endif - -@@ -152,7 +155,7 @@ typedef BIGNUM * MP_t; - - /* RFC 2631, Section 2.1.5, http://www.ietf.org/rfc/rfc2631.txt */ - static int --isValidPublicKey(MP_t y, MP_t p, MP_t q) -+isValidPublicKey(const MP_t y,const MP_t p, MP_t q) - { - int ret = TRUE; - MP_t bn; -@@ -211,20 +214,33 @@ DHInit(int nKeyBits) - if (!dh) - goto failed; - -- MP_new(dh->g); -+ MP_t g,p; -+ MP_new(g); - -- if (!dh->g) -+ if (!g) -+ { - goto failed; -+ } - -- MP_gethex(dh->p, P1024, res); /* prime P1024, see dhgroups.h */ -+ DH_get0_pqg(dh, (BIGNUM const**)&p, NULL, NULL); -+ MP_gethex(p, P1024, res); /* prime P1024, see dhgroups.h */ - if (!res) - { - goto failed; - } - -- MP_set_w(dh->g, 2); /* base 2 */ -- -- dh->length = nKeyBits; -+ MP_set_w(g, 2); /* base 2 */ -+ MPH_set_pqg(dh,p,NULL,g, res); -+ if (!res) -+ { -+ MP_free(g); -+ goto failed; -+ } -+ MPH_set_length(dh,nKeyBits, res); -+ if (!res) -+ { -+ goto failed; -+ } - return dh; - - failed: -@@ -250,14 +267,11 @@ DHGenerateKey(MDH *dh) - - MP_gethex(q1, Q1024, res); - assert(res); -- -- res = isValidPublicKey(dh->pub_key, dh->p, q1); -+ res = isValidPublicKey(DH_get0_pub_key(dh), DH_get0_p(dh), q1); - if (!res) -- { -- MP_free(dh->pub_key); -- MP_free(dh->priv_key); -- dh->pub_key = dh->priv_key = 0; -- } -+ { -+ MDH_free(dh); // Cannot set priv_key to nullptr so there is no way to generate a new pub/priv key pair in openssl 1.1.1. -+ } - - MP_free(q1); - } -@@ -272,15 +286,16 @@ static int - DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen) - { - int len; -- if (!dh || !dh->pub_key) -+ MP_t pub = DH_get0_pub_key(dh); -+ if (!dh || !pub) - return 0; - -- len = MP_bytes(dh->pub_key); -+ len = MP_bytes(pub); - if (len <= 0 || len > (int) nPubkeyLen) - return 0; - - memset(pubkey, 0, nPubkeyLen); -- MP_setbin(dh->pub_key, pubkey + (nPubkeyLen - len), len); -+ MP_setbin(pub, pubkey + (nPubkeyLen - len), len); - return 1; - } - -@@ -288,15 +303,16 @@ DHGetPublicKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen) - static int - DHGetPrivateKey(MDH *dh, uint8_t *privkey, size_t nPrivkeyLen) - { -- if (!dh || !dh->priv_key) -+ MP_t priv = DH_get0_priv_key(dh); -+ if (!dh || !priv) - return 0; - -- int len = MP_bytes(dh->priv_key); -+ int len = MP_bytes(priv); - if (len <= 0 || len > (int) nPrivkeyLen) - return 0; - - memset(privkey, 0, nPrivkeyLen); -- MP_setbin(dh->priv_key, privkey + (nPrivkeyLen - len), len); -+ MP_setbin(priv, privkey + (nPrivkeyLen - len), len); - return 1; - } - #endif -@@ -322,7 +338,7 @@ DHComputeSharedSecretKey(MDH *dh, uint8_t *pubkey, size_t nPubkeyLen, - MP_gethex(q1, Q1024, len); - assert(len); - -- if (isValidPublicKey(pubkeyBn, dh->p, q1)) -+ if (isValidPublicKey(pubkeyBn, DH_get0_p(dh), q1)) - res = MDH_compute_key(secret, nPubkeyLen, pubkeyBn, dh); - else - res = -1; diff --git a/ports/librtmp/handshake.patch b/ports/librtmp/handshake.patch deleted file mode 100644 index 88f5d245855564..00000000000000 --- a/ports/librtmp/handshake.patch +++ /dev/null @@ -1,35 +0,0 @@ -diff --git a/librtmp/handshake.h b/librtmp/handshake.h -index 98bf3c877..0819152bd 100644 ---- a/librtmp/handshake.h -+++ b/librtmp/handshake.h -@@ -66,9 +66,9 @@ typedef gcry_cipher_hd_t RC4_handle; - #if OPENSSL_VERSION_NUMBER < 0x0090800 || !defined(SHA256_DIGEST_LENGTH) - #error Your OpenSSL is too old, need 0.9.8 or newer with SHA256 - #endif --#define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, len, EVP_sha256(), 0) --#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, buf, len) --#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, dig, &dlen); HMAC_CTX_cleanup(&ctx) -+#define HMAC_setup(ctx, key, len) ctx = HMAC_CTX_new(); HMAC_Init_ex(ctx, key, len, EVP_sha256(), 0) -+#define HMAC_crunch(ctx, buf, len) HMAC_Update(ctx, buf, len) -+#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, dig, &dlen); HMAC_CTX_free(ctx) - - typedef RC4_KEY * RC4_handle; - #define RC4_alloc(h) *h = malloc(sizeof(RC4_KEY)) -@@ -114,7 +114,7 @@ static void InitRC4Encryption - { - uint8_t digest[SHA256_DIGEST_LENGTH]; - unsigned int digestLen = 0; -- HMAC_CTX ctx; -+ HMAC_CTX *ctx; - - RC4_alloc(rc4keyIn); - RC4_alloc(rc4keyOut); -@@ -263,7 +263,7 @@ HMACsha256(const uint8_t *message, size_t messageLen, const uint8_t *key, - size_t keylen, uint8_t *digest) - { - unsigned int digestLen; -- HMAC_CTX ctx; -+ HMAC_CTX *ctx; - - HMAC_setup(ctx, key, keylen); - HMAC_crunch(ctx, message, messageLen); diff --git a/ports/librtmp/hashswf.patch b/ports/librtmp/hashswf.patch deleted file mode 100644 index fb29549f3d12f6..00000000000000 --- a/ports/librtmp/hashswf.patch +++ /dev/null @@ -1,28 +0,0 @@ -diff --git a/librtmp/hashswf.c b/librtmp/hashswf.c -index 3c56b6922..964a64d01 100644 ---- a/librtmp/hashswf.c -+++ b/librtmp/hashswf.c -@@ -57,10 +57,10 @@ - #include - #include - #include --#define HMAC_setup(ctx, key, len) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, (unsigned char *)key, len, EVP_sha256(), 0) --#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, (unsigned char *)buf, len) --#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, (unsigned char *)dig, &dlen); --#define HMAC_close(ctx) HMAC_CTX_cleanup(&ctx) -+#define HMAC_setup(ctx, key, len) ctx = HMAC_CTX_new(); HMAC_Init_ex(ctx, (unsigned char *)key, len, EVP_sha256(), 0) -+#define HMAC_crunch(ctx, buf, len) HMAC_Update(ctx, (unsigned char *)buf, len) -+#define HMAC_finish(ctx, dig, dlen) HMAC_Final(ctx, (unsigned char *)dig, &dlen); -+#define HMAC_close(ctx) HMAC_CTX_free(ctx) - #endif - - extern void RTMP_TLS_Init(); -@@ -289,7 +289,7 @@ leave: - struct info - { - z_stream *zs; -- HMAC_CTX ctx; -+ HMAC_CTX *ctx; - int first; - int zlib; - int size; diff --git a/ports/librtmp/pkgconfig.patch b/ports/librtmp/pkgconfig.patch new file mode 100644 index 00000000000000..c5be81d12dbc0c --- /dev/null +++ b/ports/librtmp/pkgconfig.patch @@ -0,0 +1,15 @@ +diff --git a/librtmp/librtmp.pc.in b/librtmp/librtmp.pc.in +--- a/librtmp/librtmp.pc.in ++++ b/librtmp/librtmp.pc.in +@@ -5,9 +5,9 @@ + + Name: librtmp + Description: RTMP implementation + Version: @VERSION@ +-Requires: @CRYPTO_REQ@ ++Requires: zlib,@CRYPTO_REQ@ + URL: http://rtmpdump.mplayerhq.hu +-Libs: -L${libdir} -lrtmp -lz @PUBLIC_LIBS@ ++Libs: -L${libdir} -lrtmp @PUBLIC_LIBS@ + Libs.private: @PRIVATE_LIBS@ + Cflags: -I${incdir} diff --git a/ports/librtmp/portfile.cmake b/ports/librtmp/portfile.cmake index 657517efa05e25..848d5945f788a7 100644 --- a/ports/librtmp/portfile.cmake +++ b/ports/librtmp/portfile.cmake @@ -1,14 +1,12 @@ vcpkg_from_github( OUT_SOURCE_PATH SOURCE_PATH REPO mirror/rtmpdump - REF c5f04a58fc2aeea6296ca7c44ee4734c18401aa3 - SHA512 d97ac38672898a96412baa5f03d1e64d512ccefe15ead0a055ca039dc6057e2e620e046c28f4d7468e132b0b5a9eb9bd171250c1afa14da53760a0d7aae3c9e9 + REF 6f6bb1353fc84f4cc37138baa99f586750028a01 + SHA512 e6c108576fdd3430d81e2f72b343864eee5d6be396c9378a2ae2bfc871e9464e20d7bd057a47ef2449a301d933b29265e7ffd3383631b24fc035f5483337bbce PATCHES - dh.patch #Openssl 1.1.1 patch - handshake.patch #Openssl 1.1.1 patch - hashswf.patch #Openssl 1.1.1 patch fix_strncasecmp.patch hide_netstackdump.patch + pkgconfig.patch ) file(COPY "${CMAKE_CURRENT_LIST_DIR}/CMakeLists.txt" DESTINATION "${SOURCE_PATH}") @@ -19,6 +17,7 @@ vcpkg_cmake_configure( ) vcpkg_cmake_install() +vcpkg_fixup_pkgconfig() file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") diff --git a/ports/librtmp/vcpkg.json b/ports/librtmp/vcpkg.json index 7998d955a8b30a..b1a89fadd399a7 100644 --- a/ports/librtmp/vcpkg.json +++ b/ports/librtmp/vcpkg.json @@ -1,7 +1,6 @@ { "name": "librtmp", - "version-date": "2019-11-11", - "port-version": 4, + "version-date": "2024-03-01", "description": "RTMPDump Real-Time Messaging Protocol API", "homepage": "https://rtmpdump.mplayerhq.hu", "dependencies": [