This commit is contained in:
Anton Afanasyeu
2026-06-23 12:29:33 +02:00
commit 59fb5013c3
26 changed files with 2375 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
# Linux RSSH device/operator simulation
Simulates the **Android RSSH path** on a laptop with real OpenSSH client + optional local `sshd`.
## Prerequisites
- `curl`, `jq`, `sshpass` (for non-interactive sim)
- Backend reachable (`CRASHES_BASE` or default from `ra_lib.sh`)
- Admin whitelist + open session for the simulated `device_id`
## Device sim (heartbeat + reverse forward)
```bash
export CRASHES_BASE="http://cast01.intra.raptor.org/app/androidcast_project/crashes"
export RA_DEVICE_ID="linux-rssh-lab-01"
# 1) First run registers heartbeat (wait)
./ra_device_sim.sh
# 2) Whitelist device + open session in admin UI, then:
export RA_SKIP_ADMIN=1
./ra_device_sim.sh
```
## Operator sim (on bastion / BE)
After device sim prints `REMOTE_BIND_PORT` and username:
```bash
./ra_operator_connect.sh 18022 ra-SESSIONID shell
./ra_operator_connect.sh 18022 ra-SESSIONID sftp
```
## Android parity
| Android | Linux sim |
|---------|-----------|
| `RemoteAccessService` poll | `ra_ra_post` via `ra_lib.sh` |
| `RsshLocalSshServer` :8022 | local `sshd -p 8022` |
| `ReverseSshTunnelBridge` JSch `-R` | `ssh -N -R …` |
See [REMOTE_ACCESS_IMPL.md](../../../docs/REMOTE_ACCESS_IMPL.md) and [20260602_REVERSE_SSH_proposals_summary.md](../../../docs/20260602_REVERSE_SSH_proposals_summary.md).

View File

@@ -0,0 +1,75 @@
#!/usr/bin/env bash
# Linux laptop simulates Android RSSH device: heartbeat poll + outbound -R + local sshd on 8022.
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
BE_SCRIPTS="$(cd "$(dirname "$0")/../../crash_reporter/backend/scripts" && pwd)"
# shellcheck source=../../crash_reporter/backend/scripts/ra_lib.sh
source "$BE_SCRIPTS/ra_lib.sh"
DEVICE_ID="${RA_DEVICE_ID:-linux-rssh-$(hostname -s)-$$}"
RANDOM_ID="${RA_RANDOM:-rssh-linux-$(date +%s)}"
LOCAL_PORT="${RA_LOCAL_PORT:-8022}"
WORKDIR="${RA_SIM_WORKDIR:-/tmp/rssh-sim-$$}"
SSH_PID=""
DB_PID=""
cleanup() {
[ -n "$SSH_PID" ] && kill "$SSH_PID" 2>/dev/null || true
[ -n "$DB_PID" ] && kill "$DB_PID" 2>/dev/null || true
rm -rf "$WORKDIR"
}
trap cleanup EXIT
mkdir -p "$WORKDIR"
HOST_KEY="$WORKDIR/host_key"
if ! command -v ssh-keygen >/dev/null 2>&1; then
echo "openssh client required" >&2
exit 1
fi
echo "== local device SSH on 127.0.0.1:${LOCAL_PORT} =="
ssh-keygen -t ed25519 -f "$HOST_KEY" -N "" -q
/usr/sbin/sshd -D -f /dev/null -h "$HOST_KEY" -p "$LOCAL_PORT" -o AuthorizedKeysFile=/dev/null \
-o PasswordAuthentication=yes -o PermitRootLogin=no -o UsePAM=no \
-o AllowUsers="${RA_SSH_USER:-rssh-sim}" 2>/dev/null &
DB_PID=$!
sleep 0.5
echo "== heartbeat enable (tunnel_mode=rssh) =="
export RA_TUNNEL_MODE=rssh
ra_ra_post enable "$DEVICE_ID" "$RANDOM_ID" "linux-sim/1.0" >/tmp/rssh-sim-wait.json
grep -q '"action":"wait"' /tmp/rssh-sim-wait.json && echo OK wait
echo "Operator must whitelist + open session in admin UI, then re-run with RA_SKIP_ADMIN=1"
if [[ "${RA_SKIP_ADMIN:-}" != "1" ]]; then
echo "Set RA_SKIP_ADMIN=1 after whitelisting device_id=$DEVICE_ID"
exit 0
fi
echo "== heartbeat connect =="
ra_ra_post enable "$DEVICE_ID" "$RANDOM_ID-b" "linux-sim/1.0" >/tmp/rssh-sim-connect.json
grep -q '"action":"connect"' /tmp/rssh-sim-connect.json || { cat /tmp/rssh-sim-connect.json; exit 1; }
echo OK connect payload
BASTION="$(ra_json -r '.credentials.bastion_host // empty' /tmp/rssh-sim-connect.json)"
BPORT="$(ra_json -r '.credentials.bastion_port // 443' /tmp/rssh-sim-connect.json)"
USER="$(ra_json -r '.credentials.username // empty' /tmp/rssh-sim-connect.json)"
PASS="$(ra_json -r '.credentials.password // empty' /tmp/rssh-sim-connect.json)"
RPORT="$(ra_json -r '.credentials.remote_bind_port // 0' /tmp/rssh-sim-connect.json)"
[ -n "$BASTION" ] && [ -n "$USER" ] && [ "$RPORT" -gt 0 ] || { echo "missing credentials"; exit 1; }
echo "== reverse SSH -R 127.0.0.1:${RPORT}:127.0.0.1:${LOCAL_PORT} =="
sshpass -p "$PASS" ssh -N \
-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
-p "$BPORT" -R "127.0.0.1:${RPORT}:127.0.0.1:${LOCAL_PORT}" \
"${USER}@${BASTION}" &
SSH_PID=$!
sleep 2
echo "Tunnel up. Operator on bastion:"
echo " ssh -p ${RPORT} ${USER}@127.0.0.1"
echo "Press Ctrl+C to stop."
wait "$SSH_PID"

View File

@@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Operator-side: SSH/SFTP to forwarded port on bastion (run on BE or jump host).
set -euo pipefail
RPORT="${1:-}"
USER="${2:-}"
MODE="${3:-shell}"
if [ -z "$RPORT" ] || [ -z "$USER" ]; then
echo "usage: $0 REMOTE_BIND_PORT RA_USERNAME [shell|sftp]" >&2
exit 1
fi
case "$MODE" in
shell)
exec ssh -p "$RPORT" -o StrictHostKeyChecking=no "${USER}@127.0.0.1"
;;
sftp)
exec sftp -P "$RPORT" -o StrictHostKeyChecking=no "${USER}@127.0.0.1"
;;
*)
echo "unknown mode: $MODE" >&2
exit 1
;;
esac