Skip to content

Commit e7c5128

Browse files
committed
webrtc-sys-build: verify downloaded prebuilt library with SHA256
1 parent 66d81e1 commit e7c5128

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

Cargo.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webrtc-sys/build/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ scratch = "1.0"
1414
fs2 = "0.4"
1515
semver = "1.0"
1616
anyhow = "1.0"
17+
sha2 = "0.10.9"
18+
hex-literal = "1.1.0"

webrtc-sys/build/src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ use std::{
2424

2525
use anyhow::{anyhow, Context, Result};
2626
use fs2::FileExt;
27+
use hex_literal::hex;
2728
use regex::Regex;
2829
use reqwest::StatusCode;
30+
use sha2::{Digest, Sha256};
2931

3032
pub const SCRATH_PATH: &str = "livekit_webrtc";
33+
// Update the hash values in download_webrtc function when updating the tag.
3134
pub const WEBRTC_TAG: &str = "webrtc-0001d84-2";
3235
pub const IGNORE_DEFINES: [&str; 2] = ["CR_CLANG_REVISION", "CR_XCODE_VERSION"];
3336

@@ -215,6 +218,56 @@ pub fn download_webrtc() -> Result<()> {
215218
return Err(anyhow!("failed to download webrtc: {}", resp.status()));
216219
}
217220

221+
let mut hasher = Sha256::new();
222+
io::copy(&mut resp, &mut hasher)?;
223+
let hash = hasher.finalize();
224+
// GitHub generates the SHA256 hashes of all artifacts attached to releases.
225+
// Copy and paste those here when updating WEBRTC_TAG.
226+
let expected_hash = match webrtc_triple().as_str() {
227+
"android-arm-release" => {
228+
hex!("9e0f49584e8fa2ed7b15e4921a8d630c1b88d891d150d7335fea91bb01844899")
229+
}
230+
"android-arm64-release" => {
231+
hex!("76007fdd92f2eee53f68990890cc52cbd98a2f33df8569dc03a3fe57aba93908")
232+
}
233+
"android-x64-release" => {
234+
hex!("fc551ce022fa69bfdb207b0878bb6d148cc5eebf283ffbf28600d25d6f97de38")
235+
}
236+
"ios-device-arm64-release" => {
237+
hex!("4fcd722678c2ceed448ffbaeba8bb1ce2063ed8ca3d5f2318d6c371f20c43851")
238+
}
239+
"ios-simulator-arm64-release" => {
240+
hex!("b9191da03c89ff39b23ee806d768f139a1b2ca0845597dd6dec2ac8500fa599b")
241+
}
242+
"linux-arm64-release" => {
243+
hex!("d3181bd42900f9b3b15bec4669187861a226d6e8657734f2f51649f71c974bc0")
244+
}
245+
"linux-x64-release" => {
246+
hex!("6a41ae5cdf27ea8fdfb7e2ae3d1abda6b74d8917b77beac5c63ee2b048e28ffd")
247+
}
248+
"mac-arm64-release" => {
249+
hex!("9d7254202cf9b242f648421369d3f053091844e13a32690db5fd5c5b507253be")
250+
}
251+
"mac-x64-release" => {
252+
hex!("d7612ca5626d3e4fc07cb7b6f2b07a9fd5184ffe3f0bba13b119b1116b4ddd9e")
253+
}
254+
"win-arm64-release" => {
255+
hex!("d28480035dc8b83aef2e40ca49bd457bf58b781ebbf274ca90e224a1b29e37c7")
256+
}
257+
"win-x64-release" => {
258+
hex!("16ebb2f7dc15db943313bd80b81bbd9689fa4cbf4bf65f3c407a93cc33d8afe8")
259+
}
260+
_ => panic!("Unsupported triple"),
261+
};
262+
// RustCrypto crypto-common traits are using an old version of generic-array
263+
// https://github.com/fizyk20/generic-array/issues/158
264+
#[allow(deprecated)]
265+
if hash.as_slice() != expected_hash {
266+
panic!("SHA256 hash of downloaded prebuilt libwebrtc C++ library did not match expected value.\nGot: {}\nExpected: {}",
267+
str::from_utf8(hash.as_slice()).unwrap(),
268+
str::from_utf8(&expected_hash).unwrap());
269+
}
270+
218271
let out_dir = env::var("OUT_DIR").unwrap();
219272
let tmp_path = PathBuf::from(out_dir).join("webrtc.zip");
220273
let mut file = fs::File::options()

0 commit comments

Comments
 (0)