Hash all fingerprints into the manual security check
The manual check used to show the first 8 bytes of the first fingerprint each SDP named, so an interposer could add its own certificate beside the claimed one and the codes still matched. Now each code is the first 16 bytes of a SHA-256 over every fingerprint the SDP names, also ones hidden in other lines, so whatever the browser uses changes the code. Without a fingerprint on either side the connection ends. End-to-end tests try a claimed certificate in several hiding places. The README says that a working connection isn't necessarily direct and what the meeting tracker sees, TODO.md lists hardening from a security review. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ae871a2647
commit
ae1e3bef9b
5 files changed
+205
-38
No files matched your search
+46
-11
@@ -508,23 +508,45 @@ describe('messages', () => {
|
||||
expect(() => decode('not base64!', 'answer')).toThrow('not a valid answer, copy all of it');
|
||||
});
|
||||
|
||||
it('counts every fingerprint once, at session or media level', () => {
|
||||
it('counts every fingerprint once, at session or media level, also hidden ones', () => {
|
||||
const sdp =
|
||||
'v=0\r\na=fingerprint:sha-256 AB:CD\r\nm=application\r\na=fingerprint:SHA-256 ab:cd\r\na=fingerprint:sha-1 01\r\n';
|
||||
expect(fingerprints(sdp)).toEqual(['sha-1 01', 'sha-256 ab:cd']);
|
||||
'v=0\r\na=fingerprint:sha-256 AB:CD\r\nm=application\r\na=fingerprint:SHA-256 ab:cd\na=fingerprint:sha-1\t01\r\n' +
|
||||
// Hidden in lines the browser reads otherwise.
|
||||
'a=candidate:1 1 udp 1 127.0.0.1 9 typ host a=fingerprint:sha-256 01:02\r\n' +
|
||||
'a=x-decoy:a=fingerprint:sha-256 03:04\r\na=x-decoy:\ra=fingerprint:sha-256 05:06\r\n' +
|
||||
// A bare CR doesn't end the line for the browser.
|
||||
'a=fingerprint:sha-256\r07:08\r\n';
|
||||
expect(fingerprints(sdp)).toEqual([
|
||||
'sha-1 01',
|
||||
'sha-256 01:02',
|
||||
'sha-256 03:04',
|
||||
'sha-256 05:06',
|
||||
'sha-256 07:08',
|
||||
'sha-256 ab:cd',
|
||||
]);
|
||||
});
|
||||
|
||||
it('shows the first 8 bytes of both fingerprints for the check', () => {
|
||||
const sdp = (fingerprint: string) => ({ sdp: `v=0\r\na=fingerprint:sha-256 ${fingerprint}\r\n` });
|
||||
it('shows the first 16 bytes of a hash over all fingerprints for the check', async () => {
|
||||
const code = (list: string[]) =>
|
||||
createHash('sha256')
|
||||
.update(JSON.stringify(list))
|
||||
.digest('hex')
|
||||
.slice(0, 32)
|
||||
.toUpperCase()
|
||||
.match(/../g)!
|
||||
.join(' ');
|
||||
const pc = {
|
||||
localDescription: sdp('aa:bb:cc:dd:ee:ff:00:11:22:33'),
|
||||
remoteDescription: sdp('01:02:03:04:05:06:07:08:09'),
|
||||
localDescription: { sdp: 'v=0\r\na=fingerprint:sha-256 aa:bb\r\n' },
|
||||
remoteDescription: { sdp: 'v=0\r\na=fingerprint:sha-256 0A:0B\r\nm=application\r\na=fingerprint:sha-1 0c\r\n' },
|
||||
} as RTCPeerConnection;
|
||||
expect(securityCheck(pc)).toEqual({ local: 'AA BB CC DD EE FF 00 11', remote: '01 02 03 04 05 06 07 08' });
|
||||
expect(securityCheck({ localDescription: null, remoteDescription: null } as RTCPeerConnection)).toEqual({
|
||||
local: '?',
|
||||
remote: '?',
|
||||
expect(await securityCheck(pc)).toEqual({
|
||||
local: code(['sha-256 aa:bb']),
|
||||
remote: code(['sha-1 0c', 'sha-256 0a:0b']),
|
||||
});
|
||||
expect(await securityCheck({ ...pc, remoteDescription: { sdp: 'v=0\r\n' } } as RTCPeerConnection)).toBeUndefined();
|
||||
expect(
|
||||
await securityCheck({ localDescription: null, remoteDescription: null } as RTCPeerConnection),
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it('names the side without a public address', () => {
|
||||
@@ -1170,6 +1192,19 @@ describe('manual exchange', () => {
|
||||
expect(openPeers()).toEqual([]);
|
||||
});
|
||||
|
||||
it('shows other codes for a peer that named a second certificate', async () => {
|
||||
const [sender, receiver] = [side(), side()];
|
||||
const { offer, accept } = await createOffer(file(10), sender.events, sender.signal);
|
||||
// The real one first, the fake one connects too. FakePeer only knows the first.
|
||||
const tampered = btoa(`${atob(offer)}m=application\r\na=fingerprint:sha-256 AA:BB\r\n`);
|
||||
await accept(await answerOffer(tampered, receiver.events, receiver.signal));
|
||||
await until(() => sender.checks[0] && receiver.checks[0]);
|
||||
const [own, peer] = [sender.checks[0]!, receiver.checks[0]!];
|
||||
expect(peer.remote).not.toBe(own.local);
|
||||
expect(peer.local).toBe(own.remote);
|
||||
expect(receiver.status()).toBe('wait: Compare the security codes above with the sender');
|
||||
});
|
||||
|
||||
it('reports a broken offer and answer, the offer stays good for the right answer', async () => {
|
||||
const receiver = side();
|
||||
await expect(answerOffer(btoa('v=0 but nothing else'), receiver.events, receiver.signal)).rejects.toThrow(
|
||||
|
||||
Reference in new issue
Block a user