Skip to content

Commit e3b118b

Browse files
committed
Support WPA entreprise
1 parent 8c504b8 commit e3b118b

20 files changed

Lines changed: 2093 additions & 63 deletions

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ serde = { version = "1", features = ["derive"] }
2323
toml = { version = "0.9" }
2424
clap = { version = "4", features = ["derive", "cargo"] }
2525
anyhow = "1"
26-
iwdrs = "0.2"
26+
iwdrs = "0.2.3"
2727
chrono = "0.4"
2828
log = "0.4"
2929
env_logger = "0.11"

src/agent.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct AuthAgent {
1717
pub rx_username_password: Receiver<(String, String)>,
1818
pub psk_required: Arc<AtomicBool>,
1919
pub private_key_passphrase_required: Arc<AtomicBool>,
20+
pub password_required: Arc<AtomicBool>,
2021
pub event_sender: UnboundedSender<Event>,
2122
}
2223

@@ -35,6 +36,7 @@ impl AuthAgent {
3536
rx_username_password,
3637
psk_required: Arc::new(AtomicBool::new(false)),
3738
private_key_passphrase_required: Arc::new(AtomicBool::new(false)),
39+
password_required: Arc::new(AtomicBool::new(false)),
3840
event_sender: sender,
3941
}
4042
}
@@ -67,11 +69,16 @@ impl Agent for AuthAgent {
6769

6870
async fn request_private_key_passphrase(
6971
&self,
70-
_network: &Network,
72+
network: &Network,
7173
) -> Result<String, iwdrs::error::agent::Canceled> {
7274
self.private_key_passphrase_required
7375
.store(true, std::sync::atomic::Ordering::Relaxed);
7476

77+
let network_name = network.name().await.map_err(|_| Canceled())?;
78+
self.event_sender
79+
.send(Event::AuthReqKeyPassphrase(network_name))
80+
.map_err(|_| Canceled())?;
81+
7582
tokio::select! {
7683
r = self.rx_passphrase.recv() => {
7784
match r {
@@ -94,11 +101,33 @@ impl Agent for AuthAgent {
94101
std::future::ready(Err(Canceled()))
95102
}
96103

97-
fn request_user_password(
104+
async fn request_user_password(
98105
&self,
99-
_network: &Network,
100-
_user_name: Option<&String>,
101-
) -> impl Future<Output = Result<(String, String), iwdrs::error::agent::Canceled>> + Send {
102-
std::future::ready(Err(Canceled()))
106+
network: &Network,
107+
user_name: Option<&String>,
108+
) -> Result<String, iwdrs::error::agent::Canceled> {
109+
self.password_required
110+
.store(true, std::sync::atomic::Ordering::Relaxed);
111+
let network_name = network.name().await.map_err(|_| Canceled())?;
112+
self.event_sender
113+
.send(Event::AuthRequestPassword((
114+
network_name,
115+
user_name.cloned(),
116+
)))
117+
.map_err(|_| Canceled())?;
118+
119+
tokio::select! {
120+
r = self.rx_passphrase.recv() => {
121+
match r {
122+
Ok(password) => Ok(password),
123+
Err(_) => Err(Canceled()),
124+
}
125+
}
126+
127+
_ = self.rx_cancel.recv() => {
128+
Err(Canceled())
129+
}
130+
131+
}
103132
}
104133
}

src/app.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub enum FocusedBlock {
2626
AdapterInfos,
2727
AccessPointInput,
2828
AccessPointConnectedDevices,
29+
RequestKeyPasshphrase,
30+
RequestPassword,
2931
}
3032

3133
#[derive(Debug)]

src/device.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl Device {
8989
match self.mode {
9090
Mode::Station => {
9191
if let Some(station) = &mut self.station {
92-
if station.diagnostic.is_none() {
92+
if station.diagnostic.is_none() && station.connected_network.is_some() {
9393
sender.send(Event::Reset(Mode::Station))?;
9494
} else {
9595
station.refresh().await?;

src/event.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ pub enum Event {
1616
Notification(Notification),
1717
Reset(Mode),
1818
Auth(String),
19+
EapNeworkConfigured,
20+
ConfigureNewEapNetwork(String),
21+
AuthRequestPassword((String, Option<String>)),
22+
AuthReqKeyPassphrase(String),
1923
}
2024

2125
#[allow(dead_code)]

src/handler.rs

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use crate::notification::Notification;
99

1010
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
1111
use iwdrs::modes::Mode;
12+
use iwdrs::network::NetworkType;
1213
use tokio::sync::mpsc::UnboundedSender;
1314
use tui_input::backend::crossterm::EventHandler;
1415

@@ -18,6 +19,11 @@ async fn toggle_connect(app: &mut App, sender: UnboundedSender<Event>) -> AppRes
1819
FocusedBlock::NewNetworks => {
1920
if let Some(net_index) = station.new_networks_state.selected() {
2021
let (net, _) = station.new_networks[net_index].clone();
22+
23+
if net.network_type == NetworkType::Eap {
24+
sender.send(Event::ConfigureNewEapNetwork(net.name.clone()))?;
25+
return Ok(());
26+
}
2127
tokio::spawn(async move {
2228
net.connect(sender.clone()).await.unwrap();
2329
});
@@ -205,9 +211,72 @@ pub async fn handle_key_events(
205211
}
206212
},
207213

208-
FocusedBlock::WpaEntrepriseAuth => {
209-
unimplemented!()
214+
FocusedBlock::RequestKeyPasshphrase => {
215+
if let Some(req) = &mut app.auth.request_key_passphrase {
216+
match key_event.code {
217+
KeyCode::Enter => {
218+
req.submit(&app.agent).await?;
219+
app.focused_block = FocusedBlock::KnownNetworks;
220+
}
221+
222+
KeyCode::Esc => {
223+
req.cancel(&app.agent).await?;
224+
app.auth.request_key_passphrase = None;
225+
app.focused_block = FocusedBlock::KnownNetworks;
226+
}
227+
228+
KeyCode::Tab => {
229+
req.show_password = !req.show_password;
230+
}
231+
232+
_ => {
233+
req.passphrase
234+
.handle_event(&crossterm::event::Event::Key(key_event));
235+
}
236+
}
237+
}
210238
}
239+
FocusedBlock::RequestPassword => {
240+
if let Some(req) = &mut app.auth.request_password {
241+
match key_event.code {
242+
KeyCode::Enter => {
243+
req.submit(&app.agent).await?;
244+
app.focused_block = FocusedBlock::KnownNetworks;
245+
}
246+
247+
KeyCode::Esc => {
248+
req.cancel(&app.agent).await?;
249+
app.auth.request_password = None;
250+
app.focused_block = FocusedBlock::KnownNetworks;
251+
}
252+
253+
KeyCode::Tab => {
254+
req.show_password = !req.show_password;
255+
}
256+
257+
_ => {
258+
req.password
259+
.handle_event(&crossterm::event::Event::Key(key_event));
260+
}
261+
}
262+
}
263+
}
264+
265+
FocusedBlock::WpaEntrepriseAuth => match key_event.code {
266+
KeyCode::Esc => {
267+
app.focused_block = FocusedBlock::NewNetworks;
268+
app.auth.reset();
269+
}
270+
271+
_ => {
272+
app.auth
273+
.eap
274+
.as_mut()
275+
.unwrap()
276+
.handle_key_events(key_event, sender)
277+
.await?
278+
}
279+
},
211280
FocusedBlock::AdapterInfos => {
212281
if key_event.code == KeyCode::Esc {
213282
app.focused_block = FocusedBlock::Device;
@@ -344,7 +413,7 @@ pub async fn handle_key_events(
344413
toggle_connect(app, sender).await?
345414
}
346415
KeyCode::Char('j') | KeyCode::Down => {
347-
if !station.known_networks.is_empty() {
416+
if !station.new_networks.is_empty() {
348417
let i = match station.new_networks_state.selected() {
349418
Some(i) => {
350419
if i < station.new_networks.len() - 1 {

src/main.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,30 @@ async fn main() -> AppResult<()> {
5555
}
5656
app = App::new(tui.events.sender.clone(), config.clone(), mode).await?;
5757
}
58+
5859
Event::Auth(network_name) => {
5960
app.network_name_requiring_auth = Some(network_name);
6061
}
62+
63+
Event::EapNeworkConfigured => {
64+
app.auth.reset();
65+
app.focused_block = impala::app::FocusedBlock::KnownNetworks;
66+
}
67+
68+
Event::ConfigureNewEapNetwork(network_name) => {
69+
app.auth.init_eap(network_name);
70+
app.focused_block = impala::app::FocusedBlock::WpaEntrepriseAuth;
71+
}
72+
73+
Event::AuthReqKeyPassphrase(network_name) => {
74+
app.auth.init_request_key_passphrase(network_name.clone());
75+
app.focused_block = impala::app::FocusedBlock::RequestKeyPasshphrase;
76+
}
77+
78+
Event::AuthRequestPassword((network_name, user_name)) => {
79+
app.auth.init_request_password(network_name, user_name);
80+
app.focused_block = impala::app::FocusedBlock::RequestPassword
81+
}
6182
_ => {}
6283
}
6384
}

0 commit comments

Comments
 (0)