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