Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marten-seemann committed Mar 18, 2024
0 parents commit 03476b3
Show file tree
Hide file tree
Showing 7 changed files with 225 additions and 0 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Build Docker images
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ github.event_name == 'push' }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build endpoint
uses: docker/build-push-action@v5
with:
push: ${{ github.event_name == 'push' }}
tags: martenseemann/chrome-webtransport-interop-runner:latest
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM martenseemann/quic-network-simulator-endpoint:latest AS builder

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && \
apt-get install -y gnupg2 python3 python3-pip unzip

RUN pip3 install selenium

RUN wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list

RUN apt-get update && \
apt-get install -y google-chrome-beta


ENV CHROMEDRIVER_VERSION="123.0.6312.46"
RUN wget -q "https://storage.googleapis.com/chrome-for-testing-public/$CHROMEDRIVER_VERSION/linux64/chromedriver-linux64.zip" && \
unzip chromedriver-linux64.zip && \
mv chromedriver-linux64/chromedriver /usr/bin && \
chmod +x /usr/bin/chromedriver && \
rm chromedriver-linux64.zip

COPY script_template.js run.py run_endpoint.sh /

ENTRYPOINT [ "/run_endpoint.sh" ]
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Marten Seemann

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Chrome Image for the WebTransport Interop Runner

This [Interop Runner](https://github.com/quic-interop/quic-interop-runner) image uses the [Dev Channel](https://www.chromium.org/getting-involved/dev-channel) release for Linux.
Chrome is controlled by [Selenium](https://www.selenium.dev/) using [ChromeDriver](https://chromedriver.chromium.org/).
59 changes: 59 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3

import argparse
import os
import array

from urllib.parse import urlparse

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

def get_args():
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--certhash", help="server certificate hash")
return parser.parse_args()

DOWNLOADS = "/downloads/"

requests = os.environ["REQUESTS"].split(" ")

options = webdriver.ChromeOptions()
options.gpu = False
options.binary_location = "/usr/bin/google-chrome-beta"
options.add_argument("--no-sandbox")
options.add_argument("--log-net-log=/logs/chrome.json")
options.add_argument("--net-log-capture-mode=IncludeSensitive")
options.add_argument("--enable-experimental-web-platform-features")
options.add_argument("--enable-features=WebTransport,WebTransportHttp3")
options.add_argument("--headless=new")

o = urlparse(requests[0])
server = o.netloc
path = o.path

with open("script_template.js") as f:
script = f.read()
script = script.replace("%%SERVER%%", server)
script = script.replace("%%TESTCASE%%", os.environ["TESTCASE"])
script = script.replace("%%CERTHASH%%", get_args().certhash)

with open('/script.js', 'w') as file:
file.write(script)

with open('/index.html', 'w') as file:
file.write("<html><head><script src='script.js'></script></head></html>")

service = Service(executable_path="/usr/bin/chromedriver")
driver = webdriver.Chrome(service=service, options=options)
driver.get("file:///index.html")
data = driver.execute_script("return request('" + path + "');")

a = array.array('B')
a.extend(data)
with open(DOWNLOADS + path, 'wb') as file:
file.write(a)

driver.close()
22 changes: 22 additions & 0 deletions run_endpoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Set up the routing needed for the simulation.
/setup.sh

if [ ! -z "$TESTCASE" ]; then
case "$TESTCASE" in
"handshake") ;;
*) exit 127 ;;
esac
fi

service dbus start

CERTHASH=$(openssl x509 -in /certs/cert.pem -outform DER | openssl dgst -sha256 -binary | base64)
echo "Certificate hash: $CERTHASH"

google-chrome-beta --version

/wait-for-it.sh sim:57832 -s -t 30

python3 run.py --certhash "$CERTHASH"
70 changes: 70 additions & 0 deletions script_template.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
function base64ToArrayBuffer(base64) {
var binaryString = atob(base64);
var bytes = new Uint8Array(binaryString.length);
for (var i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i);
}
return bytes.buffer;
}

async function establishSession(url) {
const transport = new WebTransport(url, {
"serverCertificateHashes": [{
"algorithm": "sha-256",
"value": base64ToArrayBuffer("%%CERTHASH%%")
}]
});

transport.closed.then(() => {
console.log(`The HTTP/3 connection to ${url} closed gracefully.`);
}).catch((error) => {
console.error(`The HTTP/3 connection to ${url} closed due to ${error}.`);
});

// Once .ready fulfills, the connection can be used.
await transport.ready;
return transport;
}

async function readFromStream(reader) {
let chunks = [];
let totalLength = 0;

while (true) {
const { value, done } = await reader.read();
if (done) { break; }
chunks.push(value);
totalLength += value.length;
}

// Combine all chunks into a single Uint8Array
let data = new Uint8Array(totalLength);
let position = 0;
for (let chunk of chunks) {
data.set(chunk, position);
position += chunk.length;
}
return data
}

async function request(path) {
const transport = await establishSession('https://%%SERVER%%/webtransport');
const data = new TextEncoder().encode("GET " + path + "\r\n");

const { writable, readable } = await transport.createBidirectionalStream();
console.log("Opened stream.");

const writer = writable.getWriter();
await writer.write(data);
try {
await writer.close();
console.log("All data has been sent on stream.");
} catch(error) {
console.error(`An error occurred: ${error}`);
}

const rsp = await readFromStream(readable.getReader());
transport.close();
return rsp;
}

0 comments on commit 03476b3

Please sign in to comment.