test_fingerprints.html (3148B)
1 <html> 2 <head> 3 <meta charset="utf-8" /> 4 <script type="application/javascript">var scriptRelativePath = "../";</script> 5 <script type="application/javascript" src="../pc.js"></script> 6 </head> 7 <body> 8 <script class="testbody" type="application/javascript"> 9 createHTML({ title: "Test multiple identity fingerprints", bug: "1005152" }); 10 11 // here we call the identity provider directly 12 async function getIdentityAssertion(fingerprint) { 13 const { IdpSandbox } = SpecialPowers.ChromeUtils.importESModule( 14 'resource://gre/modules/media/IdpSandbox.sys.mjs' 15 ); 16 const sandbox = new IdpSandbox('example.com', 'idp.js', window); 17 const idp = SpecialPowers.wrap(await sandbox.start()); 18 const assertion = SpecialPowers.wrap(await 19 idp.generateAssertion(JSON.stringify({ fingerprint }), 20 'https://example.com', 21 {})); 22 const assertionString = btoa(JSON.stringify(assertion)); 23 sandbox.stop(); 24 return assertionString; 25 } 26 27 // This takes a real fingerprint and makes some extra bad ones. 28 function makeFingerprints(algorithm, digest) { 29 const fingerprints = []; 30 fingerprints.push({ algorithm, digest }); 31 for (var i = 0; i < 3; ++i) { 32 fingerprints.push({ 33 algorithm, 34 digest: digest.replace(/:./g, ':' + i.toString(16)) 35 }); 36 } 37 return fingerprints; 38 } 39 40 const fingerprintRegex = /^a=fingerprint:(\S+) (\S+)/m; 41 const identityRegex = /^a=identity:(\S+)/m; 42 43 function fingerprintSdp(fingerprints) { 44 return fingerprints.map(fp => 'a=fInGeRpRiNt:' + fp.algorithm + 45 ' ' + fp.digest + '\n').join(''); 46 } 47 48 // Firefox only uses a single fingerprint. 49 // That doesn't mean we have it create SDP that describes two. 50 // This function synthesizes that SDP and tries to set it. 51 52 runNetworkTest(async () => { 53 // this one fails setRemoteDescription if the identity is not good 54 const pcStrict = new RTCPeerConnection({ peerIdentity: 'someone@example.com'}); 55 // this one will be manually tweaked to have two fingerprints 56 const pcDouble = new RTCPeerConnection({}); 57 58 const stream = await getUserMedia({ video: true }); 59 ok(stream, 'Got test stream'); 60 const [track] = stream.getTracks(); 61 pcDouble.addTrack(track, stream); 62 try { 63 const offer = await pcDouble.createOffer(); 64 ok(offer, 'Got offer'); 65 const match = offer.sdp.match(fingerprintRegex); 66 if (!match) { 67 throw new Error('No fingerprint in offer SDP'); 68 } 69 const fingerprints = makeFingerprints(match[1], match[2]); 70 const assertion = await getIdentityAssertion(fingerprints); 71 ok(assertion, 'Should have assertion'); 72 73 const sdp = offer.sdp.slice(0, match.index) + 74 'a=identity:' + assertion + '\n' + 75 fingerprintSdp(fingerprints.slice(1)) + 76 offer.sdp.slice(match.index); 77 78 await pcStrict.setRemoteDescription({ type: 'offer', sdp }); 79 ok(true, 'Modified fingerprints were accepted'); 80 } catch (error) { 81 const e = SpecialPowers.wrap(error); 82 ok(false, 'error in test: ' + 83 (e.message ? (e.message + '\n' + e.stack) : e)); 84 } 85 pcStrict.close(); 86 pcDouble.close(); 87 track.stop(); 88 }); 89 </script> 90 </body> 91 </html>