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
|
<html>
<head>
<meta charset="utf-8" />
<script type="application/javascript">var scriptRelativePath = "../";</script>
<script type="application/javascript" src="../pc.js"></script>
</head>
<body>
<script class="testbody" type="application/javascript">
createHTML({ title: "Test multiple identity fingerprints", bug: "1005152" });
// here we call the identity provider directly
async function getIdentityAssertion(fingerprint) {
const { IdpSandbox } = SpecialPowers.ChromeUtils.import(
'resource://gre/modules/media/IdpSandbox.jsm'
);
const sandbox = new IdpSandbox('example.com', 'idp.js', window);
const idp = SpecialPowers.wrap(await sandbox.start());
const assertion = SpecialPowers.wrap(await
idp.generateAssertion(JSON.stringify({ fingerprint }),
'https://example.com',
{}));
const assertionString = btoa(JSON.stringify(assertion));
sandbox.stop();
return assertionString;
}
// This takes a real fingerprint and makes some extra bad ones.
function makeFingerprints(algorithm, digest) {
const fingerprints = [];
fingerprints.push({ algorithm, digest });
for (var i = 0; i < 3; ++i) {
fingerprints.push({
algorithm,
digest: digest.replace(/:./g, ':' + i.toString(16))
});
}
return fingerprints;
}
const fingerprintRegex = /^a=fingerprint:(\S+) (\S+)/m;
const identityRegex = /^a=identity:(\S+)/m;
function fingerprintSdp(fingerprints) {
return fingerprints.map(fp => 'a=fInGeRpRiNt:' + fp.algorithm +
' ' + fp.digest + '\n').join('');
}
// Firefox only uses a single fingerprint.
// That doesn't mean we have it create SDP that describes two.
// This function synthesizes that SDP and tries to set it.
runNetworkTest(async () => {
// this one fails setRemoteDescription if the identity is not good
const pcStrict = new RTCPeerConnection({ peerIdentity: 'someone@example.com'});
// this one will be manually tweaked to have two fingerprints
const pcDouble = new RTCPeerConnection({});
const stream = await getUserMedia({ video: true });
ok(stream, 'Got test stream');
const [track] = stream.getTracks();
pcDouble.addTrack(track, stream);
try {
const offer = await pcDouble.createOffer();
ok(offer, 'Got offer');
const match = offer.sdp.match(fingerprintRegex);
if (!match) {
throw new Error('No fingerprint in offer SDP');
}
const fingerprints = makeFingerprints(match[1], match[2]);
const assertion = await getIdentityAssertion(fingerprints);
ok(assertion, 'Should have assertion');
const sdp = offer.sdp.slice(0, match.index) +
'a=identity:' + assertion + '\n' +
fingerprintSdp(fingerprints.slice(1)) +
offer.sdp.slice(match.index);
await pcStrict.setRemoteDescription({ type: 'offer', sdp });
ok(true, 'Modified fingerprints were accepted');
} catch (error) {
const e = SpecialPowers.wrap(error);
ok(false, 'error in test: ' +
(e.message ? (e.message + '\n' + e.stack) : e));
}
pcStrict.close();
pcDouble.close();
track.stop();
});
</script>
</body>
</html>
|