Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@ jobs:
# The drop zone's pure logic and its offscreen renders (snapshots are uploaded).
- run: "cargo test --locked --features edge edge::"
- run: cargo build --release --locked --features webview,edge
env:
# Lets the in-app updater tell which main build this is.
AIRBRIDGE_BUILD: ${{ github.run_number }}
- run: packaging/appimage.sh target/release/airbridge
- uses: actions/upload-artifact@v6
with:
name: edge-snapshots
path: linux/target/edge-snapshots
- uses: actions/upload-artifact@v6
with:
name: airbridge-linux-x86_64
path: linux/target/release/airbridge
path: linux/airbridge-x86_64.AppImage

android:
name: Android app + interop with Linux
Expand Down Expand Up @@ -104,14 +108,24 @@ jobs:
with:
name: airbridge-android-apk
path: release
- name: Package release assets
- name: Package and sign release assets
env:
UPDATE_SIGNING_KEY: ${{ secrets.UPDATE_SIGNING_KEY }}
TAG: main-${{ github.run_number }}
run: |
test -s release/airbridge
test -s release/airbridge-x86_64.AppImage
test -s release/app-release.apk
[ -n "$UPDATE_SIGNING_KEY" ] || { echo "UPDATE_SIGNING_KEY secret is missing; refusing to publish an unsigned build"; exit 1; }
# Artifact downloads do not preserve the Linux executable bit.
chmod +x release/airbridge
tar -C release -czf airbridge-linux-x86_64.tar.gz airbridge
install -m755 release/airbridge-x86_64.AppImage airbridge-x86_64.AppImage
cp release/app-release.apk airbridge-android.apk
# The in-app updater checks this: the AppImage, a newline, then its tag.
umask 077
printf '%s\n' "$UPDATE_SIGNING_KEY" > "$RUNNER_TEMP/key.pem"
{ cat airbridge-x86_64.AppImage; printf '\n%s' "$TAG"; } > "$RUNNER_TEMP/message"
openssl pkeyutl -sign -rawin -inkey "$RUNNER_TEMP/key.pem" -in "$RUNNER_TEMP/message" -out airbridge-x86_64.AppImage.sig
rm -f "$RUNNER_TEMP/key.pem" "$RUNNER_TEMP/message"
test "$(stat -c %s airbridge-x86_64.AppImage.sig)" -eq 64
- uses: softprops/action-gh-release@v3
with:
tag_name: main-${{ github.run_number }}
Expand All @@ -126,9 +140,10 @@ jobs:

**Downloads**
- `airbridge-android.apk`: Android 10 or newer.
- `airbridge-linux-x86_64.tar.gz`: unpack and run `./airbridge`.
- `airbridge-x86_64.AppImage`: make it executable and run it. It updates itself from the app's Update button.

The APK uses a debug signing key; Android may require uninstalling the previous build before installation.
files: |
airbridge-linux-x86_64.tar.gz
airbridge-x86_64.AppImage
airbridge-x86_64.AppImage.sig
airbridge-android.apk
11 changes: 6 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ jobs:
working-directory: linux
run: |
cargo build --release --locked --features webview,edge
tar -C target/release -czf ../airbridge-linux-x86_64.tar.gz airbridge
packaging/appimage.sh target/release/airbridge ..
- uses: actions/upload-artifact@v6
with:
name: release-linux-x86_64
path: airbridge-linux-x86_64.tar.gz
path: airbridge-x86_64.AppImage
if-no-files-found: error

android:
Expand Down Expand Up @@ -106,7 +106,8 @@ jobs:
merge-multiple: true
- name: Check release assets
run: |
test -s airbridge-linux-x86_64.tar.gz
test -s airbridge-x86_64.AppImage
chmod +x airbridge-x86_64.AppImage
test -s airbridge-android.apk
- uses: softprops/action-gh-release@v3
with:
Expand All @@ -116,10 +117,10 @@ jobs:
body: |
**Downloads**
- `airbridge-android.apk`: the Android app (Android 10 or newer). Allow installs from your browser or file manager when asked.
- `airbridge-linux-x86_64.tar.gz`: the Linux app. Unpack it and run `./airbridge`, or install it with `packaging/install.sh` from the source.
- `airbridge-x86_64.AppImage`: the Linux app. Make it executable and run it (needs GTK 3 and WebKitGTK 4.1, present on most desktops).

The APK is signed with a debug key made for this build, not a private release key, so a newer release may need the old app uninstalled first. See [SECURITY.md](https://github.com/${{ github.repository }}/blob/${{ env.VERSION }}/docs/SECURITY.md).
files: |
airbridge-linux-x86_64.tar.gz
airbridge-x86_64.AppImage
airbridge-android.apk
generate_release_notes: true
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ Received photos show up as a preview in the notification.

### Linux

Download `airbridge-x86_64.AppImage` from the newest
[release](https://github.com/MDHaarith/Linux-Android-AirDrop/releases), then:

```bash
chmod +x airbridge-x86_64.AppImage && ./airbridge-x86_64.AppImage
```

It uses the system's GTK 3, WebKitGTK 4.1 and gtk-layer-shell, which most desktops already have.
When a newer build of `main` passes CI, an **Update** button appears in the toolbar. It
downloads the new AppImage, checks its Ed25519 signature against the key built into the app,
swaps the file and restarts. Unsigned or older builds are refused.

#### From source

You need [Rust](https://rustup.rs) 1.89 or newer and the Wayland client headers
(`libwayland-dev` / `wayland-devel`, used by the file picker). For a native app window, also
install WebKitGTK. Without it, AirBridge opens in a Chromium app window or your default browser.
Expand Down
10 changes: 10 additions & 0 deletions docs/SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ to your own verified devices. Devices at the phone's own address are refused
transfers, received text is marked sensitive on the clipboard, and malformed
requests cannot crash the app.

## Updates

The Linux AppImage updates itself only from `main-N` prereleases on GitHub, over
HTTPS (system CA store, HTTPS-only redirects). CI signs each AppImage with an
Ed25519 key kept in the `UPDATE_SIGNING_KEY` secret. The signature covers the
file and its tag, and the public key is built into the app. A download with a
bad signature, an older or equal build number, or one that is not an ELF file
is rejected before anything is written. The swap is atomic (temp file, fsync,
rename). Only the token-protected local UI can start an update.

## Known limits

- The official LocalSend apps do not present client certificates. They work,
Expand Down
37 changes: 37 additions & 0 deletions linux/packaging/appimage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
# Packs a release binary into airbridge-x86_64.AppImage.
# ./appimage.sh path/to/airbridge [output-dir]
# GTK, WebKitGTK 4.1 and gtk-layer-shell come from the system, as on any desktop.
set -euo pipefail

bin="$(realpath "$1")"
out="$(realpath "${2:-.}")"
here="$(cd "$(dirname "$0")" && pwd)"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT

# Pinned tools, checked before use.
fetch() { # url sha256 dest
curl -fsSL --proto '=https' --retry 3 -o "$3" "$1"
echo "$2 $3" | sha256sum -c --quiet
}
fetch https://github.com/AppImage/appimagetool/releases/download/1.9.1/appimagetool-x86_64.AppImage \
ed4ce84f0d9caff66f50bcca6ff6f35aae54ce8135408b3fa33abfc3cb384eb0 "$work/appimagetool"
fetch https://github.com/AppImage/type2-runtime/releases/download/20251108/runtime-x86_64 \
2fca8b443c92510f1483a883f60061ad09b46b978b2631c807cd873a47ec260d "$work/runtime"
chmod +x "$work/appimagetool"

app="$work/AirBridge.AppDir"
install -Dm755 "$bin" "$app/usr/bin/airbridge"
install -Dm644 "$here/../ui/icon.svg" "$app/airbridge.svg"
install -Dm644 "$here/../ui/icon.svg" "$app/usr/share/icons/hicolor/scalable/apps/airbridge.svg"
install -Dm644 "$here/airbridge.desktop" "$app/airbridge.desktop"
cat > "$app/AppRun" <<'EOF'
#!/bin/sh
exec "$(dirname "$(readlink -f "$0")")/usr/bin/airbridge" "$@"
EOF
chmod +x "$app/AppRun"

# No FUSE on CI runners.
APPIMAGE_EXTRACT_AND_RUN=1 ARCH=x86_64 "$work/appimagetool" --no-appstream \
--runtime-file "$work/runtime" "$app" "$out/airbridge-x86_64.AppImage"
37 changes: 37 additions & 0 deletions linux/src/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,43 @@ async fn stage(name: &str, data: &[u8]) -> Result<SendItem> {
})
}

/// Downloads `url` into memory over HTTPS only (redirects included), up to `max` bytes.
pub async fn download(url: &str, max: u64) -> Result<Vec<u8>> {
let mut uri: Uri = url.parse().context("not a valid link")?;
for _ in 0..=MAX_REDIRECTS {
if uri.scheme_str() != Some("https") {
bail!("refusing a non-HTTPS download");
}
let response = get(&uri).await?;
let status = response.status();
if status.is_redirection() {
let location = response
.headers()
.get(hyper::header::LOCATION)
.and_then(|v| v.to_str().ok())
.ok_or_else(|| anyhow!("redirect without a location"))?;
uri = resolve(&uri, location)?;
continue;
}
if status != StatusCode::OK {
bail!("the server answered {status}");
}
let mut stream = response.into_body().into_data_stream();
let mut data = Vec::new();
while let Some(chunk) = timeout(IO_TIMEOUT, stream.next())
.await
.map_err(|_| anyhow!("the download stalled"))?
{
data.extend_from_slice(&chunk?);
if data.len() as u64 > max {
bail!("the download is too large");
}
}
return Ok(data);
}
bail!("too many redirects")
}

async fn stage_stream(name: &str, body: hyper::body::Incoming) -> Result<SendItem> {
let path = staging_path(name);
tokio::fs::create_dir_all(path.parent().unwrap()).await?;
Expand Down
17 changes: 16 additions & 1 deletion linux/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod transfers;
#[cfg(feature = "tray")]
mod tray;
mod ui;
mod update;
#[cfg(feature = "webview")]
mod window;

Expand Down Expand Up @@ -157,13 +158,27 @@ fn main() -> ExitCode {
};
}
let runtime = tokio::runtime::Runtime::new().expect("tokio runtime");
match runtime.block_on(run(cli)) {
let code = match runtime.block_on(run(cli)) {
Ok(code) => code,
Err(err) => {
eprintln!("airbridge: {err:#}");
ExitCode::FAILURE
}
};
if update::RESTART.load(std::sync::atomic::Ordering::Relaxed) {
// Close every socket first so the new version can take the ports.
runtime.shutdown_timeout(Duration::from_secs(3));
if let Some(appimage) = update::appimage() {
use std::os::unix::process::CommandExt;
if let Err(err) = std::process::Command::new(appimage)
.process_group(0)
.spawn()
{
eprintln!("airbridge: could not restart after the update: {err}");
}
}
}
code
}

async fn run(cli: Cli) -> Result<ExitCode> {
Expand Down
39 changes: 39 additions & 0 deletions linux/src/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use crate::config;
use crate::desktop;
use crate::receiver::constant_time_eq;
use crate::sender::{expand_paths, SendItem};
use crate::update;

const COOKIE: &str = "airbridge_token";

Expand Down Expand Up @@ -64,6 +65,7 @@ pub fn router(app: Arc<App>) -> Router {
.route("/open-downloads", post(open_downloads))
.route("/show", post(show))
.route("/quit", post(quit))
.route("/update", get(check_update).post(apply_update))
.layer(middleware::from_fn_with_state(app.clone(), auth));
Router::new()
.route("/", get(index))
Expand Down Expand Up @@ -665,3 +667,40 @@ async fn quit(State(app): State<Arc<App>>) -> StatusCode {
app.shutdown.cancel();
StatusCode::NO_CONTENT
}

async fn check_update() -> Response {
match update::check().await {
Ok(available) => Json(json!({
"current": update::current_build(),
"available": available,
"canInstall": update::appimage().is_some(),
}))
.into_response(),
Err(err) => bad_request(format!("Could not check for updates: {err:#}")),
}
}

/// Installs the newest build and restarts; outside the AppImage it opens the release page.
async fn apply_update(State(app): State<Arc<App>>) -> Response {
let available = match update::check().await {
Ok(Some(available)) => available,
Ok(None) => return bad_request("AirBridge is up to date."),
Err(err) => return bad_request(format!("Could not check for updates: {err:#}")),
};
if update::appimage().is_none() {
desktop::open_url(&available.page);
return Json(json!({ "restarting": false })).into_response();
}
if let Err(err) = update::install(&available).await {
tracing::warn!("Update failed: {err:#}");
return bad_request(format!("Update failed: {err:#}"));
}
tracing::info!("Updated to {}; restarting", available.tag);
update::RESTART.store(true, Ordering::Relaxed);
// Let this answer reach the window before the server goes away.
tokio::spawn(async move {
tokio::time::sleep(std::time::Duration::from_millis(500)).await;
app.shutdown.cancel();
});
Json(json!({ "restarting": true })).into_response()
}
Loading