Bug 1523562 [wpt PR 14908] - Adds pre shared key support to RTCQuicTransport., a=testonly

Automatic update from web-platform-tests
Adds pre shared key support to RTCQuicTransport.

This change adds the PSK APIs to the RTCQuicTransport object. This is
done with a readonly key, connect() and listen() methods. This change
keeps the C++ objects certificate support with the current APIs, but
removes these from being exposed in the web idl file. Tests are updated
by moving web platform tests that involve certificates into C++
tests.

Bug: 874296
Change-Id: I58500dca36bfdb6fdb605d540ccbfc49ed6ec878
Reviewed-on: https://chromium-review.googlesource.com/c/1415839
Commit-Queue: Seth Hampson <shampson@chromium.org>
Reviewed-by: Steve Anton <steveanton@chromium.org>
Cr-Commit-Position: refs/heads/master@{#624411}

--

wpt-commits: b759655abcdddff933d46d6e98f0eac0fc31bd41
wpt-pr: 14908
This commit is contained in:
Seth Hampson 2019-01-31 18:58:05 +00:00 коммит произвёл James Graham
Родитель f719065022
Коммит 5c4db2b658
2 изменённых файлов: 114 добавлений и 137 удалений

Просмотреть файл

@ -7,21 +7,11 @@
// makeIceTransport
// makeGatherAndStartTwoIceTransports
// Return a promise to generate an RTCCertificate with the given keygen
// algorithm or a default one if none provided.
function generateCertificate(keygenAlgorithm) {
return RTCPeerConnection.generateCertificate({
name: 'ECDSA',
namedCurve: 'P-256',
...keygenAlgorithm,
});
}
// Construct an RTCQuicTransport instance with the given RTCIceTransport
// instance and the given certificates. The RTCQuicTransport instance will be
// automatically cleaned up when the test finishes.
function makeQuicTransport(t, iceTransport, certificates) {
const quicTransport = new RTCQuicTransport(iceTransport, certificates);
function makeQuicTransport(t, iceTransport) {
const quicTransport = new RTCQuicTransport(iceTransport);
t.add_cleanup(() => quicTransport.stop());
return quicTransport;
}
@ -30,9 +20,8 @@ function makeQuicTransport(t, iceTransport, certificates) {
// and a single, newly-generated certificate. The RTCQuicTransport and
// RTCIceTransport instances will be automatically cleaned up when the test
// finishes.
async function makeStandaloneQuicTransport(t) {
const certificate = await generateCertificate();
return makeQuicTransport(t, makeIceTransport(t), [ certificate ]);
function makeStandaloneQuicTransport(t) {
return makeQuicTransport(t, makeIceTransport(t));
}
// Construct two RTCQuicTransport instances and each call start() with the other
@ -40,17 +29,16 @@ async function makeStandaloneQuicTransport(t) {
// Returns a 2-list:
// [ server RTCQuicTransport,
// client RTCQuicTransport ]
async function makeAndStartTwoQuicTransports(t) {
const [ localCertificate, remoteCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
function makeAndStartTwoQuicTransports(t) {
const [ localIceTransport, remoteIceTransport ] =
makeGatherAndStartTwoIceTransports(t);
const localQuicTransport =
makeQuicTransport(t, localIceTransport, [ localCertificate ]);
makeQuicTransport(t, localIceTransport);
const remoteQuicTransport =
makeQuicTransport(t, remoteIceTransport, [ remoteCertificate ]);
localQuicTransport.start(remoteQuicTransport.getLocalParameters());
remoteQuicTransport.start(localQuicTransport.getLocalParameters());
makeQuicTransport(t, remoteIceTransport);
const remote_key = remoteQuicTransport.getKey();
localQuicTransport.listen(remote_key);
remoteQuicTransport.connect();
return [ localQuicTransport, remoteQuicTransport ];
}

Просмотреть файл

@ -17,153 +17,50 @@
// makeAndGatherTwoIceTransports
// The following helper functions are called from RTCQuicTransport-helper.js:
// generateCertificate
// makeQuicTransport
// makeStandaloneQuicTransport
// makeAndStartTwoQuicTransports
// makeTwoConnectedQuicTransports
promise_test(async t => {
const certificate = await generateCertificate();
test(t => {
const iceTransport = makeIceTransport(t);
const quicTransport = makeQuicTransport(t, iceTransport, [ certificate ]);
const quicTransport = makeQuicTransport(t, iceTransport);
assert_equals(quicTransport.transport, iceTransport,
'Expect transport to be the same as the one passed in the constructor.');
assert_equals(quicTransport.state, 'new', `Expect state to be 'new'.`);
assert_object_equals(quicTransport.getLocalParameters(),
{ role: 'auto', fingerprints: certificate.getFingerprints() },
'Expect local parameters to be initialized.');
assert_equals(quicTransport.getRemoteParameters(), null,
'Expect no remote parameters.');
assert_array_equals(quicTransport.getCertificates(), [ certificate ],
'Expect one certificate.');
assert_array_equals(quicTransport.getRemoteCertificates(), [],
'Expect no remote certificates.');
}, 'RTCQuicTransport initial properties are set.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, makeIceTransport(t),
[ firstCertificate, secondCertificate ]);
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getCertificates() returns the certificates passed in the constructor.');
promise_test(async t => {
const [ firstCertificate, secondCertificate ] =
await Promise.all([ generateCertificate(), generateCertificate() ]);
const quicTransport =
makeQuicTransport(t, makeIceTransport(t),
[ firstCertificate, secondCertificate ]);
assert_object_equals(quicTransport.getLocalParameters(), {
role: 'auto',
fingerprints:
[ firstCertificate.getFingerprints()[0],
secondCertificate.getFingerprints()[0] ],
});
assert_array_equals(quicTransport.getCertificates(),
[ firstCertificate, secondCertificate ]);
}, 'getLocalParameters() has fingerprints for all certificates passed in the ' +
'constructor.');
promise_test(async t => {
const expiredCertificate = await generateCertificate({ expires: 0 });
assert_throws(new TypeError(),
() => makeQuicTransport(t, makeIceTransport(t), [ expiredCertificate ]));
}, 'RTCQuicTransport constructor throws if passed an expired certificate.');
promise_test(async t => {
const certificate = await generateCertificate();
test(t => {
const iceTransport = makeIceTransport(t);
iceTransport.stop();
assert_throws('InvalidStateError',
() => makeQuicTransport(t, iceTransport, [ certificate ]));
() => makeQuicTransport(t, iceTransport));
}, 'RTCQuicTransport constructor throws if passed a closed RTCIceTransport.');
promise_test(async t => {
const certificate = await generateCertificate();
test(t => {
const iceTransport = makeIceTransport(t);
const firstQuicTransport =
makeQuicTransport(t, iceTransport, [ certificate ]);
makeQuicTransport(t, iceTransport);
assert_throws('InvalidStateError',
() => makeQuicTransport(t, iceTransport, [ certificate ]));
() => makeQuicTransport(t, iceTransport));
}, 'RTCQuicTransport constructor throws if passed an RTCIceTransport that ' +
'already has an active RTCQuicTransport.');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_equals(quicTransport.state, 'closed');
}, `stop() changes state to 'closed'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_equals(quicTransport.state, 'closed');
}, `RTCIceTransport.stop() changes RTCQuicTransport.state to 'closed'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.start(quicTransport.getLocalParameters());
assert_equals(quicTransport.state, 'new');
}, 'start() with a non-started RTCIceTransport does not change state.');
promise_test(async t => {
const certificate = await generateCertificate();
const [ localIceTransport, remoteIceTransport ] =
makeAndGatherTwoIceTransports(t);
const quicTransport =
makeQuicTransport(t, localIceTransport, [ certificate ]);
quicTransport.start(quicTransport.getLocalParameters());
const iceTransportWatcher =
new EventWatcher(t, remoteIceTransport, 'icecandidate');
await iceTransportWatcher.wait_for('icecandidate');
localIceTransport.start(remoteIceTransport.getLocalParameters(),
'controlling');
assert_equals(quicTransport.state, 'connecting');
}, 'start() with a non-started RTCIceTransport later changes state to ' +
`'connecting' once the RTCIceTransport.start() is called.`);
promise_test(async t => {
const certificate = await generateCertificate();
const [ localIceTransport, remoteIceTransport ] =
makeAndGatherTwoIceTransports(t);
const quicTransport =
makeQuicTransport(t, localIceTransport, [ certificate ]);
const iceTransportWatcher =
new EventWatcher(t, remoteIceTransport, 'icecandidate');
await iceTransportWatcher.wait_for('icecandidate');
localIceTransport.start(remoteIceTransport.getLocalParameters());
quicTransport.start(quicTransport.getLocalParameters());
assert_equals(quicTransport.state, 'connecting');
}, `start() with a started RTCIceTransport changes state to 'connecting'.`);
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called after stop().');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called after the RTCIceTransport has stopped.');
promise_test(async t => {
const quicTransport = await makeStandaloneQuicTransport(t);
quicTransport.start(quicTransport.getLocalParameters());
assert_throws('InvalidStateError',
() => quicTransport.start(quicTransport.getLocalParameters()));
}, 'start() throws if called twice.');
promise_test(async t => {
const [ localQuicTransport, remoteQuicTransport ] =
await makeAndStartTwoQuicTransports(t);
makeAndStartTwoQuicTransports(t);
const localWatcher = new EventWatcher(t, localQuicTransport, 'statechange');
const remoteWatcher = new EventWatcher(t, remoteQuicTransport, 'statechange');
await Promise.all([
@ -185,5 +82,97 @@ promise_test(async t => {
assert_equals(remoteQuicTransport.state, 'closed');
}, `stop() fires a statechange event to 'closed' on the remote transport`);
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.connect();
assert_equals(quicTransport.state, 'connecting');
}, `connect() changes state to 'connecting'.`);
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.connect();
assert_throws('InvalidStateError',
() => quicTransport.connect());
}, 'connect() throws if already called connect().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.listen(new Uint8Array([12345]));
assert_throws('InvalidStateError',
() => quicTransport.connect());
}, 'connect() throws if already called listen().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_throws('InvalidStateError',
() => quicTransport.connect());
}, 'connect() throws after stop().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_throws('InvalidStateError',
() => quicTransport.connect());
}, 'connect() throws if called after RTCIceTransport has stopped.');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.listen(new Uint8Array([12345]));
assert_equals(quicTransport.state, 'connecting');
}, `listen() changes state to 'connecting'.`);
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.connect();
assert_throws('InvalidStateError',
() => quicTransport.listen(new Uint8Array([12345])));
}, 'listen() throws if already called connect().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.listen(new Uint8Array([12345]));
assert_throws('InvalidStateError',
() => quicTransport.listen(new Uint8Array([12345])));
}, 'listen() throws if already called listen().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.stop();
assert_throws('InvalidStateError',
() => quicTransport.listen(new Uint8Array([12345])));
}, 'listen() throws after stop().');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
quicTransport.transport.stop();
assert_throws('InvalidStateError',
() => quicTransport.listen(new Uint8Array([12345])));
}, 'listen() throws if called after RTCIceTransport has stopped.');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
const key = quicTransport.getKey();
assert_equals(key.byteLength, 16);
}, 'RTCQuicTransport.getKey() attribute is 16 bytes.');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
const key = new Uint8Array();
assert_throws('NotSupportedError',
() => quicTransport.listen(key));
}, 'listen() throws if given an empty key.');
test(t => {
const quicTransport = makeStandaloneQuicTransport(t);
const key = quicTransport.getKey();
let update_key = new Uint8Array(key);
for (let i = 0; i < update_key.length; i++) {
update_key[i] = 0;
}
const new_key = quicTransport.getKey();
assert_not_equals(update_key, new Uint8Array(new_key));
}, 'Cannot mutate key retrieved from getKey().');
</script>