tester: add wifi_reset const in config.rs

this variable sets whether we just reset wifi or do a full config send
delete extraneous wifi.rs binary
This commit is contained in:
irriden
2023-08-02 03:14:40 +00:00
parent 84ec318450
commit 754cfd771b
3 changed files with 34 additions and 86 deletions

View File

@@ -33,10 +33,6 @@ sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git" }
name = "config"
path = "src/config.rs"
[[bin]]
name = "wifi"
path = "src/wifi.rs"
[[bin]]
name = "config-server"
path = "src/server.rs"

View File

@@ -4,11 +4,14 @@ use serde::{Deserialize, Serialize};
use sphinx_crypter::chacha::{encrypt, MSG_LEN, NONCE_LEN};
use sphinx_crypter::ecdh::{derive_shared_secret_from_slice, PUBLIC_KEY_LEN};
use sphinx_crypter::secp256k1::Secp256k1;
use sphinx_signer::sphinx_glyph::control::Config;
use std::convert::TryInto;
use std::env;
use std::time::Duration;
const URL: &str = "http://192.168.71.1";
// Set to true to only reset wifi credentials, and not transmit the seed again
const WIFI_RESET: bool = false;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct EcdhBody {
@@ -59,32 +62,42 @@ async fn main() -> anyhow::Result<()> {
.build()
.expect("couldnt build reqwest client");
let res = client
.get(format!("{}/{}", url, "ecdh"))
.header("Content-Type", "application/json")
.send()
.await?;
let their_ecdh: EcdhBody = res.json().await?;
let their_pk = hex::decode(their_ecdh.pubkey)?;
let conf_string = if !WIFI_RESET {
let res = client
.get(format!("{}/{}", url, "ecdh"))
.header("Content-Type", "application/json")
.send()
.await?;
let their_ecdh: EcdhBody = res.json().await?;
let their_pk = hex::decode(their_ecdh.pubkey)?;
let their_pk_bytes: [u8; PUBLIC_KEY_LEN] = their_pk[..PUBLIC_KEY_LEN].try_into()?;
let shared_secret = derive_shared_secret_from_slice(their_pk_bytes, sk1.secret_bytes())?;
let their_pk_bytes: [u8; PUBLIC_KEY_LEN] = their_pk[..PUBLIC_KEY_LEN].try_into()?;
let shared_secret = derive_shared_secret_from_slice(their_pk_bytes, sk1.secret_bytes())?;
let mut nonce_end = [0; NONCE_LEN];
OsRng.fill_bytes(&mut nonce_end);
let cipher = encrypt(seed, shared_secret, nonce_end)?;
let mut nonce_end = [0; NONCE_LEN];
OsRng.fill_bytes(&mut nonce_end);
let cipher = encrypt(seed, shared_secret, nonce_end)?;
let cipher_seed = hex::encode(cipher);
let config = ConfigBody {
seed: cipher_seed,
ssid,
pass,
broker,
network,
pubkey: hex::encode(pk1.serialize()),
let cipher_seed = hex::encode(cipher);
let config = ConfigBody {
seed: cipher_seed,
ssid,
pass,
broker,
network,
pubkey: hex::encode(pk1.serialize()),
};
serde_json::to_string(&config)?
} else {
let config = Config {
ssid,
pass,
broker,
network,
};
serde_json::to_string(&config)?
};
let conf_string = serde_json::to_string(&config)?;
let conf_encoded = urlencoding::encode(&conf_string).to_owned();
let res2 = client

View File

@@ -1,61 +0,0 @@
use dotenv::dotenv;
use serde::{Deserialize, Serialize};
use std::env;
use std::time::Duration;
use sphinx_signer::sphinx_glyph::control::Config;
const URL: &str = "http://192.168.71.1";
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct ConfigResponse {
pub success: bool,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenv().ok();
let url: String = env::var("URL").unwrap_or(URL.to_string());
let ssid: String = env::var("SSID").expect("no ssid");
let pass: String = env::var("PASS").expect("no pass");
let broker: String = env::var("BROKER").expect("no broker");
let network: String = env::var("NETWORK").unwrap_or("regtest".to_string());
if !(network == "bitcoin"
|| network == "mainnet"
|| network == "testnet"
|| network == "signet"
|| network == "regtest")
{
panic!("invalid network string");
}
println!("network {:?}", network);
let client = reqwest::Client::builder()
.timeout(Duration::from_secs(10))
.build()
.expect("couldnt build reqwest client");
let config = Config {
ssid,
pass,
broker,
network,
};
let conf_string = serde_json::to_string(&config)?;
let conf_encoded = urlencoding::encode(&conf_string).to_owned();
let res = client
.post(format!("{}/{}={}", url, "config?config", conf_encoded))
.send()
.await?;
let conf_res: ConfigResponse = res.json().await?;
if conf_res.success {
println!("SUCCESS!")
}
Ok(())
}