File: Unbundle-libSRTP.patch

package info (click to toggle)
libtgowt 0~git20230105.5098730%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,344 kB
  • sloc: cpp: 856,908; ansic: 119,817; asm: 36,281; java: 23,481; python: 6,553; objc: 4,297; sh: 2,619; cs: 471; makefile: 351; javascript: 286; xml: 272
file content (124 lines) | stat: -rw-r--r-- 3,832 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
Description: Avoid private symbols and link against system-wide libSRTP
 The package no longer uses outdated bundled copy of the library. The change
 fixes incompatibility with OpenSSL 3.0.0 or later.
 .
 The excluded code in SrtpSession looks unreachable from the call integration
 in Telegram Desktop. Though, I can't 100% confirm this.
Author: Nicholas Guriev <guriev-ns@ya.ru>
Forwarded: https://github.com/desktop-app/tg_owt/pull/123
Last-Update: Thu, 04 May 2023 16:21:09 +0300

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2658,6 +2658,9 @@ if (TG_OWT_USE_PROTOBUF)
     list(APPEND export_targets proto)
 endif()
 
+if (LIBSRTP_FOUND)
+    target_compile_definitions(tg_owt PRIVATE HAVE_LIBSRTP)
+endif()
 if (NOT absl_FOUND)
     include(cmake/libabsl.cmake)
     list(APPEND export_targets libabsl)
--- a/cmake/libsrtp.cmake
+++ b/cmake/libsrtp.cmake
@@ -1,3 +1,16 @@
+find_package(PkgConfig REQUIRED)
+pkg_check_modules(LIBSRTP libsrtp2)
+
+if (LIBSRTP_FOUND)
+    add_library(libsrtp INTERFACE EXCLUDE_FROM_ALL)
+    add_library(tg_owt::libsrtp ALIAS libsrtp)
+
+    target_include_directories(libsrtp INTERFACE ${LIBSRTP_INCLUDE_DIRS} ${LIBSRTP_CFLAGS_OTHER})
+    target_link_libraries(libsrtp INTERFACE ${LIBSRTP_LINK_LIBRARIES} ${LIBSRTP_LDFLAGS_OTHER})
+
+    return()
+endif()
+
 add_library(libsrtp OBJECT EXCLUDE_FROM_ALL)
 init_target(libsrtp)
 add_library(tg_owt::libsrtp ALIAS libsrtp)
--- a/src/pc/external_hmac.cc
+++ b/src/pc/external_hmac.cc
@@ -15,7 +15,6 @@
 
 #include "rtc_base/logging.h"
 #include "rtc_base/zero_memory.h"
-#include "third_party/libsrtp/include/srtp.h"
 
 // Begin test case 0 */
 static const uint8_t kExternalHmacTestCase0Key[20] = {
--- a/src/pc/external_hmac.h
+++ b/src/pc/external_hmac.h
@@ -30,9 +30,12 @@
 
 #include <stdint.h>
 
-#include "third_party/libsrtp/crypto/include/crypto_types.h"
-#include "third_party/libsrtp/include/srtp.h"
-#include "third_party/libsrtp/include/srtp_priv.h"
+#ifdef HAVE_LIBSRTP
+# include <srtp2/auth.h>
+# include <srtp2/srtp.h>
+#else
+# include "srtp_priv.h"
+#endif
 
 #define EXTERNAL_HMAC_SHA1 SRTP_HMAC_SHA1 + 1
 #define HMAC_KEY_LENGTH 20
--- a/src/pc/srtp_session.cc
+++ b/src/pc/srtp_session.cc
@@ -30,8 +30,12 @@
 #include "rtc_base/thread_annotations.h"
 #include "rtc_base/time_utils.h"
 #include "system_wrappers/include/metrics.h"
-#include "third_party/libsrtp/include/srtp.h"
-#include "third_party/libsrtp/include/srtp_priv.h"
+
+#ifdef HAVE_LIBSRTP
+# include <srtp2/srtp.h>
+#else
+# include "srtp_priv.h"
+#endif
 
 namespace cricket {
 
@@ -290,6 +294,7 @@ bool SrtpSession::UnprotectRtcp(void* p,
 bool SrtpSession::GetRtpAuthParams(uint8_t** key, int* key_len, int* tag_len) {
   RTC_DCHECK(thread_checker_.IsCurrent());
   RTC_DCHECK(IsExternalAuthActive());
+#ifndef HAVE_LIBSRTP
   if (!IsExternalAuthActive()) {
     return false;
   }
@@ -313,6 +318,10 @@ bool SrtpSession::GetRtpAuthParams(uint8
   *key_len = external_hmac->key_length;
   *tag_len = rtp_auth_tag_len_;
   return true;
+#else
+  RTC_LOG_F(LS_WARNING) << "unavailable";
+  return false;
+#endif
 }
 
 int SrtpSession::GetSrtpOverhead() const {
@@ -336,6 +345,7 @@ bool SrtpSession::GetSendStreamPacketInd
                                            int in_len,
                                            int64_t* index) {
   RTC_DCHECK(thread_checker_.IsCurrent());
+#ifndef HAVE_LIBSRTP
   srtp_hdr_t* hdr = reinterpret_cast<srtp_hdr_t*>(p);
   srtp_stream_ctx_t* stream = srtp_get_stream(session_, hdr->ssrc);
   if (!stream) {
@@ -346,6 +356,10 @@ bool SrtpSession::GetSendStreamPacketInd
   *index = static_cast<int64_t>(rtc::NetworkToHost64(
       srtp_rdbx_get_packet_index(&stream->rtp_rdbx) << 16));
   return true;
+#else
+  RTC_LOG_F(LS_WARNING) << "unavailable";
+  return false;
+#endif
 }
 
 bool SrtpSession::DoSetKey(int type,