Skip to content

Commit

Permalink
Merge branch 'release/2023.16.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
melpon committed Nov 19, 2023
2 parents 7fe2df8 + b69d81f commit 6b20a5d
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 5 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

## develop

## 2023.16.0 (2023-11-19)

- [ADD] SRTP keying material を取得する機能を実装
- @melpon

## 2023.15.1 (2023-11-09)

- [FIX] macOS で USB 接続されたカメラが利用できなくなっていた問題を修正する
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ target_sources(sora
src/sora_signaling.cpp
src/sora_video_decoder_factory.cpp
src/sora_video_encoder_factory.cpp
src/srtp_keying_material_exporter.cpp
src/ssl_verifier.cpp
src/url_parts.cpp
src/version.cpp
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SORA_CPP_SDK_VERSION=2023.15.1
SORA_CPP_SDK_VERSION=2023.16.0
WEBRTC_BUILD_VERSION=m119.6045.2.1
BOOST_VERSION=1.83.0
CMAKE_VERSION=3.27.7
Expand Down
1 change: 1 addition & 0 deletions include/sora/sora_signaling.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ class SoraSignaling : public std::enable_shared_from_this<SoraSignaling>,
std::lock_guard<std::mutex> lock(m);
this->s = s;
}

private:
std::string s;
mutable std::mutex m;
Expand Down
24 changes: 24 additions & 0 deletions include/sora/srtp_keying_material_exporter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef SORA_SRTP_KEYING_MATERIAL_EXPORTER_H_
#define SORA_SRTP_KEYING_MATERIAL_EXPORTER_H_

#include <string>

#include <absl/types/optional.h>
#include <api/peer_connection_interface.h>

namespace sora {

struct KeyingMaterial {
std::vector<uint8_t> client_write_key;
std::vector<uint8_t> server_write_key;
std::vector<uint8_t> client_write_salt;
std::vector<uint8_t> server_write_salt;
};

absl::optional<KeyingMaterial> ExportKeyingMaterial(
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc,
const std::string& mid);

} // namespace sora

#endif
8 changes: 4 additions & 4 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,10 +408,10 @@ def build_install_webrtc(version, source_dir, build_dir, install_dir, platform,

# インクルードディレクトリを増やしたくないので、
# __config_site を libc++ のディレクトリにコピーしておく
libcxx_dir = os.path.join(source_dir, 'webrtc', 'src', 'third_party', 'libc++')
if not os.path.exists(os.path.join(libcxx_dir, 'src', 'include', '__config_site')):
shutil.copyfile(os.path.join(libcxx_dir, '__config_site'),
os.path.join(libcxx_dir, 'src', 'include', '__config_site'))
src_config = os.path.join(source_dir, 'webrtc', 'src', 'buildtools', 'third_party', 'libc++', '__config_site')
dst_config = os.path.join(source_dir, 'webrtc', 'src', 'third_party', 'libc++', 'src', 'include', '__config_site')
if not os.path.exists(dst_config):
shutil.copyfile(src_config, dst_config)


class WebrtcInfo(NamedTuple):
Expand Down
1 change: 1 addition & 0 deletions src/sora_signaling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "sora/rtc_ssl_verifier.h"
#include "sora/rtc_stats.h"
#include "sora/session_description.h"
#include "sora/srtp_keying_material_exporter.h"
#include "sora/url_parts.h"
#include "sora/version.h"
#include "sora/zlib_helper.h"
Expand Down
78 changes: 78 additions & 0 deletions src/srtp_keying_material_exporter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "sora/srtp_keying_material_exporter.h"

#include <p2p/base/dtls_transport.h>
#include <pc/dtls_transport.h>
#include <rtc_base/logging.h>
#include <rtc_base/ssl_stream_adapter.h>

namespace sora {

// Value specified in RFC 5764.
static const char kDtlsSrtpExporterLabel[] = "EXTRACTOR-dtls_srtp";

absl::optional<KeyingMaterial> ExportKeyingMaterial(
rtc::scoped_refptr<webrtc::PeerConnectionInterface> pc,
const std::string& mid) {
rtc::scoped_refptr<webrtc::DtlsTransportInterface> dtls_interface =
pc->LookupDtlsTransportByMid(mid);
if (dtls_interface == nullptr) {
RTC_LOG(LS_ERROR) << "Failed to lookup DtlsTransportInterface";
return absl::nullopt;
}

// shiguredo-webrtc-build/webrtc-build の libwebrtc は
// RTTI を有効にしてるので dynamic_cast ができる
webrtc::DtlsTransport* dtls_impl =
dynamic_cast<webrtc::DtlsTransport*>(dtls_interface.get());
if (dtls_impl == nullptr) {
RTC_LOG(LS_ERROR) << "Failed to cast webrtc::DtlsTransport";
return absl::nullopt;
}

cricket::DtlsTransport* dtls =
dynamic_cast<cricket::DtlsTransport*>(dtls_impl->internal());
if (dtls == nullptr) {
RTC_LOG(LS_ERROR) << "Failed to cast cricket::DtlsTransport";
return absl::nullopt;
}

int crypto_suite;
if (!dtls->GetSrtpCryptoSuite(&crypto_suite)) {
RTC_LOG(LS_ERROR) << "Failed to get SrtpCryptoSuite";
return absl::nullopt;
}

int key_len;
int salt_len;
if (!rtc::GetSrtpKeyAndSaltLengths(crypto_suite, &key_len, &salt_len)) {
RTC_LOG(LS_ERROR) << "Failed to get SrtpKeyAndSaltLengths";
return absl::nullopt;
}

std::vector<uint8_t> buf(key_len * 2 + salt_len * 2);

if (!dtls->ExportKeyingMaterial(kDtlsSrtpExporterLabel, nullptr, 0, false,
buf.data(), buf.size())) {
RTC_LOG(LS_ERROR) << "Failed to ExportKeyingMaterial";
return absl::nullopt;
};

KeyingMaterial km;
km.client_write_key.resize(key_len);
km.server_write_key.resize(key_len);
km.client_write_salt.resize(salt_len);
km.server_write_salt.resize(salt_len);
int n = 0;
memcpy(km.client_write_key.data(), buf.data() + n, key_len);
n += key_len;
memcpy(km.server_write_key.data(), buf.data() + n, key_len);
n += key_len;
memcpy(km.client_write_salt.data(), buf.data() + n, salt_len);
n += salt_len;
memcpy(km.server_write_salt.data(), buf.data() + n, salt_len);
n += salt_len;

return km;
}

} // namespace sora

0 comments on commit 6b20a5d

Please sign in to comment.