Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Remote desktop video: unit tests and fuzzing for the SDP, candidate, STUN/TURN, RTCP, DCEP and RTP code

Federico Pereiradbcb85b92195
diff --git a/server/Makefile b/server/Makefile
index 17ad1cf..e6cccca 100644
--- a/server/Makefile
+++ b/server/Makefile
@@ -238,13 +238,13 @@ build/tzif-test: tests/tzif_test.c src/ui/tzif.c src/ui/tzif.h
# connection rate; then the same parsers under ASan+UBSan with many random and mutated inputs
REMOTE_SEC_SRC := src/remote/rsec.c src/remote/ipnet.c src/remote/lockout.c src/remote/rtcwire.c
test: build/remote-sec-test build/remote-fuzz
-build/remote-sec-test: tests/remote_sec_test.c $(REMOTE_SEC_SRC) src/remote/rsec.h src/remote/ipnet.h src/remote/lockout.h src/remote/rtcwire.h
+build/remote-sec-test: tests/remote_sec_test.c $(REMOTE_SEC_SRC) src/remote/rsec.h src/remote/ipnet.h src/remote/lockout.h src/remote/rtcwire.h tests/rtc_offer_chrome.h
@mkdir -p build
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/remote_sec_test.c $(REMOTE_SEC_SRC)
./$@ || { rm -f $@; exit 1; }
-build/remote-fuzz: tests/remote_fuzz.c $(REMOTE_SEC_SRC) src/remote/rsec.h src/remote/ipnet.h src/remote/lockout.h src/remote/rtcwire.h
+build/remote-fuzz: tests/remote_fuzz.c $(REMOTE_SEC_SRC) src/remote/rsec.h src/remote/ipnet.h src/remote/lockout.h src/remote/rtcwire.h tests/rtc_offer_chrome.h
@mkdir -p build
- $(CC) $(CPPFLAGS) -O1 -g $(WARN) -std=c11 -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer \
+ $(CC) $(CPPFLAGS) -Itests -O1 -g $(WARN) -std=c11 -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer \
-o $@ tests/remote_fuzz.c $(REMOTE_SEC_SRC)
./$@ 100000 || { rm -f $@; exit 1; }
# journal reader (Logs): normal and compact synthetic files, LZ4 and XZ, broken and
diff --git a/server/src/remote/rtcwire.h b/server/src/remote/rtcwire.h
index 70a6b3c..8cfd091 100644
--- a/server/src/remote/rtcwire.h
+++ b/server/src/remote/rtcwire.h
@@ -33,7 +33,7 @@ int rw_turn_pass_valid(const char *s);
#define RW_SDP_LINES 600
#define RW_SDP_LINE 1024
#define RW_MAX_MEDIA 4 /* video, audio, data channel (+1 spare) */
-#define RW_MAX_PT 48 /* payload types per m= line */
+#define RW_MAX_PT 64 /* payload types per m= line */
#define RW_MAX_CAND 16
enum { RW_KIND_AUDIO = 1, RW_KIND_VIDEO, RW_KIND_APP };
diff --git a/server/tests/remote_fuzz.c b/server/tests/remote_fuzz.c
index d2c8a23..2c7b54a 100644
--- a/server/tests/remote_fuzz.c
+++ b/server/tests/remote_fuzz.c
@@ -5,6 +5,8 @@
#include "remote/rsec.h"
#include "remote/ipnet.h"
#include "remote/lockout.h"
+#include "remote/rtcwire.h"
+#include "rtc_offer_chrome.h"
#include <stdio.h>
#include <stdlib.h>
@@ -109,6 +111,114 @@ static void one(const char *b, size_t n) {
free(c);
}
+/* ---- the video path (rtcwire.c): SDP offers, candidates, STUN/TURN, RTCP, DCEP, RTP payloads ---- */
+
+static void fake_hmac(const uint8_t *key, size_t kl, const uint8_t *m, size_t n, uint8_t out[20]) {
+ uint32_t h = 2166136261u;
+ for (size_t i = 0; i < kl; i++) h = (h ^ key[i]) * 16777619u;
+ for (size_t i = 0; i < n; i++) h = (h ^ m[i]) * 16777619u;
+ for (int i = 0; i < 20; i++) out[i] = (uint8_t)(h >> (i % 4 * 8));
+}
+static void pk(void *ud, const uint8_t *h, size_t hl, const uint8_t *d, size_t n, int marker) {
+ (void)ud; (void)marker;
+ volatile uint8_t x = 0;
+ for (size_t i = 0; i < hl; i++) x ^= h[i];
+ for (size_t i = 0; i < n; i++) x ^= d[i]; /* ASan checks every byte handed out */
+}
+static void fb(void *ud, const RwFb *f) { (void)ud; (void)f; }
+
+static void rtc_one(const uint8_t *b, size_t n) {
+ uint8_t *c = malloc(n + 1);
+ memcpy(c, b, n);
+ RwOffer *o = malloc(sizeof *o);
+ if (!rw_sdp_parse_offer((const char *)c, n, (int)(rnd() & 1), o)) {
+ static char ans[16384];
+ uint8_t fp[32] = { 0 };
+ RwLocalCand lc = { "192.168.1.5", 4000, RW_CAND_HOST, 1, "", 0 };
+ RwAnswer a = { "ufraguf", "passwordpasswordpassword", fp, 1, 2, 1, &lc, 1, 3 };
+ rw_sdp_answer(o, &a, ans, (size_t)(1 + rnd() % sizeof ans));
+ }
+ free(o);
+ RwCand cd;
+ rw_cand_parse((const char *)c, n, &cd);
+ RwStun st;
+ if (!rw_stun_parse(c, n, &st)) rw_stun_check_mi(c, n, &st, (const uint8_t *)"k", 1, fake_hmac);
+ rw_is_stun(c, n);
+ rw_rtcp_parse(c, n, fb, NULL);
+ RwDcOpen dc;
+ rw_dcep_open(c, n, &dc);
+ rw_h264_packetize(c, n, 64 + rnd() % 1500, pk, NULL);
+ rw_h264_is_idr(c, n);
+ rw_vp8_packetize(c, n, 64 + rnd() % 1500, pk, NULL);
+ c[n] = 0;
+ rw_ice_server_valid((const char *)c);
+ rw_turn_user_valid((const char *)c);
+ rw_turn_pass_valid((const char *)c);
+ RwAddr ad;
+ if (!rw_addr_text((const char *)c, &ad)) { char t[64]; rw_addr_format(&ad, t, sizeof t); }
+ free(c);
+}
+
+/* seeds for rtc_one: well-formed STUN/TURN messages and RTCP compounds, built here */
+static size_t rtc_seed(uint8_t *b, size_t cap) {
+ uint8_t tid[12];
+ for (int i = 0; i < 12; i++) tid[i] = (uint8_t)rnd();
+ RwStunOut o;
+ RwAddr a = { (int)(rnd() % 2 ? 4 : 6), { 10, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, (uint16_t)rnd() };
+ switch (rnd() % 8) {
+ case 0: {
+ size_t n = strlen(chrome_offer);
+ memcpy(b, chrome_offer, n);
+ return mutate((char *)b, n, cap);
+ }
+ case 1: {
+ static const char *const cs[] = { "candidate:1 1 udp 2113937151 192.168.1.20 54321 typ host generation 0 network-cost 999",
+ "candidate:3 1 UDP 33554431 2001:db8::7 3478 typ relay raddr 2001:db8::1 rport 9",
+ "candidate:4 1 udp 2113937151 3d9863a1-3b3d-48f6-9ff1-49c2bc04877f.local 64198 typ host",
+ "stun.example.org:3478", "[2001:db8::1]:3478" };
+ const char *s = cs[rnd() % 5];
+ size_t n = strlen(s);
+ memcpy(b, s, n);
+ return mutate((char *)b, n, 2048);
+ }
+ case 2: case 3:
+ rw_so_init(&o, (uint16_t)(rnd() % 2 ? RW_STUN_BINDING_REQ : RW_TURN_ALLOCATE_OK), tid);
+ if (rnd() % 2) rw_so_attr(&o, RW_ATTR_USERNAME, "abcd:efgh", 9);
+ if (rnd() % 2) rw_so_u32(&o, RW_ATTR_PRIORITY, rnd());
+ if (rnd() % 2) rw_so_xaddr(&o, RW_ATTR_XOR_MAPPED, &a);
+ if (rnd() % 2) rw_so_xaddr(&o, RW_ATTR_XOR_RELAYED, &a);
+ if (rnd() % 3 == 0) rw_so_attr(&o, RW_ATTR_DATA, "\x16\xfe\xfd payload", 12);
+ if (rnd() % 2) rw_so_mi(&o, (const uint8_t *)"k", 1, fake_hmac);
+ if (rnd() % 2) rw_so_fingerprint(&o);
+ memcpy(b, o.b, o.n);
+ return rnd() % 2 ? mutate((char *)b, o.n, 1500) : o.n;
+ case 4: {
+ static const uint8_t rr[] = { 0x81, 0xc9, 0, 7, 1, 1, 1, 1, 2, 2, 2, 2, 25, 0, 0, 5, 0, 0, 1, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0x81, 0xcd, 0, 3, 1, 1, 1, 1, 2, 2, 2, 2, 0, 100, 0, 15,
+ 0x8f, 0xce, 0, 5, 1, 1, 1, 1, 0, 0, 0, 0, 'R', 'E', 'M', 'B', 1, 8, 0xe8, 0, 2, 2, 2, 2 };
+ memcpy(b, rr, sizeof rr);
+ return mutate((char *)b, sizeof rr, 1500);
+ }
+ case 5: {
+ static const uint8_t op[] = { 3, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 'i', 'n', 'p', 'u', 't' };
+ memcpy(b, op, sizeof op);
+ return mutate((char *)b, sizeof op, 200);
+ }
+ default: { /* an Annex B stream of random NAL units */
+ size_t n = 0;
+ while (n + 2000 < cap && rnd() % 6) {
+ static const uint8_t sc[] = { 0, 0, 0, 1 };
+ size_t k = 3 + rnd() % 2;
+ memcpy(b + n, sc + 4 - k, k);
+ n += k;
+ size_t l = rnd() % (rnd() % 4 ? 200 : 1800);
+ for (size_t i = 0; i < l; i++) b[n++] = (uint8_t)(rnd() % 5 ? rnd() | 1 : 0);
+ }
+ return n;
+ }
+ }
+}
+
/* random WebSocket stream: well-formed frames with random flags, lengths and payloads */
static size_t ws_stream(unsigned char *b, size_t cap) {
size_t o = 0;
@@ -132,7 +242,12 @@ int main(int argc, char **argv) {
static char b[200000];
for (long i = 0; i < iters; i++) {
size_t n;
- unsigned kind = rnd() % 10;
+ unsigned kind = rnd() % 14;
+ if (kind >= 10) {
+ n = rtc_seed((uint8_t *)b, 40000);
+ rtc_one((const uint8_t *)b, n);
+ continue;
+ }
if (kind < 6) {
const char *s = seeds[rnd() % (sizeof seeds / sizeof *seeds)];
n = strlen(s);
diff --git a/server/tests/remote_sec_test.c b/server/tests/remote_sec_test.c
index 771f23e..ed60dac 100644
--- a/server/tests/remote_sec_test.c
+++ b/server/tests/remote_sec_test.c
@@ -4,9 +4,12 @@
#include "remote/rsec.h"
#include "remote/ipnet.h"
#include "remote/lockout.h"
+#include "remote/rtcwire.h"
+#include "rtc_offer_chrome.h"
#include <stdio.h>
#include <stdlib.h>
+#include <stdint.h>
#include <string.h>
static int fails, checks;
@@ -448,6 +451,403 @@ static void test_lockout(void) {
CHECK(rc_take(&rc, "1.2.3.5", 10.6) == 1); /* others are not affected */
}
+/* ---- the video path's wire formats (rtcwire.c; docs/REMOTE.md, "Video (WebRTC)") ---- */
+
+/* A small SHA-1 + HMAC for the STUN tests (the test program links only libc). */
+typedef struct { uint32_t h[5]; uint64_t n; uint8_t b[64]; size_t bl; } Sha1;
+static uint32_t rol(uint32_t x, int k) { return x << k | x >> (32 - k); }
+static void sha1_block(Sha1 *s, const uint8_t *p) {
+ uint32_t w[80], a = s->h[0], b = s->h[1], c = s->h[2], d = s->h[3], e = s->h[4];
+ for (int i = 0; i < 16; i++) w[i] = (uint32_t)p[i * 4] << 24 | (uint32_t)p[i * 4 + 1] << 16 | (uint32_t)p[i * 4 + 2] << 8 | p[i * 4 + 3];
+ for (int i = 16; i < 80; i++) w[i] = rol(w[i - 3] ^ w[i - 8] ^ w[i - 14] ^ w[i - 16], 1);
+ for (int i = 0; i < 80; i++) {
+ uint32_t f, k;
+ if (i < 20) { f = (b & c) | (~b & d); k = 0x5A827999; }
+ else if (i < 40) { f = b ^ c ^ d; k = 0x6ED9EBA1; }
+ else if (i < 60) { f = (b & c) | (b & d) | (c & d); k = 0x8F1BBCDC; }
+ else { f = b ^ c ^ d; k = 0xCA62C1D6; }
+ uint32_t t = rol(a, 5) + f + e + k + w[i];
+ e = d; d = c; c = rol(b, 30); b = a; a = t;
+ }
+ s->h[0] += a; s->h[1] += b; s->h[2] += c; s->h[3] += d; s->h[4] += e;
+}
+static void sha1_init(Sha1 *s) { *s = (Sha1){ { 0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0 }, 0, { 0 }, 0 }; }
+static void sha1_add(Sha1 *s, const uint8_t *p, size_t n) {
+ s->n += n;
+ while (n--) { s->b[s->bl++] = *p++; if (s->bl == 64) { sha1_block(s, s->b); s->bl = 0; } }
+}
+static void sha1_end(Sha1 *s, uint8_t out[20]) {
+ uint64_t bits = s->n * 8;
+ uint8_t pad = 0x80, z = 0;
+ sha1_add(s, &pad, 1);
+ while (s->bl != 56) sha1_add(s, &z, 1);
+ uint8_t l[8];
+ for (int i = 0; i < 8; i++) l[i] = (uint8_t)(bits >> (56 - 8 * i));
+ sha1_add(s, l, 8);
+ for (int i = 0; i < 5; i++) { out[i * 4] = (uint8_t)(s->h[i] >> 24); out[i * 4 + 1] = (uint8_t)(s->h[i] >> 16); out[i * 4 + 2] = (uint8_t)(s->h[i] >> 8); out[i * 4 + 3] = (uint8_t)s->h[i]; }
+}
+static void hmac1(const uint8_t *key, size_t kl, const uint8_t *m, size_t n, uint8_t out[20]) {
+ uint8_t k[64] = { 0 }, ip[64], op[64], in[20];
+ if (kl > 64) { Sha1 s; sha1_init(&s); sha1_add(&s, key, kl); sha1_end(&s, k); } else memcpy(k, key, kl);
+ for (int i = 0; i < 64; i++) { ip[i] = k[i] ^ 0x36; op[i] = k[i] ^ 0x5c; }
+ Sha1 s;
+ sha1_init(&s); sha1_add(&s, ip, 64); sha1_add(&s, m, n); sha1_end(&s, in);
+ sha1_init(&s); sha1_add(&s, op, 64); sha1_add(&s, in, 20); sha1_end(&s, out);
+}
+
+static int hexbytes(const char *h, uint8_t *out) {
+ int n = 0;
+ for (; h[0] && h[1]; h += 2) { unsigned v; sscanf(h, "%2x", &v); out[n++] = (uint8_t)v; }
+ return n;
+}
+
+/* the offer with one line replaced (or removed, rep = NULL), or one line added after `after` */
+static char *offer_edit(const char *find, const char *rep) {
+ static char buf[40000];
+ const char *at = strstr(chrome_offer, find);
+ if (!at) { snprintf(buf, sizeof buf, "%s", chrome_offer); return buf; }
+ const char *end = strstr(at, "\r\n");
+ size_t pre = (size_t)(at - chrome_offer);
+ snprintf(buf, sizeof buf, "%.*s%s%s", (int)pre, chrome_offer, rep ? rep : "", end ? end + (rep ? 0 : 2) : "");
+ return buf;
+}
+
+static void test_sdp(void) {
+ RwOffer o;
+ size_t n = strlen(chrome_offer);
+ CHECK(rw_sdp_parse_offer(chrome_offer, n, 1, &o) == RW_OK);
+ CHECK(o.nmedia == 3 && o.vm == 0 && o.am == 1 && o.dm == 2 && o.vcodec == RW_CODEC_H264);
+ CHECK(o.m[o.vm].pt[0].pt == 96 && o.m[o.dm].sctp_port == 5000 && o.m[o.dm].max_msg == 262144);
+ int h264 = 0;
+ for (int i = 0; i < o.m[0].npt; i++) if (o.m[0].pt[i].pt == o.vpt) h264 = o.m[0].pt[i].plid == 0x42e01f && o.m[0].pt[i].pmode == 1;
+ CHECK(h264); /* constrained baseline, mode 1 */
+ CHECK(!strcmp(o.ufrag, "z1TV") && !strcmp(o.pwd, "RifL1wLzVBkO+l3mNSAqrSe8") && o.fp[0] == 0x70 && o.fp[31] == 0x39);
+ CHECK(o.setup == RW_SETUP_ACTPASS && o.ncand >= 1 && o.cand[0].mdns);
+ CHECK(rw_sdp_parse_offer(chrome_offer, n, 0, &o) == RW_OK && o.vcodec == RW_CODEC_VP8 && o.vpt == 96); /* no H.264 encoder */
+ /* broken offers */
+ const char *e;
+ e = offer_edit("a=ice-ufrag:z1TV", NULL); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_OK); /* the other sections carry it */
+ e = offer_edit("a=ice-ufrag:z1TV", "a=ice-ufrag:zzzz"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EICE); /* two in one bundle */
+ e = offer_edit("a=ice-ufrag:z1TV", "a=ice-ufrag:z1"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EICE); /* too short */
+ e = offer_edit("a=ice-ufrag:z1TV", "a=ice-ufrag:z1T;V"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EICE);
+ e = offer_edit("a=ice-pwd:RifL1wLzVBkO+l3mNSAqrSe8", "a=ice-pwd:short"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EICE);
+ e = offer_edit("a=fingerprint:sha-256 70:59", NULL); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_OK); /* the others remain */
+ e = offer_edit("a=fingerprint:sha-256 70:59", "a=fingerprint:sha-256 70:59:D6"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EFP);
+ e = offer_edit("a=fingerprint:sha-256 70:59", "a=fingerprint:sha-256 71:59:D6:4B:A3:67:6E:BD:AC:6A:5E:0D:3B:95:92:BA:40:F4:86:12:84:69:6C:F8:F8:D1:A0:A3:D1:C6:46:39");
+ CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_EFP); /* two different fingerprints in one bundle */
+ e = offer_edit("a=setup:actpass", "a=setup:passive"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=group:BUNDLE 0 1 2", NULL); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=mid:1", "a=mid:0"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* duplicate mid */
+ e = offer_edit("a=mid:1", "a=mid:bad mid"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=rtcp-mux", NULL); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* video without rtcp-mux */
+ e = offer_edit("a=rtpmap:96 VP8/90000", "a=rtpmap:96 VP8/90000/"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=rtpmap:96 VP8/90000", "a=rtpmap:200 VP8/90000"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* pt not listed */
+ e = offer_edit("a=rtpmap:96 VP8/90000", "a=rtpmap:97 VP8/90000"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* twice */
+ e = offer_edit("a=fmtp:97 apt=96", "a=fmtp:97 apt=96\r\na=fmtp:97 apt=96"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=recvonly", "a=sendonly"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ECODEC); /* no video to send */
+ e = offer_edit("v=0", "v=1"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("s=-", "s=\x01"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* control byte */
+ e = offer_edit("s=-", "s=\xc3\xa9"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX); /* non-ASCII */
+ e = offer_edit("s=-", "S=-"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ e = offer_edit("a=candidate:2529583990", "a=candidate:x 1 udp 1 1.2.3.4 0 typ host"); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ESYNTAX);
+ static char strip[40000];
+ for (int pass = 0; pass < 2; pass++) { /* no ufrag anywhere; no fingerprint anywhere */
+ const char *key = pass ? "a=fingerprint:" : "a=ice-ufrag:";
+ size_t o2 = 0;
+ for (const char *q = chrome_offer; *q;) {
+ const char *eol = strstr(q, "\r\n");
+ size_t l = eol ? (size_t)(eol - q) + 2 : strlen(q);
+ if (strncmp(q, key, strlen(key))) { memcpy(strip + o2, q, l); o2 += l; }
+ q += l;
+ }
+ strip[o2] = 0;
+ CHECK(rw_sdp_parse_offer(strip, o2, 1, &o) == (pass ? RW_EFP : RW_EICE));
+ }
+ /* sizes */
+ static char big[RW_SDP_MAX + 100];
+ memset(big, 0, sizeof big);
+ snprintf(big, sizeof big, "%s", chrome_offer);
+ size_t bl = strlen(big);
+ while (bl + 20 < RW_SDP_MAX + 50) { memcpy(big + bl, "a=x-filler:1\r\n", 14); bl += 14; }
+ CHECK(rw_sdp_parse_offer(big, bl, 1, &o) == RW_ETOOBIG);
+ char longline[2000];
+ memset(longline, 'a', sizeof longline);
+ memcpy(longline, "a=x:", 4);
+ longline[1500] = 0;
+ e = offer_edit("s=-", longline); CHECK(rw_sdp_parse_offer(e, strlen(e), 1, &o) == RW_ETOOBIG);
+ static char many[RW_SDP_MAX];
+ size_t ml = (size_t)snprintf(many, sizeof many, "v=0\r\n");
+ for (int i = 0; i < 700 && ml + 8 < sizeof many; i++) { memcpy(many + ml, "a=x\r\n", 5); ml += 5; }
+ CHECK(rw_sdp_parse_offer(many, ml, 1, &o) == RW_ETOOBIG);
+ CHECK(rw_sdp_parse_offer("", 0, 1, &o) == RW_ESYNTAX);
+ /* the answer */
+ CHECK(rw_sdp_parse_offer(chrome_offer, n, 1, &o) == RW_OK);
+ uint8_t fp[32];
+ for (int i = 0; i < 32; i++) fp[i] = (uint8_t)i;
+ RwLocalCand c[2] = { { "192.168.1.5", 40000, RW_CAND_HOST, 2130706431, "", 0 }, { "203.0.113.9", 3478, RW_CAND_RELAY, 33554431, "198.51.100.2", 5555 } };
+ RwAnswer a = { "AbCdEfGh", "0123456789abcdefABCDEF01", fp, 111, 222, 1, c, 2, 42 };
+ char ans[16384];
+ int al = rw_sdp_answer(&o, &a, ans, sizeof ans);
+ CHECK(al > 0 && strstr(ans, "a=ice-lite\r\n") && strstr(ans, "a=setup:passive\r\n") && strstr(ans, "a=group:BUNDLE 0 1 2\r\n"));
+ CHECK(strstr(ans, "a=fingerprint:sha-256 00:01:02:03:") != NULL);
+ char want[64];
+ snprintf(want, sizeof want, "a=rtpmap:%d H264/90000\r\n", o.vpt);
+ CHECK(strstr(ans, want) && strstr(ans, "packetization-mode=1;profile-level-id=42e01f"));
+ CHECK(strstr(ans, "a=candidate:10 1 udp 2130706431 192.168.1.5 40000 typ host\r\n"));
+ CHECK(strstr(ans, "typ relay raddr 198.51.100.2 rport 5555\r\n") && strstr(ans, "a=sctp-port:5000"));
+ CHECK(strstr(ans, "a=ssrc:111 cname:lordos") && strstr(ans, "a=ssrc:222 cname:lordos") && strstr(ans, "a=rtpmap:111 opus/48000/2"));
+ CHECK(!strstr(ans, "RifL1w")); /* never echoes the browser's secrets */
+ CHECK(rw_sdp_answer(&o, &a, ans, 200) == -1); /* doesn't fit */
+}
+
+static void test_cand(void) {
+ RwCand c;
+ const char *ok[] = {
+ "candidate:1 1 udp 2113937151 192.168.1.20 54321 typ host generation 0 network-cost 999",
+ "a=candidate:842163049 1 udp 1677729535 203.0.113.4 61000 typ srflx raddr 0.0.0.0 rport 0 generation 0",
+ "candidate:3 1 UDP 33554431 2001:db8::7 3478 typ relay raddr 2001:db8::1 rport 9",
+ "candidate:4 1 udp 2113937151 3d9863a1-3b3d-48f6-9ff1-49c2bc04877f.local 64198 typ host",
+ "candidate:5 1 tcp 1518280447 192.168.1.20 9 typ host tcptype active",
+ };
+ for (size_t i = 0; i < sizeof ok / sizeof ok[0]; i++) CHECK(rw_cand_parse(ok[i], strlen(ok[i]), &c) == RW_OK);
+ CHECK(rw_cand_parse(ok[0], strlen(ok[0]), &c) == 0 && c.type == RW_CAND_HOST && c.addr.family == 4 && c.addr.port == 54321 && !c.mdns);
+ CHECK(rw_cand_parse(ok[2], strlen(ok[2]), &c) == 0 && c.type == RW_CAND_RELAY && c.addr.family == 6);
+ CHECK(rw_cand_parse(ok[3], strlen(ok[3]), &c) == 0 && c.mdns);
+ CHECK(rw_cand_parse(ok[4], strlen(ok[4]), &c) == 0 && c.tcp);
+ const char *bad[] = {
+ "candidate:1 1 udp 2113937151 192.168.1.20 0 typ host", /* port 0 */
+ "candidate:1 1 udp 2113937151 192.168.1.20 70000 typ host",
+ "candidate:1 1 udp 4294967296 192.168.1.20 5 typ host", /* priority over 32 bits */
+ "candidate:1 1 sctp 1 192.168.1.20 5 typ host",
+ "candidate:1 1 udp 1 192.168.1.20 5 typ hostx",
+ "candidate:1 1 udp 1 192.168.001.20 5 typ host", /* leading zeros */
+ "candidate:1 1 udp 1 evil.example.com 5 typ host", /* only mDNS names */
+ "candidate:1 1 udp 1 1.2.3.4 5 typ host raddr", /* odd extension */
+ "candidate:1 1 udp 1 1.2.3.4 5 typ host X y",
+ "candidate:1 1 udp 1 1.2.3.4 5 typ host", /* double space */
+ "candidate:1 1 udp 1 1.2.3.4 5 typ host ",
+ "candidate:a;b 1 udp 1 1.2.3.4 5 typ host",
+ "candidate:1 0 udp 1 1.2.3.4 5 typ host",
+ "candidate:1 1 udp 1 1.2.3.4 5 typ host\x01",
+ "cand:1 1 udp 1 1.2.3.4 5 typ host",
+ "",
+ };
+ for (size_t i = 0; i < sizeof bad / sizeof bad[0]; i++) CHECK(rw_cand_parse(bad[i], strlen(bad[i]), &c) != RW_OK);
+ char huge[700];
+ memset(huge, 'a', sizeof huge);
+ memcpy(huge, "candidate:", 10);
+ CHECK(rw_cand_parse(huge, sizeof huge, &c) != RW_OK);
+ CHECK(rw_ice_server_valid("stun.example.org:3478") && rw_ice_server_valid("192.0.2.1:19302") && rw_ice_server_valid("[2001:db8::1]:3478"));
+ CHECK(!rw_ice_server_valid("stun.example.org") && !rw_ice_server_valid("a:0") && !rw_ice_server_valid("a:65536") && !rw_ice_server_valid("a:03478"));
+ CHECK(!rw_ice_server_valid("-a.example:1") && !rw_ice_server_valid("a..b:1") && !rw_ice_server_valid("a b:1") && !rw_ice_server_valid("[1.2.3.4]:5"));
+ CHECK(!rw_ice_server_valid("turn:x.example:1") && !rw_ice_server_valid("x.example:1\n"));
+ CHECK(rw_turn_user_valid("1700000000:alice") && !rw_turn_user_valid("al ice") && !rw_turn_user_valid("a\"b") && !rw_turn_user_valid(""));
+ CHECK(rw_turn_pass_valid("p a$$ w0rd") && !rw_turn_pass_valid("a\nb") && !rw_turn_pass_valid(""));
+}
+
+static void test_stun(void) {
+ /* a real answer of ours to Chrome, checked by hand (ICE password tnGnUTLhcP7YsCoR9B8TOTo3) */
+ uint8_t p[200];
+ int n = hexbytes("0101002c2112a442496f307873764d3849326171002000080001df408d03a44700080014891a716ef20e7a305d8e94f44f899dba06a12704802800049abe8fcc", p);
+ RwStun s;
+ CHECK(rw_is_stun(p, (size_t)n) && rw_stun_parse(p, (size_t)n, &s) == 0);
+ CHECK(s.type == RW_STUN_BINDING_OK && s.has_fp && s.mi_off == 32 && s.xor_mapped.family == 4 && s.xor_mapped.port == 65106);
+ CHECK(s.xor_mapped.a[0] == 172 && s.xor_mapped.a[1] == 17 && s.xor_mapped.a[3] == 5);
+ const char *pw = "tnGnUTLhcP7YsCoR9B8TOTo3";
+ CHECK(rw_stun_check_mi(p, (size_t)n, &s, (const uint8_t *)pw, strlen(pw), hmac1));
+ CHECK(!rw_stun_check_mi(p, (size_t)n, &s, (const uint8_t *)"wrong-password-xxxxxxxx", 23, hmac1));
+ /* our builder makes the same bytes */
+ RwStunOut o;
+ rw_so_init(&o, RW_STUN_BINDING_OK, p + 8);
+ rw_so_xaddr(&o, RW_ATTR_XOR_MAPPED, &s.xor_mapped);
+ rw_so_mi(&o, (const uint8_t *)pw, strlen(pw), hmac1);
+ rw_so_fingerprint(&o);
+ CHECK(!o.bad && o.n == (size_t)n && !memcmp(o.b, p, (size_t)n));
+ /* a request like Chrome's: username, priority, controlling, use-candidate */
+ uint8_t tid[12] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 }, ctl[8] = { 0 };
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_attr(&o, RW_ATTR_USERNAME, "AbCdEfGh:z1TV", 13);
+ rw_so_u32(&o, RW_ATTR_PRIORITY, 1853824767);
+ rw_so_attr(&o, RW_ATTR_CONTROLLING, ctl, 8);
+ rw_so_attr(&o, RW_ATTR_USE_CAND, NULL, 0);
+ rw_so_attr(&o, 0xc057, "\0\0\x03\xe7", 4); /* comprehension-optional: skipped */
+ rw_so_mi(&o, (const uint8_t *)"key", 3, hmac1);
+ rw_so_fingerprint(&o);
+ CHECK(rw_stun_parse(o.b, o.n, &s) == 0 && s.ulen == 13 && s.use_candidate && s.controlling && s.priority == 1853824767);
+ CHECK(rw_stun_check_mi(o.b, o.n, &s, (const uint8_t *)"key", 3, hmac1));
+ /* tampering */
+ uint8_t t[RW_STUN_MAX];
+ memcpy(t, o.b, o.n);
+ t[30] ^= 1;
+ CHECK(rw_stun_parse(t, o.n, &s) != 0); /* the fingerprint catches it */
+ memcpy(t, o.b, o.n);
+ t[3] += 4;
+ CHECK(rw_stun_parse(t, o.n, &s) != 0); /* length doesn't match */
+ CHECK(rw_stun_parse(o.b, o.n - 1, &s) != 0 && rw_stun_parse(o.b, 19, &s) != 0);
+ memcpy(t, o.b, o.n);
+ t[4] = 0;
+ CHECK(rw_stun_parse(t, o.n, &s) != 0 && !rw_is_stun(t, o.n)); /* no magic cookie */
+ /* structure rules */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_attr(&o, RW_ATTR_USERNAME, "a:b", 3);
+ rw_so_attr(&o, RW_ATTR_USERNAME, "a:b", 3);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* the same attribute twice */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_mi(&o, (const uint8_t *)"k", 1, hmac1);
+ rw_so_attr(&o, RW_ATTR_USERNAME, "a:b", 3);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* something after MESSAGE-INTEGRITY */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_fingerprint(&o);
+ rw_so_attr(&o, RW_ATTR_SOFTWARE, "x", 1);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* something after FINGERPRINT */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_attr(&o, 0x0030, "x", 1);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* unknown comprehension-required */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_attr(&o, RW_ATTR_PRIORITY, "abc", 3);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* wrong size */
+ rw_so_init(&o, RW_STUN_BINDING_REQ, tid);
+ rw_so_attr(&o, RW_ATTR_XOR_MAPPED, "\0\3\0\0\0\0\0\0", 8);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* unknown address family */
+ rw_so_init(&o, RW_TURN_ALLOCATE_ERR, tid);
+ rw_so_attr(&o, RW_ATTR_ERROR, "\0\0\4\1Unauthorized", 16);
+ rw_so_attr(&o, RW_ATTR_REALM, "lordos.test", 11);
+ rw_so_attr(&o, RW_ATTR_NONCE, "abcdef", 6);
+ CHECK(rw_stun_parse(o.b, o.n, &s) == 0 && s.error == 401 && s.rlen == 11 && s.nlen == 6);
+ rw_so_init(&o, RW_TURN_ALLOCATE_ERR, tid);
+ rw_so_attr(&o, RW_ATTR_ERROR, "\0\0\x09\1x", 5);
+ CHECK(rw_stun_parse(o.b, o.n, &s) != 0); /* class 9 */
+ RwAddr v6 = { 6, { 0x20, 0x01, 0x0d, 0xb8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7 }, 3478 };
+ rw_so_init(&o, RW_TURN_ALLOCATE_OK, tid);
+ rw_so_xaddr(&o, RW_ATTR_XOR_RELAYED, &v6);
+ rw_so_u32(&o, RW_ATTR_LIFETIME, 600);
+ CHECK(rw_stun_parse(o.b, o.n, &s) == 0 && rw_addr_equal(&s.xor_relayed, &v6) && s.lifetime == 600);
+ char txt[64];
+ rw_addr_format(&v6, txt, sizeof txt);
+ CHECK(!strcmp(txt, "2001:db8::7"));
+}
+
+typedef struct { int n, rr, pli, fir, nack, remb; uint64_t br; } FbCount;
+static void fb_count(void *ud, const RwFb *f) {
+ FbCount *c = ud;
+ c->n++;
+ if (f->kind == RW_FB_RR) c->rr++;
+ if (f->kind == RW_FB_PLI) c->pli++;
+ if (f->kind == RW_FB_FIR) c->fir++;
+ if (f->kind == RW_FB_NACK) c->nack++;
+ if (f->kind == RW_FB_REMB) { c->remb++; c->br = f->bitrate; }
+}
+
+static void test_rtcp(void) {
+ uint8_t p[300];
+ FbCount c = { 0 };
+ /* RR with one block + PLI + NACK(2 items) + REMB, one compound packet */
+ int n = hexbytes("81c90007" "11111111" "22222222" "19000005" "00000100" "00000010" "00000000" "00000000"
+ "81ce0002" "11111111" "22222222"
+ "81cd0004" "11111111" "22222222" "0064000f" "00c80000"
+ "8fce0005" "11111111" "00000000" "52454d42" "0108e800" "22222222", p);
+ CHECK(rw_rtcp_parse(p, (size_t)n, fb_count, &c) == 0 && c.rr == 1 && c.pli == 1 && c.nack == 2 && c.remb == 1 && c.br == (uint64_t)0xe800 << 2);
+ int k = hexbytes("84ce0004" "11111111" "00000000" "22222222" "05000000", p);
+ memset(&c, 0, sizeof c);
+ CHECK(rw_rtcp_parse(p, (size_t)k, fb_count, &c) == 0 && c.fir == 1);
+ /* broken: wrong version, length past the end, an RR claiming more blocks, a NACK without items,
+ * padding not at the end, a non-RTCP type; nothing is reported for a broken packet */
+ const char *bad[] = { "41ce000211111111" "22222222", "81ce000311111111" "22222222", "82c9000711111111" "22222222",
+ "81cd000211111111" "22222222", "a1ce0002111111112222222281ce00021111111122222222", "81c8000011111111" "",
+ "81640001" "00000000", "80c9" };
+ for (size_t i = 0; i < sizeof bad / sizeof bad[0]; i++) {
+ memset(&c, 0, sizeof c);
+ int bn = hexbytes(bad[i], p);
+ CHECK(rw_rtcp_parse(p, (size_t)bn, fb_count, &c) != 0 && c.n == 0);
+ }
+ /* a valid packet followed by garbage: the good part isn't reported either */
+ n = hexbytes("81ce0002" "11111111" "22222222" "ff", p);
+ memset(&c, 0, sizeof c);
+ CHECK(rw_rtcp_parse(p, (size_t)n, fb_count, &c) != 0 && c.n == 0);
+}
+
+static void test_dcep(void) {
+ RwDcOpen o;
+ uint8_t p[100];
+ int n = hexbytes("0300000000000000000500006c6f6c6f6c", p); /* label "lolol" */
+ CHECK(rw_dcep_open(p, (size_t)n, &o) == 0 && !strcmp(o.label, "lolol"));
+ n = hexbytes("03800000000000000005000074696c6573", p);
+ CHECK(rw_dcep_open(p, (size_t)n, &o) == 0 && o.chan_type == 0x80 && !strcmp(o.label, "tiles"));
+ n = hexbytes("0301000000000003000500006c6f6c6f6c", p); /* partially reliable: refused */
+ CHECK(rw_dcep_open(p, (size_t)n, &o) != 0);
+ n = hexbytes("0300000000000000000500016c6f6c6f6c78", p); /* a subprotocol */
+ CHECK(rw_dcep_open(p, (size_t)n, &o) != 0);
+ n = hexbytes("0300000000000000000600006c6f6c6f6c", p); /* label longer than the message */
+ CHECK(rw_dcep_open(p, (size_t)n, &o) != 0);
+ n = hexbytes("030000000000000000050000496e505554", p); /* capitals */
+ CHECK(rw_dcep_open(p, (size_t)n, &o) != 0);
+ n = hexbytes("02", p);
+ CHECK(rw_dcep_open(p, (size_t)n, &o) != 0);
+ CHECK(rw_dcep_open(p, 0, &o) != 0);
+}
+
+typedef struct { int n, marker_at, starts, ends; size_t bytes; uint8_t first_hdr[2]; } PkCount;
+static void pk_out(void *ud, const uint8_t *h, size_t hl, const uint8_t *d, size_t n, int marker) {
+ PkCount *c = ud;
+ (void)d;
+ if (hl == 2 && (h[1] & 0x80)) c->starts++;
+ if (hl == 2 && (h[1] & 0x40)) c->ends++;
+ if (!c->n && hl) memcpy(c->first_hdr, h, hl < 2 ? hl : 2);
+ if (marker) c->marker_at = c->n;
+ c->n++;
+ c->bytes += hl + n;
+}
+
+static void test_rtp(void) {
+ static uint8_t au[4000];
+ size_t n = 0;
+ const uint8_t sps[] = { 0, 0, 0, 1, 0x67, 0x42, 0xe0, 0x1f, 0xaa }, pps[] = { 0, 0, 1, 0x68, 0xce, 0x3c, 0x80 };
+ memcpy(au + n, sps, sizeof sps); n += sizeof sps;
+ memcpy(au + n, pps, sizeof pps); n += sizeof pps;
+ au[n++] = 0; au[n++] = 0; au[n++] = 0; au[n++] = 1; au[n++] = 0x65; /* IDR */
+ for (int i = 0; i < 3000; i++) au[n++] = (uint8_t)(i % 251 + 1);
+ PkCount c = { 0 };
+ CHECK(rw_h264_is_idr(au, n));
+ int k = rw_h264_packetize(au, n, 1100, pk_out, &c);
+ CHECK(k == 2 + 3 && c.n == 5 && c.marker_at == 4 && c.starts == 1 && c.ends == 1);
+ CHECK(c.bytes == 5 + 4 + 3 * 2 + 3000); /* SPS, PPS, FU-A headers + IDR body */
+ uint8_t p[] = { 0, 0, 1, 0x41, 1, 2, 3 };
+ memset(&c, 0, sizeof c);
+ CHECK(rw_h264_packetize(p, sizeof p, 1100, pk_out, &c) == 1 && !rw_h264_is_idr(p, sizeof p) && c.marker_at == 0);
+ uint8_t nostart[] = { 0x65, 1, 2, 3 };
+ CHECK(rw_h264_packetize(nostart, sizeof nostart, 1100, pk_out, &c) == -1);
+ uint8_t forbidden[] = { 0, 0, 1, 0xe5, 1 };
+ CHECK(rw_h264_packetize(forbidden, sizeof forbidden, 1100, pk_out, &c) == -1);
+ CHECK(rw_h264_packetize(au, n, 10, pk_out, &c) == -1);
+ memset(&c, 0, sizeof c);
+ CHECK(rw_vp8_packetize(au, 2500, 1000, pk_out, &c) == 3 && c.marker_at == 2 && c.first_hdr[0] == 0x10);
+}
+
+static void test_signal(void) {
+ char sb[256];
+ RsJson o;
+ RsInput in;
+ const char *j = "{\"t\":\"rtc\",\"sdp\":\"v=0\\r\\nm=video 9\"}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_RTC && in.tlen == 14);
+ j = "{\"t\":\"rtc\",\"sdp\":\"v=0\"}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_NONE); /* too short */
+ j = "{\"t\":\"rtc\",\"sdp\":5}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_NONE);
+ j = "{\"t\":\"ice\",\"c\":\"candidate:1 1 udp 1 1.2.3.4 5 typ host\"}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_ICE);
+ j = "{\"t\":\"ice\",\"c\":\"\"}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_ICE && in.tlen == 0);
+ j = "{\"t\":\"vmode\",\"on\":1}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_VMODE && in.a == 1);
+ j = "{\"t\":\"vmode\",\"on\":2}";
+ CHECK(rs_json_parse(j, strlen(j), &o, sb, sizeof sb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_NONE);
+ static char big[RS_SDP_MAX + 64], bsb[RS_SDP_MAX + 64];
+ size_t bl = (size_t)snprintf(big, sizeof big, "{\"t\":\"rtc\",\"sdp\":\"");
+ while (bl < RS_SDP_MAX + 30) big[bl++] = 'a';
+ bl += (size_t)snprintf(big + bl, sizeof big - bl, "\"}");
+ CHECK(rs_json_parse(big, bl, &o, bsb, sizeof bsb) == 0 && rs_browser_input(&o, 1280, 800, &in) == RS_IN_NONE); /* oversized offer */
+}
+
int main(void) {
test_head();
test_small();
@@ -456,6 +856,13 @@ int main(void) {
test_json();
test_ipnet();
test_lockout();
+ test_sdp();
+ test_cand();
+ test_stun();
+ test_rtcp();
+ test_dcep();
+ test_rtp();
+ test_signal();
printf("remote-sec-test: %d checks, %d failed\n", checks, fails);
return fails ? 1 : 0;
}
diff --git a/server/tests/rtc_offer_chrome.h b/server/tests/rtc_offer_chrome.h
new file mode 100644
index 0000000..a4320e4
--- /dev/null
+++ b/server/tests/rtc_offer_chrome.h
@@ -0,0 +1,253 @@
+/* rtc_offer_chrome.h — a real offer from Chrome 155 (recvonly video and audio, two data channels),
+ * as the remote desktop page makes it; for build/remote-sec-test and build/remote-fuzz. */
+static const char chrome_offer[] =
+ "v=0\r\n"
+ "o=- 6903865704898867732 2 IN IP4 127.0.0.1\r\n"
+ "s=-\r\n"
+ "t=0 0\r\n"
+ "a=group:BUNDLE 0 1 2\r\n"
+ "a=extmap-allow-mixed\r\n"
+ "a=msid-semantic: WMS\r\n"
+ "m=video 9 UDP/TLS/RTP/SAVPF 96 97 98 99 100 101 35 36 37 38 102 103 104 107 108 109 114 115 116 117 39 40 41 42 43 44 45 46 47 48 118 119 120 121 49 50 51 52 122 123 124 53\r\n"
+ "c=IN IP4 0.0.0.0\r\n"
+ "a=rtcp:9 IN IP4 0.0.0.0\r\n"
+ "a=candidate:2529583990 1 udp 2113937151 3d9863a1-3b3d-48f6-9ff1-49c2bc04877f.local 64198 typ host generation 0 network-cost 999\r\n"
+ "a=ice-ufrag:z1TV\r\n"
+ "a=ice-pwd:RifL1wLzVBkO+l3mNSAqrSe8\r\n"
+ "a=ice-options:trickle\r\n"
+ "a=fingerprint:sha-256 70:59:D6:4B:A3:67:6E:BD:AC:6A:5E:0D:3B:95:92:BA:40:F4:86:12:84:69:6C:F8:F8:D1:A0:A3:D1:C6:46:39\r\n"
+ "a=setup:actpass\r\n"
+ "a=mid:0\r\n"
+ "a=extmap:1 urn:ietf:params:rtp-hdrext:toffset\r\n"
+ "a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n"
+ "a=extmap:3 urn:3gpp:video-orientation\r\n"
+ "a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n"
+ "a=extmap:5 http://www.webrtc.org/experiments/rtp-hdrext/playout-delay\r\n"
+ "a=extmap:6 http://www.webrtc.org/experiments/rtp-hdrext/video-content-type\r\n"
+ "a=extmap:7 http://www.webrtc.org/experiments/rtp-hdrext/video-timing\r\n"
+ "a=extmap:8 http://www.webrtc.org/experiments/rtp-hdrext/color-space\r\n"
+ "a=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid\r\n"
+ "a=extmap:10 urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id\r\n"
+ "a=extmap:11 urn:ietf:params:rtp-hdrext:sdes:repaired-rtp-stream-id\r\n"
+ "a=recvonly\r\n"
+ "a=rtcp-mux\r\n"
+ "a=rtcp-rsize\r\n"
+ "a=rtcp-xr:rcvr-rtt=all\r\n"
+ "a=rtpmap:96 VP8/90000\r\n"
+ "a=rtcp-fb:96 goog-remb\r\n"
+ "a=rtcp-fb:96 transport-cc\r\n"
+ "a=rtcp-fb:96 ccm fir\r\n"
+ "a=rtcp-fb:96 nack\r\n"
+ "a=rtcp-fb:96 nack pli\r\n"
+ "a=rtpmap:97 rtx/90000\r\n"
+ "a=fmtp:97 apt=96\r\n"
+ "a=rtpmap:98 VP9/90000\r\n"
+ "a=rtcp-fb:98 goog-remb\r\n"
+ "a=rtcp-fb:98 transport-cc\r\n"
+ "a=rtcp-fb:98 ccm fir\r\n"
+ "a=rtcp-fb:98 nack\r\n"
+ "a=rtcp-fb:98 nack pli\r\n"
+ "a=fmtp:98 profile-id=0\r\n"
+ "a=rtpmap:99 rtx/90000\r\n"
+ "a=fmtp:99 apt=98\r\n"
+ "a=rtpmap:100 VP9/90000\r\n"
+ "a=rtcp-fb:100 goog-remb\r\n"
+ "a=rtcp-fb:100 transport-cc\r\n"
+ "a=rtcp-fb:100 ccm fir\r\n"
+ "a=rtcp-fb:100 nack\r\n"
+ "a=rtcp-fb:100 nack pli\r\n"
+ "a=fmtp:100 profile-id=2\r\n"
+ "a=rtpmap:101 rtx/90000\r\n"
+ "a=fmtp:101 apt=100\r\n"
+ "a=rtpmap:35 VP9/90000\r\n"
+ "a=rtcp-fb:35 goog-remb\r\n"
+ "a=rtcp-fb:35 transport-cc\r\n"
+ "a=rtcp-fb:35 ccm fir\r\n"
+ "a=rtcp-fb:35 nack\r\n"
+ "a=rtcp-fb:35 nack pli\r\n"
+ "a=fmtp:35 profile-id=1\r\n"
+ "a=rtpmap:36 rtx/90000\r\n"
+ "a=fmtp:36 apt=35\r\n"
+ "a=rtpmap:37 VP9/90000\r\n"
+ "a=rtcp-fb:37 goog-remb\r\n"
+ "a=rtcp-fb:37 transport-cc\r\n"
+ "a=rtcp-fb:37 ccm fir\r\n"
+ "a=rtcp-fb:37 nack\r\n"
+ "a=rtcp-fb:37 nack pli\r\n"
+ "a=fmtp:37 profile-id=3\r\n"
+ "a=rtpmap:38 rtx/90000\r\n"
+ "a=fmtp:38 apt=37\r\n"
+ "a=rtpmap:102 H264/90000\r\n"
+ "a=rtcp-fb:102 goog-remb\r\n"
+ "a=rtcp-fb:102 transport-cc\r\n"
+ "a=rtcp-fb:102 ccm fir\r\n"
+ "a=rtcp-fb:102 nack\r\n"
+ "a=rtcp-fb:102 nack pli\r\n"
+ "a=fmtp:102 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42001f\r\n"
+ "a=rtpmap:103 rtx/90000\r\n"
+ "a=fmtp:103 apt=102\r\n"
+ "a=rtpmap:104 H264/90000\r\n"
+ "a=rtcp-fb:104 goog-remb\r\n"
+ "a=rtcp-fb:104 transport-cc\r\n"
+ "a=rtcp-fb:104 ccm fir\r\n"
+ "a=rtcp-fb:104 nack\r\n"
+ "a=rtcp-fb:104 nack pli\r\n"
+ "a=fmtp:104 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42001f\r\n"
+ "a=rtpmap:107 rtx/90000\r\n"
+ "a=fmtp:107 apt=104\r\n"
+ "a=rtpmap:108 H264/90000\r\n"
+ "a=rtcp-fb:108 goog-remb\r\n"
+ "a=rtcp-fb:108 transport-cc\r\n"
+ "a=rtcp-fb:108 ccm fir\r\n"
+ "a=rtcp-fb:108 nack\r\n"
+ "a=rtcp-fb:108 nack pli\r\n"
+ "a=fmtp:108 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=42e01f\r\n"
+ "a=rtpmap:109 rtx/90000\r\n"
+ "a=fmtp:109 apt=108\r\n"
+ "a=rtpmap:114 H264/90000\r\n"
+ "a=rtcp-fb:114 goog-remb\r\n"
+ "a=rtcp-fb:114 transport-cc\r\n"
+ "a=rtcp-fb:114 ccm fir\r\n"
+ "a=rtcp-fb:114 nack\r\n"
+ "a=rtcp-fb:114 nack pli\r\n"
+ "a=fmtp:114 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=42e01f\r\n"
+ "a=rtpmap:115 rtx/90000\r\n"
+ "a=fmtp:115 apt=114\r\n"
+ "a=rtpmap:116 H264/90000\r\n"
+ "a=rtcp-fb:116 goog-remb\r\n"
+ "a=rtcp-fb:116 transport-cc\r\n"
+ "a=rtcp-fb:116 ccm fir\r\n"
+ "a=rtcp-fb:116 nack\r\n"
+ "a=rtcp-fb:116 nack pli\r\n"
+ "a=fmtp:116 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=4d001f\r\n"
+ "a=rtpmap:117 rtx/90000\r\n"
+ "a=fmtp:117 apt=116\r\n"
+ "a=rtpmap:39 H264/90000\r\n"
+ "a=rtcp-fb:39 goog-remb\r\n"
+ "a=rtcp-fb:39 transport-cc\r\n"
+ "a=rtcp-fb:39 ccm fir\r\n"
+ "a=rtcp-fb:39 nack\r\n"
+ "a=rtcp-fb:39 nack pli\r\n"
+ "a=fmtp:39 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=4d001f\r\n"
+ "a=rtpmap:40 rtx/90000\r\n"
+ "a=fmtp:40 apt=39\r\n"
+ "a=rtpmap:41 H264/90000\r\n"
+ "a=rtcp-fb:41 goog-remb\r\n"
+ "a=rtcp-fb:41 transport-cc\r\n"
+ "a=rtcp-fb:41 ccm fir\r\n"
+ "a=rtcp-fb:41 nack\r\n"
+ "a=rtcp-fb:41 nack pli\r\n"
+ "a=fmtp:41 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=f4001f\r\n"
+ "a=rtpmap:42 rtx/90000\r\n"
+ "a=fmtp:42 apt=41\r\n"
+ "a=rtpmap:43 H264/90000\r\n"
+ "a=rtcp-fb:43 goog-remb\r\n"
+ "a=rtcp-fb:43 transport-cc\r\n"
+ "a=rtcp-fb:43 ccm fir\r\n"
+ "a=rtcp-fb:43 nack\r\n"
+ "a=rtcp-fb:43 nack pli\r\n"
+ "a=fmtp:43 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=f4001f\r\n"
+ "a=rtpmap:44 rtx/90000\r\n"
+ "a=fmtp:44 apt=43\r\n"
+ "a=rtpmap:45 AV1/90000\r\n"
+ "a=rtcp-fb:45 goog-remb\r\n"
+ "a=rtcp-fb:45 transport-cc\r\n"
+ "a=rtcp-fb:45 ccm fir\r\n"
+ "a=rtcp-fb:45 nack\r\n"
+ "a=rtcp-fb:45 nack pli\r\n"
+ "a=fmtp:45 level-idx=5;profile=0;tier=0\r\n"
+ "a=rtpmap:46 rtx/90000\r\n"
+ "a=fmtp:46 apt=45\r\n"
+ "a=rtpmap:47 AV1/90000\r\n"
+ "a=rtcp-fb:47 goog-remb\r\n"
+ "a=rtcp-fb:47 transport-cc\r\n"
+ "a=rtcp-fb:47 ccm fir\r\n"
+ "a=rtcp-fb:47 nack\r\n"
+ "a=rtcp-fb:47 nack pli\r\n"
+ "a=fmtp:47 level-idx=5;profile=1;tier=0\r\n"
+ "a=rtpmap:48 rtx/90000\r\n"
+ "a=fmtp:48 apt=47\r\n"
+ "a=rtpmap:118 H264/90000\r\n"
+ "a=rtcp-fb:118 goog-remb\r\n"
+ "a=rtcp-fb:118 transport-cc\r\n"
+ "a=rtcp-fb:118 ccm fir\r\n"
+ "a=rtcp-fb:118 nack\r\n"
+ "a=rtcp-fb:118 nack pli\r\n"
+ "a=fmtp:118 level-asymmetry-allowed=1;packetization-mode=1;profile-level-id=64001f\r\n"
+ "a=rtpmap:119 rtx/90000\r\n"
+ "a=fmtp:119 apt=118\r\n"
+ "a=rtpmap:120 H264/90000\r\n"
+ "a=rtcp-fb:120 goog-remb\r\n"
+ "a=rtcp-fb:120 transport-cc\r\n"
+ "a=rtcp-fb:120 ccm fir\r\n"
+ "a=rtcp-fb:120 nack\r\n"
+ "a=rtcp-fb:120 nack pli\r\n"
+ "a=fmtp:120 level-asymmetry-allowed=1;packetization-mode=0;profile-level-id=64001f\r\n"
+ "a=rtpmap:121 rtx/90000\r\n"
+ "a=fmtp:121 apt=120\r\n"
+ "a=rtpmap:49 H265/90000\r\n"
+ "a=rtcp-fb:49 goog-remb\r\n"
+ "a=rtcp-fb:49 transport-cc\r\n"
+ "a=rtcp-fb:49 ccm fir\r\n"
+ "a=rtcp-fb:49 nack\r\n"
+ "a=rtcp-fb:49 nack pli\r\n"
+ "a=fmtp:49 level-id=180;profile-id=1;tier-flag=0;tx-mode=SRST\r\n"
+ "a=rtpmap:50 rtx/90000\r\n"
+ "a=fmtp:50 apt=49\r\n"
+ "a=rtpmap:51 H265/90000\r\n"
+ "a=rtcp-fb:51 goog-remb\r\n"
+ "a=rtcp-fb:51 transport-cc\r\n"
+ "a=rtcp-fb:51 ccm fir\r\n"
+ "a=rtcp-fb:51 nack\r\n"
+ "a=rtcp-fb:51 nack pli\r\n"
+ "a=fmtp:51 level-id=180;profile-id=2;tier-flag=0;tx-mode=SRST\r\n"
+ "a=rtpmap:52 rtx/90000\r\n"
+ "a=fmtp:52 apt=51\r\n"
+ "a=rtpmap:122 red/90000\r\n"
+ "a=rtpmap:123 rtx/90000\r\n"
+ "a=fmtp:123 apt=122\r\n"
+ "a=rtpmap:124 ulpfec/90000\r\n"
+ "a=rtpmap:53 flexfec-03/90000\r\n"
+ "a=rtcp-fb:53 goog-remb\r\n"
+ "a=rtcp-fb:53 transport-cc\r\n"
+ "a=fmtp:53 repair-window=10000000\r\n"
+ "m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126\r\n"
+ "c=IN IP4 0.0.0.0\r\n"
+ "a=rtcp:9 IN IP4 0.0.0.0\r\n"
+ "a=candidate:2529583990 1 udp 2113937151 3d9863a1-3b3d-48f6-9ff1-49c2bc04877f.local 61431 typ host generation 0 network-cost 999\r\n"
+ "a=ice-ufrag:z1TV\r\n"
+ "a=ice-pwd:RifL1wLzVBkO+l3mNSAqrSe8\r\n"
+ "a=ice-options:trickle\r\n"
+ "a=fingerprint:sha-256 70:59:D6:4B:A3:67:6E:BD:AC:6A:5E:0D:3B:95:92:BA:40:F4:86:12:84:69:6C:F8:F8:D1:A0:A3:D1:C6:46:39\r\n"
+ "a=setup:actpass\r\n"
+ "a=mid:1\r\n"
+ "a=extmap:14 urn:ietf:params:rtp-hdrext:ssrc-audio-level\r\n"
+ "a=extmap:2 http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time\r\n"
+ "a=extmap:4 http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01\r\n"
+ "a=extmap:9 urn:ietf:params:rtp-hdrext:sdes:mid\r\n"
+ "a=recvonly\r\n"
+ "a=rtcp-mux\r\n"
+ "a=rtcp-rsize\r\n"
+ "a=rtcp-xr:rcvr-rtt=all\r\n"
+ "a=rtpmap:111 opus/48000/2\r\n"
+ "a=rtcp-fb:111 transport-cc\r\n"
+ "a=fmtp:111 minptime=10;useinbandfec=1\r\n"
+ "a=rtpmap:63 red/48000/2\r\n"
+ "a=fmtp:63 111/111\r\n"
+ "a=rtpmap:9 G722/8000\r\n"
+ "a=rtpmap:0 PCMU/8000\r\n"
+ "a=rtpmap:8 PCMA/8000\r\n"
+ "a=rtpmap:13 CN/8000\r\n"
+ "a=rtpmap:110 telephone-event/48000\r\n"
+ "a=rtpmap:126 telephone-event/8000\r\n"
+ "m=application 9 UDP/DTLS/SCTP webrtc-datachannel\r\n"
+ "c=IN IP4 0.0.0.0\r\n"
+ "a=candidate:2529583990 1 udp 2113937151 3d9863a1-3b3d-48f6-9ff1-49c2bc04877f.local 52777 typ host generation 0 network-cost 999\r\n"
+ "a=ice-ufrag:z1TV\r\n"
+ "a=ice-pwd:RifL1wLzVBkO+l3mNSAqrSe8\r\n"
+ "a=ice-options:trickle\r\n"
+ "a=fingerprint:sha-256 70:59:D6:4B:A3:67:6E:BD:AC:6A:5E:0D:3B:95:92:BA:40:F4:86:12:84:69:6C:F8:F8:D1:A0:A3:D1:C6:46:39\r\n"
+ "a=setup:actpass\r\n"
+ "a=mid:2\r\n"
+ "a=sctp-port:5000\r\n"
+ "a=max-message-size:262144\r\n";