From 14397d1b445dd3fc9c8b7145309a42bd9b0e4c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=BA=E6=A2=B0=E5=B0=8F=E9=B8=BD?= <128568434+jixiexiaoge@users.noreply.github.com> Date: Wed, 5 Mar 2025 18:31:22 +0800 Subject: [PATCH] export API_HOST=https://api.konik.ai export ATHENA_HOST=wss://athena.konik.ai export MAPS_HOST=https://api.konik.ai/maps --- generate_keys.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++ launch_openpilot.sh | 4 ++- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 generate_keys.sh diff --git a/generate_keys.sh b/generate_keys.sh new file mode 100644 index 0000000..816fa2f --- /dev/null +++ b/generate_keys.sh @@ -0,0 +1,80 @@ +#!/bin/env sh + +persist_dir=/persist +target_dir=${persist_dir}/comma +# Change target dir from sunnylink to comma to make this no longer a test + + +# Function to remount /persist as read-only +cleanup() { + echo "Remounting ${persist_dir} as read-only..." + sudo mount -o remount,ro ${persist_dir} +} + +# Function to check and backup existing keys +backup_keys() { + if [ -f "id_rsa" ] || [ -f "id_rsa.pub" ]; then + timestamp=$(date +%s) + backup_base="id_rsa_backup_$timestamp" + backup_private="$backup_base" + backup_public="${backup_base}.pub" + + # Ensure we're not overwriting an existing backup + counter=0 + while [ -f "$backup_private" ] || [ -f "$backup_public" ]; do + counter=$((counter + 1)) + backup_private="${backup_base}_$counter" + backup_public="${backup_base}_$counter.pub" + done + + # Backup the keys + cp id_rsa "$backup_private" + cp id_rsa.pub "$backup_public" + + # Verify the backup + original_private_hash=$(sha256sum id_rsa | cut -d ' ' -f 1) + backup_private_hash=$(sha256sum "$backup_private" | cut -d ' ' -f 1) + original_public_hash=$(sha256sum id_rsa.pub | cut -d ' ' -f 1) + backup_public_hash=$(sha256sum "$backup_public" | cut -d ' ' -f 1) + + if [ "$original_private_hash" = "$backup_private_hash" ] && [ "$original_public_hash" = "$backup_public_hash" ]; then + echo "Backup verified successfully." + # Safe to delete original keys after successful backup verification + else + echo "Backup verification failed. Aborting operation." + exit 1 + fi + + echo "Existing keys backed up as $backup_private and $backup_public" + fi +} + +# Remount /persist as read-write +sudo mount -o remount,rw ${persist_dir} + +# Ensure the directory exists +mkdir -p ${target_dir} +cd ${target_dir} + +# Check for and backup existing keys +#backup_keys + +# Generate new keys +if ! ssh-keygen -t rsa -b 4096 -m PEM -f id_rsa -N ''; then + echo "Failed to generate new RSA keys. Exiting..." + exit 1 +fi +chmod +r id_rsa +# Convert the generated SSH public key to PEM format and store it temporarily +if ! openssl rsa -pubout -in id_rsa -out id_rsa.pub -outform PEM; then + echo "Failed to convert the public key to PEM format. Exiting..." + exit 1 +fi + +# Display the public key +echo "Displaying the public key:" +cat id_rsa.pub + +# Cleanup will be called automatically due to trap on EXIT +#echo "Operation completed successfully. System will reboot now." +#sudo reboot diff --git a/launch_openpilot.sh b/launch_openpilot.sh index d6e3424..72cb7ab 100755 --- a/launch_openpilot.sh +++ b/launch_openpilot.sh @@ -1,3 +1,5 @@ #!/usr/bin/env bash - +export API_HOST=https://api.konik.ai +export ATHENA_HOST=wss://athena.konik.ai +export MAPS_HOST=https://api.konik.ai/maps exec ./launch_chffrplus.sh