mirror of
https://github.com/stakwork/sphinx-key.git
synced 2025-12-17 15:24:32 +01:00
sphinx-key: add a fixed prefix to client id
this prefix is persisted to flash storage
This commit is contained in:
12
Cargo.lock
generated
12
Cargo.lock
generated
@@ -1199,7 +1199,7 @@ checksum = "b06a4cde4c0f271a446782e3eff8de789548ce57dbc8eca9292c27f4a42004b4"
|
||||
[[package]]
|
||||
name = "lss-connector"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
@@ -1571,7 +1571,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rmp-utils"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
@@ -1778,7 +1778,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-auther"
|
||||
version = "0.1.12"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.21.2",
|
||||
@@ -1790,7 +1790,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-crypter"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chacha20poly1305",
|
||||
@@ -1801,7 +1801,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-glyph"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"hex",
|
||||
@@ -1852,7 +1852,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-signer"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs.git?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bip39",
|
||||
|
||||
10
broker/Cargo.lock
generated
10
broker/Cargo.lock
generated
@@ -1700,7 +1700,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "lss-connector"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"lightning-storage-server",
|
||||
@@ -2694,7 +2694,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "rmp-utils"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"log",
|
||||
@@ -3308,7 +3308,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-auther"
|
||||
version = "0.1.12"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64 0.21.2",
|
||||
@@ -3320,7 +3320,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-glyph"
|
||||
version = "0.1.2"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"hex",
|
||||
@@ -3366,7 +3366,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "sphinx-signer"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=253b45a659b1b395e3ff4435f4b7a3e4036da521#253b45a659b1b395e3ff4435f4b7a3e4036da521"
|
||||
source = "git+https://github.com/stakwork/sphinx-rs?rev=894614fa71fec312d95b762e704d5892a4f27b96#894614fa71fec312d95b762e704d5892a4f27b96"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bip39",
|
||||
|
||||
@@ -39,8 +39,8 @@ vls-proxy = { git = "https://gitlab.com/lightning-signer/validating-li
|
||||
# vls-protocol-client = { path = "../../vls/vls-protocol-client" }
|
||||
# vls-proxy = { path = "../../vls/vls-proxy" }
|
||||
|
||||
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "253b45a659b1b395e3ff4435f4b7a3e4036da521" }
|
||||
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "253b45a659b1b395e3ff4435f4b7a3e4036da521" }
|
||||
lss-connector = { git = "https://github.com/stakwork/sphinx-rs", rev = "894614fa71fec312d95b762e704d5892a4f27b96" }
|
||||
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs", rev = "894614fa71fec312d95b762e704d5892a4f27b96" }
|
||||
# lss-connector = { path = "../../sphinx-rs/lss-connector" }
|
||||
# sphinx-signer = { path = "../../sphinx-rs/signer" }
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ serde_json = { version = "1.0.81", default-features = false }
|
||||
serde_urlencoded = "0.7.1"
|
||||
url = "2"
|
||||
|
||||
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "253b45a659b1b395e3ff4435f4b7a3e4036da521" }
|
||||
lss-connector = { git = "https://github.com/stakwork/sphinx-rs.git", default-features = false, rev = "894614fa71fec312d95b762e704d5892a4f27b96" }
|
||||
# lss-connector = { path = "../../sphinx-rs/lss-connector", default-features = false }
|
||||
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "253b45a659b1b395e3ff4435f4b7a3e4036da521" }
|
||||
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git", rev = "894614fa71fec312d95b762e704d5892a4f27b96" }
|
||||
# sphinx-crypter = { path = "../../sphinx-rs/crypter" }
|
||||
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "253b45a659b1b395e3ff4435f4b7a3e4036da521" }
|
||||
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git", optional = true, rev = "894614fa71fec312d95b762e704d5892a4f27b96" }
|
||||
# sphinx-signer = { path = "../../sphinx-rs/signer", optional = true }
|
||||
|
||||
anyhow.workspace = true
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use crate::ID_LEN;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use embedded_svc::storage::RawStorage;
|
||||
use esp_idf_svc::nvs::{EspDefaultNvs, EspDefaultNvsPartition};
|
||||
@@ -79,6 +80,19 @@ impl ControlPersist for FlashPersister {
|
||||
self.0.remove(FlashKey::Seed.as_str())?;
|
||||
Ok(())
|
||||
}
|
||||
fn write_id(&mut self, id: String) -> Result<()> {
|
||||
let id = id.into_bytes();
|
||||
self.0.set_raw(FlashKey::Id.as_str(), &id[..])?;
|
||||
Ok(())
|
||||
}
|
||||
fn read_id(&self) -> Result<String> {
|
||||
let mut buf = [0u8; ID_LEN];
|
||||
let existing = self
|
||||
.0
|
||||
.get_raw(FlashKey::Id.as_str(), &mut buf)?
|
||||
.ok_or(anyhow!("no existing id"))?;
|
||||
Ok(String::from_utf8(existing.to_vec()).expect("bad byte conversion to utf8"))
|
||||
}
|
||||
fn read_policy(&self) -> Result<Policy> {
|
||||
let mut buf = [0u8; 250];
|
||||
let existing = self
|
||||
|
||||
@@ -32,6 +32,8 @@ const CLIENT_ID: &str = "sphinx-1";
|
||||
#[cfg(feature = "pingpong")]
|
||||
const CLIENT_ID: &str = "test-1";
|
||||
|
||||
const ID_LEN: usize = 8;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
// Temporary. Will disappear once ESP-IDF 4.4 is released, but for now it is necessary to call this function once,
|
||||
// or else some patches to the runtime implemented by esp-idf-sys might not link properly.
|
||||
@@ -67,6 +69,7 @@ fn main() -> Result<()> {
|
||||
let mut flash = FlashPersister::new(default_nvs.clone());
|
||||
if let Ok(exist) = flash.read_config() {
|
||||
let seed = flash.read_seed().expect("no seed...");
|
||||
let id = flash.read_id().expect("no id...");
|
||||
let policy = flash.read_policy().unwrap_or_default();
|
||||
let velocity = flash.read_velocity().ok();
|
||||
println!(
|
||||
@@ -102,6 +105,7 @@ fn main() -> Result<()> {
|
||||
if let Ok(()) = make_and_launch_client(
|
||||
exist.clone(),
|
||||
seed,
|
||||
id.clone(),
|
||||
&policy,
|
||||
&velocity,
|
||||
led_tx.clone(),
|
||||
@@ -121,6 +125,9 @@ fn main() -> Result<()> {
|
||||
Ok((_wifi, config, seed)) => {
|
||||
flash.write_config(config).expect("could not store config");
|
||||
flash.write_seed(seed).expect("could not store seed");
|
||||
flash
|
||||
.write_id(random_word(ID_LEN))
|
||||
.expect("could not store id");
|
||||
println!("CONFIG SAVED");
|
||||
unsafe { esp_idf_sys::esp_restart() };
|
||||
}
|
||||
@@ -134,6 +141,7 @@ fn main() -> Result<()> {
|
||||
fn make_and_launch_client(
|
||||
config: Config,
|
||||
seed: [u8; 32],
|
||||
id: String,
|
||||
policy: &Policy,
|
||||
velocity: &Option<Velocity>,
|
||||
led_tx: mpsc::Sender<Status>,
|
||||
@@ -158,7 +166,7 @@ fn make_and_launch_client(
|
||||
let token = ctrlr.make_auth_token().expect("couldnt make auth token");
|
||||
log::info!("PUBKEY {} TOKEN {}", &pubkey_str, &token);
|
||||
|
||||
let client_id = random_word(8);
|
||||
let client_id = format!("{}_{}", id, random_word(8));
|
||||
let mqtt_client =
|
||||
conn::mqtt::make_client(&config.broker, &client_id, &pubkey_str, &token, tx.clone())?;
|
||||
// let mqtt_client = conn::mqtt::start_listening(mqtt, connection, tx)?;
|
||||
|
||||
Reference in New Issue
Block a user