tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_http3_kyber.js (2326B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 registerCleanupFunction(async () => {
      6  Services.prefs.clearUserPref("security.tls.enable_kyber");
      7  Services.prefs.clearUserPref("network.http.http3.enable_kyber");
      8  http3_clear_prefs();
      9 });
     10 
     11 add_task(async function setup() {
     12  Services.prefs.setBoolPref("security.tls.enable_kyber", true);
     13  Services.prefs.setBoolPref("network.http.http3.enable_kyber", true);
     14  await http3_setup_tests("h3");
     15 });
     16 
     17 let Http3Listener = function () {};
     18 
     19 Http3Listener.prototype = {
     20  expectedKeaGroup: undefined,
     21 
     22  onStartRequest: function testOnStartRequest(request) {
     23    Assert.equal(request.status, Cr.NS_OK);
     24    Assert.equal(request.responseStatus, 200);
     25 
     26    Assert.equal(request.securityInfo.keaGroupName, this.expectedKeaGroup);
     27  },
     28 
     29  onDataAvailable: function testOnDataAvailable(request, stream, off, cnt) {
     30    read_stream(stream, cnt);
     31  },
     32 
     33  onStopRequest: function testOnStopRequest(request) {
     34    let httpVersion = "";
     35    try {
     36      httpVersion = request.protocolVersion;
     37    } catch (e) {}
     38    Assert.equal(httpVersion, "h3");
     39 
     40    this.finish();
     41  },
     42 };
     43 
     44 function chanPromise(chan, listener) {
     45  return new Promise(resolve => {
     46    function finish(result) {
     47      resolve(result);
     48    }
     49    listener.finish = finish;
     50    chan.asyncOpen(listener);
     51  });
     52 }
     53 
     54 function makeChan(uri) {
     55  let chan = NetUtil.newChannel({
     56    uri,
     57    loadUsingSystemPrincipal: true,
     58  }).QueryInterface(Ci.nsIHttpChannel);
     59  chan.loadFlags = Ci.nsIChannel.LOAD_INITIAL_DOCUMENT_URI;
     60  return chan;
     61 }
     62 
     63 add_task(async function test_kyber_success() {
     64  let listener = new Http3Listener();
     65  listener.expectedKeaGroup = "mlkem768x25519";
     66  let chan = makeChan("https://foo.example.com");
     67  await chanPromise(chan, listener);
     68 });
     69 
     70 add_task(async function test_no_kyber_on_retry() {
     71  Services.obs.notifyObservers(null, "net:cancel-all-connections");
     72 
     73  let listener = new Http3Listener();
     74  listener.expectedKeaGroup = "x25519";
     75  let chan = makeChan("https://foo.example.com");
     76  chan.QueryInterface(Ci.nsIHttpChannelInternal).tlsFlags =
     77    Ci.nsIHttpChannelInternal.TLS_FLAG_CONFIGURE_AS_RETRY;
     78  await chanPromise(chan, listener);
     79 });