diff options
Diffstat (limited to 'standalone-tools')
-rw-r--r-- | standalone-tools/.gitignore | 2 | ||||
-rw-r--r-- | standalone-tools/Makefile | 31 | ||||
-rw-r--r-- | standalone-tools/addonsd.sh | 37 | ||||
-rw-r--r-- | standalone-tools/installer.sh | 65 |
4 files changed, 135 insertions, 0 deletions
diff --git a/standalone-tools/.gitignore b/standalone-tools/.gitignore new file mode 100644 index 0000000..030cc7a --- /dev/null +++ b/standalone-tools/.gitignore @@ -0,0 +1,2 @@ +wireguard-tools.zip +build diff --git a/standalone-tools/Makefile b/standalone-tools/Makefile new file mode 100644 index 0000000..1e49b07 --- /dev/null +++ b/standalone-tools/Makefile @@ -0,0 +1,31 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + +ARCHS := $(shell ndk-build NDK_PROJECT_PATH=$(PWD)/build APP_BUILD_SCRIPT=$(PWD)/../Android.mk APP_PLATFORM=21 DUMP_NDK_KNOWN_DEVICE_ABIS 2>/dev/null) + +all: wireguard-tools.zip + +clean: + rm -rf build wireguard-tools.zip + +wg-build: ../wg-quick.c + ndk-build NDK_PROJECT_PATH=$(PWD)/build APP_BUILD_SCRIPT=$(PWD)/../Android.mk APP_PLATFORM=21 + +$(foreach ARCH,$(ARCHS),build/libs/$(ARCH)/wg build/libs/$(ARCH)/wg-quick): wg-build + +wireguard-tools.zip: $(foreach ARCH,$(ARCHS),build/libs/$(ARCH)/wg-quick build/libs/$(ARCH)/wg) installer.sh addonsd.sh + rm -rf $@ build/zip build/*.zip + mkdir -p build/zip build/zip/addon.d build/zip/META-INF/com/google/android + ln -frs build/libs build/zip/arch + ln -frs addonsd.sh build/zip/addon.d/40-wireguard.sh + ln -frs installer.sh build/zip/META-INF/com/google/android/update-binary + touch build/zip/META-INF/com/google/android/updater-script + cd build/zip && zip -0Xr ../unaligned-$@ . + openssl req -x509 -nodes -newkey rsa:2048 -keyout build/key.pem -out build/cert.pem -days 3650 -subj /CN=$$(hostname)/ + openssl pkcs8 -topk8 -inform PEM -outform DER -in build/key.pem -out build/key.pk8 -nocrypt + $(ANDROID_HOME)/build-tools/27.0.1/zipalign -v -p 4 build/unaligned-$@ build/aligned-$@ + $(ANDROID_HOME)/build-tools/27.0.1/apksigner sign --key build/key.pk8 --cert build/cert.pem --min-sdk-version 21 --out $@ build/aligned-$@ + +.PHONY: clean all +.SECONDARY: diff --git a/standalone-tools/addonsd.sh b/standalone-tools/addonsd.sh new file mode 100644 index 0000000..90865d0 --- /dev/null +++ b/standalone-tools/addonsd.sh @@ -0,0 +1,37 @@ +#!/sbin/sh + +. /tmp/backuptool.functions + +list_files() { +cat <<_EOF +xbin/wg +xbin/wg-quick +_EOF +} + +case "$1" in + backup) + list_files | while read FILE DUMMY; do + backup_file $S/"$FILE" + done + ;; + restore) + list_files | while read FILE REPLACEMENT; do + R="" + [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT" + [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R" + done + ;; + pre-backup) + # Stub + ;; + post-backup) + # Stub + ;; + pre-restore) + # Stub + ;; + post-restore) + # Stub + ;; +esac diff --git a/standalone-tools/installer.sh b/standalone-tools/installer.sh new file mode 100644 index 0000000..84dacdc --- /dev/null +++ b/standalone-tools/installer.sh @@ -0,0 +1,65 @@ +#!/sbin/sh +# SPDX-License-Identifier: GPL-2.0 +# +# Copyright (C) 2015-2017 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + +SCRIPT="$1" +OUTFD="$2" +ZIP="$3" +ARCH="$(getprop ro.product.cpu.abi)" + +print() { + echo "ui_print [+] $*" >&$OUTFD +} + +die() { + echo "ui_print [-] $*" >&$OUTFD + exit 1 +} + +cleanup() { + mount -o ro,remount /system + rm -rf /tmp/wireguard +} + +mount_system() { + local slot dev + + if grep -q /system /proc/mounts; then + print "Remounting system partition r/w" + mount -o rw,remount /system + else + print "Mounting system partition" + + slot="$(getprop ro.boot.slot_suffix)" + [ -z "$slot" ] && slot="$(getprop ro.boot.slot)" + + dev="$(find /dev/block -iname "system$slot" -print | head -n 1)" + [ -n "$dev" ] || die "Could not find system partition" + + mount -o rw "$dev" /system || die "Could not mount system partition" + fi +} + +echo "ui_print ==================================" >&$OUTFD +echo "ui_print = WireGuard Tools =" >&$OUTFD +echo "ui_print = by zx2c4 =" >&$OUTFD +echo "ui_print = www.wireguard.com =" >&$OUTFD +echo "ui_print ==================================" >&$OUTFD + +trap cleanup INT TERM EXIT + +mount_system + +rm -rf /tmp/wireguard +mkdir -p /tmp/wireguard +print "Extracting files" +unzip -d /tmp/wireguard "$ZIP" +[ -d /tmp/wireguard/arch/$ARCH ] || die "Not available for device's ABI" +print "Installing WireGuard tools" +cp /tmp/wireguard/arch/$(getprop ro.product.cpu.abi)/* /system/xbin/ +cp /tmp/wireguard/addon.d/40-wireguard.sh /system/addon.d/ +chmod 755 /system/xbin/wg /system/xbin/wg-quick /system/addon.d/40-wireguard.sh + +mkdir -pm 700 /data/misc/wireguard +print "Success! Be sure your kernel has the WireGuard module enabled." |