Skip to content

Commit

Permalink
bcrypt 0.15. check ip address prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mkj committed Jul 12, 2023
1 parent cf05049 commit c55b452
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 14 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ cyw43 = { git = "https://github.com/embassy-rs/embassy/", rev = "2eb7a67c7027c67
cyw43-pio = { git = "https://github.com/embassy-rs/embassy/", rev = "2eb7a67c7027c6768fa95031caf60bcd0eade1ad" }
embassy-net-w5500 = { git = "https://github.com/embassy-rs/embassy/", rev = "2eb7a67c7027c6768fa95031caf60bcd0eade1ad" }

bcrypt = { version = "0.14", git = "https://github.com/mkj/rust-bcrypt", branch = "noalloc" }

# these are mostly applicable to picow, but can't hurt generally
[profile.dev]
debug = 2
Expand Down
2 changes: 1 addition & 1 deletion embassy/demos/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ heapless = "0.7.15"
embedded-io = { version = "0.4", features = ["async"] }
sha2 = { version = "0.10", default-features = false }
hmac = { version = "0.12", default-features = false }
bcrypt = { version = "0.14", default-features = false }
bcrypt = { version = "0.15", default-features = false }
ed25519-dalek = { version = "2.0.0-rc.2", default-features = false }

defmt = { version = "0.3", optional = true }
Expand Down
9 changes: 7 additions & 2 deletions embassy/demos/common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ where
let ad: [u8; 4] = SSHDecode::dec(s)?;
let ad = Ipv4Address::from_bytes(&ad);
let prefix = SSHDecode::dec(s)?;
if prefix > 32 {
// emabassy panics, so test it here
debug!("Prefix {} > 32", prefix);
return Err(WireError::PacketWrong)
}
let gw: Option<[u8; 4]> = dec_option(s)?;
let gateway = gw.map(|gw| Ipv4Address::from_bytes(&gw));
Ok(StaticConfigV4 {
Expand Down Expand Up @@ -365,8 +370,8 @@ mod tests {
),
mac: [6, 2, 3, 4, 5, 6],
ip4_static: Some(embassy_net::StaticConfigV4 {
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address::UNSPECIFIED, 8),
gateway: Some(embassy_net::Ipv4Address::UNSPECIFIED),
address: embassy_net::Ipv4Cidr::new(embassy_net::Ipv4Address([44,33,22,11]), 8),
gateway: Some(embassy_net::Ipv4Address([1,2,3,4])),
// no dns servers. may need changing later?
dns_servers: heapless::Vec::new(),
}),
Expand Down
19 changes: 12 additions & 7 deletions embassy/demos/std/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,18 @@ async fn net_task(stack: &'static Stack<TunTapDevice>) -> ! {
async fn main_task(spawner: Spawner) {
// TODO config
let opt_tap0 = "tap0";
let net_config = Config::dhcpv4(Default::default());

let config = &*singleton!( {
let mut config = SSHConfig::new().unwrap();
// config.set_console_pw(Some("pw")).unwrap();
SunsetMutex::new(config)
} );

let net_config = if let Some(ref s) = config.lock().await.ip4_static {
embassy_net::Config::ipv4_static(s.clone())
} else {
embassy_net::Config::dhcpv4(Default::default())
};

// Init network device
let device = TunTapDevice::new(opt_tap0).unwrap();
Expand All @@ -62,12 +73,6 @@ async fn main_task(spawner: Spawner) {
// Launch network task
spawner.spawn(net_task(stack)).unwrap();

let config = &*singleton!( {
let mut config = SSHConfig::new().unwrap();
// config.set_console_pw(Some("pw")).unwrap();
SunsetMutex::new(config)
} );

for _ in 0..NUM_LISTENERS {
spawner.spawn(listener(stack, config)).unwrap();
}
Expand Down

0 comments on commit c55b452

Please sign in to comment.