mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 07:14:23 +01:00
sphinx-key: read config wifi creds from sdcard
This commit is contained in:
18
deploy.sh
18
deploy.sh
@@ -1,9 +1,6 @@
|
||||
check_exists() {
|
||||
command -v "$1" > /dev/null
|
||||
}
|
||||
check_port() {
|
||||
cargo espflash board-info --port "$1" &> /dev/null
|
||||
}
|
||||
if ! check_exists esptool.py
|
||||
then
|
||||
echo "esptool.py not installed!"
|
||||
@@ -28,21 +25,6 @@ then
|
||||
echo "install with this command: cargo install espflash"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SSID" ]
|
||||
then
|
||||
echo "Please set environment variable SSID to the SSID of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$PASS" ]
|
||||
then
|
||||
echo "Please set environment variable PASS to the password of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ ${#PASS} -lt 8 ]
|
||||
then
|
||||
echo "Please set PASS to a password longer than 7 characters."
|
||||
exit 1
|
||||
fi
|
||||
cargo espflash erase-flash
|
||||
git pull &&
|
||||
cd factory &&
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
check_exists() {
|
||||
command -v "$1" > /dev/null
|
||||
}
|
||||
check_port() {
|
||||
cargo espflash board-info --port "$1" &> /dev/null
|
||||
}
|
||||
if ! check_exists esptool.py
|
||||
then
|
||||
echo "esptool.py not installed!"
|
||||
@@ -28,21 +25,6 @@ then
|
||||
echo "install with this command: cargo install espflash"
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$SSID" ]
|
||||
then
|
||||
echo "Please set environment variable SSID to the SSID of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ -z "$PASS" ]
|
||||
then
|
||||
echo "Please set environment variable PASS to the password of the wifi you'll use to configure your sphinx-key."
|
||||
exit 1
|
||||
fi
|
||||
if [ ${#PASS} -lt 8 ]
|
||||
then
|
||||
echo "Please set PASS to a password longer than 7 characters."
|
||||
exit 1
|
||||
fi
|
||||
cargo espflash save-image --bin sphinx-key --release --chip esp32c3 sphinx-key.bin &&
|
||||
espsecure.py sign_data sphinx-key.bin --version 2 --keyfile ../secure_boot_signing_key.pem &&
|
||||
espflash write-bin 0x50000 sphinx-key.bin &&
|
||||
|
||||
@@ -9,6 +9,10 @@ use esp_idf_svc::wifi::{
|
||||
};
|
||||
use log::*;
|
||||
use sphinx_signer::sphinx_glyph::control::Config;
|
||||
use std::fs;
|
||||
|
||||
const SSID_FILE: &str = "/sdcard/ssid.txt";
|
||||
const PASS_FILE: &str = "/sdcard/password.txt";
|
||||
|
||||
pub fn start_client(
|
||||
modem: impl peripheral::Peripheral<P = esp_idf_svc::hal::modem::Modem> + 'static,
|
||||
@@ -89,15 +93,30 @@ pub fn start_access_point(
|
||||
sysloop,
|
||||
)?;
|
||||
|
||||
let ssid: &'static str = env!("SSID");
|
||||
let password: &'static str = env!("PASS");
|
||||
let ssid = match fs::read_to_string(SSID_FILE) {
|
||||
Ok(ssid) => ssid.trim().to_string(),
|
||||
Err(_) => {
|
||||
warn!("Could not read ssid from sd card, using default setting");
|
||||
"sphinx".to_string()
|
||||
}
|
||||
};
|
||||
let password = match fs::read_to_string(PASS_FILE) {
|
||||
Ok(password) => password.trim().to_string(),
|
||||
Err(_) => {
|
||||
warn!("Could not read password from sd card, using default setting");
|
||||
"sphinxkey".to_string()
|
||||
}
|
||||
};
|
||||
if password.len() < 8 {
|
||||
return Err(anyhow::anyhow!("Password error!\nCurrent password: {}\nYour wifi password must be >= 8 characters. Compile this software again with a longer password.", password));
|
||||
return Err(anyhow::anyhow!(
|
||||
"Password error!\nCurrent password: {}\nYour wifi password must be >= 8 characters",
|
||||
password
|
||||
));
|
||||
}
|
||||
|
||||
wifi.set_configuration(&Configuration::AccessPoint(AccessPointConfiguration {
|
||||
ssid: ssid.into(),
|
||||
password: password.into(),
|
||||
ssid: ssid.as_str().into(),
|
||||
password: password.as_str().into(),
|
||||
channel: 6,
|
||||
auth_method: AuthMethod::WPA2Personal,
|
||||
..Default::default()
|
||||
|
||||
Reference in New Issue
Block a user