Add rebuild and build-time encryption support to decky template

This commit is contained in:
NGnius (Graham) 2022-12-03 17:32:37 -05:00
parent c51cbc9aab
commit fbaef000b5
23 changed files with 4235 additions and 747 deletions

107
Cargo.lock generated
View file

@ -66,6 +66,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
[[package]]
name = "backend"
version = "0.1.0"
dependencies = [
"log",
"simplelog",
"usdpl-back 0.7.2",
]
[[package]]
name = "base64"
version = "0.13.0"
@ -545,6 +554,15 @@ dependencies = [
"libc",
]
[[package]]
name = "num_threads"
version = "0.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44"
dependencies = [
"libc",
]
[[package]]
name = "obfstr"
version = "0.3.0"
@ -762,6 +780,17 @@ dependencies = [
"digest 0.10.3",
]
[[package]]
name = "simplelog"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "48dfff04aade74dd495b007c831cd6f4e0cee19c344dd9dc0884c0289b70a786"
dependencies = [
"log",
"termcolor",
"time",
]
[[package]]
name = "slab"
version = "0.4.7"
@ -812,6 +841,15 @@ dependencies = [
"winapi",
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thiserror"
version = "1.0.35"
@ -832,6 +870,35 @@ dependencies = [
"syn",
]
[[package]]
name = "time"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a561bf4617eebd33bca6434b988f39ed798e527f51a1e797d0ee4f61c0a38376"
dependencies = [
"itoa",
"libc",
"num_threads",
"serde",
"time-core",
"time-macros",
]
[[package]]
name = "time-core"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd"
[[package]]
name = "time-macros"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d967f99f534ca7e495c575c62638eebc2898a8c84c119b89e250477bc4ba16b2"
dependencies = [
"time-core",
]
[[package]]
name = "tinyvec"
version = "1.6.0"
@ -1035,6 +1102,23 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "usdpl-back"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58928ed65332c30b9b9be5140fcdab97e45db679a5845d829aa26492765272e5"
dependencies = [
"async-recursion",
"async-trait",
"bytes",
"hex",
"log",
"obfstr",
"tokio",
"usdpl-core 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"warp",
]
[[package]]
name = "usdpl-back"
version = "0.8.0"
@ -1046,7 +1130,7 @@ dependencies = [
"log",
"obfstr",
"tokio",
"usdpl-core",
"usdpl-core 0.6.0",
"warp",
]
@ -1059,6 +1143,16 @@ dependencies = [
"hex-literal",
]
[[package]]
name = "usdpl-core"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "862153581fac266458521f49e5906a71c1eee1665cb4c7d71e9586bd34b45394"
dependencies = [
"aes-gcm-siv",
"base64",
]
[[package]]
name = "usdpl-front"
version = "0.7.0"
@ -1067,7 +1161,7 @@ dependencies = [
"hex",
"js-sys",
"obfstr",
"usdpl-core",
"usdpl-core 0.6.0",
"wasm-bindgen",
"wasm-bindgen-futures",
"wasm-bindgen-test",
@ -1265,6 +1359,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"

View file

@ -21,5 +21,6 @@ codegen-units = 4
members = [
"usdpl-core",
"usdpl-front",
"usdpl-back"
"usdpl-back",
"templates/decky/backend"
]

View file

@ -42,9 +42,9 @@ yalc.lock
.vscode/settings.json
# ignore Rust compiler files
/server/target
backend
/**/target
/bin
/bin/backend
# packaged teasers
*.zip

1213
templates/decky/backend/Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -6,12 +6,16 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
usdpl-back = { version = "0.5.3", features = ["decky"] }
usdpl-back = { version = "0.7", features = ["decky", "encrypt"] }
# logging
log = "0.4"
simplelog = "0.12"
[feature]
default = []
encrypt = ["usdpl-back/encrypt"]
[profile.release]
debug = false
strip = true

View file

@ -1,6 +1,6 @@
#!/bin/bash
cargo build --release
mkdir ../bin
cargo build --target x86_64-unknown-linux-musl --features encrypt
mkdir -p ../bin
# TODO replace "backend" \/ with binary name
cp ./target/release/backend ../bin/backend

10
templates/decky/build.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
export USDPL_ENCRYPTION_KEY=$(openssl enc -aes-256-cbc -k caylon -pbkdf2 -P -md sha1 | awk -F= '{if ($1 == "key") print $2}')
echo USDPL key: $USDPL_ENCRYPTION_KEY
cd ./backend && ./build.sh && cd ..
cd ./src/usdpl_front && ./rebuild.sh decky encrypt && cd ../..
npm install
npm run build

2592
templates/decky/package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,9 @@
[![Crates.io](https://img.shields.io/crates/v/usdpl-front?style=flat-square)](https://crates.io/crates/usdpl-front)
# usdpl-front-front
Front-end library to be called from Javascript.
Targets WASM.
In true Javascript tradition, this part of the library does not support error handling.

View file

@ -0,0 +1,21 @@
{
"name": "usdpl-front",
"collaborators": [
"NGnius (Graham) <ngniusness@gmail.com>"
],
"description": "Universal Steam Deck Plugin Library front-end designed for WASM",
"version": "0.7.0",
"license": "GPL-3.0-only",
"repository": {
"type": "git",
"url": "https://github.com/NGnius/usdpl-rs"
},
"files": [
"usdpl_front_bg.wasm",
"usdpl_front.js",
"usdpl_front.d.ts"
],
"module": "usdpl_front.js",
"types": "usdpl_front.d.ts",
"sideEffects": false
}

View file

@ -0,0 +1,13 @@
#!/bin/bash
git clone https://github.com/NGnius/usdpl-rs usdpl-rs
cd usdpl-rs/usdpl-front/
./build.sh $1 $2
cd ../..
cp -f ./usdpl-rs/usdpl-front/pkg/* ./
#rm ./.gitignore
rm -rf ./usdpl-rs

View file

@ -1,57 +0,0 @@
/* tslint:disable */
/* eslint-disable */
/**
* Initialize the front-end library
* @param {number} port
*/
export function init_usdpl(port: number): void;
/**
* Get the targeted plugin framework, or "any" if unknown
* @returns {string}
*/
export function target(): string;
/**
* Call a function on the back-end.
* Returns null (None) if this fails for any reason.
* @param {string} name
* @param {any[]} parameters
* @returns {Promise<any>}
*/
export function call_backend(name: string, parameters: any[]): Promise<any>;
/**
*/
export class UsdplContext {
free(): void;
}
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly __wbg_usdplcontext_free: (a: number) => void;
readonly init_usdpl: (a: number) => void;
readonly target: (a: number) => void;
readonly call_backend: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_malloc: (a: number) => number;
readonly __wbindgen_realloc: (a: number, b: number, c: number) => number;
readonly __wbindgen_export_2: WebAssembly.Table;
readonly _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ac289f583b8044: (a: number, b: number, c: number) => void;
readonly __wbindgen_add_to_stack_pointer: (a: number) => number;
readonly __wbindgen_free: (a: number, b: number) => void;
readonly __wbindgen_exn_store: (a: number) => void;
readonly wasm_bindgen__convert__closures__invoke2_mut__ha1c5a356ae6a22de: (a: number, b: number, c: number, d: number) => void;
}
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
* for everything else, calls `WebAssembly.instantiate` directly.
*
* @param {InitInput | Promise<InitInput>} module_or_path
*
* @returns {Promise<InitOutput>}
*/
export default function init (module_or_path?: InitInput | Promise<InitInput>): Promise<InitOutput>;
// USDPL customization
export function init_embedded();

File diff suppressed because one or more lines are too long

View file

@ -1,15 +0,0 @@
/* tslint:disable */
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function __wbg_usdplcontext_free(a: number): void;
export function init_usdpl(a: number): void;
export function target(a: number): void;
export function call_backend(a: number, b: number, c: number, d: number): number;
export function __wbindgen_malloc(a: number): number;
export function __wbindgen_realloc(a: number, b: number, c: number): number;
export const __wbindgen_export_2: WebAssembly.Table;
export function _dyn_core__ops__function__FnMut__A____Output___R_as_wasm_bindgen__closure__WasmClosure___describe__invoke__h16ac289f583b8044(a: number, b: number, c: number): void;
export function __wbindgen_add_to_stack_pointer(a: number): number;
export function __wbindgen_free(a: number, b: number): void;
export function __wbindgen_exn_store(a: number): void;
export function wasm_bindgen__convert__closures__invoke2_mut__ha1c5a356ae6a22de(a: number, b: number, c: number, d: number): void;

View file

@ -9,7 +9,25 @@ export function init_usdpl(port: number): void;
* Get the targeted plugin framework, or "any" if unknown
* @returns {string}
*/
export function target(): string;
export function target_usdpl(): string;
/**
* Get the UDSPL front-end version
* @returns {string}
*/
export function version_usdpl(): string;
/**
* Get the targeted plugin framework, or "any" if unknown
* @param {string} key
* @param {any} value
* @returns {any}
*/
export function set_value(key: string, value: any): any;
/**
* Get the targeted plugin framework, or "any" if unknown
* @param {string} key
* @returns {any}
*/
export function get_value(key: string): any;
/**
* Call a function on the back-end.
* Returns null (None) if this fails for any reason.
@ -24,7 +42,10 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
export interface InitOutput {
readonly memory: WebAssembly.Memory;
readonly init_usdpl: (a: number) => void;
readonly target: (a: number) => void;
readonly target_usdpl: (a: number) => void;
readonly version_usdpl: (a: number) => void;
readonly set_value: (a: number, b: number, c: number) => number;
readonly get_value: (a: number, b: number) => number;
readonly call_backend: (a: number, b: number, c: number, d: number) => number;
readonly __wbindgen_export_0: (a: number) => number;
readonly __wbindgen_export_1: (a: number, b: number, c: number) => number;
@ -36,14 +57,16 @@ export interface InitOutput {
readonly __wbindgen_export_6: (a: number, b: number, c: number, d: number) => void;
}
export type SyncInitInput = BufferSource | WebAssembly.Module;
/**
* Synchronously compiles the given `bytes` and instantiates the WebAssembly module.
* Instantiates the given `module`, which can either be bytes or
* a precompiled `WebAssembly.Module`.
*
* @param {BufferSource} bytes
* @param {SyncInitInput} module
*
* @returns {InitOutput}
*/
export function initSync(bytes: BufferSource): InitOutput;
export function initSync(module: SyncInitInput): InitOutput;
/**
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and

File diff suppressed because one or more lines are too long

View file

@ -2,7 +2,10 @@
/* eslint-disable */
export const memory: WebAssembly.Memory;
export function init_usdpl(a: number): void;
export function target(a: number): void;
export function target_usdpl(a: number): void;
export function version_usdpl(a: number): void;
export function set_value(a: number, b: number, c: number): number;
export function get_value(a: number, b: number): number;
export function call_backend(a: number, b: number, c: number, d: number): number;
export function __wbindgen_export_0(a: number): number;
export function __wbindgen_export_1(a: number, b: number, c: number): number;

View file

@ -6,17 +6,17 @@ $0 [decky|crankshaft|<nothing>]"
exit 0
elif [ "$1" == "decky" ]; then
echo "Building WASM module for decky framework"
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features decky
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features decky,$2
elif [ "$1" == "crankshaft" ]; then
echo "WARNING: crankshaft support is unimplemented"
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features crankshaft
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features crankshaft,$2
else
echo "Unsupported plugin framework \`$1\`"
exit 1
fi
else
echo "WARNING: Building for any plugin framework, which may not work for every framework"
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features debug
RUSTFLAGS="--cfg aes_compact" wasm-pack build --target web --features debug,$2
fi
python3 ./scripts/generate_embedded_wasm.py

View file

@ -69,7 +69,7 @@ pub async fn send_js(
}
#[cfg(feature = "encrypt")]
match socket::Packet::load_encrypted(string.as_string().unwrap().as_bytes(), key.as_slice(), &NONCE)
match socket::Packet::load_encrypted(rust_str.as_bytes(), key.as_slice(), &NONCE)
.map_err(super::convert::str_to_js)?
.0
{