-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
picow flash config, ed25519 key as plain bytes
- ServBehaviour::hostkeys() now returns a slice of references since we can't clone SignKeys and don't want to move them out of Config. May need rethinking. - embassy demos common code is now a proper crate - Updated various embassy deps
- Loading branch information
Showing
23 changed files
with
614 additions
and
177 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
[package] | ||
name = "sunset-demo-embassy-common" | ||
description = "Shared code for Sunset demos" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[workspace] | ||
# blank | ||
|
||
[dependencies] | ||
sunset-embassy = { path = "../../" } | ||
sunset = { path = "../../.." } | ||
sunset-sshwire-derive = { version = "0.1", path = "../../../sshwire-derive" } | ||
|
||
embassy-sync = { version = "0.2.0" } | ||
embassy-net = { version = "0.1.0", features = ["tcp", "dhcpv4", "medium-ethernet", "nightly"] } | ||
embassy-net-driver = { version = "0.1.0" } | ||
embassy-futures = { version = "0.1.0" } | ||
|
||
heapless = "0.7.15" | ||
menu = "0.3" | ||
embedded-io = { version = "0.4", features = ["async"] } | ||
|
||
defmt = { version = "0.3", optional = true } | ||
log = { version = "0.4", optional = true } | ||
|
||
[features] | ||
defmt = ["dep:defmt", "embassy-net/defmt", "embedded-io/defmt"] | ||
log = ["dep:log", "embassy-net/log"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# Embassy demos common | ||
|
||
The [picow](../picow) and [std](../std) demos share this common code. | ||
Currently not a full crate, just source modules included. | ||
The [picow](../picow) and [std](../std) demos share this common code. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
#[allow(unused_imports)] | ||
use { | ||
sunset::error::{Error, Result, TrapBug}, | ||
}; | ||
|
||
#[allow(unused_imports)] | ||
#[cfg(not(feature = "defmt"))] | ||
use { | ||
log::{debug, error, info, log, trace, warn}, | ||
}; | ||
|
||
#[allow(unused)] | ||
#[cfg(feature = "defmt")] | ||
use defmt::{debug, info, warn, panic, error, trace}; | ||
|
||
use heapless::String; | ||
|
||
use sunset_sshwire_derive::*; | ||
use sunset::sshwire; | ||
use sunset::sshwire::{BinString, SSHEncode, SSHDecode, WireResult, SSHSource, SSHSink, WireError}; | ||
|
||
use sunset::{SignKey, KeyType}; | ||
|
||
// Be sure to bump picow flash_config::CURRENT_VERSION | ||
// if this struct changes (or encode/decode impls). | ||
#[derive(Debug)] | ||
pub struct SSHConfig { | ||
pub hostkey: SignKey, | ||
/// login password | ||
pub pw_hash: Option<[u8; 32]>, | ||
/// SSID | ||
pub wifi_net: String<32>, | ||
/// WPA2 passphrase. None is Open network. | ||
pub wifi_pw: Option<String<63>>, | ||
} | ||
|
||
impl SSHConfig { | ||
/// Creates a new config with default parameters. | ||
/// | ||
/// Will only fail on RNG failure. | ||
pub fn new() -> Result<Self> { | ||
let hostkey = SignKey::generate(KeyType::Ed25519, None)?; | ||
|
||
let wifi_net = option_env!("WIFI_NETWORK").unwrap_or("guest").into(); | ||
let wifi_pw = option_env!("WIFI_PASSWORD").map(|p| p.into()); | ||
Ok(SSHConfig { | ||
hostkey, | ||
pw_hash: None, | ||
wifi_net, | ||
wifi_pw, | ||
}) | ||
} | ||
} | ||
|
||
// a private encoding specific to demo config, not SSH defined. | ||
fn enc_signkey(k: &SignKey, s: &mut dyn SSHSink) -> WireResult<()> { | ||
// need to add a variant field if we support more key types. | ||
match k { | ||
SignKey::Ed25519(seed) => seed.enc(s), | ||
_ => Err(WireError::UnknownVariant), | ||
} | ||
} | ||
|
||
fn dec_signkey<'de, S>(s: &mut S) -> WireResult<SignKey> where S: SSHSource<'de> { | ||
Ok(SignKey::Ed25519(SSHDecode::dec(s)?)) | ||
} | ||
|
||
impl SSHEncode for SSHConfig { | ||
fn enc(&self, s: &mut dyn SSHSink) -> WireResult<()> { | ||
enc_signkey(&self.hostkey, s)?; | ||
self.pw_hash.is_some().enc(s)?; | ||
self.pw_hash.enc(s)?; | ||
|
||
self.wifi_net.as_str().enc(s)?; | ||
|
||
self.wifi_pw.is_some().enc(s)?; | ||
if let Some(ref p) = self.wifi_pw { | ||
p.as_str().enc(s)?; | ||
} | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl<'de> SSHDecode<'de> for SSHConfig { | ||
fn dec<S>(s: &mut S) -> WireResult<Self> where S: SSHSource<'de> { | ||
let hostkey = dec_signkey(s)?; | ||
|
||
let have_pw_hash = bool::dec(s)?; | ||
let pw_hash = have_pw_hash.then(|| SSHDecode::dec(s)).transpose()?; | ||
|
||
let wifi_net = <&str>::dec(s)?.into(); | ||
let have_wifi_pw = bool::dec(s)?; | ||
|
||
let wifi_pw = have_wifi_pw.then(|| { | ||
let p: &str = SSHDecode::dec(s)?; | ||
Ok(p.into()) | ||
}) | ||
.transpose()?; | ||
Ok(Self { | ||
hostkey, | ||
pw_hash, | ||
wifi_net, | ||
wifi_pw, | ||
}) | ||
} | ||
} | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
embassy/demos/common/demo_menu.rs → embassy/demos/common/src/demo_menu.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![no_std] | ||
|
||
#![feature(type_alias_impl_trait)] | ||
#![feature(async_fn_in_trait)] | ||
// #![allow(incomplete_features)] | ||
|
||
mod config; | ||
mod server; | ||
|
||
pub mod demo_menu; | ||
|
||
pub use server::{Shell, listener}; | ||
pub use config::SSHConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.