-
-
Notifications
You must be signed in to change notification settings - Fork 12
Reimplement library on top of rustls::kernel
API (continuation of #61)
#62
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cxw620
wants to merge
33
commits into
rustls:main
Choose a base branch
from
cxw620:use-rustls-kernel-connection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
7216686
chore(ktls): sort and update deps
cxw620 197ac8a
PR 62: partial: optimize workspace
cxw620 fed94a7
PR 62: partial: add rustfmt
cxw620 f19c87d
PR 62: partial: add lints like rustls
cxw620 9ea2dce
refactor(setup): setup ULP and TLS params [NOT COMPILED]
cxw620 91995c9
PR 62: partial: make logging optional [NOT COMPILED]
cxw620 4545957
PR 62: partial: implement enum KeyUpdateRequest since rustls doesn't …
cxw620 7742408
refactor(ktls): unified error type [NOT COMPILED]
cxw620 f95b5da
PR 62: partial: implement KtlsStream [NOT COMPILED]
cxw620 7e691ed
PR 62: partial: implement Read / Write for KtlsStream
cxw620 591993d
PR 62: partial: optional implement AsyncRead / AsyncWrite for KtlsStream
cxw620 02aa230
refactor(probe): probe ktls compatibility
cxw620 0db74e5
PR 62: partial: export most-frequently-used type
cxw620 25b5909
PR 62: partial: prepare ktls-util crate
cxw620 722f28e
PR 62: partial: implement KtlsConnector in ktls-util
cxw620 0fa74fe
PR 62: partial: implement KtlsAcceptor in ktls-util
cxw620 677c79d
PR 62: partial: export raw-apis of KtlsStream
cxw620 e58ecf1
PR 62: partial: tests and examples
cxw620 4dd5fe7
PR 62: partial: adjust Justfile
cxw620 b3dfee6
PR 62: partial: adjust CI tests
cxw620 f21ef5f
PR 62: partial: add CI: kernel compatibility test
cxw620 2f43fd6
PR 62: partial: fix MSRV and clippy
cxw620 87ad314
PR 62: partial: cargo docs
cxw620 5ea6fa1
PR 62: partial: cleanup
cxw620 9f1fe01
PR 62: partial: adjust README
cxw620 449bf63
fix(ci): checkout no persist credentials
cxw620 2c838fa
[skip ci] apply rustfmt
cxw620 8a44203
refactor: replace pin-project with lite version
cxw620 d9b529b
refactor: remove thiserror (syn)
cxw620 9605c84
refactor: adjust default features
cxw620 54af664
fix: clippy and cargo-doc, and feature flag
cxw620 1e6fdb5
fix: add Debug impl back for KtlsStream
cxw620 cd4f967
fix: update debug desc of InvalidCryptoInfo::UnsupportedCipherSuite
cxw620 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
merge_group: | ||
|
||
permissions: | ||
contents: read | ||
|
||
env: | ||
RUSTFLAGS: -Dwarnings | ||
RUST_BACKTRACE: 1 | ||
|
||
jobs: | ||
test: | ||
name: Test (Rust ${{matrix.toolchain}}, target ${{matrix.target}}) | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
toolchain: ["nightly", "beta", "stable"] | ||
target: ["x86_64-unknown-linux-gnu", "x86_64-unknown-linux-musl"] | ||
timeout-minutes: 45 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: ${{matrix.toolchain}} | ||
components: llvm-tools, clippy, rust-src | ||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: just,cargo-llvm-cov,cargo-nextest | ||
- name: Enable type layout randomization | ||
if: matrix.toolchain == 'nightly' | ||
run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV | ||
- run: sudo apt-get update && sudo apt-get install -y musl-tools | ||
if: endsWith(matrix.target, 'musl') | ||
- run: rustup target add ${{matrix.target}} | ||
- run: just example client --target ${{matrix.target}} | ||
- run: just build --tests --release --target ${{matrix.target}} | ||
- run: just ci-test --target ${{matrix.target}} | ||
|
||
msrv: | ||
name: MSRV | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 45 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: 1.77.0 | ||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: just | ||
- run: just build --package ktls | ||
- run: just build --package ktls-sys | ||
- run: just build --package ktls-test | ||
- run: just build --package ktls-util | ||
|
||
doc: | ||
name: Documentation | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 45 | ||
env: | ||
RUSTDOCFLAGS: -Dwarnings | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: dtolnay/rust-toolchain@nightly | ||
- uses: dtolnay/install@cargo-docs-rs | ||
- run: cargo docs-rs --package ktls | ||
|
||
clippy: | ||
name: Clippy | ||
runs-on: ubuntu-latest | ||
if: github.event_name != 'pull_request' | ||
timeout-minutes: 45 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: 1.77.0 | ||
components: clippy | ||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: just | ||
- run: just clippy | ||
|
||
coverage: | ||
name: Test Coverage | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
- uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: 1.77.0 | ||
components: llvm-tools, clippy, rust-src | ||
- uses: taiki-e/install-action@v2 | ||
with: | ||
tool: just,cargo-llvm-cov,cargo-nextest | ||
- run: just example client | ||
- run: just build --tests --release | ||
- run: just ci-test | ||
- name: Upload coverage information | ||
run: | | ||
curl -Os https://uploader.codecov.io/latest/linux/codecov | ||
chmod +x codecov | ||
./codecov |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
# Credits: https://github.com/tokio-rs/io-uring/blob/master/.github/workflows/kernel-version-test.yml | ||
# | ||
# Tests kTLS functionality across multiple kernel versions. | ||
# Default matrix: 6.12, 6.6, 6.1, 5.15, 5.10, 5.4 | ||
# Manual trigger supports custom space-separated version list. | ||
|
||
name: Kernel Compatibility Test | ||
|
||
on: | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
merge_group: | ||
workflow_dispatch: | ||
inputs: | ||
kernel_versions: | ||
description: "Space-separated list of Linux kernel versions to test (e.g., '6.12 6.6 6.1.148 5.15.189 5.10.240 5.4.296')" | ||
required: true | ||
|
||
permissions: | ||
contents: read | ||
|
||
jobs: | ||
prepare-matrix: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
matrix: ${{ steps.set-matrix.outputs.matrix }} | ||
steps: | ||
- name: Set matrix | ||
id: set-matrix | ||
run: | | ||
if [ -n "${GITHUB_EVENT_INPUTS_KERNEL_VERSIONS}" ]; then | ||
# Manual trigger with custom versions | ||
versions="${GITHUB_EVENT_INPUTS_KERNEL_VERSIONS}" | ||
echo "Using manual input versions: $versions" | ||
else | ||
# Default versions for push events | ||
versions="6.12 6.6 6.1.148 5.15.189 5.10.240 5.4.296" | ||
echo "Using default versions: $versions" | ||
fi | ||
|
||
# Convert space-separated list to JSON array | ||
json_array=$(echo "$versions" | tr ' ' '\n' | jq -R . | jq -s -c .) | ||
echo "matrix={\"kernel_version\":$json_array}" >> $GITHUB_OUTPUT | ||
echo "Generated matrix: {\"kernel_version\":$json_array}" | ||
env: | ||
GITHUB_EVENT_INPUTS_KERNEL_VERSIONS: ${{ github.event.inputs.kernel_versions }} | ||
|
||
build: | ||
needs: prepare-matrix | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}} | ||
fail-fast: false | ||
env: | ||
KERNEL_VERSION: ${{ matrix.kernel_version }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
with: | ||
persist-credentials: false | ||
|
||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y \ | ||
bison flex libelf-dev \ | ||
qemu-system-x86 busybox-static cpio xz-utils wget e2fsprogs \ | ||
musl-tools | ||
|
||
- name: Install Rust 1.77.0 | ||
uses: dtolnay/rust-toolchain@master | ||
with: | ||
toolchain: 1.77.0 | ||
targets: x86_64-unknown-linux-musl | ||
|
||
- name: Generate the test binary | ||
run: | | ||
cargo build --package ktls-test --example client --release --target x86_64-unknown-linux-musl | ||
|
||
- name: Cache Linux source | ||
id: cache-kernel | ||
uses: actions/cache@v4 | ||
with: | ||
path: linux-${{ env.KERNEL_VERSION }} | ||
key: kernel-${{ env.KERNEL_VERSION }} | ||
|
||
- name: Download & build Linux kernel | ||
if: steps.cache-kernel.outputs.cache-hit != 'true' | ||
run: | | ||
MAJOR=${KERNEL_VERSION%%.*} | ||
wget https://cdn.kernel.org/pub/linux/kernel/v${MAJOR}.x/linux-${KERNEL_VERSION}.tar.xz | ||
tar xf linux-${KERNEL_VERSION}.tar.xz | ||
cd linux-${KERNEL_VERSION} | ||
|
||
# Generate the default config | ||
make defconfig | ||
|
||
# Enable essentials as built-ins | ||
scripts/config --enable CONFIG_DEVTMPFS | ||
scripts/config --enable CONFIG_DEVTMPFS_MOUNT | ||
|
||
# Enable virtio drivers | ||
scripts/config --enable CONFIG_VIRTIO | ||
scripts/config --enable CONFIG_VIRTIO_PCI | ||
scripts/config --enable CONFIG_VIRTIO_BLK | ||
|
||
# Enable kTLS support | ||
scripts/config --enable CONFIG_TLS | ||
scripts/config --enable CONFIG_TLS_DEVICE | ||
|
||
# Generate the updated config | ||
make olddefconfig | ||
|
||
make -j$(nproc) | ||
|
||
- name: Prepare initramfs + tests binaries | ||
run: | | ||
rm -rf initramfs && mkdir -p initramfs/{bin,sbin,proc,sys,tmp} | ||
|
||
# Copy the test binary | ||
cp target/x86_64-unknown-linux-musl/release/examples/client initramfs/bin/ktls-test | ||
|
||
# Add necessary binaries from busybox | ||
cp /usr/bin/busybox initramfs/bin/ | ||
for cmd in sh mount ip ifconfig cat; do ln -sf busybox initramfs/bin/$cmd; done | ||
ln -sf ../bin/busybox initramfs/sbin/poweroff | ||
|
||
# Generate init script | ||
cat > initramfs/init << 'EOF' | ||
#!/bin/sh | ||
set -e | ||
|
||
# Activating the loopback interface (it's required for some network tests) | ||
ip link set lo up | ||
|
||
mkdir -p /dev | ||
|
||
# Enable necessary devices | ||
# https://www.kernel.org/doc/Documentation/admin-guide/devices.txt | ||
mknod /dev/port c 1 4 | ||
mknod /dev/null c 1 3 | ||
mknod /dev/zero c 1 5 | ||
mknod /dev/tty c 5 0 | ||
|
||
mkdir -p /tmp && mount -t tmpfs -o mode=1777 tmpfs /tmp | ||
|
||
# Bring up ext4 test volume at /mnt | ||
mount -t devtmpfs devtmpfs /dev | ||
|
||
exit_code=0 | ||
|
||
# Run the test binary | ||
RUST_BACKTRACE=1 /bin/ktls-test || exit_code=1 | ||
|
||
# If the test binary exited with a non-zero code, write it to /dev/port. | ||
# This lets QEMU exit with non-zero exit-code, triggering a CI error. | ||
[ $exit_code -eq 0 ] || printf '\x01' \ | ||
| dd of=/dev/port bs=1 seek=244 count=1 2>/dev/null | ||
|
||
/sbin/poweroff -f | ||
|
||
EOF | ||
|
||
chmod +x initramfs/init | ||
|
||
# Pack into a CPIO archive | ||
(cd initramfs && find . -print0 \ | ||
| cpio --null -ov --format=newc | gzip -9 > ../initramfs.cpio.gz) | ||
|
||
- name: Run tests in QEMU | ||
run: | | ||
qemu-system-x86_64 \ | ||
-device isa-debug-exit,iobase=0xf4,iosize=0x04 \ | ||
-kernel linux-${KERNEL_VERSION}/arch/x86/boot/bzImage \ | ||
-initrd initramfs.cpio.gz \ | ||
-netdev user,id=net0 \ | ||
-device e1000,netdev=net0 \ | ||
-append "console=ttyS0 rootfstype=ramfs panic=1" \ | ||
-nographic -no-reboot -m 1024 -action panic=exit-failure | ||
|
||
if [ $? -ne 0 ]; then | ||
echo "tests failed (QEMU exited abnormally)" | ||
exit 1 | ||
else | ||
echo "all tests passed" | ||
fi |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the CI changes should go into a separate PR.